Example usage for java.awt MenuItem setEnabled

List of usage examples for java.awt MenuItem setEnabled

Introduction

In this page you can find the example usage for java.awt MenuItem setEnabled.

Prototype

public synchronized void setEnabled(boolean b) 

Source Link

Document

Sets whether or not this menu item can be chosen.

Usage

From source file:de.tbuchloh.kiskis.gui.MainFrame.java

/**
 * @see de.tbuchloh.kiskis.gui.systray.IMainFrame#getPopupMenu()
 *///from   w w w  . ja  v a 2 s. co  m
@Override
public PopupMenu getPopupMenu() {
    final PopupMenu popup = new PopupMenu();
    for (final Action act : _main.getPopupActions()) {
        if (act == null) {
            popup.addSeparator();
        } else {
            final MenuItem mi = new MenuItem((String) act.getValue(Action.NAME));
            mi.setEnabled(act.isEnabled());
            mi.addActionListener(act);
            mi.setFont(new Font("Arial", Font.BOLD, 12));
            popup.add(mi);
        }
    }
    return popup;
}

From source file:javazoom.jlgui.player.amp.Player.java

/**
 * Loads a skin from a SkinLoader./*w w  w  .  j a va  2  s.co  m*/
 */
protected void loadSkin(SkinLoader skl) throws Exception {
    skl.loadImages();
    imMain = skl.getImage(theMain);
    imButtons = skl.getImage(theButtons);
    imTitleBar = skl.getImage(theTitleBar);
    imText = skl.getImage(theText);
    imMode = skl.getImage(theMode);
    imNumbers = skl.getImage(theNumbers);
    // add by John Yang
    if (imNumbers == null) {
        log.info("Try load nums_ex.bmp !");
        imNumbers = skl.getImage(theNumEx);
    }
    imVolume = skl.getImage(theVolume);
    imBalance = skl.getImage(theBalance);
    imIcons = skl.getImage(theIcons);
    imPosBar = skl.getImage(thePosBar);
    imEPSRButtons = skl.getImage(theEPSRButtons);

    // Computes volume slider height :
    int vh = (imVolume.getHeight(null) - 422);
    if (vh > 0) {
        releasedVolumePanel0[3] = vh;
        pressedVolumePanel0[3] = vh;
        releasedVolumePanel1[3] = vh;
        pressedVolumePanel1[3] = vh;
    }
    // Computes balance slider height :
    if (imBalance == null)
        imBalance = imVolume;
    int bh = (imBalance.getHeight(null) - 422);
    if (bh > 0) {
        releasedBalancePanel0[3] = bh;
        pressedBalancePanel0[3] = bh;
        releasedBalancePanel1[3] = bh;
        pressedBalancePanel1[3] = bh;
    }

    // Compute posbar height.
    int ph = imPosBar.getHeight(null);
    if (ph > 0) {
        releasedPosPanel[3] = ph;
        pressedPosPanel[3] = ph;
    }

    WinHeight = imMain.getHeight(this); // 275
    WinWidth = imMain.getWidth(this); // 116
    setSize(WinWidth, WinHeight);
    setLocation(OrigineX, OrigineY);
    //setBackground(Color.black);
    show();

    offScreenImage = createImage(WinWidth, WinHeight);
    offScreenGraphics = offScreenImage.getGraphics();
    // E.B Fix for JDK 1.4 slow down problem.
    hide();
    // End Fix.
    offScreenGraphics.drawImage(imMain, 0, 0, this);

    // M.S : Remove all components when loading a new skin.
    if (acPrevious != null)
        remove(acPrevious);
    if (acPlay != null)
        remove(acPlay);
    if (acPause != null)
        remove(acPause);
    if (acStop != null)
        remove(acStop);
    if (acNext != null)
        remove(acNext);
    if (acEject != null)
        remove(acEject);
    if (acTitleBar != null)
        remove(acTitleBar);
    if (acExit != null)
        remove(acExit);
    if (acMinimize != null)
        remove(acMinimize);
    if (acVolume != null)
        remove((Component) acVolume);
    if (acBalance != null)
        remove((Component) acBalance);
    if (acPosBar != null)
        remove(acPosBar);
    if (acPlaylist != null)
        remove(acPlaylist);
    if (acRepeat != null)
        remove(acRepeat);
    if (acShuffle != null)
        remove(acShuffle);
    if (acEqualizer != null)
        remove(acEqualizer);
    if (fileList != null)
        fileList.dispose();
    if (equalizer != null)
        equalizer.dispose();
    System.gc();

    /*-- Buttons --*/
    readPanel(releasedImage, releasedPanel, pressedImage, pressedPanel, imButtons);
    setButtonsPanel();

    /*-- Volume/Balance --*/
    if (skinVersion.equals("1")) {
        readPanel(releasedVolumeImage, releasedVolumePanel0, pressedVolumeImage, pressedVolumePanel0, imVolume);
        readPanel(releasedBalanceImage, releasedBalancePanel0, pressedBalanceImage, pressedBalancePanel0,
                imBalance);
    } else {
        readPanel(releasedVolumeImage, releasedVolumePanel1, pressedVolumeImage, pressedVolumePanel1, imVolume);
        readPanel(releasedBalanceImage, releasedBalancePanel1, pressedBalanceImage, pressedBalancePanel1,
                imBalance);
    }
    setVolumeBalancePanel(vh, bh);

    /*-- Title Bar --*/
    readPanel(releasedTitleIm, releasedTitlePanel, pressedTitleIm, pressedTitlePanel, imTitleBar);
    setTitleBarPanel();

    /*-- Exit --*/
    readPanel(releasedExitIm, releasedExitPanel, pressedExitIm, pressedExitPanel, imTitleBar);
    setExitPanel();

    /*-- Minimize --*/
    readPanel(releasedMinimizeIm, releasedMinimizePanel, pressedMinimizeIm, pressedMinimizePanel, imTitleBar);
    setMinimizePanel();

    /*-- Mode --*/
    readPanel(activeModeImage, activeModePanel, passiveModeImage, passiveModePanel, imMode);
    offScreenGraphics.drawImage(passiveModeImage[0], stereoLocation[0], stereoLocation[1], this);
    offScreenGraphics.drawImage(passiveModeImage[1], monoLocation[0], monoLocation[1], this);

    /*-- Text --*/
    sampleRateClearImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, sampleRateClearText))
            .getBanner();
    bitsRateClearImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, bitsRateClearText))
            .getBanner();
    clearImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, clearText)).getBanner(0, 0, 155, 6);
    titleImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, titleText)).getBanner(0, 0, 155, 6);
    offScreenGraphics.drawImage(titleImage, titleLocation[0], titleLocation[1], this);

    /*-- Numbers --*/
    for (int h = 0; h < numberIndex.length(); h++) {
        timeImage[h] = (new Taftb(numberIndex, imNumbers, numberWidth, numberHeight, 0,
                "" + numberIndex.charAt(h))).getBanner();
    }

    /*--  Icons --*/
    readPanel(iconsImage, iconsPanel, null, null, imIcons);
    offScreenGraphics.drawImage(iconsImage[2], iconsLocation[0], iconsLocation[1], this);

    /*-- Pos Bar --*/
    readPanel(releasedPosIm, releasedPosPanel, pressedPosIm, pressedPosPanel, imPosBar);
    setPosBarPanel();

    /*-- Equalizer/Playlist/Shuffle/Repeat  --*/
    readPanel(releasedEPSRImage, releasedEPSRPanel, pressedEPSRImage, pressedEPSRPanel, imEPSRButtons);
    setEPSRButtonsPanel();

    // Popup menu on TitleBar
    PopupMenu mainpopup = new PopupMenu("Setup");
    Font fnt = new Font("Dialog", Font.PLAIN, 11);
    mainpopup.setFont(fnt);
    MenuItem mi = new MenuItem(TITLETEXT + "- JavaZOOM");
    //mi.setEnabled(false);
    mi.addActionListener(this);
    mainpopup.add(mi);
    mainpopup.addSeparator();
    mi = new MenuItem("Preferences");
    // TODO
    mi.setEnabled(false);
    mi.addActionListener(this);
    mainpopup.add(mi);
    mi = new MenuItem("Load Skin");
    //mi.setEnabled(false);
    mi.addActionListener(this);
    mainpopup.add(mi);
    //mainpopup.addSeparator();
    mi = new MenuItem("Exit");
    mi.addActionListener(this);
    mainpopup.add(mi);
    acTitleBar.setPopup(mainpopup);

    /* -- create MP3File List Window --*/
    if (showPlaylist != null)
        config.setPlaylistEnabled(true);
    fileList = new MP3Files(topFrame, this, playlist, skl, OrigineX, OrigineY + WinHeight,
            config.isPlaylistEnabled());

    /* -- create Equalizer Window --*/
    if (showEqualizer != null)
        config.setEqualizerEnabled(true);
    int factor = 1;
    if (config.isPlaylistEnabled())
        factor = 2;
    equalizer = new Equalizer(topFrame, this, skl, OrigineX, OrigineY + WinHeight * factor,
            config.isEqualizerEnabled());
    show();
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Loads a skin from a SkinLoader.// w ww.  j av  a  2 s  .c  o  m
 */
protected void loadSkin(SkinLoader skl) throws Exception {
    skl.loadImages();
    imMain = skl.getImage(theMain);
    imButtons = skl.getImage(theButtons);
    imTitleBar = skl.getImage(theTitleBar);
    imText = skl.getImage(theText);
    imMode = skl.getImage(theMode);
    imNumbers = skl.getImage(theNumbers);
    // add by John Yang
    if (imNumbers == null) {
        log.info("Try load nums_ex.bmp !");
        imNumbers = skl.getImage(theNumEx);
    }
    imVolume = skl.getImage(theVolume);
    imBalance = skl.getImage(theBalance);
    imIcons = skl.getImage(theIcons);
    imPosBar = skl.getImage(thePosBar);
    imEPSRButtons = skl.getImage(theEPSRButtons);

    // Computes volume slider height :
    int vh = (imVolume.getHeight(null) - 422);
    if (vh > 0) {
        releasedVolumePanel0[3] = vh;
        pressedVolumePanel0[3] = vh;
        releasedVolumePanel1[3] = vh;
        pressedVolumePanel1[3] = vh;
    }
    // Computes balance slider height :
    if (imBalance == null)
        imBalance = imVolume;
    int bh = (imBalance.getHeight(null) - 422);
    if (bh > 0) {
        releasedBalancePanel0[3] = bh;
        pressedBalancePanel0[3] = bh;
        releasedBalancePanel1[3] = bh;
        pressedBalancePanel1[3] = bh;
    }

    // Compute posbar height.
    int ph = imPosBar.getHeight(null);
    if (ph > 0) {
        releasedPosPanel[3] = ph;
        pressedPosPanel[3] = ph;
    }

    WinHeight = imMain.getHeight(this); // 275
    WinWidth = imMain.getWidth(this); // 116
    setSize(WinWidth, WinHeight);
    setLocation(OrigineX, OrigineY);
    //setBackground(Color.black);
    show();

    offScreenImage = createImage(WinWidth, WinHeight);
    offScreenGraphics = offScreenImage.getGraphics();
    // E.B Fix for JDK 1.4 slow down problem.
    hide();
    // End Fix.
    offScreenGraphics.drawImage(imMain, 0, 0, this);

    // M.S : Remove all components when loading a new skin.
    if (acPrevious != null)
        remove(acPrevious);
    if (acPlay != null)
        remove(acPlay);
    if (acPause != null)
        remove(acPause);
    if (acStop != null)
        remove(acStop);
    if (acNext != null)
        remove(acNext);
    if (acEject != null)
        remove(acEject);
    if (acTitleBar != null)
        remove(acTitleBar);
    if (acExit != null)
        remove(acExit);
    if (acMinimize != null)
        remove(acMinimize);
    if (acVolume != null)
        remove((Component) acVolume);
    if (acBalance != null)
        remove((Component) acBalance);
    if (acPosBar != null)
        remove(acPosBar);
    if (acPlaylist != null)
        remove(acPlaylist);
    if (acRepeat != null)
        remove(acRepeat);
    if (acShuffle != null)
        remove(acShuffle);
    if (acEqualizer != null)
        remove(acEqualizer);
    if (fileList != null)
        remove(fileList);
    if (equalizer != null)
        remove(equalizer);
    System.gc();

    /*-- Buttons --*/
    readPanel(releasedImage, releasedPanel, pressedImage, pressedPanel, imButtons);
    setButtonsPanel();

    /*-- Volume/Balance --*/
    if (skinVersion.equals("1")) {
        readPanel(releasedVolumeImage, releasedVolumePanel0, pressedVolumeImage, pressedVolumePanel0, imVolume);
        readPanel(releasedBalanceImage, releasedBalancePanel0, pressedBalanceImage, pressedBalancePanel0,
                imBalance);
    } else {
        readPanel(releasedVolumeImage, releasedVolumePanel1, pressedVolumeImage, pressedVolumePanel1, imVolume);
        readPanel(releasedBalanceImage, releasedBalancePanel1, pressedBalanceImage, pressedBalancePanel1,
                imBalance);
    }
    setVolumeBalancePanel(vh, bh);

    /*-- Title Bar --*/
    readPanel(releasedTitleIm, releasedTitlePanel, pressedTitleIm, pressedTitlePanel, imTitleBar);
    setTitleBarPanel();

    /*-- Exit --*/
    readPanel(releasedExitIm, releasedExitPanel, pressedExitIm, pressedExitPanel, imTitleBar);
    setExitPanel();

    /*-- Minimize --*/
    readPanel(releasedMinimizeIm, releasedMinimizePanel, pressedMinimizeIm, pressedMinimizePanel, imTitleBar);
    setMinimizePanel();

    /*-- Mode --*/
    readPanel(activeModeImage, activeModePanel, passiveModeImage, passiveModePanel, imMode);
    offScreenGraphics.drawImage(passiveModeImage[0], stereoLocation[0], stereoLocation[1], this);
    offScreenGraphics.drawImage(passiveModeImage[1], monoLocation[0], monoLocation[1], this);

    /*-- Text --*/
    sampleRateClearImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, sampleRateClearText))
            .getBanner();
    bitsRateClearImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, bitsRateClearText))
            .getBanner();
    clearImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, clearText)).getBanner(0, 0, 155, 6);
    titleImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, titleText)).getBanner(0, 0, 155, 6);
    offScreenGraphics.drawImage(titleImage, titleLocation[0], titleLocation[1], this);

    /*-- Numbers --*/
    for (int h = 0; h < numberIndex.length(); h++) {
        timeImage[h] = (new Taftb(numberIndex, imNumbers, numberWidth, numberHeight, 0,
                "" + numberIndex.charAt(h))).getBanner();
    }

    /*--  Icons --*/
    readPanel(iconsImage, iconsPanel, null, null, imIcons);
    offScreenGraphics.drawImage(iconsImage[2], iconsLocation[0], iconsLocation[1], this);

    /*-- Pos Bar --*/
    readPanel(releasedPosIm, releasedPosPanel, pressedPosIm, pressedPosPanel, imPosBar);
    setPosBarPanel();

    /*-- Equalizer/Playlist/Shuffle/Repeat  --*/
    readPanel(releasedEPSRImage, releasedEPSRPanel, pressedEPSRImage, pressedEPSRPanel, imEPSRButtons);
    setEPSRButtonsPanel();

    // Popup menu on TitleBar
    PopupMenu mainpopup = new PopupMenu("Setup");
    Font fnt = new Font("Dialog", Font.PLAIN, 11);
    mainpopup.setFont(fnt);
    MenuItem mi = new MenuItem(TITLETEXT + "- JavaZOOM");
    mi.setEnabled(false);
    mi.addActionListener(this);
    mainpopup.add(mi);
    mainpopup.addSeparator();
    mi = new MenuItem("Preferences");
    mi.setEnabled(false);
    mi.addActionListener(this);
    mainpopup.add(mi);
    mi = new MenuItem("Skins");
    mi.setEnabled(false);
    mi.addActionListener(this);
    mainpopup.add(mi);
    mainpopup.addSeparator();
    mi = new MenuItem("Exit");
    mi.setEnabled(false);
    mi.addActionListener(this);
    mainpopup.add(mi);
    acTitleBar.setPopup(mainpopup);

    /* -- create MP3File List Window --*/
    if (showPlaylist != null)
        config.setPlaylistEnabled(true);
    fileList = new MP3FilesApplet(topFrame, this, playlist, skl, OrigineX, OrigineY + WinHeight,
            config.isPlaylistEnabled());
    add(fileList);

    /* -- create Equalizer Window --*/
    if (showEqualizer != null)
        config.setEqualizerEnabled(true);
    int factor = 1;
    if (config.isPlaylistEnabled())
        factor = 2;
    equalizer = new EqualizerApplet(topFrame, this, skl, OrigineX, OrigineY + WinHeight * factor,
            config.isEqualizerEnabled());
    add(equalizer);
    show();
}

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  w w  w. java  2s .c  om*/
    }
    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);
        }
    });
}

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);//w  ww. j a va 2  s.  c  om

    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;
}