diff --git a/src/dorkbox/systemTray/MenuEntry.java b/src/dorkbox/systemTray/MenuEntry.java index f8c61a0..712533e 100644 --- a/src/dorkbox/systemTray/MenuEntry.java +++ b/src/dorkbox/systemTray/MenuEntry.java @@ -16,6 +16,7 @@ package dorkbox.systemTray; +import java.io.File; import java.io.InputStream; import java.net.URL; @@ -36,6 +37,13 @@ interface MenuEntry { */ void setText(String newText); + /** + * Specifies the new image to set for a menu entry, NULL to delete the image + * + * @param imageFile the file of the image to use or null + */ + void setImage(File imageFile); + /** * Specifies the new image to set for a menu entry, NULL to delete the image * diff --git a/src/dorkbox/systemTray/linux/GtkMenuEntry.java b/src/dorkbox/systemTray/linux/GtkMenuEntry.java index 372f78a..2c331ee 100644 --- a/src/dorkbox/systemTray/linux/GtkMenuEntry.java +++ b/src/dorkbox/systemTray/linux/GtkMenuEntry.java @@ -82,6 +82,17 @@ class GtkMenuEntry implements MenuEntry { }); } + @Override + public + void setImage(final File imageFile) { + if (imageFile == null) { + setImage_(null); + } + else { + setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageFile)); + } + } + @Override public final void setImage(final String imagePath) { diff --git a/src/dorkbox/systemTray/swing/SwingMenuEntry.java b/src/dorkbox/systemTray/swing/SwingMenuEntry.java index a75b2bd..1ee2aa3 100644 --- a/src/dorkbox/systemTray/swing/SwingMenuEntry.java +++ b/src/dorkbox/systemTray/swing/SwingMenuEntry.java @@ -30,18 +30,18 @@ abstract class SwingMenuEntry implements MenuEntry { private final int id = SwingSystemTray.MENU_ID_COUNTER.getAndIncrement(); - final SwingSystemTray systemTray; + private final SwingSystemTrayMenuPopup menu; final JComponent menuItem; // this have to be volatile, because they can be changed from any thread private volatile String text; // this is ALWAYS called on the EDT. - SwingMenuEntry(JComponent menuItem, final SwingSystemTray systemTray) { + SwingMenuEntry(JComponent menuItem, final SwingSystemTrayMenuPopup menu) { this.menuItem = menuItem; - this.systemTray = systemTray; + this.menu = menu; - systemTray.getMenu().add(menuItem); + menu.add(menuItem); } /** @@ -74,6 +74,17 @@ class SwingMenuEntry implements MenuEntry { }); } + @Override + public + void setImage(final File imageFile) { + if (imageFile == null) { + setImage_(null); + } + else { + setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageFile)); + } + } + @Override public final void setImage(final String imagePath) { @@ -126,7 +137,7 @@ class SwingMenuEntry implements MenuEntry { public void run() { removePrivate(); - systemTray.getMenu().remove(menuItem); + menu.remove(menuItem); } }); } diff --git a/src/dorkbox/systemTray/util/ImageUtils.java b/src/dorkbox/systemTray/util/ImageUtils.java index 9a78790..fdfdb79 100644 --- a/src/dorkbox/systemTray/util/ImageUtils.java +++ b/src/dorkbox/systemTray/util/ImageUtils.java @@ -258,6 +258,10 @@ class ImageUtils { return null; } + public static synchronized + File resizeAndCache(final int size, final File file) { + return resizeAndCache(size, file.getAbsolutePath()); + } public static synchronized File resizeAndCache(final int size, final String fileName) {