Add comment for each major step in BitsquareUI#start

This commit is contained in:
Chris Beams 2014-11-03 19:15:57 +01:00
parent 78819d7e13
commit 2af861a776
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73

View file

@ -67,8 +67,14 @@ public class BitsquareUI extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
BitsquareUI.primaryStage = primaryStage; BitsquareUI.primaryStage = primaryStage;
Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> Popups.handleUncaughtExceptions
(Throwables.getRootCause(throwable))); // route uncaught exceptions to a user-facing dialog
Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) ->
Popups.handleUncaughtExceptions(Throwables.getRootCause(throwable)));
// configure the Bitsquare application data directory
try { try {
AppDirectory.initAppDir(Bitsquare.getAppName()); AppDirectory.initAppDir(Bitsquare.getAppName());
@ -77,10 +83,8 @@ public class BitsquareUI extends Application {
} }
// currently there is not SystemTray support for java fx (planned for version 3) so we use the old AWT // load and apply any stored settings
AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class), this);
// apply stored data
User user = injector.getInstance(User.class); User user = injector.getInstance(User.class);
Settings settings = injector.getInstance(Settings.class); Settings settings = injector.getInstance(Settings.class);
Persistence persistence = injector.getInstance(Persistence.class); Persistence persistence = injector.getInstance(Persistence.class);
@ -91,16 +95,10 @@ public class BitsquareUI extends Application {
settings.applyPersistedSettings((Settings) persistence.read(settings.getClass().getName())); settings.applyPersistedSettings((Settings) persistence.read(settings.getClass().getName()));
primaryStage.setTitle("Bitsquare (" + Bitsquare.getAppName() + ")");
// sometimes there is a rendering bug, see https://github.com/bitsquare/bitsquare/issues/160 // load the main view and create the main scene
if (ImageUtil.isRetina())
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/images/window_icon@2x.png")));
else
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/images/window_icon.png")));
ViewLoader.setInjector(injector); ViewLoader.setInjector(injector);
ViewLoader loader = new ViewLoader(Navigation.Item.MAIN, false); ViewLoader loader = new ViewLoader(Navigation.Item.MAIN, false);
Parent view = loader.load(); Parent view = loader.load();
@ -109,24 +107,31 @@ public class BitsquareUI extends Application {
"/io/bitsquare/gui/bitsquare.css", "/io/bitsquare/gui/bitsquare.css",
"/io/bitsquare/gui/images.css"); "/io/bitsquare/gui/images.css");
setupCloseHandlers(primaryStage, scene);
primaryStage.setScene(scene); // configure the system tray
primaryStage.setMinWidth(75); AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class), this);
primaryStage.setMinHeight(50);
primaryStage.show();
}
private void setupCloseHandlers(Stage primaryStage, Scene scene) {
primaryStage.setOnCloseRequest(e -> AWTSystemTray.setStageHidden()); primaryStage.setOnCloseRequest(e -> AWTSystemTray.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(); AWTSystemTray.setStageHidden();
}); });
// configure the primary stage
primaryStage.setTitle("Bitsquare (" + Bitsquare.getAppName() + ")");
primaryStage.setScene(scene);
primaryStage.setMinWidth(75);
primaryStage.setMinHeight(50);
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(
ImageUtil.isRetina() ? "/images/window_icon@2x.png" : "/images/window_icon.png")));
// make the UI visible
primaryStage.show();
} }
@Override @Override