From 3a599caefc55d9ad1c2c5fc00216d750d2b12717 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Sat, 20 Jul 2024 15:27:46 +0200 Subject: [PATCH] Create SVG of Draw2D CheckBox icons and recreate them as png This adds 96 and 192 DPI variants for the "checked" and "unchecked" icons used in the CheckBox figure. A minor change has been done do the images, where the white pixels outside of the check box have been removed. On Linux, the icons can be generated automatically via the build.sh script in the "icons" folder, which also moves them to the correct location in the bundle projects. --- icons/.project | 11 ++ .../org.eclipse.core.resources.prefs | 2 + icons/build.sh | 12 ++ .../draw2d/images/checkboxenabledoff.svg | 133 +++++++++++++++++ .../draw2d/images/checkboxenabledon.svg | 137 ++++++++++++++++++ .../src/org/eclipse/draw2d/CheckBox.java | 22 +-- .../draw2d/images/checkboxenabledoff.gif | Bin 856 -> 0 bytes .../draw2d/images/checkboxenabledoff.png | Bin 0 -> 229 bytes .../draw2d/images/checkboxenabledoff@2x.png | Bin 0 -> 298 bytes .../draw2d/images/checkboxenabledon.gif | Bin 874 -> 0 bytes .../draw2d/images/checkboxenabledon.png | Bin 0 -> 402 bytes .../draw2d/images/checkboxenabledon@2x.png | Bin 0 -> 660 bytes .../internal/FileImageDataProvider.java | 72 +++++++++ 13 files changed, 372 insertions(+), 17 deletions(-) create mode 100644 icons/.project create mode 100644 icons/.settings/org.eclipse.core.resources.prefs create mode 100755 icons/build.sh create mode 100644 icons/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.svg create mode 100644 icons/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.svg delete mode 100644 org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.gif create mode 100644 org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.png create mode 100644 org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff@2x.png delete mode 100644 org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.gif create mode 100644 org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.png create mode 100644 org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon@2x.png create mode 100644 org.eclipse.draw2d/src/org/eclipse/draw2d/internal/FileImageDataProvider.java diff --git a/icons/.project b/icons/.project new file mode 100644 index 000000000..a13962428 --- /dev/null +++ b/icons/.project @@ -0,0 +1,11 @@ + + + icons + + + + + + + + diff --git a/icons/.settings/org.eclipse.core.resources.prefs b/icons/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 000000000..99f26c020 --- /dev/null +++ b/icons/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/icons/build.sh b/icons/build.sh new file mode 100755 index 000000000..0dd5f7e43 --- /dev/null +++ b/icons/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Convert all svg to png files +SVG_FILES=$(find . -type f -name "*.svg") +for f in $SVG_FILES; do + echo $f + inkscape $f -d 96 -o ${f%.svg}.png; + inkscape $f -d 192 -o ${f%.svg}@2x.png; +done + +# Move all png files to their respective bundles +rsync -rv --include='*.png' --include='*/' --exclude='*' --remove-source-files --prune-empty-dirs . ../ diff --git a/icons/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.svg b/icons/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.svg new file mode 100644 index 000000000..6a07667f3 --- /dev/null +++ b/icons/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.svg @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/icons/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.svg b/icons/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.svg new file mode 100644 index 000000000..15fc72968 --- /dev/null +++ b/icons/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.svg @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/CheckBox.java b/org.eclipse.draw2d/src/org/eclipse/draw2d/CheckBox.java index 7de0cb4ac..522151bea 100644 --- a/org.eclipse.draw2d/src/org/eclipse/draw2d/CheckBox.java +++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/CheckBox.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -12,32 +12,20 @@ *******************************************************************************/ package org.eclipse.draw2d; -import java.io.IOException; -import java.io.InputStream; - import org.eclipse.swt.graphics.Image; +import org.eclipse.draw2d.internal.FileImageDataProvider; + /** * A Checkbox is a toggle figure which toggles between the checked and unchecked * figures to simulate a check box. A check box contains a text label to * represent it. */ public final class CheckBox extends Toggle { - private Label label = null; - static final Image UNCHECKED = createImage("images/checkboxenabledoff.gif"); //$NON-NLS-1$ - static final Image CHECKED = createImage("images/checkboxenabledon.gif"); //$NON-NLS-1$ - - private static Image createImage(String name) { - InputStream stream = CheckBox.class.getResourceAsStream(name); - Image image = new Image(null, stream); - try { - stream.close(); - } catch (IOException ioe) { - } - return image; - } + static final Image UNCHECKED = FileImageDataProvider.createImage(CheckBox.class, "images/checkboxenabledoff.png"); //$NON-NLS-1$ + static final Image CHECKED = FileImageDataProvider.createImage(CheckBox.class, "images/checkboxenabledon.png"); //$NON-NLS-1$ /** * Constructs a CheckBox with no text. diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.gif b/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.gif deleted file mode 100644 index 4399d9105f6f8a27d2fabf4f4b8c26f4c912c05c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 856 zcmZ?wbhEHb(+DU&Rx59?*Awl4S^9B0y+#p0Llvt9JUOsED|0Y z5*U~m88l)}1TZ);uqb&=d13JINVlkB+>##!%I@8AoGCn-o03mVRQIh~qp{#A!*r%N LK7~p{1qN#XNB|Ha diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.png b/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff.png new file mode 100644 index 0000000000000000000000000000000000000000..f60cbfb13a7e9655cdaad6f9eebfc325e0d3c29f GIT binary patch literal 229 zcmeAS@N?(olHy`uVBq!ia0vp@Ak4uAB#T}@sR2@)1s;*b3=DjSL74G){)!Z!pk#?_ zL`iUdT1k0gQ7S`udAVL@UUqSEVnM22eo^}DcQ#TW13Xqm`P@t9Cs}1bI~f%2xg4~2T&_RoUV88h3xz(zGiRLgU4$&3S8yzkD^-=| UzHqg470`ADPgg&ebxsLQ0KgnmG5`Po literal 0 HcmV?d00001 diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff@2x.png b/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledoff@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..12e4d84a4fd0e5f76f9cfaa8ebcce7b0dd49c4bf GIT binary patch literal 298 zcmeAS@N?(olHy`uVBq!ia0vp^QXtI11|(N{`J4k%oCO|{#S9Fx?I6t9|MX)jP*AeO zHKHUqKdq!Zu_%?Hyu4g5GcUV1Ik6yBFTW^#_B$JpG21;|978-h-%dNoc|<|Lb-q&O ziDaz}?AjX~v;~SbF?(-dE#&uh;<3yvQB?eI^dfQIe0{4!)$xoi0$y_J`Xne*Hduq2ZeFmunlBb0}U3 q@=D&Gel@Co`GT+Y@|KLY!SdgKsw}Fisoeqe0)wZkpUXO@geCwn>~qin literal 0 HcmV?d00001 diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.gif b/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.gif deleted file mode 100644 index 252f76221a0327ca527557d9744893d6f90411c4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 874 zcmZ?wbhEHbqNKMQOXkKU?p=z3 eeKC^3PmWF&Pvnv~F!=z(eEa%mGEoW&4AubPeH7dP diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.png b/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon.png new file mode 100644 index 0000000000000000000000000000000000000000..dd645503155bf50cd798e5133d72243c4b19a9d6 GIT binary patch literal 402 zcmV;D0d4+?P)pF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H10Ut?3 zK~yM_jgmcz!T=CP-z3(ltW#K8YNcSnCh5e+6Ii9R(MAZ?lAJ*7Y|;iqEk)Dj3IR#u z8I;+=RdzS4LSBpJW&Yp65M+-EODz`CQ-W zcDw0*zt{WyuIKYvzY7>2J4~ljJkMjZ*&rg1u1^Ob%d%gy_1NMZe#Fjr;FTK@b3Nxm=h`CXC195&%&9dA)A8i|e|G2+QTNbjjCve-mLC wV%s*RX}*QzbULZ3R(c~5q1|pvsah3%0l0m1DOX5GNdN!<07*qoM6N<$f_`wQpa1{> literal 0 HcmV?d00001 diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon@2x.png b/org.eclipse.draw2d/src/org/eclipse/draw2d/images/checkboxenabledon@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..8863d3eb9ed1ba9434b7e999412712b17d8ff790 GIT binary patch literal 660 zcmV;F0&D$=P)EUp-~z3}kz=BEC9&sTn@T+X@M`P}clXJ?n0&*wS-Fbsotk2aePkw}CA0QRpS z-$wwjU7h`Y4@r{n4s$phAcPoV6eLL!qR}X1S^hPMWm$t73et5Q03gdUvf1p9lIyxo zldGzV^?Gf98P4dZrYH({o=3mmr?K0d>~A5OrhyQG&1M5a2r88d-J!QCDi(_vkH-MM zwy)i8Lzd~=d7WiXicv(>t z#N% clazz; + private final String basePath; + private final String fileExtension; + + public FileImageDataProvider(Class clazz, String path) { + int separator = path.lastIndexOf("."); //$NON-NLS-1$ + this.clazz = clazz; + this.basePath = path.substring(0, separator); + this.fileExtension = path.substring(separator + 1); + } + + @Override + public ImageData getImageData(int zoom) { + if (zoom == 100) { + return createImageData(basePath + '.' + fileExtension); + } + if (zoom == 200) { + return createImageData(basePath + "@2x." + fileExtension); //$NON-NLS-1$ + } + return null; + } + + private ImageData createImageData(String name) { + try (InputStream stream = clazz.getResourceAsStream(name)) { + return new ImageData(stream); + } catch (IOException ioe) { + LOGGER.error(ioe.getLocalizedMessage(), ioe); + return null; + } + } + + /** + * Convenience method for creating DPI-aware images. The returned image is owned + * by the called method, which needs to make sure that the resource is disposed + * at an appropriate time. + */ + public static Image createImage(Class clazz, String name) { + return new Image(null, new FileImageDataProvider(clazz, name)); + } +}