List of usage examples for javafx.application Platform setImplicitExit
public static void setImplicitExit(boolean implicitExit)
From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java
private void initializeUI() { Wandora wandora = Wandora.getWandora(); if (options == null) { if (USE_LOCAL_OPTIONS) { options = new Options(wandora.getOptions()); } else {/*from w w w. j av a 2 s. c o m*/ options = wandora.getOptions(); } } tm = wandora.getTopicMap(); initComponents(); Platform.setImplicitExit(false); final WandoraJFXPanel fxPanel = new WandoraJFXPanel(); fxPanelHandle = fxPanel; this.add(fxPanel, BorderLayout.CENTER); Platform.runLater(new Runnable() { @Override public void run() { initFX(fxPanel); browse(rootTopic); } }); this.addComponentListener(this); backButton.setText(""); backButton.setIcon(UIBox.getIcon("gui/icons/webview/backward.png")); forwardButton.setText(""); forwardButton.setIcon(UIBox.getIcon("gui/icons/webview/forward.png")); stopButton.setText(""); stopButton.setIcon(UIBox.getIcon("gui/icons/webview/stop.png")); reloadButton.setText(""); reloadButton.setIcon(UIBox.getIcon("gui/icons/webview/reload.png")); menuButton.setText(""); menuButton.setIcon(UIBox.getIcon("gui/icons/webview/menu.png")); }
From source file:org.yccheok.jstock.gui.JStock.java
/** * @param args the command line arguments *//*from ww w . jav a 2 s. com*/ public static void main(String args[]) { /*********************************************************************** * UI Manager initialization via JStockOptions. **********************************************************************/ final JStockOptions jStockOptions = getJStockOptionsViaXML(); // OSX menu bar at top. if (Utils.isMacOSX()) { System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("apple.awt.brushMetalLook", "true"); } boolean uiManagerLookAndFeelSuccess = false; try { String lookNFeel = jStockOptions.getLooknFeel(); if (null != lookNFeel) { UIManager.setLookAndFeel(lookNFeel); uiManagerLookAndFeelSuccess = true; } } catch (java.lang.ClassNotFoundException | java.lang.InstantiationException | java.lang.IllegalAccessException | javax.swing.UnsupportedLookAndFeelException exp) { log.error(null, exp); } if (!uiManagerLookAndFeelSuccess) { String className = Utils.setDefaultLookAndFeel(); if (null != className) { final String lookNFeel = jStockOptions.getLooknFeel(); // When jStockOptions.getLookNFeel returns null, it means we wish // to use system default value. Hence, don't overwrite the null value, // so that we can use the same jStockOptions, across different // platforms. if (lookNFeel != null) { jStockOptions.setLooknFeel(className); } } } /*********************************************************************** * Ensure correct localization. **********************************************************************/ // This global effect, should just come before anything else, // after we get an instance of JStockOptions. Locale.setDefault(jStockOptions.getLocale()); /*********************************************************************** * Single application instance enforcement. **********************************************************************/ if (false == AppLock.lock()) { final int choice = JOptionPane.showOptionDialog(null, MessagesBundle.getString("warning_message_running_2_jstock"), MessagesBundle.getString("warning_title_running_2_jstock"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { MessagesBundle.getString("yes_button_running_2_jstock"), MessagesBundle.getString("no_button_running_2_jstock") }, MessagesBundle.getString("no_button_running_2_jstock")); if (choice != JOptionPane.YES_OPTION) { System.exit(0); return; } } // Avoid "JavaFX IllegalStateException when disposing JFXPanel in Swing" // http://stackoverflow.com/questions/16867120/javafx-illegalstateexception-when-disposing-jfxpanel-in-swing Platform.setImplicitExit(false); // As ProxyDetector is affected by system properties // http.proxyHost, we are forced to initialized ProxyDetector right here, // before we manually change the system properties according to // JStockOptions. ProxyDetector.getInstance(); /*********************************************************************** * Apply large font if possible. **********************************************************************/ if (jStockOptions.useLargeFont()) { java.util.Enumeration keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value != null && value instanceof javax.swing.plaf.FontUIResource) { javax.swing.plaf.FontUIResource fr = (javax.swing.plaf.FontUIResource) value; UIManager.put(key, new javax.swing.plaf.FontUIResource( fr.deriveFont((float) fr.getSize2D() * (float) Constants.FONT_ENLARGE_FACTOR))); } } } /*********************************************************************** * GA tracking. **********************************************************************/ GA.trackAsynchronously("main"); java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { final JStock mainFrame = JStock.instance(); // We need to first assign jStockOptions to mainFrame, as during // Utils.migrateXMLToCSVPortfolios, we will be accessing mainFrame's // jStockOptions. mainFrame.initJStockOptions(jStockOptions); mainFrame.init(); mainFrame.setVisible(true); mainFrame.updateDividerLocation(); mainFrame.requestFocusOnJComboBox(); } }); }
From source file:utybo.branchingstorytree.swing.OpenBST.java
/** * Launch OpenBST/*www .j av a2s . co m*/ * * @param args * Arguments. The first argument is the language code to be used */ public static void main(final String[] args) { // Before we do anything, setup system properties // First one to ensure Java 9's scaling system gets out of the way System.setProperty("sun.java2d.uiScale", "1.0"); // Second one to force hardware acceleration System.setProperty("sun.java2d.opengl", "true"); LOG.info("OpenBST version " + VERSION + ", part of the BST project"); LOG.trace("[ INIT ]"); LOG.trace("Loading language files"); loadLang(args.length > 0 ? args[0] : null); LOG.trace("Applying Look and Feel"); OpenBSTGUI.initializeLaF(); VisualsUtils.fixTextFontScaling(); LOG.trace("Loading scaling factor"); Icons.loadScalingFactor(); Splashscreen sc = Splashscreen.start(); SwingWorker<Void, String> sw = new SwingWorker<Void, String>() { @Override protected Void doInBackground() { LOG.trace("Initializing JavaFX"); publish(Lang.get("splash.init")); // Necessary - because we are killing Scenes all the time with WebViews in NodePanels, // JFX may think we just ended our application. // OpenBST exits with a dirty System.exit() anyway. Platform.setImplicitExit(false); // Initialize JavaFX new JFXPanel(); VisualsUtils.invokeJfxAndWait(() -> { // Initialize the web engine new WebEngine(); // Initialize a view new WebView(); }); LOG.info("Loading icons..."); publish(Lang.get("splash.icons")); long timeAtIconStart = System.currentTimeMillis(); Icons.load(); LOG.info("Time taken to load icons : " + (System.currentTimeMillis() - timeAtIconStart) + " ms"); LOG.info("Loading backgrounds..."); publish(Lang.get("splash.loadbg")); Icons.loadBackgrounds(); // $EXPERIMENTAL LOG.info("Caching backgrounds..."); publish(Lang.get("splash.processbg")); IMGClient.initInternal(); // $EXPERIMENTAL LOG.info("Loading internal BTS files..."); publish(Lang.get("splash.loadinternalbst")); loadInternalBSTFiles(); return null; } @Override protected void process(List<String> chunks) { String s = chunks.get(chunks.size() - 1); sc.setText(s); } }; sw.execute(); try { sw.get(); } catch (InterruptedException | ExecutionException e1) { OpenBST.LOG.error(e1); } VisualsUtils.invokeSwingAndWait(() -> { sc.setText(Lang.get("splash.launch")); sc.lock(); sc.stop(); }); LOG.trace("Launching app..."); OpenBSTGUI.launch(); VisualsUtils.invokeSwingAndWait(() -> sc.dispose()); LOG.trace("Checking versions..."); if (!"<unknown version>".equals(VERSION)) { SwingWorker<UpdateInfo, Void> worker = new SwingWorker<UpdateInfo, Void>() { @Override protected UpdateInfo doInBackground() throws Exception { URL updateInfoSite = new URL("https://utybo.github.io/BST/version.json"); UpdateInfo info = new Gson().fromJson( new InputStreamReader(updateInfoSite.openStream(), StandardCharsets.UTF_8), UpdateInfo.class); return info; } @Override protected void done() { try { UpdateInfo remoteVersion = this.get(); ComparableVersion remoteUnstable = new ComparableVersion(remoteVersion.unstable), remoteStable = new ComparableVersion(remoteVersion.stable); ComparableVersion local = new ComparableVersion(VERSION.substring(0, VERSION.length() - 1)); if (VERSION.endsWith("u")) { // Local version is unstable // Show updates to either the most recent unstable or the most recent stable if (local.compareTo(remoteStable) < 0 && remoteStable.compareTo(remoteUnstable) < 0) { // local (unstable) < stable < unstable // Give options for both unstable and stable JButton stablebtn = new JButton(Lang.get("up.moreinfostable")); stablebtn.addActionListener(e -> { VisualsUtils.browse(remoteVersion.stableurl); }); JButton unstablebtn = new JButton(Lang.get("up.moreinfounstable")); unstablebtn.addActionListener(e -> { VisualsUtils.browse(remoteVersion.unstableurl); }); OpenBSTGUI.getInstance() .addBanner(new JBannerPanel( new ImageIcon(Icons.getImage("Installing Updates", 48)), new Color(142, 255, 159), Lang.get("up.message1"), stablebtn, false, unstablebtn)); } else if (remoteStable.compareTo(local) < 0 && local.compareTo(remoteUnstable) < 0) { // stable < local (unstable) < unstable JButton unstablebtn = new JButton(Lang.get("up.moreinfo")); unstablebtn.addActionListener(e -> { VisualsUtils.browse(remoteVersion.unstableurl); }); OpenBSTGUI.getInstance().addBanner(new JBannerPanel( new ImageIcon(Icons.getImage("Installing Updates", 48)), new Color(142, 255, 159), Lang.get("up.message2"), unstablebtn, false)); } else if (remoteUnstable.compareTo(remoteStable) < 0 && local.compareTo(remoteStable) < 0) { // local (unstable) < stable // and unstable < stable JButton stablebtn = new JButton(Lang.get("up.moreinfo")); stablebtn.addActionListener(e -> { VisualsUtils.browse(remoteVersion.stableurl); }); OpenBSTGUI.getInstance().addBanner(new JBannerPanel( new ImageIcon(Icons.getImage("Installing Updates", 48)), new Color(142, 255, 159), Lang.get("up.message3"), stablebtn, false)); } } else { // If we're not running an unstable version, the only interesting case is local < stable if (local.compareTo(remoteStable) < 0) { // local (stable) < stable JButton stablebtn = new JButton(Lang.get("up.moreinfo")); stablebtn.addActionListener(e -> { VisualsUtils.browse(remoteVersion.stableurl); }); OpenBSTGUI.getInstance().addBanner(new JBannerPanel( new ImageIcon(Icons.getImage("Installing Updates", 48)), new Color(142, 255, 159), Lang.get("up.message4"), stablebtn, false)); } } } catch (InterruptedException | ExecutionException e) { LOG.warn("Failed to read update information", e); JButton showDetails = new JButton(Lang.get("up.showdetails")); showDetails.addActionListener(ev -> Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("up.failedmessage"), e)); OpenBSTGUI.getInstance() .addBanner(new JBannerPanel(new ImageIcon(Icons.getImage("Cancel", 16)), new Color(255, 144, 144), Lang.get("up.failedbanner"), showDetails, false)); } } }; worker.execute(); } }
From source file:view.EditorView.java
@Override public void start(Stage primaryStage) throws Exception { Platform.setImplicitExit(true); bundle = ResourceBundle.getBundle("view.strings"); stage = primaryStage;//from ww w . j a v a 2 s. com try { Parent root = FXMLLoader.load(getClass().getResource("EditorMain.fxml"), bundle); Scene scene = new Scene(root); scene.getStylesheets().add(getClass().getResource("EditorMain.css").toExternalForm()); primaryStage.setMinWidth(scene.getRoot().minWidth(0) + 70); primaryStage.setMinHeight(scene.getRoot().minHeight(0) + 70); primaryStage.setScene(scene); // Set Icon primaryStage.getIcons().add(new Image(MainWindow.class.getResourceAsStream("icon.png"))); primaryStage.show(); } catch (Exception e) { FOKLogger.log(MainWindow.class.getName(), Level.SEVERE, "An error occurred", e); } }