forked from dorkbox/SystemTray
Added setImage from a file
This commit is contained in:
parent
ddcec4cb68
commit
83c865a51c
@ -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
|
||||
*
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user