Search in sources :

Example 1 with Taskbar

use of java.awt.Taskbar 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)

Aggregations

Font (java.awt.Font)1 Image (java.awt.Image)1 Taskbar (java.awt.Taskbar)1 JFXPanel (javafx.embed.swing.JFXPanel)1 ToolTipManager (javax.swing.ToolTipManager)1 ExitCode (net.sf.mzmine.util.ExitCode)1 MultiLineToolTipUI (net.sf.mzmine.util.components.MultiLineToolTipUI)1