Rename AWTSystemTray=>SystemTray and remove statics

This commit is contained in:
Chris Beams 2014-11-03 19:29:01 +01:00
parent 2af861a776
commit 0fb5caa7ba
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
2 changed files with 23 additions and 23 deletions

View file

@ -18,7 +18,7 @@
package io.bitsquare; package io.bitsquare;
import io.bitsquare.di.BitsquareModule; import io.bitsquare.di.BitsquareModule;
import io.bitsquare.gui.AWTSystemTray; import io.bitsquare.gui.SystemTray;
import io.bitsquare.gui.Navigation; import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.components.Popups;
import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.ImageUtil;
@ -110,12 +110,12 @@ public class BitsquareUI extends Application {
// configure the system tray // configure the system tray
AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class), this); SystemTray systemTray = new SystemTray(primaryStage, injector.getInstance(ActorSystem.class), this);
primaryStage.setOnCloseRequest(e -> AWTSystemTray.setStageHidden()); primaryStage.setOnCloseRequest(e -> systemTray.setStageHidden());
KeyCodeCombination keyCodeCombination = new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN); KeyCodeCombination keyCodeCombination = new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN);
scene.setOnKeyReleased(keyEvent -> { scene.setOnKeyReleased(keyEvent -> {
if (keyCodeCombination.match(keyEvent)) if (keyCodeCombination.match(keyEvent))
AWTSystemTray.setStageHidden(); systemTray.setStageHidden();
}); });

View file

@ -17,7 +17,6 @@
package io.bitsquare.gui; package io.bitsquare.gui;
import io.bitsquare.Bitsquare; import io.bitsquare.Bitsquare;
import io.bitsquare.BitsquareUI; import io.bitsquare.BitsquareUI;
import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.ImageUtil;
@ -39,27 +38,28 @@ import scala.concurrent.duration.Duration;
/** /**
* There is no JavaFX support yet, so we need to use AWT. * There is no JavaFX support yet, so we need to use AWT.
* TODO research more
*/ */
public class AWTSystemTray { public class SystemTray {
private static final Logger log = LoggerFactory.getLogger(AWTSystemTray.class); private static final Logger log = LoggerFactory.getLogger(SystemTray.class);
private static boolean isStageVisible = true;
private static MenuItem showGuiItem;
private static Stage stage;
private static ActorSystem actorSystem;
private static BitsquareUI application;
private static TrayIcon trayIcon;
public static void createSystemTray(Stage stage, ActorSystem actorSystem, BitsquareUI application) { private final Stage stage;
AWTSystemTray.stage = stage; private final ActorSystem actorSystem;
AWTSystemTray.actorSystem = actorSystem; private final BitsquareUI application;
AWTSystemTray.application = application;
if (SystemTray.isSupported()) { private boolean isStageVisible = true;
private MenuItem showGuiItem;
private TrayIcon trayIcon;
public SystemTray(Stage stage, ActorSystem actorSystem, BitsquareUI application) {
this.stage = stage;
this.actorSystem = actorSystem;
this.application = application;
if (java.awt.SystemTray.isSupported()) {
// prevent exiting the app when the last window get closed // prevent exiting the app when the last window get closed
Platform.setImplicitExit(false); Platform.setImplicitExit(false);
SystemTray systemTray = SystemTray.getSystemTray(); java.awt.SystemTray systemTray = java.awt.SystemTray.getSystemTray();
if (ImageUtil.isRetina()) if (ImageUtil.isRetina())
trayIcon = new TrayIcon(getImage(ImageUtil.SYS_TRAY_HI_RES)); trayIcon = new TrayIcon(getImage(ImageUtil.SYS_TRAY_HI_RES));
else else
@ -121,13 +121,13 @@ public class AWTSystemTray {
} }
} }
public static void setStageHidden() { public void setStageHidden() {
stage.hide(); stage.hide();
isStageVisible = false; isStageVisible = false;
showGuiItem.setLabel("Open exchange window"); showGuiItem.setLabel("Open exchange window");
} }
private static Image getImage(String path) { private Image getImage(String path) {
return new ImageIcon(AWTSystemTray.class.getResource(path), "system tray icon").getImage(); return new ImageIcon(SystemTray.class.getResource(path), "system tray icon").getImage();
} }
} }