Example usage for java.awt SystemTray getSystemTray

List of usage examples for java.awt SystemTray getSystemTray

Introduction

In this page you can find the example usage for java.awt SystemTray getSystemTray.

Prototype

public static SystemTray getSystemTray() 

Source Link

Document

Gets the SystemTray instance that represents the desktop's tray area.

Usage

From source file:org.gtdfree.GTDFree.java

private void aborting() {

    logger.debug("Cleanup while engine aborting."); //$NON-NLS-1$

    if (closed) {
        return;/*from   www .jav a2  s  .co  m*/
    }

    if (monitor != null) {
        monitor.close();
    }

    if (flasher != null) {
        flasher.dispose();
    }

    if (dbInfoDialog != null) {
        dbInfoDialog.dispose();
    }
    if (jFrame != null) {
        jFrame.dispose();
    }
    if (trayIconPopup != null) {
        trayIconPopup.setVisible(false);
    }
    if (trayIcon != null) {
        SystemTray.getSystemTray().remove(trayIcon);
    }

    if (stub != null) {
        try {
            stub = null;
            UnicastRemoteObject.unexportObject(this, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:de.bwravencl.controllerbuddy.gui.Main.java

private Main() {
    Singleton.start(this, SINGLETON_ID);

    frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {

        @Override/*from   ww  w  . j  a va 2  s .  c o  m*/
        public void windowClosing(final WindowEvent e) {
            super.windowClosing(e);

            if (showMenuItem != null)
                showMenuItem.setEnabled(true);
        }

        @Override
        public void windowDeiconified(final WindowEvent e) {
            super.windowDeiconified(e);

            if (showMenuItem != null)
                showMenuItem.setEnabled(false);
        }

        @Override
        public void windowIconified(final WindowEvent e) {
            super.windowIconified(e);

            if (showMenuItem != null)
                showMenuItem.setEnabled(true);
        }

        @Override
        public void windowOpened(final WindowEvent e) {
            super.windowOpened(e);

            if (showMenuItem != null)
                showMenuItem.setEnabled(false);
        }

    });

    frame.setBounds(DIALOG_BOUNDS_X, DIALOG_BOUNDS_Y, DIALOG_BOUNDS_WIDTH, DIALOG_BOUNDS_HEIGHT);
    frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final var icons = new ArrayList<Image>();
    for (final var path : ICON_RESOURCE_PATHS) {
        final var icon = new ImageIcon(Main.class.getResource(path));
        icons.add(icon.getImage());
    }
    frame.setIconImages(icons);

    frame.setJMenuBar(menuBar);

    menuBar.add(fileMenu);
    final QuitAction quitAction = new QuitAction();
    fileMenu.add(quitAction);
    menuBar.add(deviceMenu);

    if (windows) {
        menuBar.add(localMenu, 2);

        final var buttonGroupLocalState = new ButtonGroup();
        startLocalRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM"));
        startLocalRadioButtonMenuItem.setAction(new StartLocalAction());
        buttonGroupLocalState.add(startLocalRadioButtonMenuItem);
        localMenu.add(startLocalRadioButtonMenuItem);

        stopLocalRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM"));
        stopLocalRadioButtonMenuItem.setAction(new StopLocalAction());
        buttonGroupLocalState.add(stopLocalRadioButtonMenuItem);
        localMenu.add(stopLocalRadioButtonMenuItem);

        menuBar.add(clientMenu);

        final var buttonGroupClientState = new ButtonGroup();

        startClientRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM"));
        startClientRadioButtonMenuItem.setAction(new StartClientAction());
        buttonGroupClientState.add(startClientRadioButtonMenuItem);
        clientMenu.add(startClientRadioButtonMenuItem);

        stopClientRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM"));
        stopClientRadioButtonMenuItem.setAction(new StopClientAction());
        buttonGroupClientState.add(stopClientRadioButtonMenuItem);
        clientMenu.add(stopClientRadioButtonMenuItem);
    }

    final var buttonGroupServerState = new ButtonGroup();
    startServerRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM"));
    startServerRadioButtonMenuItem.setAction(new StartServerAction());
    buttonGroupServerState.add(startServerRadioButtonMenuItem);
    serverMenu.add(startServerRadioButtonMenuItem);

    stopServerRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM"));
    stopServerRadioButtonMenuItem.setAction(new StopServerAction());
    buttonGroupServerState.add(stopServerRadioButtonMenuItem);
    serverMenu.add(stopServerRadioButtonMenuItem);

    final var helpMenu = new JMenu(rb.getString("HELP_MENU"));
    menuBar.add(helpMenu);
    helpMenu.add(new ShowAboutDialogAction());

    frame.getContentPane().add(tabbedPane);

    settingsPanel = new JPanel();
    settingsPanel.setLayout(new GridBagLayout());

    settingsScrollPane.setViewportView(settingsPanel);
    tabbedPane.addTab(rb.getString("SETTINGS_TAB"), null, settingsScrollPane);

    final var panelGridBagConstraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0,
            GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 5);

    final var panelFlowLayout = new FlowLayout(FlowLayout.LEADING, 10, 10);

    final var pollIntervalPanel = new JPanel(panelFlowLayout);
    settingsPanel.add(pollIntervalPanel, panelGridBagConstraints);

    final var pollIntervalLabel = new JLabel(rb.getString("POLL_INTERVAL_LABEL"));
    pollIntervalLabel.setPreferredSize(new Dimension(120, 15));
    pollIntervalPanel.add(pollIntervalLabel);

    final var pollIntervalSpinner = new JSpinner(new SpinnerNumberModel(
            preferences.getInt(PREFERENCES_POLL_INTERVAL, OutputThread.DEFAULT_POLL_INTERVAL), 10, 500, 1));
    final JSpinner.DefaultEditor pollIntervalSpinnerEditor = new JSpinner.NumberEditor(pollIntervalSpinner,
            "#");
    ((DefaultFormatter) pollIntervalSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true);
    pollIntervalSpinner.setEditor(pollIntervalSpinnerEditor);
    pollIntervalSpinner.addChangeListener(
            e -> preferences.putInt(PREFERENCES_POLL_INTERVAL, (int) ((JSpinner) e.getSource()).getValue()));
    pollIntervalPanel.add(pollIntervalSpinner);

    if (windows) {
        final var vJoyDirectoryPanel = new JPanel(panelFlowLayout);
        settingsPanel.add(vJoyDirectoryPanel, panelGridBagConstraints);

        final var vJoyDirectoryLabel = new JLabel(rb.getString("VJOY_DIRECTORY_LABEL"));
        vJoyDirectoryLabel.setPreferredSize(new Dimension(120, 15));
        vJoyDirectoryPanel.add(vJoyDirectoryLabel);

        vJoyDirectoryLabel1 = new JLabel(
                preferences.get(PREFERENCES_VJOY_DIRECTORY, VJoyOutputThread.getDefaultInstallationPath()));
        vJoyDirectoryPanel.add(vJoyDirectoryLabel1);

        final var vJoyDirectoryButton = new JButton(new ChangeVJoyDirectoryAction());
        vJoyDirectoryPanel.add(vJoyDirectoryButton);

        final var vJoyDevicePanel = new JPanel(panelFlowLayout);
        settingsPanel.add(vJoyDevicePanel, panelGridBagConstraints);

        final var vJoyDeviceLabel = new JLabel(rb.getString("VJOY_DEVICE_LABEL"));
        vJoyDeviceLabel.setPreferredSize(new Dimension(120, 15));
        vJoyDevicePanel.add(vJoyDeviceLabel);

        final var vJoyDeviceSpinner = new JSpinner(new SpinnerNumberModel(
                preferences.getInt(PREFERENCES_VJOY_DEVICE, VJoyOutputThread.DEFAULT_VJOY_DEVICE), 1, 16, 1));
        final JSpinner.DefaultEditor vJoyDeviceSpinnerEditor = new JSpinner.NumberEditor(vJoyDeviceSpinner,
                "#");
        ((DefaultFormatter) vJoyDeviceSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true);
        vJoyDeviceSpinner.setEditor(vJoyDeviceSpinnerEditor);
        vJoyDeviceSpinner.addChangeListener(
                e -> preferences.putInt(PREFERENCES_VJOY_DEVICE, (int) ((JSpinner) e.getSource()).getValue()));
        vJoyDevicePanel.add(vJoyDeviceSpinner);

        final var hostPanel = new JPanel(panelFlowLayout);
        settingsPanel.add(hostPanel, panelGridBagConstraints);

        final var hostLabel = new JLabel(rb.getString("HOST_LABEL"));
        hostLabel.setPreferredSize(new Dimension(120, 15));
        hostPanel.add(hostLabel);

        hostTextField = new JTextField(preferences.get(PREFERENCES_HOST, ClientVJoyOutputThread.DEFAULT_HOST),
                10);
        final var setHostAction = new SetHostAction(hostTextField);
        hostTextField.addActionListener(setHostAction);
        hostTextField.addFocusListener(setHostAction);
        hostPanel.add(hostTextField);
    }

    final var portPanel = new JPanel(panelFlowLayout);
    settingsPanel.add(portPanel, panelGridBagConstraints);

    final var portLabel = new JLabel(rb.getString("PORT_LABEL"));
    portLabel.setPreferredSize(new Dimension(120, 15));
    portPanel.add(portLabel);

    final var portSpinner = new JSpinner(new SpinnerNumberModel(
            preferences.getInt(PREFERENCES_PORT, ServerOutputThread.DEFAULT_PORT), 1024, 65535, 1));
    final JSpinner.DefaultEditor portSpinnerEditor = new JSpinner.NumberEditor(portSpinner, "#");
    ((DefaultFormatter) portSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true);
    portSpinner.setEditor(portSpinnerEditor);
    portSpinner.addChangeListener(
            e -> preferences.putInt(PREFERENCES_PORT, (int) ((JSpinner) e.getSource()).getValue()));
    portPanel.add(portSpinner);

    final var timeoutPanel = new JPanel(panelFlowLayout);
    settingsPanel.add(timeoutPanel, panelGridBagConstraints);

    final var timeoutLabel = new JLabel(rb.getString("TIMEOUT_LABEL"));
    timeoutLabel.setPreferredSize(new Dimension(120, 15));
    timeoutPanel.add(timeoutLabel);

    final var timeoutSpinner = new JSpinner(new SpinnerNumberModel(
            preferences.getInt(PREFERENCES_TIMEOUT, ServerOutputThread.DEFAULT_TIMEOUT), 10, 60000, 1));
    final JSpinner.DefaultEditor timeoutSpinnerEditor = new JSpinner.NumberEditor(timeoutSpinner, "#");
    ((DefaultFormatter) timeoutSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true);
    timeoutSpinner.setEditor(timeoutSpinnerEditor);
    timeoutSpinner.addChangeListener(
            e -> preferences.putInt(PREFERENCES_TIMEOUT, (int) ((JSpinner) e.getSource()).getValue()));
    timeoutPanel.add(timeoutSpinner);

    final var alwaysOnTopSupported = Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
    if (alwaysOnTopSupported || preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, alwaysOnTopSupported)) {
        final var overlaySettingsPanel = new JPanel(panelFlowLayout);
        settingsPanel.add(overlaySettingsPanel, panelGridBagConstraints);

        final var overlayLabel = new JLabel(rb.getString("OVERLAY_LABEL"));
        overlayLabel.setPreferredSize(new Dimension(120, 15));
        overlaySettingsPanel.add(overlayLabel);

        final var showOverlayCheckBox = new JCheckBox(rb.getString("SHOW_OVERLAY_CHECK_BOX"));
        showOverlayCheckBox.setSelected(preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, true));
        showOverlayCheckBox.addActionListener(e -> {
            final boolean showOverlay = ((JCheckBox) e.getSource()).isSelected();

            preferences.putBoolean(PREFERENCES_SHOW_OVERLAY, showOverlay);
        });
        overlaySettingsPanel.add(showOverlayCheckBox);
    }

    if (windows) {
        if (preferences.getBoolean(PREFERENCES_SHOW_VR_OVERLAY, true)) {
            final var vrOverlaySettingsPanel = new JPanel(panelFlowLayout);
            settingsPanel.add(vrOverlaySettingsPanel, panelGridBagConstraints);

            final var vrOverlayLabel = new JLabel(rb.getString("VR_OVERLAY_LABEL"));
            vrOverlayLabel.setPreferredSize(new Dimension(120, 15));
            vrOverlaySettingsPanel.add(vrOverlayLabel);

            final var showVrOverlayCheckBox = new JCheckBox(rb.getString("SHOW_VR_OVERLAY_CHECK_BOX"));
            showVrOverlayCheckBox.setSelected(preferences.getBoolean(PREFERENCES_SHOW_VR_OVERLAY, true));
            showVrOverlayCheckBox.addActionListener(e -> {
                final var showVrOverlay = ((JCheckBox) e.getSource()).isSelected();

                preferences.putBoolean(PREFERENCES_SHOW_VR_OVERLAY, showVrOverlay);
            });
            vrOverlaySettingsPanel.add(showVrOverlayCheckBox);
        }

        final var preventPowerSaveModeSettingsPanel = new JPanel(panelFlowLayout);
        settingsPanel.add(preventPowerSaveModeSettingsPanel, panelGridBagConstraints);

        final var preventPowerSaveModeLabel = new JLabel(rb.getString("POWER_SAVE_MODE_LABEL"));
        preventPowerSaveModeLabel.setPreferredSize(new Dimension(120, 15));
        preventPowerSaveModeSettingsPanel.add(preventPowerSaveModeLabel);

        final var preventPowerSaveModeCheckBox = new JCheckBox(
                rb.getString("PREVENT_POWER_SAVE_MODE_CHECK_BOX"));
        preventPowerSaveModeCheckBox
                .setSelected(preferences.getBoolean(PREFERENCES_PREVENT_POWER_SAVE_MODE, true));
        preventPowerSaveModeCheckBox.addActionListener(e -> {
            final var preventPowerSaveMode = ((JCheckBox) e.getSource()).isSelected();

            preferences.putBoolean(PREFERENCES_PREVENT_POWER_SAVE_MODE, preventPowerSaveMode);
        });
        preventPowerSaveModeSettingsPanel.add(preventPowerSaveModeCheckBox);
    }

    if (SystemTray.isSupported()) {
        final var popupMenu = new PopupMenu();

        final var showAction = new ShowAction();
        showMenuItem = new MenuItem((String) showAction.getValue(Action.NAME));
        showMenuItem.addActionListener(showAction);
        popupMenu.add(showMenuItem);

        popupMenu.addSeparator();

        final var openMenuItem = new MenuItem((String) openAction.getValue(Action.NAME));
        openMenuItem.addActionListener(openAction);
        popupMenu.add(openMenuItem);

        popupMenu.addSeparator();

        final var quitMenuItem = new MenuItem((String) quitAction.getValue(Action.NAME));
        quitMenuItem.addActionListener(quitAction);
        popupMenu.add(quitMenuItem);

        trayIcon = new TrayIcon(frame.getIconImage());
        trayIcon.addActionListener(showAction);
        trayIcon.setPopupMenu(popupMenu);
        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (final AWTException e) {
            log.log(Logger.Level.ERROR, e.getMessage(), e);
        }
    }

    updateTitleAndTooltip();

    settingsPanel.add(Box.createGlue(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0,
            GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

    final var outsideBorder = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
    final var insideBorder = BorderFactory.createEmptyBorder(0, 5, 0, 5);
    statusLabel.setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder));
    frame.add(statusLabel, BorderLayout.SOUTH);

    final var glfwInitialized = glfwInit();
    if (!glfwInitialized)
        if (windows)
            JOptionPane.showMessageDialog(frame, rb.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT_WINDOWS"),
                    rb.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE);
        else {
            JOptionPane.showMessageDialog(frame, rb.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT"),
                    rb.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE);
            quit();
        }

    final var presentJids = new HashSet<Integer>();
    for (var jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
        if (glfwJoystickPresent(jid) && glfwJoystickIsGamepad(jid))
            presentJids.add(jid);

    final var lastControllerGuid = preferences.get(PREFERENCES_LAST_CONTROLLER, null);
    for (final var jid : presentJids) {
        final var lastControllerFound = lastControllerGuid != null
                ? lastControllerGuid.equals(glfwGetJoystickGUID(jid))
                : false;

        if (!isSelectedJidValid() || lastControllerFound)
            selectedJid = jid;

        if (lastControllerFound)
            break;
    }

    newProfile();

    onControllersChanged(true);

    glfwSetJoystickCallback(new GLFWJoystickCallback() {

        @Override
        public void invoke(final int jid, final int event) {
            final var disconnected = event == GLFW_DISCONNECTED;
            if (disconnected || glfwJoystickIsGamepad(jid)) {
                if (disconnected && selectedJid == jid)
                    selectedJid = INVALID_JID;

                invokeOnEventDispatchThreadIfRequired(() -> onControllersChanged(false));
            }

        }
    });

    if (glfwInitialized && presentJids.isEmpty()) {
        if (windows)
            JOptionPane.showMessageDialog(frame, rb.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT_WINDOWS"),
                    rb.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE);
        else
            JOptionPane.showMessageDialog(frame, rb.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT"),
                    rb.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE);
    } else {
        final String path = preferences.get(PREFERENCES_LAST_PROFILE, null);
        if (path != null)
            loadProfile(new File(path));
    }
}

From source file:org.yccheok.jstock.gui.MainFrame.java

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    isFormWindowClosedCalled = true;//  w w  w. j av a2s .c o  m

    try {
        ExecutorService _stockInfoDatabaseMetaPool = this.stockInfoDatabaseMetaPool;
        this.stockInfoDatabaseMetaPool = null;

        _stockInfoDatabaseMetaPool.shutdownNow();

        // Always be the first statement. As no matter what happen, we must
        // save all the configuration files.
        this.save();

        if (this.needToSaveUserDefinedDatabase) {
            // We are having updated user database in memory.
            // Save it to disk.
            this.saveUserDefinedDatabaseAsCSV(jStockOptions.getCountry(), stockInfoDatabase);
        }

        // Hide the icon immediately.
        TrayIcon _trayIcon = trayIcon;
        if (_trayIcon != null) {
            SystemTray.getSystemTray().remove(_trayIcon);
            trayIcon = null;
        }

        dettachAllAndStopAutoCompleteJComboBox();
        this.indicatorPanel.dettachAllAndStopAutoCompleteJComboBox();

        log.info("latestNewsTask stop...");

        if (this.latestNewsTask != null) {
            this.latestNewsTask.cancel(true);
        }

        _stockInfoDatabaseMetaPool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);

        // We suppose to call shutdownAll to clean up all network resources.
        // However, that will cause Exception in other threads if they are still using httpclient.
        // Exception in thread "Thread-4" java.lang.IllegalStateException: Connection factory has been shutdown.
        //
        // MultiThreadedHttpConnectionManager.shutdownAll();

        log.info("Widnow is closed.");
    } catch (Exception exp) {
        log.error("Unexpected error while trying to quit application", exp);
    }

    // All the above operations are done within try block, to ensure
    // System.exit(0) will always be called.
    //
    // Final clean up.
    System.exit(0);
}

From source file:org.yccheok.jstock.gui.JStock.java

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    isFormWindowClosedCalled = true;//from   w  w w.ja  v  a 2 s  .co  m

    try {
        ExecutorService _stockInfoDatabaseMetaPool = this.stockInfoDatabaseMetaPool;
        this.stockInfoDatabaseMetaPool = null;

        _stockInfoDatabaseMetaPool.shutdownNow();

        // Always be the first statement. As no matter what happen, we must
        // save all the configuration files.
        this.save();

        if (this.needToSaveUserDefinedDatabase) {
            // We are having updated user database in memory.
            // Save it to disk.
            this.saveUserDefinedDatabaseAsCSV(jStockOptions.getCountry(), stockInfoDatabase);
        }

        // Hide the icon immediately.
        TrayIcon _trayIcon = trayIcon;
        if (_trayIcon != null) {
            SystemTray.getSystemTray().remove(_trayIcon);
            trayIcon = null;
        }

        dettachAllAndStopAutoCompleteJComboBox();
        this.indicatorPanel.dettachAllAndStopAutoCompleteJComboBox();

        log.info("latestNewsTask stop...");

        if (this.latestNewsTask != null) {
            this.latestNewsTask.cancel(true);
        }

        _stockInfoDatabaseMetaPool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);

        // We suppose to call shutdownAll to clean up all network resources.
        // However, that will cause Exception in other threads if they are still using httpclient.
        // Exception in thread "Thread-4" java.lang.IllegalStateException: Connection factory has been shutdown.
        //
        // MultiThreadedHttpConnectionManager.shutdownAll();

        log.info("Widnow is closed.");
    } catch (Exception exp) {
        log.error("Unexpected error while trying to quit application", exp);
    }

    Platform.exit();

    // All the above operations are done within try block, to ensure
    // System.exit(0) will always be called.
    //
    // Final clean up.
    System.exit(0);
}

From source file:org.gtdfree.GTDFree.java

private ActionMap getActionMap() {
    if (actionMap == null) {
        actionMap = new ActionMap();

        AbstractAction a = new AbstractAction(Messages.getString("GTDFree.View.Closed")) { //$NON-NLS-1$
            private static final long serialVersionUID = 1L;

            @Override//from   ww  w . j  a v a 2 s .c o m
            public void actionPerformed(ActionEvent e) {
                getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_ALL_ACTIONS,
                        !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_ALL_ACTIONS));
            }
        };
        a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Closed.desc")); //$NON-NLS-1$
        actionMap.put(GlobalProperties.SHOW_ALL_ACTIONS, a);

        a = new AbstractAction(Messages.getString("GTDFree.View.Empty")) { //$NON-NLS-1$
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_EMPTY_FOLDERS, !getEngine()
                        .getGlobalProperties().getBoolean(GlobalProperties.SHOW_EMPTY_FOLDERS, true));
            }
        };
        a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Empty.desc")); //$NON-NLS-1$
        actionMap.put(GlobalProperties.SHOW_EMPTY_FOLDERS, a);

        a = new AbstractAction(Messages.getString("GTDFree.View.ClosedLists")) { //$NON-NLS-1$
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_CLOSED_FOLDERS,
                        !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_CLOSED_FOLDERS));
            }
        };
        a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.ClosedLists.desc")); //$NON-NLS-1$
        actionMap.put(GlobalProperties.SHOW_CLOSED_FOLDERS, a);

        a = new AbstractAction(Messages.getString("GTDFree.View.Overview")) { //$NON-NLS-1$
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_OVERVIEW_TAB,
                        !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_OVERVIEW_TAB));
            }
        };
        a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Overview.desc")); //$NON-NLS-1$
        actionMap.put(GlobalProperties.SHOW_OVERVIEW_TAB, a);

        a = new AbstractAction(Messages.getString("GTDFree.View.Quick")) { //$NON-NLS-1$
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent e) {
                getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_QUICK_COLLECT,
                        !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_QUICK_COLLECT));
            }
        };
        a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Quick.desc")); //$NON-NLS-1$
        actionMap.put(GlobalProperties.SHOW_QUICK_COLLECT, a);

        a = new AbstractAction(Messages.getString("GTDFree.View.Tray")) { //$NON-NLS-1$
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent e) {
                boolean b = !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_TRAY_ICON);
                getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_TRAY_ICON, b);
                if (b) {
                    try {
                        SystemTray.getSystemTray().add(getTrayIcon());
                    } catch (AWTException e1) {
                        Logger.getLogger(this.getClass()).error("System tray icon initialization failed.", e1); //$NON-NLS-1$
                    }
                } else {
                    SystemTray.getSystemTray().remove(getTrayIcon());
                }
            }
        };
        a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Tray.desc")); //$NON-NLS-1$
        a.setEnabled(SystemTray.isSupported());
        actionMap.put(GlobalProperties.SHOW_TRAY_ICON, a);

        a = new AbstractAction(Messages.getString("GTDFree.ImportExamples")) { //$NON-NLS-1$
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent e) {
                getImportDialog().getDialog(getJFrame()).setVisible(true);
            }
        };
        a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.ImportExamples.desc")); //$NON-NLS-1$
        actionMap.put("importDialog", a); //$NON-NLS-1$
    }

    return actionMap;
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

private void minimizeToTray() {

    if (SystemTray.isSupported()) {

        trayIcon = new TrayIcon(getImage("open_alt-small.png").getImage());

        trayIcon.addMouseListener(new MouseAdapter() {
            @Override//from   www. ja  v  a 2 s  .com
            public void mouseClicked(MouseEvent e) {
                trayIconClicked();
            }
        });

        trayIcon.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                trayIconClicked();
            }
        });

        //      trayIcon.setPopupMenu(popup);

        trayIcon.setToolTip(APP_NAME);

        try {
            SystemTray.getSystemTray().add(trayIcon);
            mainFrame.setVisible(false);
        } catch (AWTException e1) {
            throw new RuntimeException(e1);
        }

    }
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

protected void trayIconClicked() {
    mainFrame.setVisible(true);
    mainFrame.setExtendedState(JFrame.NORMAL);
    SystemTray.getSystemTray().remove(trayIcon);
    trayIcon = null;
}

From source file:com.puzzle.gui.MainFrame.java

public void tray() {//-----ljs
    tray = SystemTray.getSystemTray(); // ?     
    PopupMenu pop = new PopupMenu(); // ????  
    final MenuItem show = new MenuItem("?");
    final MenuItem exit = new MenuItem("?");
    pop.add(show);/*w ww .j a  v  a  2 s . co  m*/
    pop.add(exit);
    show.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showMouseClick(e);
        }
    });
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            exitMouseClick(e);
        }
    });

    trayIcon = new TrayIcon(
            Toolkit.getDefaultToolkit().getImage(MainFrame.class.getResource("/images/flag.png")),
            "??V1.0", pop);//  
    trayIcon.setImageAutoSize(true);
    //?  
    trayIcon.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            trayIconMouseClick(e);
        }
    });

    try {
        tray.add(trayIcon); //   
    } catch (AWTException ex) {
        log.error(ex.getMessage(), ex);
        ex.printStackTrace();
    }

}

From source file:neembuu.uploader.NeembuuUploader.java

private void formWindowIconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowIconified
    if (!Application.get(Settings.class).minimizetotray() || !SystemTray.isSupported() || trayIcon == null
            || !isActive()) {//from   w  w  w.  j  a  v a2  s .  co m
        return;
    }
    NULogger.getLogger().info("Minimizing to Tray");
    setVisible(false);
    try {
        SystemTray.getSystemTray().add(trayIcon);
    } catch (AWTException ex) {
        setVisible(true);
        Logger.getLogger(NeembuuUploader.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ui.main.MainViewController.java

private void showNotifications(String chat, String message) {
    // a general method for view notifications -> windows notification
    if (!isnotifiable.isSelected()) {
        return;// www. j  a  v  a  2  s.  com
    }
    URL url = System.class.getResource("/resources/LogoTransparent.png");
    java.awt.Image image = Toolkit.getDefaultToolkit().getImage(url);
    TrayIcon trayIcon = new TrayIcon(image, "Instant Messenger Plus");
    if (SystemTray.isSupported()) {
        SystemTray tray = SystemTray.getSystemTray();

        trayIcon.setImageAutoSize(true);
        try {
            tray.add(trayIcon);

        } catch (AWTException e) {
            System.err.println("TrayIcon could not be added.");
        }

        trayIcon.displayMessage("IMP: " + chat, message, TrayIcon.MessageType.INFO);
    }
}