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

View file

@ -17,7 +17,6 @@
package io.bitsquare.gui;
import io.bitsquare.Bitsquare;
import io.bitsquare.BitsquareUI;
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.
* TODO research more
*/
public class AWTSystemTray {
private static final Logger log = LoggerFactory.getLogger(AWTSystemTray.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 class SystemTray {
private static final Logger log = LoggerFactory.getLogger(SystemTray.class);
public static void createSystemTray(Stage stage, ActorSystem actorSystem, BitsquareUI application) {
AWTSystemTray.stage = stage;
AWTSystemTray.actorSystem = actorSystem;
AWTSystemTray.application = application;
private final Stage stage;
private final ActorSystem actorSystem;
private final BitsquareUI 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
Platform.setImplicitExit(false);
SystemTray systemTray = SystemTray.getSystemTray();
java.awt.SystemTray systemTray = java.awt.SystemTray.getSystemTray();
if (ImageUtil.isRetina())
trayIcon = new TrayIcon(getImage(ImageUtil.SYS_TRAY_HI_RES));
else
@ -121,13 +121,13 @@ public class AWTSystemTray {
}
}
public static void setStageHidden() {
public void setStageHidden() {
stage.hide();
isStageVisible = false;
showGuiItem.setLabel("Open exchange window");
}
private static Image getImage(String path) {
return new ImageIcon(AWTSystemTray.class.getResource(path), "system tray icon").getImage();
private Image getImage(String path) {
return new ImageIcon(SystemTray.class.getResource(path), "system tray icon").getImage();
}
}