Changed Util class names
This commit is contained in:
parent
3d652e2d14
commit
839d264d31
|
@ -18,7 +18,7 @@ package dorkbox.systemTray;
|
|||
import java.awt.event.ActionListener;
|
||||
|
||||
import dorkbox.systemTray.peer.CheckboxPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
/**
|
||||
* This represents a common menu-checkbox entry, that is cross platform in nature
|
||||
|
@ -189,7 +189,7 @@ class Checkbox extends Entry {
|
|||
*/
|
||||
public
|
||||
void setShortcut(final int key) {
|
||||
this.mnemonicKey = SwingUtil.getFromVirtualKey(key);
|
||||
this.mnemonicKey = Swing.getFromVirtualKey(key);
|
||||
|
||||
if (peer != null) {
|
||||
((CheckboxPeer) peer).setShortcut(this);
|
||||
|
|
|
@ -25,7 +25,7 @@ import javax.imageio.stream.ImageInputStream;
|
|||
|
||||
import dorkbox.systemTray.peer.MenuItemPeer;
|
||||
import dorkbox.systemTray.util.ImageResizeUtil;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
/**
|
||||
* This represents a common menu-entry, that is cross platform in nature
|
||||
|
@ -336,7 +336,7 @@ class MenuItem extends Entry {
|
|||
*/
|
||||
public
|
||||
void setShortcut(final int key) {
|
||||
this.mnemonicKey = SwingUtil.getFromVirtualKey(key);
|
||||
this.mnemonicKey = Swing.getFromVirtualKey(key);
|
||||
|
||||
if (peer != null) {
|
||||
((MenuItemPeer) peer).setShortcut(this);
|
||||
|
|
|
@ -38,27 +38,27 @@ import javax.swing.UIManager;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import dorkbox.systemTray.jna.linux.AppIndicator;
|
||||
import dorkbox.systemTray.jna.linux.Gtk;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.ui.awt._AwtTray;
|
||||
import dorkbox.systemTray.ui.gtk._AppIndicatorNativeTray;
|
||||
import dorkbox.systemTray.ui.gtk._GtkStatusIconNativeTray;
|
||||
import dorkbox.systemTray.ui.swing.SwingUIFactory;
|
||||
import dorkbox.systemTray.ui.swing._SwingTray;
|
||||
import dorkbox.systemTray.util.ImageResizeUtil;
|
||||
import dorkbox.systemTray.util.JavaFX;
|
||||
import dorkbox.systemTray.util.LinuxSwingUI;
|
||||
import dorkbox.systemTray.util.SizeAndScalingUtil;
|
||||
import dorkbox.systemTray.util.Swt;
|
||||
import dorkbox.systemTray.util.SystemTrayFixes;
|
||||
import dorkbox.systemTray.util.WindowsSwingUI;
|
||||
import dorkbox.util.CacheUtil;
|
||||
import dorkbox.util.Cache;
|
||||
import dorkbox.util.Framework;
|
||||
import dorkbox.util.IO;
|
||||
import dorkbox.util.JavaFX;
|
||||
import dorkbox.util.OS;
|
||||
import dorkbox.util.OSUtil;
|
||||
import dorkbox.util.Property;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
import dorkbox.util.jna.linux.AppIndicator;
|
||||
import dorkbox.util.jna.linux.Gtk;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
|
||||
|
@ -140,35 +140,6 @@ class SystemTray {
|
|||
private static volatile SystemTray systemTray = null;
|
||||
private static volatile Tray systemTrayMenu = null;
|
||||
|
||||
public final static boolean isJavaFxLoaded;
|
||||
public final static boolean isSwtLoaded;
|
||||
|
||||
|
||||
static {
|
||||
boolean isJavaFxLoaded_ = false;
|
||||
boolean isSwtLoaded_ = false;
|
||||
try {
|
||||
// this is important to use reflection, because if JavaFX is not being used, calling getToolkit() will initialize it...
|
||||
java.lang.reflect.Method m = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class);
|
||||
m.setAccessible(true);
|
||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||
|
||||
// JavaFX Java7,8 is GTK2 only. Java9 can have it be GTK3 if -Djdk.gtk.version=3 is specified
|
||||
// see http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-May/019100.html
|
||||
isJavaFxLoaded_ = (null != m.invoke(cl, "com.sun.javafx.tk.Toolkit")) || (null != m.invoke(cl, "javafx.application.Application"));
|
||||
|
||||
// maybe we should load the SWT version? (In order for us to work with SWT, BOTH must be the same!!
|
||||
// SWT is GTK2, but if -DSWT_GTK3=1 is specified, it can be GTK3
|
||||
isSwtLoaded_ = null != m.invoke(cl, "org.eclipse.swt.widgets.Display");
|
||||
} catch (Throwable e) {
|
||||
if (DEBUG) {
|
||||
logger.debug("Error detecting javaFX/SWT mode", e);
|
||||
}
|
||||
}
|
||||
|
||||
isJavaFxLoaded = isJavaFxLoaded_;
|
||||
isSwtLoaded = isSwtLoaded_;
|
||||
}
|
||||
|
||||
private static
|
||||
boolean isTrayType(final Class<? extends Tray> tray, final TrayType trayType) {
|
||||
|
@ -319,7 +290,7 @@ class SystemTray {
|
|||
return selectTypeQuietly(TrayType.AppIndicator);
|
||||
}
|
||||
case Unity7: {
|
||||
// Ubuntu Unity is a weird combination. It's "Gnome", but it's not "Gnome Shell".
|
||||
// Ubuntu Unity7 is a weird combination. It's "Gnome", but it's not "Gnome Shell".
|
||||
return selectTypeQuietly(TrayType.AppIndicator);
|
||||
}
|
||||
case XFCE: {
|
||||
|
@ -439,7 +410,7 @@ class SystemTray {
|
|||
// cannot mix Swing/AWT and JavaFX for MacOSX in java7 (fixed in java8) without special stuff.
|
||||
// https://bugs.openjdk.java.net/browse/JDK-8116017
|
||||
// https://bugs.openjdk.java.net/browse/JDK-8118714
|
||||
if (isJavaFxLoaded && OS.javaVersion <= 7 && !System.getProperty("javafx.macosx.embedded", "false").equals("true")) {
|
||||
if (Framework.isJavaFxLoaded && OS.javaVersion <= 7 && !System.getProperty("javafx.macosx.embedded", "false").equals("true")) {
|
||||
|
||||
logger.error("MacOSX JavaFX (Java7) is incompatible with the SystemTray by default. See issue: " +
|
||||
"'https://bugs.openjdk.java.net/browse/JDK-8116017' and 'https://bugs.openjdk.java.net/browse/JDK-8118714'\n" +
|
||||
|
@ -457,7 +428,7 @@ class SystemTray {
|
|||
|
||||
// cannot mix Swing and SWT on MacOSX (for all versions of java) so we force native menus instead, which work just fine with SWT
|
||||
// http://mail.openjdk.java.net/pipermail/bsd-port-dev/2008-December/000173.html
|
||||
if (isSwtLoaded && FORCE_TRAY_TYPE == TrayType.Swing) {
|
||||
if (Framework.isSwtLoaded && FORCE_TRAY_TYPE == TrayType.Swing) {
|
||||
if (AUTO_FIX_INCONSISTENCIES) {
|
||||
logger.warn("Unable to load Swing + SWT (for all versions of Java). Using the AWT Tray type instead.");
|
||||
|
||||
|
@ -485,7 +456,7 @@ class SystemTray {
|
|||
|
||||
// NOTE: if the UI uses the 'getSystemLookAndFeelClassName' and is on Linux, this will cause GTK2 to get loaded first,
|
||||
// which will cause conflicts if one tries to use GTK3
|
||||
if (!FORCE_GTK2 && !isJavaFxLoaded && !isSwtLoaded) {
|
||||
if (!FORCE_GTK2 && !Framework.isJavaFxLoaded && !Framework.isSwtLoaded) {
|
||||
|
||||
String currentUI = UIManager.getLookAndFeel()
|
||||
.getClass()
|
||||
|
@ -522,20 +493,11 @@ class SystemTray {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (isSwtLoaded) {
|
||||
else if (Framework.isSwtLoaded) {
|
||||
// Necessary for us to work with SWT based on version info. We can try to set us to be compatible with whatever it is set to
|
||||
// System.setProperty("SWT_GTK3", "0");
|
||||
|
||||
// was SWT forced?
|
||||
String swt_gtk3 = System.getProperty("SWT_GTK3");
|
||||
boolean isSwt_GTK3 = swt_gtk3 != null && !swt_gtk3.equals("0");
|
||||
if (!isSwt_GTK3) {
|
||||
// check a different property
|
||||
String property = System.getProperty("org.eclipse.swt.internal.gtk.version");
|
||||
isSwt_GTK3 = property != null && !property.startsWith("2.");
|
||||
}
|
||||
|
||||
if (isSwt_GTK3 && FORCE_GTK2) {
|
||||
if (Framework.isSwtGtk3 && FORCE_GTK2) {
|
||||
logger.error("Unable to use the SystemTray when SWT is configured to use GTK3 and the SystemTray is configured to use " +
|
||||
"GTK2. Please configure SWT to use GTK2, via `System.setProperty(\"SWT_GTK3\", \"0\");` before SWT is " +
|
||||
"initialized, or set `SystemTray.FORCE_GTK2=false;`");
|
||||
|
@ -543,21 +505,21 @@ class SystemTray {
|
|||
systemTrayMenu = null;
|
||||
systemTray = null;
|
||||
return;
|
||||
} else if (!isSwt_GTK3 && !FORCE_GTK2 && AUTO_FIX_INCONSISTENCIES) {
|
||||
} else if (!Framework.isSwtGtk3 && !FORCE_GTK2 && AUTO_FIX_INCONSISTENCIES) {
|
||||
// we must use GTK2, because SWT is GTK2
|
||||
FORCE_GTK2 = true;
|
||||
|
||||
logger.warn("Forcing GTK2 because SWT is GTK2");
|
||||
}
|
||||
}
|
||||
else if (isJavaFxLoaded) {
|
||||
else if (Framework.isJavaFxLoaded) {
|
||||
// JavaFX Java7,8 is GTK2 only. Java9 can MAYBE have it be GTK3 if `-Djdk.gtk.version=3` is specified
|
||||
// see
|
||||
// http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-May/019100.html
|
||||
// https://docs.oracle.com/javafx/2/system_requirements_2-2-3/jfxpub-system_requirements_2-2-3.htm
|
||||
// from the page: JavaFX 2.2.3 for Linux requires gtk2 2.18+.
|
||||
boolean isJava_GTK3_Possible = OS.javaVersion >= 9 && System.getProperty("jdk.gtk.version", "2").equals("3");
|
||||
if (isJava_GTK3_Possible && FORCE_GTK2) {
|
||||
|
||||
if (Framework.isJavaFxGtk3 && FORCE_GTK2) {
|
||||
// if we are java9, then we can change it -- otherwise we cannot.
|
||||
if (OS.javaVersion == 9 && AUTO_FIX_INCONSISTENCIES) {
|
||||
FORCE_GTK2 = false;
|
||||
|
@ -574,7 +536,7 @@ class SystemTray {
|
|||
systemTray = null;
|
||||
return;
|
||||
}
|
||||
} else if (!isJava_GTK3_Possible && !FORCE_GTK2 && AUTO_FIX_INCONSISTENCIES) {
|
||||
} else if (!Framework.isJavaFxGtk3 && !FORCE_GTK2 && AUTO_FIX_INCONSISTENCIES) {
|
||||
// we must use GTK2, because JavaFX is GTK2
|
||||
FORCE_GTK2 = true;
|
||||
|
||||
|
@ -596,8 +558,8 @@ class SystemTray {
|
|||
|
||||
|
||||
logger.debug("Is Auto sizing tray/menu? {}", AUTO_SIZE);
|
||||
logger.debug("Is JavaFX detected? {}", isJavaFxLoaded);
|
||||
logger.debug("Is SWT detected? {}", isSwtLoaded);
|
||||
logger.debug("Is JavaFX detected? {}", Framework.isJavaFxLoaded);
|
||||
logger.debug("Is SWT detected? {}", Framework.isSwtLoaded);
|
||||
logger.debug("Java Swing L&F: {}", UIManager.getLookAndFeel().getID());
|
||||
if (FORCE_TRAY_TYPE == TrayType.AutoDetect) {
|
||||
logger.debug("Auto-detecting tray type");
|
||||
|
@ -683,13 +645,27 @@ class SystemTray {
|
|||
|
||||
// - appIndicator/gtk require strings (which is the path)
|
||||
// - swing version loads as an image (which can be stream or path, we use path)
|
||||
CacheUtil.tempDir = "SystemTrayImages";
|
||||
Cache.tempDir = "SystemTrayImages";
|
||||
|
||||
// This will initialize javaFX/SWT event dispatch methods
|
||||
Framework.initDispatch();
|
||||
|
||||
|
||||
try {
|
||||
// at this point, the tray type is what it should be. If there are failures or special cases, all types will fall back to
|
||||
// Swing.
|
||||
|
||||
if (isNix) {
|
||||
// linux/unix need access to GTK, so load it up before the tray is loaded!
|
||||
GtkEventDispatch.startGui(FORCE_GTK2, DEBUG);
|
||||
GtkEventDispatch.waitForEventsToComplete();
|
||||
|
||||
if (DEBUG) {
|
||||
// output what version of GTK we have loaded.
|
||||
logger.debug("GTK Version: " + Gtk.MAJOR + "." + Gtk.MINOR + "." + Gtk.MICRO);
|
||||
logger.debug("Is the system already running GTK? {}", Gtk.alreadyRunningGTK);
|
||||
}
|
||||
|
||||
// NOTE: appindicator1 -> GTk2, appindicator3 -> GTK3.
|
||||
// appindicator3 doesn't support menu icons via GTK2!!
|
||||
if (!Gtk.isLoaded) {
|
||||
|
@ -739,24 +715,9 @@ class SystemTray {
|
|||
|
||||
|
||||
|
||||
if (isJavaFxLoaded) {
|
||||
// This will initialize javaFX dispatch methods
|
||||
JavaFX.init();
|
||||
}
|
||||
else if (isSwtLoaded) {
|
||||
// This will initialize swt dispatch methods
|
||||
Swt.init();
|
||||
}
|
||||
|
||||
if (isNix) {
|
||||
// linux/unix need access to GTK, so load it up before the tray is loaded!
|
||||
GtkEventDispatch.startGui();
|
||||
GtkEventDispatch.waitForEventsToComplete();
|
||||
}
|
||||
|
||||
|
||||
// have to make adjustments BEFORE the tray/menu image size calculations
|
||||
if (AUTO_FIX_INCONSISTENCIES && isTrayType(trayType, TrayType.Swing) && SystemTray.SWING_UI == null && SwingUtil.isDefaultLookAndFeel()) {
|
||||
if (AUTO_FIX_INCONSISTENCIES && isTrayType(trayType, TrayType.Swing) && SystemTray.SWING_UI == null && Swing.isDefaultLookAndFeel()) {
|
||||
if (isNix) {
|
||||
SystemTray.SWING_UI = new LinuxSwingUI();
|
||||
}
|
||||
|
@ -792,7 +753,7 @@ class SystemTray {
|
|||
|
||||
|
||||
|
||||
if ((isJavaFxLoaded || isSwtLoaded) && SwingUtilities.isEventDispatchThread()) {
|
||||
if ((Framework.isJavaFxLoaded || Framework.isSwtLoaded) && SwingUtilities.isEventDispatchThread()) {
|
||||
// This WILL NOT WORK. Let the dev know
|
||||
logger.error("SystemTray initialization for JavaFX or SWT **CAN NOT** occur on the Swing Event Dispatch Thread " +
|
||||
"(EDT). Something is seriously wrong.");
|
||||
|
@ -807,7 +768,7 @@ class SystemTray {
|
|||
// linux + GTK/AppIndicator menus must not start on the EDT!
|
||||
|
||||
// AWT/Swing must be constructed on the EDT however...
|
||||
if (isJavaFxLoaded || isSwtLoaded ||
|
||||
if (Framework.isJavaFxLoaded || Framework.isSwtLoaded ||
|
||||
(isNix && (isTrayType(trayType, TrayType.GtkStatusIcon) || isTrayType(trayType, TrayType.AppIndicator)))
|
||||
) {
|
||||
try {
|
||||
|
@ -821,7 +782,7 @@ class SystemTray {
|
|||
|
||||
// have to construct swing stuff inside the swing EDT
|
||||
final Class<? extends Menu> finalTrayType = trayType;
|
||||
SwingUtil.invokeAndWait(new Runnable() {
|
||||
Swing.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -850,7 +811,7 @@ class SystemTray {
|
|||
|
||||
// These install a shutdown hook in JavaFX/SWT, so that when the main window is closed -- the system tray is ALSO closed.
|
||||
if (ENABLE_SHUTDOWN_HOOK) {
|
||||
if (isJavaFxLoaded) {
|
||||
if (Framework.isJavaFxLoaded) {
|
||||
// Necessary because javaFX **ALSO** runs a gtk main loop, and when it stops (if we don't stop first), we become unresponsive.
|
||||
// Also, it's nice to have us shutdown at the same time as the main application
|
||||
JavaFX.onShutdown(new Runnable() {
|
||||
|
@ -863,10 +824,10 @@ class SystemTray {
|
|||
}
|
||||
});
|
||||
}
|
||||
else if (isSwtLoaded) {
|
||||
else if (Framework.isSwtLoaded) {
|
||||
// this is because SWT **ALSO** runs a gtk main loop, and when it stops (if we don't stop first), we become unresponsive
|
||||
// Also, it's nice to have us shutdown at the same time as the main application
|
||||
Swt.onShutdown(new Runnable() {
|
||||
dorkbox.util.Swt.onShutdown(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -26,7 +26,7 @@ import dorkbox.systemTray.MenuItem;
|
|||
import dorkbox.systemTray.Separator;
|
||||
import dorkbox.systemTray.Status;
|
||||
import dorkbox.systemTray.peer.MenuPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
// this is a weird composite class, because it must be a Menu, but ALSO a Entry -- so it has both
|
||||
@SuppressWarnings("ForLoopReplaceableByForEach")
|
||||
|
@ -53,7 +53,7 @@ class AwtMenu implements MenuPeer {
|
|||
public
|
||||
void add(final Menu parentMenu, final Entry entry, final int index) {
|
||||
// must always be called on the EDT
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -92,7 +92,7 @@ class AwtMenu implements MenuPeer {
|
|||
@Override
|
||||
public
|
||||
void setEnabled(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -105,7 +105,7 @@ class AwtMenu implements MenuPeer {
|
|||
@Override
|
||||
public
|
||||
void setText(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -125,9 +125,9 @@ class AwtMenu implements MenuPeer {
|
|||
public
|
||||
void setShortcut(final MenuItem menuItem) {
|
||||
// yikes...
|
||||
final int vKey = SwingUtil.getVirtualKey(menuItem.getShortcut());
|
||||
final int vKey = Swing.getVirtualKey(menuItem.getShortcut());
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -139,7 +139,7 @@ class AwtMenu implements MenuPeer {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.awt.event.ActionListener;
|
|||
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.peer.MenuItemPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
class AwtMenuItem implements MenuItemPeer {
|
||||
|
||||
|
@ -45,7 +45,7 @@ class AwtMenuItem implements MenuItemPeer {
|
|||
@Override
|
||||
public
|
||||
void setEnabled(final dorkbox.systemTray.MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -57,7 +57,7 @@ class AwtMenuItem implements MenuItemPeer {
|
|||
@Override
|
||||
public
|
||||
void setText(final dorkbox.systemTray.MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -103,9 +103,9 @@ class AwtMenuItem implements MenuItemPeer {
|
|||
void setShortcut(final dorkbox.systemTray.MenuItem menuItem) {
|
||||
char shortcut = menuItem.getShortcut();
|
||||
// yikes...
|
||||
final int vKey = SwingUtil.getVirtualKey(shortcut);
|
||||
final int vKey = Swing.getVirtualKey(shortcut);
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -118,7 +118,7 @@ class AwtMenuItem implements MenuItemPeer {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.awt.event.ActionListener;
|
|||
import dorkbox.systemTray.Checkbox;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.peer.CheckboxPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
class AwtMenuItemCheckbox implements CheckboxPeer {
|
||||
|
||||
|
@ -42,7 +42,7 @@ class AwtMenuItemCheckbox implements CheckboxPeer {
|
|||
@Override
|
||||
public
|
||||
void setEnabled(final Checkbox menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -54,7 +54,7 @@ class AwtMenuItemCheckbox implements CheckboxPeer {
|
|||
@Override
|
||||
public
|
||||
void setText(final Checkbox menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -102,9 +102,9 @@ class AwtMenuItemCheckbox implements CheckboxPeer {
|
|||
void setShortcut(final Checkbox menuItem) {
|
||||
char shortcut = menuItem.getShortcut();
|
||||
// yikes...
|
||||
final int vKey = SwingUtil.getVirtualKey(shortcut);
|
||||
final int vKey = Swing.getVirtualKey(shortcut);
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -122,7 +122,7 @@ class AwtMenuItemCheckbox implements CheckboxPeer {
|
|||
if (checked != this.isChecked) {
|
||||
this.isChecked = checked;
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -136,7 +136,7 @@ class AwtMenuItemCheckbox implements CheckboxPeer {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -17,7 +17,7 @@ package dorkbox.systemTray.ui.awt;
|
|||
|
||||
|
||||
import dorkbox.systemTray.peer.EntryPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
class AwtMenuItemSeparator implements EntryPeer {
|
||||
|
||||
|
@ -34,7 +34,7 @@ class AwtMenuItemSeparator implements EntryPeer {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.awt.MenuItem;
|
|||
|
||||
import dorkbox.systemTray.Status;
|
||||
import dorkbox.systemTray.peer.StatusPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
class AwtMenuItemStatus implements StatusPeer {
|
||||
|
||||
|
@ -39,7 +39,7 @@ class AwtMenuItemStatus implements StatusPeer {
|
|||
@Override
|
||||
public
|
||||
void setText(final Status menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -63,7 +63,7 @@ class AwtMenuItemStatus implements StatusPeer {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -27,7 +27,7 @@ import javax.swing.ImageIcon;
|
|||
import dorkbox.systemTray.MenuItem;
|
||||
import dorkbox.systemTray.Tray;
|
||||
import dorkbox.util.OS;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
/**
|
||||
* Class for handling all system tray interaction, via AWT. Pretty much EXCLUSIVELY for on MacOS, because that is the only time this
|
||||
|
@ -69,7 +69,7 @@ class _AwtTray extends Tray {
|
|||
@Override
|
||||
public
|
||||
void setEnabled(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -136,7 +136,7 @@ class _AwtTray extends Tray {
|
|||
return;
|
||||
}
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -185,7 +185,7 @@ class _AwtTray extends Tray {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -217,7 +217,7 @@ class _AwtTray extends Tray {
|
|||
}
|
||||
this.tooltipText = tooltipText;
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -15,16 +15,16 @@
|
|||
*/
|
||||
package dorkbox.systemTray.ui.gtk;
|
||||
|
||||
import static dorkbox.systemTray.jna.linux.Gtk.Gtk2;
|
||||
import static dorkbox.util.jna.linux.Gtk.Gtk2;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import dorkbox.systemTray.jna.linux.Gobject;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.peer.EntryPeer;
|
||||
import dorkbox.systemTray.util.ImageResizeUtil;
|
||||
import dorkbox.util.jna.linux.Gobject;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
|
||||
abstract
|
||||
class GtkBaseMenuItem implements EntryPeer {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package dorkbox.systemTray.ui.gtk;
|
||||
|
||||
import static dorkbox.systemTray.jna.linux.Gtk.Gtk2;
|
||||
import static dorkbox.util.jna.linux.Gtk.Gtk2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -29,8 +29,8 @@ import dorkbox.systemTray.Menu;
|
|||
import dorkbox.systemTray.MenuItem;
|
||||
import dorkbox.systemTray.Separator;
|
||||
import dorkbox.systemTray.Status;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.peer.MenuPeer;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class GtkMenu extends GtkBaseMenuItem implements MenuPeer {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package dorkbox.systemTray.ui.gtk;
|
||||
|
||||
import static dorkbox.systemTray.jna.linux.Gtk.Gtk2;
|
||||
import static dorkbox.util.jna.linux.Gtk.Gtk2;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
|
@ -23,10 +23,10 @@ import com.sun.jna.Pointer;
|
|||
|
||||
import dorkbox.systemTray.MenuItem;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.jna.linux.GCallback;
|
||||
import dorkbox.systemTray.jna.linux.Gobject;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.peer.MenuItemPeer;
|
||||
import dorkbox.util.jna.linux.GCallback;
|
||||
import dorkbox.util.jna.linux.Gobject;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
|
||||
class GtkMenuItem extends GtkBaseMenuItem implements MenuItemPeer, GCallback {
|
||||
private final GtkMenu parent;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package dorkbox.systemTray.ui.gtk;
|
||||
|
||||
import static dorkbox.systemTray.jna.linux.Gtk.Gtk2;
|
||||
import static dorkbox.util.jna.linux.Gtk.Gtk2;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
|
@ -26,14 +26,14 @@ import com.sun.jna.Pointer;
|
|||
|
||||
import dorkbox.systemTray.Checkbox;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.jna.linux.GCallback;
|
||||
import dorkbox.systemTray.jna.linux.Gobject;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.jna.linux.GtkTheme;
|
||||
import dorkbox.systemTray.peer.CheckboxPeer;
|
||||
import dorkbox.systemTray.util.HeavyCheckMark;
|
||||
import dorkbox.systemTray.util.ImageResizeUtil;
|
||||
import dorkbox.util.OSUtil;
|
||||
import dorkbox.util.jna.linux.GCallback;
|
||||
import dorkbox.util.jna.linux.Gobject;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.util.jna.linux.GtkTheme;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class GtkMenuItemCheckbox extends GtkBaseMenuItem implements CheckboxPeer, GCallback {
|
||||
|
@ -52,7 +52,7 @@ class GtkMenuItemCheckbox extends GtkBaseMenuItem implements CheckboxPeer, GCall
|
|||
(SystemTray.get().getMenu() instanceof _AppIndicatorNativeTray) && OSUtil.Linux.isUbuntu()) {
|
||||
useFakeCheckMark = true;
|
||||
} else {
|
||||
useFakeCheckMark = true;
|
||||
useFakeCheckMark = false;
|
||||
}
|
||||
|
||||
if (SystemTray.DEBUG) {
|
||||
|
@ -99,7 +99,13 @@ class GtkMenuItemCheckbox extends GtkBaseMenuItem implements CheckboxPeer, GCall
|
|||
|
||||
if (useFakeCheckMark) {
|
||||
if (checkedFile == null) {
|
||||
final Color color = GtkTheme.getTextColor();
|
||||
Color color = GtkTheme.getTextColor();
|
||||
if (color == null) {
|
||||
SystemTray.logger.error("Unable to determine the text color in use by your system. Please create an issue and include your " +
|
||||
"full OS configuration and desktop environment, including theme details, such as the theme name, color " +
|
||||
"variant, and custom theme options (if any).");
|
||||
color = Color.BLACK;
|
||||
}
|
||||
|
||||
if (checkedFile == null) {
|
||||
Rectangle size = GtkTheme.getPixelTextHeight("X");
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
*/
|
||||
package dorkbox.systemTray.ui.gtk;
|
||||
|
||||
import static dorkbox.systemTray.jna.linux.Gtk.Gtk2;
|
||||
import static dorkbox.util.jna.linux.Gtk.Gtk2;
|
||||
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.peer.EntryPeer;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
|
||||
class GtkMenuItemSeparator extends GtkBaseMenuItem implements EntryPeer {
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
*/
|
||||
package dorkbox.systemTray.ui.gtk;
|
||||
|
||||
import static dorkbox.systemTray.jna.linux.Gtk.Gtk2;
|
||||
import static dorkbox.util.jna.linux.Gtk.Gtk2;
|
||||
|
||||
import dorkbox.systemTray.Status;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.peer.StatusPeer;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
|
||||
// you might wonder WHY this extends MenuEntryItem -- the reason is that an AppIndicator "status" will be offset from everyone else,
|
||||
// where a GtkStatusIconTray + SwingUI will have everything lined up. (with or without icons). This is to normalize how it looks
|
||||
|
|
|
@ -24,11 +24,11 @@ import dorkbox.systemTray.MenuItem;
|
|||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.Tray;
|
||||
import dorkbox.systemTray.gnomeShell.Extension;
|
||||
import dorkbox.systemTray.jna.linux.AppIndicator;
|
||||
import dorkbox.systemTray.jna.linux.Gobject;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.jna.linux.structs.AppIndicatorInstanceStruct;
|
||||
import dorkbox.systemTray.util.ImageResizeUtil;
|
||||
import dorkbox.util.jna.linux.AppIndicator;
|
||||
import dorkbox.util.jna.linux.Gobject;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.util.jna.linux.structs.AppIndicatorInstanceStruct;
|
||||
|
||||
/**
|
||||
* Class for handling all system tray interactions.
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package dorkbox.systemTray.ui.gtk;
|
||||
|
||||
import static dorkbox.systemTray.jna.linux.Gtk.Gtk2;
|
||||
import static dorkbox.util.jna.linux.Gtk.Gtk2;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -26,10 +26,11 @@ import dorkbox.systemTray.MenuItem;
|
|||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.Tray;
|
||||
import dorkbox.systemTray.gnomeShell.Extension;
|
||||
import dorkbox.systemTray.jna.linux.GEventCallback;
|
||||
import dorkbox.systemTray.jna.linux.Gobject;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.systemTray.jna.linux.structs.GdkEventButton;
|
||||
import dorkbox.util.Framework;
|
||||
import dorkbox.util.jna.linux.GEventCallback;
|
||||
import dorkbox.util.jna.linux.Gobject;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.util.jna.linux.structs.GdkEventButton;
|
||||
|
||||
/**
|
||||
* Class for handling all system tray interactions via GTK.
|
||||
|
@ -193,7 +194,7 @@ class _GtkStatusIconNativeTray extends Tray {
|
|||
// BUT this is REQUIRED when running JavaFX or Gnome For unknown reasons, the title isn't pushed to GTK, so our
|
||||
// gnome-shell extension cannot see our tray icon -- so naturally, it won't move it to the "top" area and
|
||||
// we appear broken.
|
||||
if (SystemTray.isJavaFxLoaded || Tray.usingGnome) {
|
||||
if (Framework.isJavaFxLoaded || Tray.usingGnome) {
|
||||
Gtk2.gtk_status_icon_set_name(trayIcon, Extension.DEFAULT_NAME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import dorkbox.systemTray.Separator;
|
|||
import dorkbox.systemTray.Status;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.peer.MenuPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
// this is a weird composite class, because it must be a Menu, but ALSO a Entry -- so it has both (and duplicate code)
|
||||
@SuppressWarnings("ForLoopReplaceableByForEach")
|
||||
|
@ -69,7 +69,7 @@ class SwingMenu implements MenuPeer {
|
|||
public
|
||||
void add(final Menu parentMenu, final Entry entry, final int index) {
|
||||
// must always be called on the EDT
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -107,7 +107,7 @@ class SwingMenu implements MenuPeer {
|
|||
@Override
|
||||
public
|
||||
void setImage(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -127,7 +127,7 @@ class SwingMenu implements MenuPeer {
|
|||
@Override
|
||||
public
|
||||
void setEnabled(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -141,7 +141,7 @@ class SwingMenu implements MenuPeer {
|
|||
@Override
|
||||
public
|
||||
void setText(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -162,9 +162,9 @@ class SwingMenu implements MenuPeer {
|
|||
void setShortcut(final MenuItem menuItem) {
|
||||
char shortcut = menuItem.getShortcut();
|
||||
// yikes...
|
||||
final int vKey = SwingUtil.getVirtualKey(shortcut);
|
||||
final int vKey = Swing.getVirtualKey(shortcut);
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -179,7 +179,7 @@ class SwingMenu implements MenuPeer {
|
|||
@Override
|
||||
public synchronized
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -28,7 +28,7 @@ import dorkbox.systemTray.MenuItem;
|
|||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.peer.MenuItemPeer;
|
||||
import dorkbox.systemTray.util.ImageResizeUtil;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
class SwingMenuItem implements MenuItemPeer {
|
||||
|
||||
|
@ -78,7 +78,7 @@ class SwingMenuItem implements MenuItemPeer {
|
|||
@Override
|
||||
public
|
||||
void setImage(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -97,7 +97,7 @@ class SwingMenuItem implements MenuItemPeer {
|
|||
@Override
|
||||
public
|
||||
void setEnabled(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -109,7 +109,7 @@ class SwingMenuItem implements MenuItemPeer {
|
|||
@Override
|
||||
public
|
||||
void setText(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -155,9 +155,9 @@ class SwingMenuItem implements MenuItemPeer {
|
|||
void setShortcut(final MenuItem menuItem) {
|
||||
char shortcut = menuItem.getShortcut();
|
||||
// yikes...
|
||||
final int vKey = SwingUtil.getVirtualKey(shortcut);
|
||||
final int vKey = Swing.getVirtualKey(shortcut);
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -170,7 +170,7 @@ class SwingMenuItem implements MenuItemPeer {
|
|||
public
|
||||
void remove() {
|
||||
//noinspection Duplicates
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -26,8 +26,8 @@ import dorkbox.systemTray.Entry;
|
|||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.peer.CheckboxPeer;
|
||||
import dorkbox.systemTray.util.HeavyCheckMark;
|
||||
import dorkbox.util.FontUtil;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Font;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
class SwingMenuItemCheckbox extends SwingMenuItem implements CheckboxPeer {
|
||||
|
||||
|
@ -50,7 +50,7 @@ class SwingMenuItemCheckbox extends SwingMenuItem implements CheckboxPeer {
|
|||
}
|
||||
|
||||
// Having the checkmark size the same size as the letter X is a reasonably nice size.
|
||||
int size = FontUtil.getFontHeight(jMenuItem.getFont(), "X");
|
||||
int size = Font.getFontHeight(jMenuItem.getFont(), "X");
|
||||
|
||||
// this is the largest size of an image used in a JMenuItem, before the size of the JMenuItem is forced to be larger
|
||||
int menuImageSize = SystemTray.get()
|
||||
|
@ -73,7 +73,7 @@ class SwingMenuItemCheckbox extends SwingMenuItem implements CheckboxPeer {
|
|||
@Override
|
||||
public
|
||||
void setEnabled(final Checkbox menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -85,7 +85,7 @@ class SwingMenuItemCheckbox extends SwingMenuItem implements CheckboxPeer {
|
|||
@Override
|
||||
public
|
||||
void setText(final Checkbox menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -133,9 +133,9 @@ class SwingMenuItemCheckbox extends SwingMenuItem implements CheckboxPeer {
|
|||
void setShortcut(final Checkbox menuItem) {
|
||||
char shortcut = menuItem.getShortcut();
|
||||
// yikes...
|
||||
final int vKey = SwingUtil.getVirtualKey(shortcut);
|
||||
final int vKey = Swing.getVirtualKey(shortcut);
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -153,7 +153,7 @@ class SwingMenuItemCheckbox extends SwingMenuItem implements CheckboxPeer {
|
|||
if (checked != this.isChecked) {
|
||||
this.isChecked = checked;
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -19,7 +19,7 @@ import javax.swing.JSeparator;
|
|||
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.peer.EntryPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
class SwingMenuItemSeparator implements EntryPeer {
|
||||
|
||||
|
@ -40,7 +40,7 @@ class SwingMenuItemSeparator implements EntryPeer {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -24,7 +24,7 @@ import dorkbox.systemTray.Entry;
|
|||
import dorkbox.systemTray.Status;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.peer.StatusPeer;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
|
||||
class SwingMenuItemStatus implements StatusPeer {
|
||||
|
||||
|
@ -54,7 +54,7 @@ class SwingMenuItemStatus implements StatusPeer {
|
|||
@Override
|
||||
public
|
||||
void setText(final Status menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -66,7 +66,7 @@ class SwingMenuItemStatus implements StatusPeer {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -28,9 +28,9 @@ import javax.swing.JPopupMenu;
|
|||
|
||||
import dorkbox.systemTray.MenuItem;
|
||||
import dorkbox.systemTray.Tray;
|
||||
import dorkbox.systemTray.jna.linux.GtkEventDispatch;
|
||||
import dorkbox.util.OS;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||
|
||||
/**
|
||||
* Class for handling all system tray interaction, via Swing.
|
||||
|
@ -66,7 +66,7 @@ class _SwingTray extends Tray {
|
|||
@Override
|
||||
public
|
||||
void setEnabled(final MenuItem menuItem) {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -104,7 +104,7 @@ class _SwingTray extends Tray {
|
|||
return;
|
||||
}
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -170,7 +170,7 @@ class _SwingTray extends Tray {
|
|||
@Override
|
||||
public
|
||||
void remove() {
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -207,7 +207,7 @@ class _SwingTray extends Tray {
|
|||
}
|
||||
this.tooltipText = tooltipText;
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
Swing.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.io.File;
|
|||
import javax.imageio.ImageIO;
|
||||
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.util.CacheUtil;
|
||||
import dorkbox.util.Cache;
|
||||
|
||||
public class HeavyCheckMark {
|
||||
private static final double SVG_ORIG_SIZE_Y = 222.0D;
|
||||
|
@ -51,7 +51,7 @@ public class HeavyCheckMark {
|
|||
targetImageSize = checkMarkSize;
|
||||
}
|
||||
|
||||
final File newFile = CacheUtil.create(name);
|
||||
final File newFile = Cache.create(name);
|
||||
if (newFile.canRead() || newFile.length() == 0) {
|
||||
try {
|
||||
BufferedImage img = HeavyCheckMark.draw(color, checkMarkSize, targetImageSize);
|
||||
|
|
|
@ -30,7 +30,7 @@ import javax.imageio.ImageIO;
|
|||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.util.CacheUtil;
|
||||
import dorkbox.util.Cache;
|
||||
import dorkbox.util.IO;
|
||||
import dorkbox.util.ImageUtil;
|
||||
|
||||
|
@ -47,7 +47,7 @@ class ImageResizeUtil {
|
|||
File getTransparentImage(final int imageSize) {
|
||||
// NOTE: this does not need to be called on the EDT
|
||||
try {
|
||||
final File newFile = CacheUtil.create(imageSize + "_empty.png");
|
||||
final File newFile = Cache.create(imageSize + "_empty.png");
|
||||
return ImageUtil.createImage(imageSize, newFile, null);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to generate transparent image! Something is severely wrong!");
|
||||
|
@ -69,12 +69,12 @@ class ImageResizeUtil {
|
|||
imageStream.mark(0);
|
||||
|
||||
// check if we already have this file information saved to disk, based on size + hash of data
|
||||
final String cacheName = size + "_" + CacheUtil.createNameAsHash(imageStream);
|
||||
final String cacheName = size + "_" + Cache.createNameAsHash(imageStream);
|
||||
((ByteArrayInputStream) imageStream).reset(); // casting to avoid unnecessary try/catch for IOException
|
||||
|
||||
|
||||
// if we already have this fileName, reuse it
|
||||
final File check = CacheUtil.check(cacheName);
|
||||
final File check = Cache.check(cacheName);
|
||||
if (check != null) {
|
||||
return check;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ class ImageResizeUtil {
|
|||
File resizedFile = resizeFileNoCheck(size, imageStream);
|
||||
|
||||
// now cache that file
|
||||
return CacheUtil.save(cacheName, resizedFile);
|
||||
return Cache.save(cacheName, resizedFile);
|
||||
} catch (Exception e) {
|
||||
// this must be thrown
|
||||
throw new RuntimeException("Serious problems! Unable to extract error image, this should NEVER happen!", e);
|
||||
|
@ -130,12 +130,12 @@ class ImageResizeUtil {
|
|||
imageStream.mark(0);
|
||||
|
||||
// check if we already have this file information saved to disk, based on size + hash of data
|
||||
cacheName = size + "_" + CacheUtil.createNameAsHash(imageStream);
|
||||
cacheName = size + "_" + Cache.createNameAsHash(imageStream);
|
||||
((ByteArrayInputStream) imageStream).reset(); // casting to avoid unnecessary try/catch for IOException
|
||||
|
||||
|
||||
// if we already have this fileName, reuse it
|
||||
final File check = CacheUtil.check(cacheName);
|
||||
final File check = Cache.check(cacheName);
|
||||
if (check != null) {
|
||||
return check;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ class ImageResizeUtil {
|
|||
|
||||
// now cache that file
|
||||
try {
|
||||
return CacheUtil.save(cacheName, resizedFile);
|
||||
return Cache.save(cacheName, resizedFile);
|
||||
} catch (Exception e) {
|
||||
// have to serve up the error image instead.
|
||||
SystemTray.logger.error("Error caching image. Using error icon instead", e);
|
||||
|
@ -181,7 +181,7 @@ class ImageResizeUtil {
|
|||
} else {
|
||||
// no resize necessary, just cache as is.
|
||||
try {
|
||||
return CacheUtil.save(cacheName, imageStream);
|
||||
return Cache.save(cacheName, imageStream);
|
||||
} catch (Exception e) {
|
||||
// have to serve up the error image instead.
|
||||
SystemTray.logger.error("Error caching image. Using error icon instead", e);
|
||||
|
@ -216,7 +216,7 @@ class ImageResizeUtil {
|
|||
File resizeFileNoCheck(final int size, InputStream inputStream) throws IOException {
|
||||
// have to resize the file (and return the new path)
|
||||
|
||||
File newFile = CacheUtil.create("temp_resize.png");
|
||||
File newFile = Cache.create("temp_resize.png");
|
||||
// if it's already there, we have to delete it
|
||||
newFile.delete();
|
||||
|
||||
|
@ -288,7 +288,7 @@ class ImageResizeUtil {
|
|||
|
||||
return file;
|
||||
} else {
|
||||
return CacheUtil.save(imageUrl);
|
||||
return Cache.save(imageUrl);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// have to serve up the error image instead.
|
||||
|
@ -307,7 +307,7 @@ class ImageResizeUtil {
|
|||
return ImageResizeUtil.resizeAndCache(getSize(isTrayImage), imageStream);
|
||||
} else {
|
||||
try {
|
||||
return CacheUtil.save(imageStream);
|
||||
return Cache.save(imageStream);
|
||||
} catch (IOException e) {
|
||||
SystemTray.logger.error("Error checking cache for information. Using error icon instead", e);
|
||||
return getErrorImage(0);
|
||||
|
@ -337,7 +337,7 @@ class ImageResizeUtil {
|
|||
|
||||
return file;
|
||||
} else {
|
||||
File file = CacheUtil.save(imageInputStream);
|
||||
File file = Cache.save(imageInputStream);
|
||||
imageInputStream.close(); // BAOS doesn't do anything, but here for completeness + documentation
|
||||
|
||||
return file;
|
||||
|
@ -362,7 +362,7 @@ class ImageResizeUtil {
|
|||
if (SystemTray.AUTO_SIZE) {
|
||||
return resizeAndCache(getSize(isTrayImage), fileStream);
|
||||
} else {
|
||||
return CacheUtil.save(fileStream);
|
||||
return Cache.save(fileStream);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// have to serve up the error image instead.
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package dorkbox.systemTray.util;
|
||||
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.util.OS;
|
||||
|
||||
/**
|
||||
* Utility methods for JavaFX.
|
||||
* <p>
|
||||
* We use reflection for these methods so that we can compile everything under Java 1.6 (which doesn't have JavaFX).
|
||||
*/
|
||||
public
|
||||
class JavaFX {
|
||||
|
||||
// Methods are cached for performance
|
||||
private static final Method dispatchMethod;
|
||||
private static final Method isEventThreadMethod;
|
||||
private static final Object isEventThreadObject;
|
||||
|
||||
static {
|
||||
Method _isEventThreadMethod = null;
|
||||
Method _dispatchMethod = null;
|
||||
Object _isEventThreadObject = null;
|
||||
|
||||
try {
|
||||
Class<?> clazz = Class.forName("javafx.application.Platform");
|
||||
_dispatchMethod = clazz.getMethod("runLater", Runnable.class);
|
||||
|
||||
// JAVA 7
|
||||
// javafx.application.Platform.isFxApplicationThread();
|
||||
|
||||
// JAVA 8
|
||||
// com.sun.javafx.tk.Toolkit.getToolkit().isFxUserThread();
|
||||
if (OS.javaVersion <= 7) {
|
||||
clazz = Class.forName("javafx.application.Platform");
|
||||
_isEventThreadMethod = clazz.getMethod("isFxApplicationThread");
|
||||
_isEventThreadObject = null;
|
||||
} else {
|
||||
clazz = Class.forName("com.sun.javafx.tk.Toolkit");
|
||||
_isEventThreadMethod = clazz.getMethod("getToolkit");
|
||||
|
||||
_isEventThreadObject = _isEventThreadMethod.invoke(null);
|
||||
_isEventThreadMethod = _isEventThreadObject.getClass()
|
||||
.getMethod("isFxUserThread", (java.lang.Class<?>[])null);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
SystemTray.logger.error("Cannot initialize JavaFX", e);
|
||||
}
|
||||
|
||||
dispatchMethod = _dispatchMethod;
|
||||
isEventThreadMethod = _isEventThreadMethod;
|
||||
isEventThreadObject = _isEventThreadObject;
|
||||
}
|
||||
|
||||
public static
|
||||
void init() {
|
||||
if (dispatchMethod == null || isEventThreadMethod == null) {
|
||||
SystemTray.logger.error("Unable to initialize JavaFX! Please create an issue with your OS and Java " +
|
||||
"version so we may further investigate this issue.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static
|
||||
void dispatch(final Runnable runnable) {
|
||||
// javafx.application.Platform.runLater(runnable);
|
||||
|
||||
try {
|
||||
dispatchMethod.invoke(null, runnable);
|
||||
} catch (Throwable e) {
|
||||
SystemTray.logger.error("Unable to execute JavaFX runLater(). Please create an issue with your OS and Java " +
|
||||
"version so we may further investigate this issue.");
|
||||
}
|
||||
}
|
||||
|
||||
public static
|
||||
boolean isEventThread() {
|
||||
// JAVA 7
|
||||
// javafx.application.Platform.isFxApplicationThread();
|
||||
|
||||
// JAVA 8
|
||||
// com.sun.javafx.tk.Toolkit.getToolkit().isFxUserThread();
|
||||
|
||||
try {
|
||||
if (OS.javaVersion <= 7) {
|
||||
return (Boolean) isEventThreadMethod.invoke(null);
|
||||
} else {
|
||||
return (Boolean) isEventThreadMethod.invoke(isEventThreadObject, (java.lang.Class<?>[])null);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
SystemTray.logger.error("Unable to check if JavaFX is in the event thread. Please create an issue with your OS and Java " +
|
||||
"version so we may further investigate this issue.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static
|
||||
void onShutdown(final Runnable runnable) {
|
||||
// com.sun.javafx.tk.Toolkit.getToolkit()
|
||||
// .addShutdownHook(runnable);
|
||||
|
||||
try {
|
||||
Class<?> clazz = Class.forName("com.sun.javafx.tk.Toolkit");
|
||||
Method method = clazz.getMethod("getToolkit");
|
||||
Object o = method.invoke(null);
|
||||
Method m = o.getClass()
|
||||
.getMethod("addShutdownHook", Runnable.class);
|
||||
m.invoke(o, runnable);
|
||||
} catch (Throwable e) {
|
||||
if (SystemTray.DEBUG) {
|
||||
SystemTray.logger.error("Cannot initialize JavaFX", e);
|
||||
}
|
||||
SystemTray.logger.error("Unable to insert shutdown hook into JavaFX. Please create an issue with your OS and Java " +
|
||||
"version so we may further investigate this issue.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,10 +31,10 @@ import javax.swing.JMenuItem;
|
|||
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.Tray;
|
||||
import dorkbox.systemTray.jna.linux.GtkTheme;
|
||||
import dorkbox.systemTray.ui.swing._SwingTray;
|
||||
import dorkbox.util.OS;
|
||||
import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.Swing;
|
||||
import dorkbox.util.jna.linux.GtkTheme;
|
||||
import dorkbox.util.jna.windows.User32;
|
||||
|
||||
public
|
||||
|
@ -147,7 +147,7 @@ class SizeAndScalingUtil {
|
|||
} else {
|
||||
final AtomicInteger iconSize = new AtomicInteger();
|
||||
|
||||
SwingUtil.invokeAndWaitQuietly(new Runnable() {
|
||||
Swing.invokeAndWaitQuietly(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
|
@ -159,7 +159,7 @@ class SizeAndScalingUtil {
|
|||
}
|
||||
|
||||
// this is the largest size of an image used in a JMenuItem, before the size of the JMenuItem is forced to be larger
|
||||
int height = SwingUtil.getLargestIconHeightForButton(jMenuItem);
|
||||
int height = Swing.getLargestIconHeightForButton(jMenuItem);
|
||||
iconSize.set(height);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package dorkbox.systemTray.util;
|
||||
|
||||
import static dorkbox.systemTray.SystemTray.logger;
|
||||
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
/**
|
||||
* Utility methods for SWT.
|
||||
* <p>
|
||||
* SWT system tray types are just GTK trays.
|
||||
*/
|
||||
public
|
||||
class Swt {
|
||||
private static final Display currentDisplay;
|
||||
private static final Thread currentDisplayThread;
|
||||
|
||||
static {
|
||||
// we MUST save this, otherwise it is "null" when methods are run from the swing EDT.
|
||||
currentDisplay = Display.getCurrent();
|
||||
|
||||
currentDisplayThread = currentDisplay.getThread();
|
||||
}
|
||||
|
||||
public static
|
||||
void init() {
|
||||
if (currentDisplay == null) {
|
||||
logger.error("Unable to get the current display for SWT. Please create an issue with your OS and Java " +
|
||||
"version so we may further investigate this issue.");
|
||||
}
|
||||
}
|
||||
|
||||
public static
|
||||
void dispatch(final Runnable runnable) {
|
||||
currentDisplay.syncExec(runnable);
|
||||
}
|
||||
|
||||
public static
|
||||
boolean isEventThread() {
|
||||
return Thread.currentThread() == currentDisplayThread;
|
||||
}
|
||||
|
||||
public static
|
||||
void onShutdown(final Runnable runnable) {
|
||||
// currentDisplay.getShells() can only happen inside the event thread!
|
||||
if (isEventThread()) {
|
||||
currentDisplay.getShells()[0].addListener(org.eclipse.swt.SWT.Close, new org.eclipse.swt.widgets.Listener() {
|
||||
@Override
|
||||
public
|
||||
void handleEvent(final org.eclipse.swt.widgets.Event event) {
|
||||
runnable.run();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dispatch(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
currentDisplay.getShells()[0].addListener(org.eclipse.swt.SWT.Close, new org.eclipse.swt.widgets.Listener() {
|
||||
@Override
|
||||
public
|
||||
void handleEvent(final org.eclipse.swt.widgets.Event event) {
|
||||
runnable.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user