Example usage for java.awt PopupMenu add

List of usage examples for java.awt PopupMenu add

Introduction

In this page you can find the example usage for java.awt PopupMenu add.

Prototype

public MenuItem add(MenuItem mi) 

Source Link

Document

Adds the specified menu item to this menu.

Usage

From source file:zxmax.tools.timerreview.Main.java

private TrayIcon getTrayIcon() throws AWTException {
    final TrayIcon trayIcon = new TrayIcon(
            createImage("images/bulb.gif", I18N.getLabel(getClass(), "tray.icon.description")));

    final SystemTray tray = SystemTray.getSystemTray();
    tray.add(trayIcon);//from w  ww. ja  v  a  2 s. com

    final PopupMenu popup = new PopupMenu();
    trayIcon.setPopupMenu(popup);

    /*
     * Serve per aprire il popup sulla tray icon con il tasto sx del mouse.
     * Il problema  chiuderla/nasconderla ...
     */
    // trayIcon.addMouseListener(new TrayIconMouseAdapter(popup));

    final MenuItem exitItem = new MenuItem(I18N.getLabel(getClass(), "exit"));
    final MenuItem newTimerItem = new MenuItem(I18N.getLabel(getClass(), "new.timer"));
    newTimerItem.setEnabled(false);
    final MenuItem infoItem = new MenuItem(I18N.getLabel(getClass(), "info"));
    popup.add(exitItem);
    popup.add(newTimerItem);
    popup.add(infoItem);

    exitItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tray.remove(trayIcon);
            System.exit(0);
        }
    });

    newTimerItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            StartTimerWindow timer = new StartTimerWindow();
            timer.setVisible(true);
        }
    });

    infoItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            InfoWindow infoWindow = new InfoWindow();
            infoWindow.setVisible(true);
            infoWindow.createBufferStrategy(1);
        }
    });
    return trayIcon;
}

From source file:com.loy.MainFrame.java

private void systemTray() {
    if (SystemTray.isSupported()) {
        ImageIcon icon = new ImageIcon(image);
        PopupMenu popupMenu = new PopupMenu();

        MenuItem itemShow = new MenuItem("Show");
        MenuItem itemExit = new MenuItem("Exit");
        itemExit.addActionListener(new ActionListener() {
            @Override/*from  w  w  w . j a v  a 2 s .  c  o m*/
            public void actionPerformed(ActionEvent e) {
                killProcess();
                System.exit(0);
            }
        });
        itemShow.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(true);
            }
        });

        popupMenu.add(itemShow);
        popupMenu.add(itemExit);
        TrayIcon trayIcon = new TrayIcon(icon.getImage(), "E-MICRO-SERVICE-START", popupMenu);
        SystemTray sysTray = SystemTray.getSystemTray();
        try {
            sysTray.add(trayIcon);
        } catch (AWTException e1) {
        }
    }
}

From source file:org.exist.launcher.Launcher.java

private PopupMenu createMenu() {

    final PopupMenu popup = new PopupMenu();
    startItem = new MenuItem("Start server");
    popup.add(startItem);
    startItem.addActionListener(actionEvent -> {
        if (jetty.isPresent()) {
            jetty.ifPresent(server -> {
                if (server.isStarted()) {
                    showTrayMessage("Server already started", TrayIcon.MessageType.WARNING);
                } else {
                    server.run(new String[] { jettyConfig.toAbsolutePath().toString() }, null);
                    if (server.isStarted()) {
                        showTrayMessage("eXist-db server running on port " + server.getPrimaryPort(),
                                TrayIcon.MessageType.INFO);
                    }/*  w w  w  .j  a va 2s  .  co  m*/
                }
                setServiceState();
            });
        } else if (runningAsService.isPresent()) {
            showTrayMessage("Starting the eXistdb service. Please wait...", TrayIcon.MessageType.INFO);
            if (runningAsService.get().start()) {
                showTrayMessage("eXistdb service started", TrayIcon.MessageType.INFO);
            } else {
                showTrayMessage("Starting eXistdb service failed", TrayIcon.MessageType.ERROR);
            }
            setServiceState();
        }
    });

    stopItem = new MenuItem("Stop server");
    popup.add(stopItem);
    stopItem.addActionListener(actionEvent -> {
        if (jetty.isPresent()) {
            jetty.get().shutdown();
            setServiceState();
            showTrayMessage("eXist-db stopped", TrayIcon.MessageType.INFO);
        } else if (runningAsService.isPresent()) {
            if (runningAsService.get().stop()) {
                showTrayMessage("eXistdb service stopped", TrayIcon.MessageType.INFO);
            } else {
                showTrayMessage("Stopping eXistdb service failed", TrayIcon.MessageType.ERROR);
            }
            setServiceState();
        }
    });

    popup.addSeparator();
    final MenuItem configItem = new MenuItem("System Configuration");
    popup.add(configItem);
    configItem.addActionListener(e -> EventQueue.invokeLater(() -> {
        configDialog.open(false);
        configDialog.toFront();
        configDialog.repaint();
        configDialog.requestFocus();
    }));

    if (SystemUtils.IS_OS_WINDOWS) {
        canUseServices = true;
    } else {
        isRoot((root) -> canUseServices = root);
    }

    final String requiresRootMsg;
    if (canUseServices) {
        requiresRootMsg = "";
    } else {
        requiresRootMsg = " (requires root)";
    }

    installServiceItem = new MenuItem("Install as service" + requiresRootMsg);

    popup.add(installServiceItem);
    installServiceItem.setEnabled(canUseServices);
    installServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::installAsService));

    uninstallServiceItem = new MenuItem("Uninstall service" + requiresRootMsg);
    popup.add(uninstallServiceItem);
    uninstallServiceItem.setEnabled(canUseServices);
    uninstallServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::uninstallService));

    if (SystemUtils.IS_OS_WINDOWS) {
        showServices = new MenuItem("Show services console");
        popup.add(showServices);
        showServices.addActionListener(e -> SwingUtilities.invokeLater(this::showServicesConsole));
    }
    popup.addSeparator();

    final MenuItem toolbar = new MenuItem("Show tool window");
    popup.add(toolbar);
    toolbar.addActionListener(actionEvent -> EventQueue.invokeLater(() -> {
        utilityPanel.toFront();
        utilityPanel.setVisible(true);
    }));

    MenuItem item;

    if (Desktop.isDesktopSupported()) {
        popup.addSeparator();
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            dashboardItem = new MenuItem("Open Dashboard");
            popup.add(dashboardItem);
            dashboardItem.addActionListener(actionEvent -> dashboard(desktop));
            eXideItem = new MenuItem("Open eXide");
            popup.add(eXideItem);
            eXideItem.addActionListener(actionEvent -> eXide(desktop));
            item = new MenuItem("Open Java Admin Client");
            popup.add(item);
            item.addActionListener(actionEvent -> client());
            monexItem = new MenuItem("Open Monitoring and Profiling");
            popup.add(monexItem);
            monexItem.addActionListener(actionEvent -> monex(desktop));
        }
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            popup.addSeparator();
            item = new MenuItem("Open exist.log");
            popup.add(item);
            item.addActionListener(new LogActionListener());
        }

        popup.addSeparator();
        quitItem = new MenuItem("Quit (and stop server)");
        popup.add(quitItem);
        quitItem.addActionListener(actionEvent -> shutdown(false));

        setServiceState();
    }
    return popup;
}

From source file:net.mybox.mybox.ClientGUI.java

private void placeTrayIconAWT() {

    //Check the SystemTray support
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray is not supported");
        return;//from   w  ww.ja  v  a 2 s. c o m
    }
    final PopupMenu popup = new PopupMenu();

    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    MenuItem aboutItem = new MenuItem("About Mybox");
    MenuItem opendirItem = new MenuItem("Open Directory");
    MenuItem prefsItem = new MenuItem("Preferences");
    MenuItem exitItem = new MenuItem("Quit Mybox");

    //Add components to popup menu

    popup.add(opendirItem);
    popup.add(pauseItem);
    popup.add(syncnowItem);

    popup.addSeparator();
    popup.add(prefsItem);
    popup.add(aboutItem);
    popup.add(connectionItem);
    popup.add(exitItem);

    trayIcon.setImageAutoSize(true);
    trayIcon.setToolTip("Mybox");

    trayIcon.setPopupMenu(popup);

    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        System.out.println("TrayIcon could not be added.");
        return;
    }

    trayIcon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            launchFileBrowser();
        }
    });

    aboutItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //JOptionPane.showMessageDialog(null, "Mybox!");

            Dialog dialog = new Dialog((ClientGUI) client.clientGui, "Mybox...");
            dialog.setVisible(true);

            //MessageDialog dialog = new InfoMessageDialog(null, "Mybox", "... is awesome!");//ErrorMessageDialog(null, "Error", message);
            //dialog.setTitle("About Mybox");
            //dialog.run();
            //dialog.hide();
        }
    });

    prefsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //window.showAll();
            ((ClientGUI) client.clientGui).setVisible(true);
        }
    });

    syncnowItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            client.FullSync();
        }
    });

    opendirItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            launchFileBrowser();
        }
    });

    pauseItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (pauseItem.getLabel().equals("Pause Syncing")) {
                client.pause();
                pauseItem.setLabel("Unpause Syncing");
            } else if (pauseItem.getLabel().equals("Unpause Syncing")) {
                client.unpause();
                pauseItem.setLabel("Pause Syncing");
            }
        }
    });

    connectionItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (connectionItem.getLabel().equals("Connect")) {
                client.start();
            } else if (connectionItem.getLabel().equals("Disconnect")) {
                client.stop();
            }
        }
    });

    exitItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            tray.remove(trayIcon);
            System.exit(0);
        }
    });
}

From source file:de.jakop.ngcalsync.application.TrayStarter.java

private void moveToTray(final Settings settings, final Application application) {

    final PopupMenu popup = new PopupMenu();

    // Create a pop-up menu components
    final MenuItem syncItem = new MenuItem(UserMessage.get().MENU_ITEM_SYNCHRONIZE());
    final CheckboxMenuItem schedulerItem = new CheckboxMenuItem(UserMessage.get().MENU_ITEM_SCHEDULER_ACTIVE());
    final MenuItem logItem = new MenuItem(UserMessage.get().MENU_ITEM_SHOW_LOG());
    final MenuItem aboutItem = new MenuItem(UserMessage.get().MENU_ITEM_ABOUT());
    final MenuItem exitItem = new MenuItem(UserMessage.get().MENU_ITEM_EXIT());

    // let the tray icon listen to sync events for state change
    application.addObserver(getTrayIcon());

    //Add components to pop-up menu
    popup.add(syncItem);
    popup.add(schedulerItem);//from  w  w w  . j a  va 2 s .  c o  m
    popup.add(logItem);
    popup.add(aboutItem);
    popup.addSeparator();
    popup.add(exitItem);
    getTrayIcon().setPopupMenu(popup);

    application.reloadSettings();

    final JFrame logWindow = createLogWindow(Level.toLevel(settings.getPopupThresholdLevel(), Level.INFO));
    final JFrame aboutWindow = createAboutWindow();

    final ActionListener syncActionListener = createSyncActionListener(application.getScheduler());
    syncItem.addActionListener(syncActionListener);
    // sync also on double click
    getTrayIcon().addActionListener(syncActionListener);
    getTrayIcon().addMouseListener(createLogMouseListener(logWindow));

    schedulerItem.addItemListener(createSchedulerItemListener(settings, application));
    logItem.addActionListener(createLogActionListener(logWindow));
    aboutItem.addActionListener(createAboutActionListener(aboutWindow));
    exitItem.addActionListener(createExitActionListener(logWindow, aboutWindow));

    schedulerItem.setState(settings.isSchedulerStarted());
    toggleScheduler(settings.isSchedulerStarted(), settings, application);

}

From source file:jatoo.app.App.java

private PopupMenu getTrayIconPopup() {

    MenuItem openItem = new MenuItem(getText("popup.open") + " " + getTitle());
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            show();//from   ww w  .  j  a va 2 s  .co  m
        }
    });

    MenuItem hideItem = new MenuItem(getText("popup.hide") + " " + getTitle());
    hideItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            hide();
        }
    });

    CheckboxMenuItem hideWhenMinimizedItem = new CheckboxMenuItem(getText("popup.hide_when_minimized"),
            isHideWhenMinimized());
    hideWhenMinimizedItem.addItemListener(new ItemListener() {
        public void itemStateChanged(final ItemEvent e) {
            setHideWhenMinimized(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    MenuItem sendToBackItem = new MenuItem(getText("popup.send_to_back"));
    sendToBackItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            sendToBack();
        }
    });

    MenuItem closeItem = new MenuItem(getText("popup.close"));
    closeItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            System.exit(0);
        }
    });

    //
    //

    Font font = new JMenuItem().getFont();

    if (font != null) {
        openItem.setFont(font.deriveFont(Font.BOLD));
        hideItem.setFont(font);
        hideWhenMinimizedItem.setFont(font);
        sendToBackItem.setFont(font);
        closeItem.setFont(font);
    }

    //
    // the popup

    PopupMenu popup = new PopupMenu(getTitle());

    popup.add(openItem);
    popup.add(hideItem);
    popup.addSeparator();
    popup.add(hideWhenMinimizedItem);
    popup.addSeparator();
    popup.add(sendToBackItem);
    popup.addSeparator();
    popup.add(closeItem);

    return popup;
}

From source file:com.darkenedsky.reddit.traders.RedditTraders.java

/**
 * Construct a new RedditTraders instance.
 * /*from w  ww .  j a va  2  s .co m*/
 * 
 */
public RedditTraders() {

    // Load XML configuration file, connect to DB and connect to Reddit API
    try {
        config = new Configuration();
        addListener(new Help(this));
        addListener(new About(this));
        addListener(new Confirm(this));
        addListener(new Activate(this));
        listeners.put("DEACTIVATE", new Activate(this));
        addListener(new CountAllSubs(this));
        addListener(new ModHelp(this));
        addListener(new AcceptModInvite(this));
        addListener(new Install(this));
        addListener(new Cake(this));
        addListener(new Trade(this));
        addListener(new TopTraders(this, "TOP20", 20));
        addListener(new Lookup(this));
        addListener(new SetLegacy(this));
        addListener(new SetTextFlair(this));
        addListener(new ViewFlair(this));
        addListener(new Resolve(this));
        listeners.put("BLAME", new Resolve(this));
        listeners.put("CLOSE", new Resolve(this));
        addListener(new SetFlair(this));
        listeners.put("REMOVEFLAIR", new SetFlair(this));
        addListener(new SetModFlair(this));
        listeners.put("REMOVEMODFLAIR", new SetModFlair(this));
        addListener(new SetBlameBan(this));
        addListener(new SetList(this));
        listeners.put("SETHAVELIST", new SetList(this));
        addListener(new GetList(this));
        listeners.put("HAVELIST", new GetList(this));
        addListener(new SetAccountAgeRequirement(this));
        addListener(new SetVerifiedEmail(this));
        addListener(new Undo(this));
        addListener(new LastTrades(this, "LAST10", 10));
        addListener(new SetCheckBan(this));
        addListener(new SetDaysBetween(this));

        // Build a system tray icon
        SystemTray tray = SystemTray.getSystemTray();

        PopupMenu popup = new PopupMenu();

        MenuItem todaysLog = new MenuItem("Today's Log");
        todaysLog.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new TextFrame("logs/RedditTraders.log").setVisible(true);
                } catch (Exception e1) {
                    LOG.error(e1);
                }
            }
        });
        popup.add(todaysLog);

        MenuItem exit = new MenuItem("Exit");
        ActionListener exitListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        };
        exit.addActionListener(exitListener);
        popup.add(exit);

        Image image = Toolkit.getDefaultToolkit().getImage("reddit.png");
        TrayIcon trayIcon = new TrayIcon(image, "RedditTraders " + config.getVersion(), popup);
        trayIcon.setImageAutoSize(true);
        tray.add(trayIcon);

        LOG.debug("RedditTraders launched OK.");
    } catch (Exception x) {
        x.printStackTrace();
        System.exit(0);
    }
}

From source file:org.sleeksnap.ScreenSnapper.java

/**
 * Initialize the tray menu//w w  w .j  av  a  2  s .c o  m
 */
private void initializeTray() {
    // Add uploaders from the list we loaded earlier
    final PopupMenu tray = new PopupMenu();
    // Add the action menu
    tray.add(new ActionMenuItem(Language.getString("cropupload"), ScreenshotAction.CROP));
    tray.add(new ActionMenuItem(Language.getString("fullupload"), ScreenshotAction.FULL));

    if (Platform.isWindows() || Platform.isLinux()) {
        tray.add(new ActionMenuItem(Language.getString("activeupload"), ScreenshotAction.ACTIVE));
    }

    tray.addSeparator();

    tray.add(new ActionMenuItem(Language.getString("clipboardupload"), ScreenshotAction.CLIPBOARD));
    tray.add(new ActionMenuItem(Language.getString("fileupload"), ScreenshotAction.FILE));

    tray.addSeparator();

    final MenuItem settings = new MenuItem(Language.getString("options"));
    settings.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            if (!openSettings()) {
                icon.displayMessage(Language.getString("error"), Language.getString("optionsOpenError"),
                        TrayIcon.MessageType.ERROR);
            }
        }
    });
    tray.add(settings);

    final MenuItem exit = new MenuItem(Language.getString("exit"));
    exit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            shutdown();
        }
    });
    tray.add(exit);

    icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(Resources.ICON),
            Application.NAME + " v" + Version.getVersionString());
    icon.setPopupMenu(tray);
    icon.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            if (lastUrl != null) {
                try {
                    Util.openURL(new URL(lastUrl));
                } catch (final Exception e1) {
                    showException(e1, "Unable to open URL");
                }
            }
        }
    });
    try {
        SystemTray.getSystemTray().add(icon);
    } catch (final AWTException e1) {
        this.showException(e1);
    }
}

From source file:streamme.visuals.Main.java

public void loadTray() {
    if (SystemTray.isSupported()) {
        tray = SystemTray.getSystemTray();

        PopupMenu popup = new PopupMenu();
        MenuItem exitItem = new MenuItem("Exit");
        exitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();/*from   w ww  . ja v  a 2 s  .c  o m*/
            }
        });

        MenuItem openItem = new MenuItem("Open");
        openItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                minimizeToTray(false);
            }
        });

        popup.add(openItem);
        popup.add(exitItem);
        trayIcon = new TrayIcon(
                Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("res/icon16.png")),
                "StreamMe", popup);
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt) {
                if (evt.getClickCount() == 2) {
                    //minimizeToTray(false);
                    return;
                }
                if (evt.getButton() == 1) {
                    minimizeToTray(!isMinimizedToTray());
                }
            }
        });

        addWindowStateListener(new WindowStateListener() {
            public void windowStateChanged(WindowEvent e) {
                if (e.getNewState() == ICONIFIED || e.getNewState() == 7) {
                    minimizeToTray(true);
                }
            }
        });

        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                minimizeToTray(true);
            }
        });
        try {
            tray.add(trayIcon);
        } catch (AWTException ex) {
            System.out.println("Error adding icon to tray");
        }
    }
}

From source file:com.jsystem.j2autoit.AutoItAgent.java

private static void createAndShowGUI() {
    //Check the SystemTray support
    if (!SystemTray.isSupported()) {
        Log.error("SystemTray is not supported\n");
        return;/*from ww w. ja  v  a2s.  com*/
    }
    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon = new TrayIcon(createImage("images/jsystem_ico.gif", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    final MenuItem aboutItem = new MenuItem("About");
    final MenuItem startAgentItem = new MenuItem("Start J2AutoIt Agent");
    final MenuItem stopAgentItem = new MenuItem("Stop J2AutoIt Agent");
    final MenuItem exitItem = new MenuItem("Exit");
    final MenuItem changePortItem = new MenuItem("Setting J2AutoIt Port");
    final MenuItem deleteTemporaryFilesItem = new MenuItem("Delete J2AutoIt Script");
    final MenuItem temporaryHistoryFilesItem = new MenuItem("History Size");
    final MenuItem displayLogFile = new MenuItem("Log");
    final MenuItem forceShutDownTimeOutItem = new MenuItem("Force ShutDown TimeOut");
    final MenuItem writeConfigurationToFile = new MenuItem("Save Configuration To File");
    final CheckboxMenuItem debugModeItem = new CheckboxMenuItem("Debug Mode", isDebug);
    final CheckboxMenuItem forceAutoItShutDownItem = new CheckboxMenuItem("Force AutoIt Script ShutDown",
            isForceAutoItShutDown);
    final CheckboxMenuItem autoDeleteHistoryItem = new CheckboxMenuItem("Auto Delete History",
            isAutoDeleteFiles);
    final CheckboxMenuItem useAutoScreenShot = new CheckboxMenuItem("Auto Screenshot", isUseScreenShot);

    //Add components to popup menu
    popup.add(aboutItem);
    popup.add(writeConfigurationToFile);
    popup.addSeparator();
    popup.add(forceAutoItShutDownItem);
    popup.add(forceShutDownTimeOutItem);
    popup.addSeparator();
    popup.add(debugModeItem);
    popup.add(displayLogFile);
    popup.add(useAutoScreenShot);
    popup.addSeparator();
    popup.add(autoDeleteHistoryItem);
    popup.add(deleteTemporaryFilesItem);
    popup.add(temporaryHistoryFilesItem);
    popup.addSeparator();
    popup.add(changePortItem);
    popup.addSeparator();
    popup.add(startAgentItem);
    popup.add(stopAgentItem);
    popup.addSeparator();
    popup.add(exitItem);

    trayIcon.setToolTip("J2AutoIt Agent");
    trayIcon.setImageAutoSize(true);
    trayIcon.setPopupMenu(popup);
    final DisplayLogFile displayLog = new DisplayLogFile();
    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        Log.error("TrayIcon could not be added.\n");
        return;
    }

    trayIcon.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
            startAgentItem.setEnabled(!serverState);
            stopAgentItem.setEnabled(serverState);
            deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries());
            autoDeleteHistoryItem.setEnabled(isDebug);
            temporaryHistoryFilesItem.setEnabled(isDebug && isAutoDeleteFiles);
            displayLogFile.setEnabled(isDebug);
            forceShutDownTimeOutItem.setEnabled(isForceAutoItShutDown);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }
    });

    writeConfigurationToFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            AutoItProperties.DEBUG_MODE_KEY.setValue(isDebug.toString());
            AutoItProperties.AUTO_DELETE_TEMPORARY_SCRIPT_FILE_KEY.setValue(isAutoDeleteFiles.toString());
            AutoItProperties.AUTO_IT_SCRIPT_HISTORY_SIZE_KEY.setValue(DEFAULT_HistorySize.toString());
            AutoItProperties.FORCE_AUTO_IT_PROCESS_SHUTDOWN_KEY.setValue(isForceAutoItShutDown.toString());
            AutoItProperties.AGENT_PORT_KEY.setValue(webServicePort.toString());
            AutoItProperties.SERVER_UP_ON_INIT_KEY.setValue(serverState.toString());
            if (!AutoItProperties.savePropertiesFileSafely()) {
                Log.error("Fail to save properties file");
            }
        }
    });

    debugModeItem.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            isDebug = (e.getStateChange() == ItemEvent.SELECTED);
            deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries());
            Log.infoLog("Keeping the temp file is " + (isDebug ? "en" : "dis") + "able\n");
            trayIcon.displayMessage((isDebug ? "Debug" : "Normal") + " Mode",
                    "The system will " + (isDebug ? "not " : "") + "delete \nthe temporary autoIt scripts."
                            + (isDebug ? "\nSee log file for more info." : ""),
                    MessageType.INFO);
        }
    });

    useAutoScreenShot.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            isUseScreenShot = (e.getStateChange() == ItemEvent.SELECTED);
            Log.infoLog("Auto screenshot is " + (isUseScreenShot ? "" : "in") + "active\n");
        }
    });

    forceAutoItShutDownItem.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            isForceAutoItShutDown = (e.getStateChange() == ItemEvent.SELECTED);
            Log.infoLog((isForceAutoItShutDown ? "Force" : "Soft") + " AutoIt Script ShutDown\n");
            trayIcon.displayMessage("AutoIt Script Termination",
                    (isForceAutoItShutDown ? "Hard shutdown" : "Soft shutdown"), MessageType.INFO);
        }
    });

    autoDeleteHistoryItem.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            isAutoDeleteFiles = (e.getStateChange() == ItemEvent.SELECTED);
            Log.infoLog((isAutoDeleteFiles ? "Auto" : "Manual") + " AutoIt Script Deletion\n");
            trayIcon.displayMessage("AutoIt Script Deletion", (isAutoDeleteFiles ? "Auto" : "Manual") + " Mode",
                    MessageType.INFO);
            if (isAutoDeleteFiles) {
                HistoryFile.init();
            } else {
                HistoryFile.close();
            }
        }
    });

    forceShutDownTimeOutItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String timeOutAsString = JOptionPane.showInputDialog(
                    "Please Insert Force ShutDown TimeOut (in seconds)",
                    String.valueOf(shutDownTimeOut / 1000));
            try {
                shutDownTimeOut = 1000 * Long.parseLong(timeOutAsString);
            } catch (Exception e2) {
            }
            Log.infoLog("Setting the force shutdown time out to : " + (shutDownTimeOut / 1000) + " seconds.\n");
        }
    });

    displayLogFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                displayLog.reBuild(Log.getCurrentLogs());
                displayLog.actionPerformed(actionEvent);
            } catch (Exception e2) {
            }
        }
    });

    temporaryHistoryFilesItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String historySize = JOptionPane.showInputDialog("Please Insert History AutoIt Script Files",
                    String.valueOf(HistoryFile.getHistory_Size()));
            try {
                int temp = Integer.parseInt(historySize);
                if (temp > 0) {
                    if (HistoryFile.getHistory_Size() != temp) {
                        HistoryFile.setHistory_Size(temp);
                        Log.infoLog("The history files size is " + historySize + NEW_LINE);
                    }
                } else {
                    Log.warning("Illegal History Size: " + historySize + NEW_LINE);
                }
            } catch (Exception exception) {
                Log.throwableLog(exception.getMessage(), exception);
            }
        }
    });

    deleteTemporaryFilesItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            HistoryFile.forceDeleteAll();
        }
    });

    startAgentItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            runWebServer();
        }
    });

    stopAgentItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            shutDownWebServer();
        }
    });

    aboutItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JOptionPane.showMessageDialog(null, "J2AutoIt Agent By JSystem And Aqua Software");
        }
    });

    changePortItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String portAsString = JOptionPane.showInputDialog("Please Insert new Port",
                    String.valueOf(webServicePort));
            if (portAsString != null) {
                try {
                    int temp = Integer.parseInt(portAsString);
                    if (temp > 1000) {
                        if (temp != webServicePort) {
                            webServicePort = temp;
                            shutDownWebServer();
                            startAutoItWebServer(webServicePort);
                            runWebServer();
                        }
                    } else {
                        Log.warning("Port number should be greater then 1000\n");
                    }
                } catch (Exception exception) {
                    Log.error("Illegal port number\n");
                    return;
                }
            }
        }
    });

    exitItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            tray.remove(trayIcon);
            shutDownWebServer();
            Log.info("Exiting from J2AutoIt Agent\n");
            System.exit(0);
        }
    });
}