Search in sources :

Example 51 with JFXPanel

use of javafx.embed.swing.JFXPanel in project mzmine2 by mzmine.

the class DesktopSetup method init.

public void init() {
    // Get tooltip manager instance
    ToolTipManager tooltipManager = ToolTipManager.sharedInstance();
    // Set tooltip display after 10 ms
    tooltipManager.setInitialDelay(10);
    // Never dismiss tooltips
    tooltipManager.setDismissDelay(Integer.MAX_VALUE);
    // Prepare default fonts
    Font defaultFont = new Font("SansSerif", Font.PLAIN, 13);
    Font smallFont = new Font("SansSerif", Font.PLAIN, 11);
    Font tinyFont = new Font("SansSerif", Font.PLAIN, 10);
    // Set default font
    Enumeration<Object> keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof Font)
            UIManager.put(key, defaultFont);
    }
    // Set small font where necessary
    UIManager.put("List.font", smallFont);
    UIManager.put("Table.font", smallFont);
    UIManager.put("ToolTip.font", tinyFont);
    // Set platform look & feel
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    // ignore
    }
    // Set tooltip UI to support multi-line tooltips
    UIManager.put("ToolTipUI", MultiLineToolTipUI.class.getName());
    UIManager.put(MultiLineToolTipUI.class.getName(), MultiLineToolTipUI.class);
    // Set basic desktop handlers
    final java.awt.Desktop awtDesktop = java.awt.Desktop.getDesktop();
    if (awtDesktop != null) {
        // Setup About handler
        if (awtDesktop.isSupported(java.awt.Desktop.Action.APP_ABOUT)) {
            awtDesktop.setAboutHandler(e -> {
                MainWindow mainWindow = (MainWindow) MZmineCore.getDesktop();
                mainWindow.showAboutDialog();
            });
        }
        // Setup Quit handler
        if (awtDesktop.isSupported(java.awt.Desktop.Action.APP_QUIT_HANDLER)) {
            awtDesktop.setQuitHandler((e, response) -> {
                ExitCode exitCode = MZmineCore.getDesktop().exitMZmine();
                if (exitCode == ExitCode.OK)
                    response.performQuit();
                else
                    response.cancelQuit();
            });
        }
    }
    if (Taskbar.isTaskbarSupported()) {
        final Taskbar taskBar = Taskbar.getTaskbar();
        // Set the app icon
        if (taskBar.isSupported(Taskbar.Feature.ICON_IMAGE)) {
            final Image mzmineIcon = MZmineCore.getDesktop().getMZmineIcon();
            if (mzmineIcon != null)
                taskBar.setIconImage(mzmineIcon);
        }
        // Add a task controller listener to show task progress
        MZmineCore.getTaskController().addTaskControlListener((numOfWaitingTasks, percentDone) -> {
            if (numOfWaitingTasks > 0) {
                if (taskBar.isSupported(Taskbar.Feature.ICON_BADGE_NUMBER)) {
                    String badge = String.valueOf(numOfWaitingTasks);
                    taskBar.setIconBadge(badge);
                }
                if (taskBar.isSupported(Taskbar.Feature.PROGRESS_STATE_WINDOW))
                    taskBar.setWindowProgressState(MZmineCore.getDesktop().getMainWindow(), Taskbar.State.NORMAL);
                if (taskBar.isSupported(Taskbar.Feature.PROGRESS_VALUE))
                    taskBar.setProgressValue(percentDone);
                if (taskBar.isSupported(Taskbar.Feature.PROGRESS_VALUE_WINDOW))
                    taskBar.setWindowProgressValue(MZmineCore.getDesktop().getMainWindow(), percentDone);
            } else {
                if (taskBar.isSupported(Taskbar.Feature.ICON_BADGE_NUMBER))
                    taskBar.setIconBadge(null);
                if (taskBar.isSupported(Taskbar.Feature.PROGRESS_STATE_WINDOW))
                    taskBar.setWindowProgressState(MZmineCore.getDesktop().getMainWindow(), Taskbar.State.OFF);
                if (taskBar.isSupported(Taskbar.Feature.PROGRESS_VALUE))
                    taskBar.setProgressValue(-1);
                if (taskBar.isSupported(Taskbar.Feature.PROGRESS_VALUE_WINDOW))
                    taskBar.setWindowProgressValue(MZmineCore.getDesktop().getMainWindow(), -1);
            }
        });
    }
    // Let the OS decide the location of new windows. Otherwise, all windows
    // would appear at the top left corner by default.
    System.setProperty("java.awt.Window.locationByPlatform", "true");
    // Initialize JavaFX
    try {
        logger.finest("Initializing the JavaFX subsystem by creating a JFXPanel instance");
        @SuppressWarnings("unused") JFXPanel dummyPanel = new JFXPanel();
        Platform.setImplicitExit(false);
    } catch (Throwable e) {
        logger.log(Level.WARNING, "Failed to initialize JavaFX", e);
        e.printStackTrace();
    }
}
Also used : ToolTipManager(javax.swing.ToolTipManager) JFXPanel(javafx.embed.swing.JFXPanel) ExitCode(net.sf.mzmine.util.ExitCode) Image(java.awt.Image) Font(java.awt.Font) MultiLineToolTipUI(net.sf.mzmine.util.components.MultiLineToolTipUI) Taskbar(java.awt.Taskbar)

Example 52 with JFXPanel

use of javafx.embed.swing.JFXPanel in project gs-ui-javafx by graphstream.

the class FxFileSinkImages method initImage.

@Override
protected void initImage() {
    // 
    // Little hack to initialize JavaFX Toolkit.
    // 
    new JFXPanel();
    image = new WritableImage(resolution.getWidth(), resolution.getHeight());
    canvas = new Canvas(resolution.getWidth(), resolution.getHeight());
}
Also used : WritableImage(javafx.scene.image.WritableImage) JFXPanel(javafx.embed.swing.JFXPanel) Canvas(javafx.scene.canvas.Canvas)

Aggregations

JFXPanel (javafx.embed.swing.JFXPanel)52 Scene (javafx.scene.Scene)16 Test (org.junit.Test)16 CountDownLatch (java.util.concurrent.CountDownLatch)11 Dimension (java.awt.Dimension)6 BorderPane (javafx.scene.layout.BorderPane)6 Stage (javafx.stage.Stage)6 FXMLLoader (javafx.fxml.FXMLLoader)5 WebView (javafx.scene.web.WebView)5 BorderLayout (java.awt.BorderLayout)4 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 ExecutorService (java.util.concurrent.ExecutorService)4 JFrame (javax.swing.JFrame)4 IOException (java.io.IOException)3 WebEngine (javafx.scene.web.WebEngine)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 Random (java.util.Random)2 FutureTask (java.util.concurrent.FutureTask)2 Memory (php.runtime.Memory)2