List of usage examples for java.awt MenuItem MenuItem
public MenuItem(String label) throws HeadlessException
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java
private PopupMenu createPopupMenu(final ViewState state) { final String ACTIONS_POP_MENU_NAME = "Actions"; final String VIEW_CONDITION_MAP = "View..."; PopupMenu actionsMenu = new PopupMenu(ACTIONS_POP_MENU_NAME); actionsMenu.add(new MenuItem(VIEW_CONDITION_MAP)); actionsMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(VIEW_CONDITION_MAP)) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getSelectionPath() .getLastPathComponent(); ModelGraph graphToFocus = null; if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS)) || Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_POSTCONDITIONS))) { // if (node.getUserObject() instanceof String && // (node.getUserObject().equals("pre-conditions") || // node.getUserObject().equals("post-conditions"))) { ModelGraph graph = state.getSelected(); if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS))) { graphToFocus = graph.getPreConditions(); } else { graphToFocus = graph.getPostConditions(); }//from w w w .ja va 2 s . c o m } else if (node.getUserObject() instanceof ModelGraph) { graphToFocus = (ModelGraph) node.getUserObject(); } DefaultTreeView.this .notifyListeners(new ViewChange.NEW_VIEW(graphToFocus, DefaultTreeView.this)); } } }); final String ORDER_SUB_POP_MENU_NAME = "Order"; final String TO_FRONT_ITEM_NAME = "Move To Front"; final String TO_BACK_ITEM_NAME = "Move To Back"; final String FORWARD_ITEM_NAME = "Move Forward"; final String BACKWARDS_ITEM_NAME = "Move Backwards"; actionsMenu.add(orderSubMenu = new PopupMenu(ORDER_SUB_POP_MENU_NAME)); orderSubMenu.add(new MenuItem(TO_FRONT_ITEM_NAME)); orderSubMenu.add(new MenuItem(TO_BACK_ITEM_NAME)); orderSubMenu.add(new MenuItem(FORWARD_ITEM_NAME)); orderSubMenu.add(new MenuItem(BACKWARDS_ITEM_NAME)); orderSubMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ModelGraph graph = state.getSelected(); ModelGraph parent = graph.getParent(); if (e.getActionCommand().equals(TO_FRONT_ITEM_NAME)) { if (parent.getChildren().remove(graph)) { parent.getChildren().add(0, graph); } } else if (e.getActionCommand().equals(TO_BACK_ITEM_NAME)) { if (parent.getChildren().remove(graph)) { parent.getChildren().add(graph); } } else if (e.getActionCommand().equals(FORWARD_ITEM_NAME)) { int index = parent.getChildren().indexOf(graph); if (index != -1) { parent.getChildren().remove(index); parent.getChildren().add(Math.max(0, index + 1), graph); } } else if (e.getActionCommand().equals(BACKWARDS_ITEM_NAME)) { int index = parent.getChildren().indexOf(graph); if (index != -1) { parent.getChildren().remove(index); parent.getChildren().add(Math.max(0, index - 1), graph); } } DefaultTreeView.this.notifyListeners(); DefaultTreeView.this.refreshView(state); } }); return actionsMenu; }
From source file:vn.topmedia.monitor.form.MDIMain.java
public void goToTray() { if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); normal = Toolkit.getDefaultToolkit().getImage("normal.gif"); MouseListener mouseListener = new MouseListener() { public void mouseClicked(MouseEvent e) { // System.out.println("Tray Icon - Mouse clicked!"); }//ww w .j av a 2s .c om public void mouseEntered(MouseEvent e) { // System.out.println("Tray Icon - Mouse entered!"); } public void mouseExited(MouseEvent e) { // System.out.println("Tray Icon - Mouse exited!"); } public void mousePressed(MouseEvent e) { // System.out.println("Tray Icon - Mouse pressed!"); showMonitor(0); } public void mouseReleased(MouseEvent e) { // System.out.println("Tray Icon - Mouse released!"); } }; ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Exiting..."); mnuItmExit.doClick(); } }; ActionListener showMonitorListener = new ActionListener() { public void actionPerformed(ActionEvent e) { showMonitor(2); } }; popup = new PopupMenu(); //--------------------------- MenuItem showItem; showItem = new MenuItem("Show"); showItem.addActionListener(showMonitorListener); popup.add(showItem); //----------------- popup.addSeparator(); //------------------------ MenuItem defaultItem = new MenuItem("Exit"); defaultItem.addActionListener(exitListener); popup.add(defaultItem); //------------------------ trayIcon = new TrayIcon(normal, "ExMonitor 1.3", popup); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { showMonitor(2); } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(actionListener); trayIcon.addMouseListener(mouseListener); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("TrayIcon could not be added."); } } else { // System Tray is not supported } }
From source file:org.sleeksnap.ScreenSnapper.java
/** * Initialize the tray menu//w w w . jav 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:javazoom.jlgui.player.amp.Player.java
/** * Loads a skin from a SkinLoader./* w w w . j a va 2s . 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: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 ava 2s. c om*/ } }); 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:edu.stanford.muse.launcher.Main.java
/** we need a system tray icon for management. * http://docs.oracle.com/javase/6/docs/api/java/awt/SystemTray.html */ public static void setupSystemTrayIcon() { // Set the app name in the menu bar for mac. // c.f. http://stackoverflow.com/questions/8918826/java-os-x-lion-set-application-name-doesnt-work System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Muse"); try {/*from w w w . ja va2 s . c om*/ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { throw new RuntimeException(e); } TrayIcon trayIcon = null; if (SystemTray.isSupported()) { System.out.println("Adding Muse to the system tray"); SystemTray tray = SystemTray.getSystemTray(); URL u = Main.class.getClassLoader().getResource("muse-icon.png"); // note: this better be 16x16, Windows doesn't resize! Mac os does. System.out.println("muse icon resource is " + u); Image image = Toolkit.getDefaultToolkit().getImage(u); System.out.println("Image = " + image); // create menu items and their listeners ActionListener openMuseControlsListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { launchBrowser(BASE_URL + "/info"); } catch (Exception e1) { e1.printStackTrace(); } } }; ActionListener QuitMuseListener = new ActionListener() { public void actionPerformed(ActionEvent e) { out.println("*** Received quit from system tray. Stopping the Jetty embedded web server."); try { server.stop(); } catch (Exception ex) { throw new RuntimeException(ex); } System.exit(0); // we need to explicitly system.exit because we now use Swing (due to system tray, etc). } }; // create a popup menu PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem("Open Muse window"); defaultItem.addActionListener(openMuseControlsListener); popup.add(defaultItem); MenuItem quitItem = new MenuItem("Quit Muse"); quitItem.addActionListener(QuitMuseListener); popup.add(quitItem); /// ... add other items // construct a TrayIcon String message = "Muse menu"; // on windows - the tray menu is a little non-intuitive, needs a right click (plain click seems unused) if (System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0) message = "Right click for Muse menu"; trayIcon = new TrayIcon(image, message, popup); System.out.println("tray Icon = " + trayIcon); // set the TrayIcon properties // trayIcon.addActionListener(openMuseControlsListener); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } // ... } else { // disable tray option in your application or // perform other actions // ... } System.out.println("Done!"); // ... // some time later // the application state has changed - update the image if (trayIcon != null) { // trayIcon.setImage(updatedImage); } // ... }
From source file:edu.stanford.epadd.launcher.Main.java
/** we need a system tray icon for management. * http://docs.oracle.com/javase/6/docs/api/java/awt/SystemTray.html */ public static void setupSystemTrayIcon() { // Set the app name in the menu bar for mac. // c.f. http://stackoverflow.com/questions/8918826/java-os-x-lion-set-application-name-doesnt-work System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "ePADD"); try {/*ww w . j a v a 2 s. co m*/ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { throw new RuntimeException(e); } TrayIcon trayIcon = null; if (SystemTray.isSupported()) { System.out.println("Adding ePADD to the system tray"); SystemTray tray = SystemTray.getSystemTray(); URL u = Main.class.getClassLoader().getResource("muse-icon.png"); // note: this better be 16x16, Windows doesn't resize! Mac os does. System.out.println("ePADD icon resource is " + u); Image image = Toolkit.getDefaultToolkit().getImage(u); System.out.println("Image = " + image); // create menu items and their listeners ActionListener openMuseControlsListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { launchBrowser(BASE_URL); // no + "info" for epadd like in muse } catch (Exception e1) { e1.printStackTrace(); } } }; ActionListener QuitMuseListener = new ActionListener() { public void actionPerformed(ActionEvent e) { out.println("*** Received quit from system tray. Stopping the Jetty embedded web server."); try { server.stop(); } catch (Exception ex) { throw new RuntimeException(ex); } System.exit(0); // we need to explicitly system.exit because we now use Swing (due to system tray, etc). } }; // create a popup menu PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem("Open ePADD window"); defaultItem.addActionListener(openMuseControlsListener); popup.add(defaultItem); MenuItem quitItem = new MenuItem("Quit ePADD"); quitItem.addActionListener(QuitMuseListener); popup.add(quitItem); /// ... add other items // construct a TrayIcon String message = "ePADD menu"; // on windows - the tray menu is a little non-intuitive, needs a right click (plain click seems unused) if (System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0) message = "Right click for ePADD menu"; trayIcon = new TrayIcon(image, message, popup); System.out.println("tray Icon = " + trayIcon); // set the TrayIcon properties // trayIcon.addActionListener(openMuseControlsListener); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } // ... } else { // disable tray option in your application or // perform other actions // ... } System.out.println("Done!"); // ... // some time later // the application state has changed - update the image if (trayIcon != null) { // trayIcon.setImage(updatedImage); } // ... }
From source file:javazoom.jlgui.player.amp.PlayerApplet.java
/** * Loads a skin from a SkinLoader./* w ww .java2 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) 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:org.languagetool.gui.Main.java
private PopupMenu makePopupMenu() { PopupMenu popup = new PopupMenu(); ActionListener rmbListener = new TrayActionRMBListener(); // Enable or disable embedded HTTP server: enableHttpServerItem = new CheckboxMenuItem(Tools.getLabel(messages.getString("tray_menu_enable_server"))); enableHttpServerItem.setState(httpServer != null && httpServer.isRunning()); enableHttpServerItem.addItemListener(new TrayActionItemListener()); popup.add(enableHttpServerItem);//from w w w. j a v a 2 s.c o m // Check clipboard text: MenuItem checkClipboardItem = new MenuItem(Tools.getLabel(messages.getString("guiMenuCheckClipboard"))); checkClipboardItem.addActionListener(rmbListener); popup.add(checkClipboardItem); // Open main window: MenuItem restoreItem = new MenuItem(Tools.getLabel(messages.getString("guiMenuShowMainWindow"))); restoreItem.addActionListener(rmbListener); popup.add(restoreItem); // Exit: MenuItem exitItem = new MenuItem(Tools.getLabel(messages.getString("guiMenuQuit"))); exitItem.addActionListener(rmbListener); popup.add(exitItem); return popup; }
From source file:edu.stanford.epadd.launcher.Splash.java
/** we need a system tray icon for management. * http://docs.oracle.com/javase/6/docs/api/java/awt/SystemTray.html */ public static void setupSystemTrayIcon() { // Set the app name in the menu bar for mac. // c.f. http://stackoverflow.com/questions/8918826/java-os-x-lion-set-application-name-doesnt-work System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "ePADD"); try {/* w w w . ja v a2s. c om*/ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { throw new RuntimeException(e); } TrayIcon trayIcon = null; if (SystemTray.isSupported()) { tellUser("Adding ePADD to the system tray"); SystemTray tray = SystemTray.getSystemTray(); URL u = ePADD.class.getClassLoader().getResource("muse-icon.png"); // note: this better be 16x16, Windows doesn't resize! Mac os does. out.println("ePADD icon resource is " + u); Image image = Toolkit.getDefaultToolkit().getImage(u); out.println("Image = " + image); // create menu items and their listeners ActionListener openMuseControlsListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { launchBrowser(BASE_URL); // no + "info" for epadd like in muse } catch (Exception e1) { e1.printStackTrace(); } } }; ActionListener QuitMuseListener = new ActionListener() { public void actionPerformed(ActionEvent e) { out.println("*** Received quit from system tray. Stopping the Tomcat embedded web server."); try { shutdownSessions(); server.stop(); } catch (Exception ex) { throw new RuntimeException(ex); } System.exit(0); // we need to explicitly system.exit because we now use Swing (due to system tray, etc). } }; // create a popup menu PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem("Open ePADD window"); defaultItem.addActionListener(openMuseControlsListener); popup.add(defaultItem); MenuItem quitItem = new MenuItem("Quit ePADD"); quitItem.addActionListener(QuitMuseListener); popup.add(quitItem); /// ... add other items // construct a TrayIcon String message = "ePADD menu"; // on windows - the tray menu is a little non-intuitive, needs a right click (plain click seems unused) if (System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0) message = "Right click for ePADD menu"; trayIcon = new TrayIcon(image, message, popup); System.out.println("tray Icon = " + trayIcon); // set the TrayIcon properties // trayIcon.addActionListener(openMuseControlsListener); try { tray.add(trayIcon); } catch (AWTException e) { out.println(e); } // ... } else { // disable tray option in your application or // perform other actions // ... } System.out.println("Done!"); // ... // some time later // the application state has changed - update the image if (trayIcon != null) { // trayIcon.setImage(updatedImage); } // ... }