Example usage for javafx.embed.swing JFXPanel JFXPanel

List of usage examples for javafx.embed.swing JFXPanel JFXPanel

Introduction

In this page you can find the example usage for javafx.embed.swing JFXPanel JFXPanel.

Prototype

public JFXPanel() 

Source Link

Document

Creates a new JFXPanel object.

Usage

From source file:utybo.branchingstorytree.swing.OpenBST.java

/**
 * Launch OpenBST//  w w w  .  ja  v a 2s  .c  o  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:Main.java

private static void initAndShowGUI() {
    final JFrame frame = new JFrame("JavaFX / Swing Integrated");
    final JFXPanel fxPanel = new JFXPanel();
    frame.add(fxPanel);/*from  w  w  w .j  a va 2s  .co  m*/
    frame.setVisible(true);

    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            initFX(fxPanel);
        }
    });
}

From source file:org.pidpys.standalone.configuration.JavaFxApplicationConfiguration.java

@PostConstruct
public void init() {
    new JFXPanel();
    Platform.setImplicitExit(false);
}

From source file:utybo.branchingstorytree.swing.impl.SSBClient.java

public SSBClient(final StoryPanel panel) {
    new JFXPanel(); // Init JavaFX
    this.panel = panel;
}

From source file:org.mskcc.shenkers.control.track.fasta.FastaViewNGTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    new JFXPanel();
    Platform.setImplicitExit(false);
}

From source file:com.adobe.ags.curly.test.ErrorBehaviorTest.java

@BeforeClass
public static void setUpClass() throws IOException, InterruptedException {
    new ToolkitApplicationLauncher().init();
    new JFXPanel();
    webserver = TestWebServer.getServer();
    webserver.requireLogin = true;//from   ww w  .j av a  2s  .  co m
}

From source file:view.TimelinePanel.java

/**
 * Creates new form TimelinePanel//  w w  w  .  j a va 2s. c  o  m
 */
public TimelinePanel() {
    initComponents();

    fxPanel = new JFXPanel();
    final Dimension size = new Dimension(960, 750);
    fxPanel.setSize(size);
    setLayout(new BorderLayout(0, 0));
    add(fxPanel);

    Platform.runLater(new Runnable() { // this will run initFX as JavaFX-Thread
        @Override
        public void run() {
            Group group = new Group();
            Scene scene = new Scene(group);
            fxPanel.setScene(scene);

            WebView webView = new WebView();

            group.getChildren().add(webView);
            webView.setMinSize(size.getWidth(), size.getHeight());
            webView.setMaxSize(size.getWidth(), size.getHeight());

            WebEngine webEngine = webView.getEngine();
            webEngine.load(
                    "http://cdn.knightlab.com/libs/timeline/latest/embed/index.html?source=0Ag1_iE674IuvdEFaZi0wOVBFY2l2OHdPUWlrZEMwaHc&font=Bevan-PotanoSans&maptype=toner&lang=en");
        }
    });
}

From source file:gui.accessories.GraphPopup.java

private void initAndShowFXGUI() {
    // This method is invoked on the EDT thread
    final JFXPanel fxPanel = new JFXPanel();

    Platform.runLater(new Runnable() {
        @Override//from w ww  .j a  v a 2 s .com
        public void run() {
            initFX(fxPanel);
        }
    });
}

From source file:gui.accessories.BattleSimFx.java

@Override
public void init() {
    tableModel = new SampleTableModel();
    // create javafx panel for charts
    chartFxPanel = new JFXPanel();
    chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT));

    //JTable//from  w w  w .ja va  2  s.  co m
    JTable table = new JTable(tableModel);
    table.setAutoCreateRowSorter(true);
    table.setGridColor(Color.DARK_GRAY);
    BattleSimFx.DecimalFormatRenderer renderer = new BattleSimFx.DecimalFormatRenderer();
    renderer.setHorizontalAlignment(JLabel.RIGHT);
    for (int i = 0; i < table.getColumnCount(); i++) {
        table.getColumnModel().getColumn(i).setCellRenderer(renderer);
    }
    JScrollPane tablePanel = new JScrollPane(table);
    tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT));

    JPanel chartTablePanel = new JPanel();
    chartTablePanel.setLayout(new BorderLayout());

    //Split pane that holds both chart and table
    JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    jsplitPane.setTopComponent(chartTablePanel);
    jsplitPane.setBottomComponent(tablePanel);
    jsplitPane.setDividerLocation(410);
    chartTablePanel.add(chartFxPanel, BorderLayout.CENTER);

    //          add(tablePanel, BorderLayout.CENTER);
    add(jsplitPane, BorderLayout.CENTER);

    // create JavaFX scene
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            createScene();
        }
    });
}

From source file:utybo.branchingstorytree.swing.visuals.NodePanel.java

public NodePanel(BranchingStory story, StoryPanel parent, final IMGClient imageClient) {
    OpenBSTGUI.getInstance().addDarkModeCallback(callback);
    callback.accept(OpenBSTGUI.getInstance().isDark());
    this.parent = parent;
    this.imageClient = imageClient;
    setLayout(new BorderLayout());

    JFXPanel panel = new JFXPanel();
    add(panel, BorderLayout.CENTER);

    CountDownLatch cdl = new CountDownLatch(1);
    Platform.runLater(() -> {//from  w w  w  .  j av a2 s. co m
        try {
            view = new WebView();
            view.getEngine().setOnAlert(e -> SwingUtilities
                    .invokeLater(() -> Messagers.showMessage(OpenBSTGUI.getInstance(), e.getData())));
            view.getEngine().getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> {
                if (newState == State.SUCCEEDED) {
                    Document doc = view.getEngine().getDocument();
                    NodeList nl = doc.getElementsByTagName("a");
                    for (int i = 0; i < nl.getLength(); i++) {
                        Node n = nl.item(i);
                        HTMLAnchorElement a = (HTMLAnchorElement) n;
                        if (a.getHref() != null) {
                            ((EventTarget) a).addEventListener("click", ev -> {
                                if (!hrefEnabled) {
                                    ev.preventDefault();
                                }
                            }, false);
                        }
                    }
                }
            });
            Scene sc = new Scene(view);
            try {
                view.getEngine()
                        .loadContent(IOUtils
                                .toString(
                                        NodePanel.class.getResourceAsStream(
                                                "/utybo/branchingstorytree/swing/html/error.html"),
                                        StandardCharsets.UTF_8)
                                .replace("$MSG", Lang.get("story.problem")).replace("$STYLE", FONT_UBUNTU));
            } catch (IOException e) {
                OpenBST.LOG.warn("Error on trying to load error HTML file", e);
            }
            panel.setScene(sc);
        } finally {
            cdl.countDown();
        }
    });
    try {
        cdl.await();
    } catch (InterruptedException e) {
        OpenBST.LOG.warn("Synchronization failed", e);
    }
}