From 91c401e389658b10bf580796f8a6adda4575e5ec Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 24 Dec 2016 01:02:23 +0100 Subject: [PATCH] Fixed system tray icon scaling issue --- src/dorkbox/systemTray/MenuItem.java | 2 +- src/dorkbox/systemTray/Tray.java | 81 ++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/dorkbox/systemTray/MenuItem.java b/src/dorkbox/systemTray/MenuItem.java index 8f866f6..48f4edf 100644 --- a/src/dorkbox/systemTray/MenuItem.java +++ b/src/dorkbox/systemTray/MenuItem.java @@ -135,7 +135,7 @@ class MenuItem extends Entry { peer.setShortcut(this); } - private + protected void setImage_(final File imageFile) { this.imageFile = imageFile; diff --git a/src/dorkbox/systemTray/Tray.java b/src/dorkbox/systemTray/Tray.java index d3d055a..8ebc22b 100644 --- a/src/dorkbox/systemTray/Tray.java +++ b/src/dorkbox/systemTray/Tray.java @@ -15,6 +15,15 @@ */ package dorkbox.systemTray; +import java.awt.Image; +import java.io.File; +import java.io.InputStream; +import java.net.URL; + +import javax.imageio.stream.ImageInputStream; + +import dorkbox.systemTray.util.ImageUtils; + public class Tray extends Menu { @@ -76,4 +85,76 @@ class Tray extends Menu { add(status, 0); } } + + /** + * Specifies the new image to set for the tray icon. + *

+ * This method will cache the image if it needs to be resized to fit. + * + * @param imageFile the file of the image to use + */ + public + void setImage(final File imageFile) { + setImage_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, imageFile)); + } + + /** + * Specifies the new image to set for the tray icon. + *

+ * This method will cache the image if it needs to be resized to fit. + * + * @param imagePath the full path of the image to use + */ + public + void setImage(final String imagePath) { + setImage_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, imagePath)); + } + + /** + * Specifies the new image to set for the tray icon. + *

+ * This method will cache the image if it needs to be resized to fit. + * + * @param imageUrl the URL of the image to use + */ + public + void setImage(final URL imageUrl) { + setImage_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, imageUrl)); + } + + /** + * Specifies the new image to set for the tray icon. + *

+ * This method will cache the image if it needs to be resized to fit. + * + * @param imageStream the InputStream of the image to use + */ + public + void setImage(final InputStream imageStream) { + setImage_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, imageStream)); + } + + /** + * Specifies the new image to set for the tray icon. + *

+ * This method will cache the image if it needs to be resized to fit. + * + * @param image the image of the image to use + */ + public + void setImage(final Image image) { + setImage_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, image)); + } + + /** + * Specifies the new image to set for the tray icon. + *

+ * This method will cache the image if it needs to be resized to fit. + * + * @param imageStream the ImageInputStream of the image to use + */ + public + void setImage(final ImageInputStream imageStream) { + setImage_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, imageStream)); + } }