-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements some tricks to have correct sizes for the buttons
- Loading branch information
1 parent
c5dd9c1
commit 46ce6f0
Showing
5 changed files
with
217 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,15 +86,15 @@ public class GamaIcon { | |
try { | ||
URL pngFolderURL = toFileURL(Platform.getBundle(IGamaIcons.PLUGIN_ID).getEntry(IGamaIcons.ICONS_PATH)); | ||
tmp = Path.of(new URI(pngFolderURL.getProtocol(), pngFolderURL.getPath(), null).normalize()); | ||
} catch (Exception e) {} | ||
} catch (Exception e) { | ||
} | ||
PATH_TO_ICONS = tmp; | ||
} | ||
|
||
/** | ||
* Preload icons. | ||
* | ||
* @param bundle | ||
* the bundle | ||
* @param bundle the bundle | ||
* @throws IOException | ||
*/ | ||
public static void preloadAllIcons() throws IOException { | ||
|
@@ -107,26 +107,43 @@ public static void preloadAllIcons() throws IOException { | |
/** | ||
* Returns the icon named after the path (eg "templates/square.template") | ||
* | ||
* @param path | ||
* the path | ||
* @param path the path | ||
* @return the gama icon | ||
*/ | ||
public static GamaIcon named(final String s) { | ||
|
||
try { | ||
// DEBUG.OUT("Looking for icon " + s); | ||
if (s != null) return ICON_CACHE.get(s, () -> new GamaIcon(s)); | ||
} catch (ExecutionException e) {} | ||
if (s != null) | ||
return ICON_CACHE.get(s, () -> new GamaIcon(s)); | ||
} catch (ExecutionException e) { | ||
} | ||
return named(MISSING); | ||
} | ||
|
||
/** | ||
* Creates a transparent icon of the desired and width (and 1px wide) | ||
* | ||
*/ | ||
|
||
public static GamaIcon ofSize(int width, int height) { | ||
final String name = "size" + width + "x" + height; | ||
try { | ||
return ICON_CACHE.get(name, () -> { | ||
DEBUG.OUT(name + " not found. Building it"); | ||
GamaImage bi = GamaImage.ofDimensions(width, height, true); | ||
return new GamaIcon(name, bi); | ||
}); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Creates a color icon, either a round square or a circle | ||
* | ||
* @param gcolor | ||
* the gcolor | ||
* @param square | ||
* the square | ||
* @param gcolor the gcolor | ||
* @param square the square | ||
* @return the image | ||
*/ | ||
|
||
|
@@ -170,12 +187,9 @@ public static GamaIcon ofColor(final GamaUIColor gcolor, final boolean square) { | |
/** | ||
* Constructor for images loaded from a plugin | ||
* | ||
* @param c | ||
* the code | ||
* @param p | ||
* the path (in the 'icons' folder) | ||
* @param plugin | ||
* the id of the plugin in which the 'icons' folder resides | ||
* @param c the code | ||
* @param p the path (in the 'icons' folder) | ||
* @param plugin the id of the plugin in which the 'icons' folder resides | ||
*/ | ||
private GamaIcon(final String c) { | ||
DEBUG.OUT("Creation of icon " + c, false); | ||
|
@@ -188,12 +202,11 @@ private GamaIcon(final String c) { | |
} | ||
|
||
/** | ||
* Instantiates a new gama icon directly from an image. We do not produce disabled versions | ||
* Instantiates a new gama icon directly from an image. We do not produce | ||
* disabled versions | ||
* | ||
* @param name | ||
* the name | ||
* @param im | ||
* the im | ||
* @param name the name | ||
* @param im the im | ||
*/ | ||
private GamaIcon(final String path, final Image im, final Image disabled) { | ||
code = path; | ||
|
@@ -207,10 +220,8 @@ private GamaIcon(final String path, final Image im, final Image disabled) { | |
* Instantiates a new gama icon. | ||
* | ||
* @author Alexis Drogoul ([email protected]) | ||
* @param path | ||
* the path | ||
* @param im | ||
* the im | ||
* @param path the path | ||
* @param im the im | ||
* @date 13 sept. 2023 | ||
*/ | ||
private GamaIcon(final String path, final GamaImage im) { | ||
|
@@ -220,15 +231,15 @@ private GamaIcon(final String path, final GamaImage im) { | |
/** | ||
* Creates a SWT image from a Java BufferedImage. | ||
* | ||
* @param bufferedImage | ||
* the image. | ||
* @param bufferedImage the image. | ||
* @return returns a SWT image. | ||
*/ | ||
public static Image toSWTImage(final GamaImage im) { | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
try { | ||
ImageIO.write(im, "png", out); | ||
} catch (IOException e) {} | ||
} catch (IOException e) { | ||
} | ||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); | ||
return new Image(Display.getCurrent(), new ImageData(in)); | ||
} | ||
|
@@ -247,10 +258,8 @@ private static class DisabledFilter extends RGBImageFilter { | |
/** | ||
* Instantiates a new disabled filter. | ||
* | ||
* @param min | ||
* the min | ||
* @param max | ||
* the max | ||
* @param min the min | ||
* @param max the max | ||
*/ | ||
DisabledFilter() { | ||
canFilterIndexColorModel = true; | ||
|
@@ -275,13 +284,13 @@ public int filterRGB(final int x, final int y, final int rgb) { | |
* To buffered image. | ||
* | ||
* @author Alexis Drogoul ([email protected]) | ||
* @param img | ||
* the img | ||
* @param img the img | ||
* @return the buffered image | ||
* @date 15 sept. 2023 | ||
*/ | ||
public static BufferedImage toBufferedImage(final java.awt.Image img) { | ||
if (img instanceof BufferedImage) return (BufferedImage) img; | ||
if (img instanceof BufferedImage) | ||
return (BufferedImage) img; | ||
BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); | ||
Graphics2D bGr = bimage.createGraphics(); | ||
bGr.drawImage(img, 0, 0, null); | ||
|
@@ -292,8 +301,7 @@ public static BufferedImage toBufferedImage(final java.awt.Image img) { | |
/** | ||
* Creates a SWT image from a Java BufferedImage. | ||
* | ||
* @param bufferedImage | ||
* the image. | ||
* @param bufferedImage the image. | ||
* @return returns a SWT image. | ||
*/ | ||
public static Image toDisabledSWTImage(final BufferedImage im) { | ||
|
@@ -302,7 +310,8 @@ public static Image toDisabledSWTImage(final BufferedImage im) { | |
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
try { | ||
ImageIO.write(toBufferedImage(gray), "png", out); | ||
} catch (IOException e) {} | ||
} catch (IOException e) { | ||
} | ||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); | ||
return new Image(Display.getCurrent(), new ImageData(in)); | ||
} | ||
|
@@ -321,16 +330,16 @@ public static Image toDisabledSWTImage(final BufferedImage im) { | |
* To checked SWT image. | ||
* | ||
* @author Alexis Drogoul ([email protected]) | ||
* @param im | ||
* the im | ||
* @param im the im | ||
* @return the image | ||
* @date 15 sept. 2023 | ||
*/ | ||
public static Image toCheckedSWTImage(final GamaImage im) { | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
try { | ||
ImageIO.write(ImageOperators.darker(null, im, 0.5), "png", out); | ||
} catch (IOException e) {} | ||
} catch (IOException e) { | ||
} | ||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); | ||
return new Image(Display.getCurrent(), new ImageData(in)); | ||
|
||
|
@@ -364,8 +373,11 @@ private Image image(final String key, final Callable<Image> imageCreator) { | |
if (image == null) { | ||
try { | ||
image = imageCreator.call(); | ||
} catch (Exception e) {} | ||
if (image == null) { image = named(MISSING).image(); } | ||
} catch (Exception e) { | ||
} | ||
if (image == null) { | ||
image = named(MISSING).image(); | ||
} | ||
if (JFaceResources.getImageRegistry().get(key) == null) { | ||
JFaceResources.getImageRegistry().put(key, image); | ||
} | ||
|
@@ -408,7 +420,9 @@ public Image checked() { | |
* | ||
* @return the code | ||
*/ | ||
public String getCode() { return code; } | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
/** | ||
* Compute URL. | ||
|
Oops, something went wrong.