List of usage examples for javax.swing JMenu getPopupMenu
@BeanProperty(bound = false)
public JPopupMenu getPopupMenu()
From source file:Main.java
public static void main(String[] argv) throws Exception { JMenu menu = new JMenu("Menu Label"); menu.add(new JMenuItem("Item Label")); boolean lwPopup = menu.getPopupMenu().isLightWeightPopupEnabled(); // true menu.getPopupMenu().setLightWeightPopupEnabled(false); }
From source file:MenuX.java
public static void main(String args[]) { ActionListener actionListener = new MenuActionListener(); MenuKeyListener menuKeyListener = new MyMenuKeyListener(); ChangeListener cListener = new MyChangeListener(); MenuListener menuListener = new MyMenuListener(); MenuSelectionManager manager = MenuSelectionManager.defaultManager(); manager.addChangeListener(cListener); JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new VerticalMenuBar(); // JMenuBar bar = new JMenuBar(); // File Menu, F - Mnemonic JMenu file = new JMenu("File"); file.setMnemonic(KeyEvent.VK_F); file.addChangeListener(cListener);/*from w w w . java 2s.c o m*/ file.addMenuListener(menuListener); file.addMenuKeyListener(menuKeyListener); JPopupMenu popupMenu = file.getPopupMenu(); popupMenu.setLayout(new GridLayout(3, 3)); bar.add(file); // File->New, N - Mnemonic JMenuItem newItem = new JMenuItem("New", KeyEvent.VK_N); newItem.addActionListener(actionListener); newItem.addChangeListener(cListener); newItem.addMenuKeyListener(menuKeyListener); file.add(newItem); // File->Open, O - Mnemonic JMenuItem openItem = new JMenuItem("Open", KeyEvent.VK_O); openItem.addActionListener(actionListener); openItem.addChangeListener(cListener); openItem.addMenuKeyListener(menuKeyListener); file.add(openItem); // File->Close, C - Mnemonic JMenuItem closeItem = new JMenuItem("Close", KeyEvent.VK_C); closeItem.addActionListener(actionListener); closeItem.addChangeListener(cListener); closeItem.addMenuKeyListener(menuKeyListener); file.add(closeItem); // Separator file.addSeparator(); // File->Save, S - Mnemonic JMenuItem saveItem = new JMenuItem("Save", KeyEvent.VK_S); saveItem.addActionListener(actionListener); saveItem.addChangeListener(cListener); saveItem.addMenuKeyListener(menuKeyListener); file.add(saveItem); // Separator file.addSeparator(); // File->Exit, X - Mnemonic JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_X); exitItem.addActionListener(actionListener); exitItem.addChangeListener(cListener); exitItem.addMenuKeyListener(menuKeyListener); file.add(exitItem); // Edit Menu, E - Mnemonic JMenu edit = new JMenu("Edit"); edit.setMnemonic(KeyEvent.VK_E); edit.addChangeListener(cListener); edit.addMenuListener(menuListener); edit.addMenuKeyListener(menuKeyListener); bar.add(edit); // Edit->Cut, T - Mnemonic, CTRL-X - Accelerator JMenuItem cutItem = new JMenuItem("Cut", KeyEvent.VK_T); cutItem.addActionListener(actionListener); cutItem.addChangeListener(cListener); cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK)); cutItem.addMenuKeyListener(menuKeyListener); edit.add(cutItem); // Edit->Copy, C - Mnemonic, CTRL-C - Accelerator JMenuItem copyItem = new JMenuItem("Copy", KeyEvent.VK_C); copyItem.addActionListener(actionListener); copyItem.addChangeListener(cListener); copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK)); copyItem.addMenuKeyListener(menuKeyListener); copyItem.setEnabled(false); edit.add(copyItem); // Edit->Paste, P - Mnemonic, CTRL-V - Accelerator, Disabled JMenuItem pasteItem = new JMenuItem("Paste", KeyEvent.VK_P); pasteItem.addActionListener(actionListener); pasteItem.addChangeListener(cListener); pasteItem.addMenuKeyListener(menuKeyListener); pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK)); pasteItem.setEnabled(false); edit.add(pasteItem); // Separator edit.addSeparator(); // Edit->Find, F - Mnemonic, F3 - Accelerator JMenuItem findItem = new JMenuItem("Find", KeyEvent.VK_F); findItem.addActionListener(actionListener); findItem.addChangeListener(cListener); findItem.addMenuKeyListener(menuKeyListener); findItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); edit.add(findItem); // Edit->Options Submenu, O - Mnemonic, at.gif - Icon Image File JMenu findOptions = new JMenu("Options"); findOptions.addChangeListener(cListener); findOptions.addMenuListener(menuListener); findOptions.addMenuKeyListener(menuKeyListener); Icon atIcon = new ImageIcon("at.gif"); findOptions.setIcon(atIcon); findOptions.setMnemonic(KeyEvent.VK_O); // ButtonGrou for radio buttons ButtonGroup directionGroup = new ButtonGroup(); // Edit->Options->Forward, F - Mnemonic, in group JRadioButtonMenuItem forward = new JRadioButtonMenuItem("Forward", true); forward.addActionListener(actionListener); forward.addChangeListener(cListener); forward.addMenuKeyListener(menuKeyListener); forward.setMnemonic(KeyEvent.VK_F); findOptions.add(forward); directionGroup.add(forward); // Edit->Options->Backward, B - Mnemonic, in group JRadioButtonMenuItem backward = new JRadioButtonMenuItem("Backward"); backward.addActionListener(actionListener); backward.addChangeListener(cListener); backward.addMenuKeyListener(menuKeyListener); backward.setMnemonic(KeyEvent.VK_B); findOptions.add(backward); directionGroup.add(backward); // Separator findOptions.addSeparator(); // Edit->Options->Case Sensitive, C - Mnemonic JCheckBoxMenuItem caseItem = new JCheckBoxMenuItem("Case Sensitive"); caseItem.addActionListener(actionListener); caseItem.addChangeListener(cListener); caseItem.addMenuKeyListener(menuKeyListener); caseItem.setMnemonic(KeyEvent.VK_C); findOptions.add(caseItem); edit.add(findOptions); frame.setJMenuBar(bar); // frame.getContentPane().add(bar, BorderLayout.EAST); frame.setSize(350, 250); frame.setVisible(true); }
From source file:MenuY.java
public static void main(String args[]) { ActionListener actionListener = new MenuActionListener(); MenuKeyListener menuKeyListener = new MyMenuKeyListener(); ChangeListener cListener = new MyChangeListener(); MenuListener menuListener = new MyMenuListener(); MenuSelectionManager manager = MenuSelectionManager.defaultManager(); manager.addChangeListener(cListener); JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new VerticalMenuBar(); // JMenuBar bar = new JMenuBar(); // File Menu, F - Mnemonic JMenu file = new JMenu("File"); file.setMnemonic(KeyEvent.VK_F); file.addChangeListener(cListener);//from ww w . jav a 2 s . c om file.addMenuListener(menuListener); file.addMenuKeyListener(menuKeyListener); JPopupMenu popupMenu = file.getPopupMenu(); popupMenu.setLayout(new GridLayout(3, 3)); bar.add(file); // File->New, N - Mnemonic JMenuItem newItem = new JMenuItem("New", KeyEvent.VK_N); newItem.addActionListener(actionListener); newItem.addChangeListener(cListener); newItem.addMenuKeyListener(menuKeyListener); file.add(newItem); // File->Open, O - Mnemonic JMenuItem openItem = new JMenuItem("Open", KeyEvent.VK_O); openItem.addActionListener(actionListener); openItem.addChangeListener(cListener); openItem.addMenuKeyListener(menuKeyListener); file.add(openItem); // File->Close, C - Mnemonic JMenuItem closeItem = new JMenuItem("Close", KeyEvent.VK_C); closeItem.addActionListener(actionListener); closeItem.addChangeListener(cListener); closeItem.addMenuKeyListener(menuKeyListener); file.add(closeItem); // Separator file.addSeparator(); // File->Save, S - Mnemonic JMenuItem saveItem = new JMenuItem("Save", KeyEvent.VK_S); saveItem.addActionListener(actionListener); saveItem.addChangeListener(cListener); saveItem.addMenuKeyListener(menuKeyListener); file.add(saveItem); // Separator file.addSeparator(); // File->Exit, X - Mnemonic JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_X); exitItem.addActionListener(actionListener); exitItem.addChangeListener(cListener); exitItem.addMenuKeyListener(menuKeyListener); file.add(exitItem); // Edit Menu, E - Mnemonic JMenu edit = new JMenu("Edit"); edit.setMnemonic(KeyEvent.VK_E); edit.addChangeListener(cListener); edit.addMenuListener(menuListener); edit.addMenuKeyListener(menuKeyListener); bar.add(edit); // Edit->Cut, T - Mnemonic, CTRL-X - Accelerator JMenuItem cutItem = new JMenuItem("Cut", KeyEvent.VK_T); cutItem.addActionListener(actionListener); cutItem.addChangeListener(cListener); cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK)); cutItem.addMenuKeyListener(menuKeyListener); edit.add(cutItem); // Edit->Copy, C - Mnemonic, CTRL-C - Accelerator JMenuItem copyItem = new JMenuItem("Copy", KeyEvent.VK_C); copyItem.addActionListener(actionListener); copyItem.addChangeListener(cListener); copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK)); copyItem.addMenuKeyListener(menuKeyListener); copyItem.setEnabled(false); edit.add(copyItem); // Edit->Paste, P - Mnemonic, CTRL-V - Accelerator, Disabled JMenuItem pasteItem = new JMenuItem("Paste", KeyEvent.VK_P); pasteItem.addActionListener(actionListener); pasteItem.addChangeListener(cListener); pasteItem.addMenuKeyListener(menuKeyListener); pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK)); pasteItem.setEnabled(false); edit.add(pasteItem); // Separator edit.addSeparator(); // Edit->Find, F - Mnemonic, F3 - Accelerator JMenuItem findItem = new JMenuItem("Find", KeyEvent.VK_F); findItem.addActionListener(actionListener); findItem.addChangeListener(cListener); findItem.addMenuKeyListener(menuKeyListener); findItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); edit.add(findItem); // Edit->Options Submenu, O - Mnemonic, at.gif - Icon Image File Icon atIcon = new ImageIcon("at.gif"); Action findAction = new AbstractAction("Options", atIcon) { ActionListener actionListener = new MenuActionListener(); public void actionPerformed(ActionEvent e) { actionListener.actionPerformed(e); } }; findAction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_O)); JMenuItem jMenuItem = new JMenuItem(findAction); JMenu findOptions = new JMenu(findAction); findOptions.addChangeListener(cListener); findOptions.addMenuListener(menuListener); findOptions.addMenuKeyListener(menuKeyListener); // ButtonGrou for radio buttons ButtonGroup directionGroup = new ButtonGroup(); // Edit->Options->Forward, F - Mnemonic, in group JRadioButtonMenuItem forward = new JRadioButtonMenuItem("Forward", true); forward.addActionListener(actionListener); forward.addChangeListener(cListener); forward.addMenuKeyListener(menuKeyListener); forward.setMnemonic(KeyEvent.VK_F); findOptions.add(forward); directionGroup.add(forward); // Edit->Options->Backward, B - Mnemonic, in group JRadioButtonMenuItem backward = new JRadioButtonMenuItem("Backward"); backward.addActionListener(actionListener); backward.addChangeListener(cListener); backward.addMenuKeyListener(menuKeyListener); backward.setMnemonic(KeyEvent.VK_B); findOptions.add(backward); directionGroup.add(backward); // Separator findOptions.addSeparator(); // Edit->Options->Case Sensitive, C - Mnemonic JCheckBoxMenuItem caseItem = new JCheckBoxMenuItem("Case Sensitive"); caseItem.addActionListener(actionListener); caseItem.addChangeListener(cListener); caseItem.addMenuKeyListener(menuKeyListener); caseItem.setMnemonic(KeyEvent.VK_C); findOptions.add(caseItem); edit.add(findOptions); frame.setJMenuBar(bar); // frame.getContentPane().add(bar, BorderLayout.EAST); frame.setSize(350, 250); frame.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);/*from w ww .j av a2 s . c o m*/ menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); JPopupMenu pop = menu.getPopupMenu(); }
From source file:edu.brown.gui.CatalogViewer.java
/** * //from w w w . j a v a 2s. com */ protected void viewerInit() { // ---------------------------------------------- // MENU // ---------------------------------------------- JMenu menu; JMenuItem menuItem; // // File Menu // menu = new JMenu("File"); menu.getPopupMenu().setLightWeightPopupEnabled(false); menu.setMnemonic(KeyEvent.VK_F); menu.getAccessibleContext().setAccessibleDescription("File Menu"); menuBar.add(menu); menuItem = new JMenuItem("Open Catalog From File"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From File"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_FILE); menu.add(menuItem); menuItem = new JMenuItem("Open Catalog From Jar"); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From Project Jar"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_JAR); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Quit", KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Quit Program"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.QUIT); menu.add(menuItem); // ---------------------------------------------- // CATALOG TREE PANEL // ---------------------------------------------- this.catalogTree = new JTree(); this.catalogTree.setEditable(false); this.catalogTree.setCellRenderer(new CatalogViewer.CatalogTreeRenderer()); this.catalogTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); this.catalogTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) CatalogViewer.this.catalogTree .getLastSelectedPathComponent(); if (node == null) return; Object user_obj = node.getUserObject(); String new_text = ""; // <html>"; boolean text_mode = true; if (user_obj instanceof WrapperNode) { CatalogType catalog_obj = ((WrapperNode) user_obj).getCatalogType(); new_text += CatalogViewer.this.getAttributesText(catalog_obj); } else if (user_obj instanceof AttributesNode) { AttributesNode wrapper = (AttributesNode) user_obj; new_text += wrapper.getAttributes(); } else if (user_obj instanceof PlanTreeCatalogNode) { final PlanTreeCatalogNode wrapper = (PlanTreeCatalogNode) user_obj; text_mode = false; CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(wrapper.getPanel(), BorderLayout.CENTER); CatalogViewer.this.mainPanel.validate(); CatalogViewer.this.mainPanel.repaint(); if (SwingUtilities.isEventDispatchThread() == false) { SwingUtilities.invokeLater(new Runnable() { public void run() { wrapper.centerOnRoot(); } }); } else { wrapper.centerOnRoot(); } } else { new_text += CatalogViewer.this.getSummaryText(); } // Text Mode if (text_mode) { if (CatalogViewer.this.text_mode == false) { CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(CatalogViewer.this.textInfoPanel); } CatalogViewer.this.textInfoTextArea.setText(new_text); // Scroll to top CatalogViewer.this.textInfoTextArea.grabFocus(); } CatalogViewer.this.text_mode = text_mode; } }); this.generateCatalogTree(this.catalog, this.catalog_file_path.getName()); // // Text Information Panel // this.textInfoPanel = new JPanel(); this.textInfoPanel.setLayout(new BorderLayout()); this.textInfoTextArea = new JTextArea(); this.textInfoTextArea.setEditable(false); this.textInfoTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); this.textInfoTextArea.setText(this.getSummaryText()); this.textInfoTextArea.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { // TODO Auto-generated method stub } @Override public void focusGained(FocusEvent e) { CatalogViewer.this.scrollTextInfoToTop(); } }); this.textInfoScroller = new JScrollPane(this.textInfoTextArea); this.textInfoPanel.add(this.textInfoScroller, BorderLayout.CENTER); this.mainPanel = new JPanel(new BorderLayout()); this.mainPanel.add(textInfoPanel, BorderLayout.CENTER); // // Search Toolbar // JPanel searchPanel = new JPanel(); searchPanel.setLayout(new BorderLayout()); JPanel innerSearchPanel = new JPanel(); innerSearchPanel.setLayout(new BoxLayout(innerSearchPanel, BoxLayout.X_AXIS)); innerSearchPanel.add(new JLabel("Search: ")); this.searchField = new JTextField(30); innerSearchPanel.add(this.searchField); searchPanel.add(innerSearchPanel, BorderLayout.EAST); this.searchField.addKeyListener(new KeyListener() { private String last = null; @Override public void keyReleased(KeyEvent e) { String value = CatalogViewer.this.searchField.getText().toLowerCase().trim(); if (!value.isEmpty() && (this.last == null || !this.last.equals(value))) { CatalogViewer.this.search(value); } this.last = value; } @Override public void keyTyped(KeyEvent e) { // Do nothing... } @Override public void keyPressed(KeyEvent e) { // Do nothing... } }); // Putting it all together JScrollPane scrollPane = new JScrollPane(this.catalogTree); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); topPanel.add(searchPanel, BorderLayout.NORTH); topPanel.add(scrollPane, BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, this.mainPanel); splitPane.setDividerLocation(400); this.add(splitPane, BorderLayout.CENTER); }
From source file:org.jdal.swing.PageableTable.java
/** * Create the right menu bar/*from www . j av a 2s . c o m*/ */ private void createMenu() { rightMenuBar = new JMenuBar(); rightMenuBar.setLayout(new BoxLayout(rightMenuBar, BoxLayout.PAGE_AXIS)); rightMenuBar.setMargin(new Insets(0, 0, 0, 0)); // Add Visibility menu JMenu menu = new JMenu(); menu.setMargin(new Insets(0, 0, 0, 0)); menu.setIcon(visibilityMenuIcon); menu.setMaximumSize(new Dimension(50, 50)); visibilityBox = new VisibilityBox(columnDescriptors); menu.add(visibilityBox); menu.getPopupMenu().addPopupMenuListener(new VisibilityPopupListener()); JMenuItem okMenuItem = new JMenuItem(new OkVisibilityAction()); JMenuItem cancelMenuItem = new JMenuItem(new CancelVisibilityAction()); menu.addSeparator(); menu.add(okMenuItem); menu.add(cancelMenuItem); rightMenuBar.add(menu); JMenu prefsMenu = new JMenu(); prefsMenu.setMargin(new Insets(0, 0, 0, 0)); prefsMenu.setIcon(userMenuIcon); prefsMenu.setMaximumSize(new Dimension(50, 50)); prefsMenu.add(new JMenuItem(new LoadPreferencesAction(this, messageSource .getMessage("PageableTable.loadPreferences", null, "Load Preferences", Locale.getDefault())))); prefsMenu.add(new JMenuItem(new SavePreferencesAction(this, messageSource .getMessage("PageableTable.savePreferences", null, "Save Preferences", Locale.getDefault())))); rightMenuBar.add(prefsMenu); rightMenuBar.add(Box.createVerticalGlue()); // Add menu bar to right add(rightMenuBar, BorderLayout.EAST); }
From source file:ca.sqlpower.swingui.object.VariablesPanel.java
@SuppressWarnings("unchecked") private void showVarsPicker() { final MultiValueMap namespaces = this.variableHelper.getNamespaces(); List<String> sortedNames = new ArrayList<String>(namespaces.keySet().size()); sortedNames.addAll(namespaces.keySet()); Collections.sort(sortedNames, new Comparator<String>() { public int compare(String o1, String o2) { if (o1 == null) { return -1; }/*ww w. java2 s . com*/ if (o2 == null) { return 1; } return o1.compareTo(o2); }; }); final JPopupMenu menu = new JPopupMenu(); for (final String name : sortedNames) { final JMenu subMenu = new JMenu(name); menu.add(subMenu); subMenu.addMenuListener(new MenuListener() { private Timer timer; public void menuSelected(MenuEvent e) { subMenu.removeAll(); subMenu.add(new PleaseWaitAction()); ActionListener menuPopulator = new ActionListener() { public void actionPerformed(ActionEvent e) { if (subMenu.isPopupMenuVisible()) { subMenu.removeAll(); for (Object namespaceO : namespaces.getCollection(name)) { String namespace = (String) namespaceO; logger.debug("Resolving variables for namespace ".concat(namespace)); int nbItems = 0; for (String key : variableHelper.keySet(namespace)) { subMenu.add(new InsertVariableAction(SPVariableHelper.getKey((String) key), (String) key)); nbItems++; } if (nbItems == 0) { subMenu.add(new DummyAction()); logger.debug("No variables found."); } } subMenu.revalidate(); subMenu.getPopupMenu().pack(); } } }; timer = new Timer(700, menuPopulator); timer.setRepeats(false); timer.start(); } public void menuDeselected(MenuEvent e) { timer.stop(); } public void menuCanceled(MenuEvent e) { timer.stop(); } }); } menu.show(varNameText, 0, varNameText.getHeight()); }
From source file:net.sf.vfsjfilechooser.filepane.VFSFilePane.java
@Override public JPopupMenu getComponentPopupMenu() { JPopupMenu popupMenu = getFileChooser().getComponentPopupMenu(); if (popupMenu != null) { return popupMenu; }/* www . j av a 2 s .c o m*/ JMenu aViewMenu = getViewMenu(); if (contextMenu == null) { contextMenu = new JPopupMenu(); if (aViewMenu != null) { contextMenu.add(aViewMenu); if (listViewWindowsStyle) { contextMenu.addSeparator(); } } ActionMap actionMap = getActionMap(); Action refreshAction = actionMap.get(ACTION_REFRESH); Action aNewFolderAction = actionMap.get(ACTION_NEW_FOLDER); if (refreshAction != null) { contextMenu.add(refreshAction); if (listViewWindowsStyle && (aNewFolderAction != null)) { contextMenu.addSeparator(); } } if (aNewFolderAction != null) { contextMenu.add(aNewFolderAction); } } if (aViewMenu != null) { aViewMenu.getPopupMenu().setInvoker(aViewMenu); } return contextMenu; }
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
@Override public JPopupMenu getComponentPopupMenu() { JPopupMenu popupMenu = getFileChooser().getComponentPopupMenu(); if (popupMenu != null) { return popupMenu; }// w w w . ja v a2s .c o m JMenu aViewMenu = getViewMenu(); if (contextMenu == null) { contextMenu = new JPopupMenu(); if (aViewMenu != null) { contextMenu.add(aViewMenu); if (listViewWindowsStyle) { contextMenu.addSeparator(); } } ActionMap actionMap = getActionMap(); Action refreshAction = actionMap.get(ACTION_REFRESH); Action aNewFolderAction = actionMap.get(ACTION_NEW_FOLDER); Action showHiddenFiles = actionMap.get(ACTION_VIEW_HIDDEN); if (refreshAction != null) { contextMenu.add(refreshAction); if (listViewWindowsStyle && (aNewFolderAction != null)) { contextMenu.addSeparator(); } } if (showHiddenFiles != null) { JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem(showHiddenFiles); menuitem.setSelected((Boolean) showHiddenFiles.getValue(Action.SELECTED_KEY)); contextMenu.add(menuitem); } if (aNewFolderAction != null) { contextMenu.add(aNewFolderAction); } } if (aViewMenu != null) { aViewMenu.getPopupMenu().setInvoker(aViewMenu); } return contextMenu; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * Build menu./*from w ww .j av a 2 s . com*/ */ public void makeMenu() { JMenuItem menuItem; JMenu menu; JMenu submenu; menuBar = new JMenuBar(); setJMenuBar(menuBar); menu = new JMenu(Menu.MENU_FILE); menu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem(Menu.NEW_SCHEME, KeyEvent.VK_N); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.LOAD_SCHEME, KeyEvent.VK_O); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD_SCHEME, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.SAVE_SCHEME, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SCHEME_AS); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.DELETE_SCHEME, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.EXPORT_MENU); menu.add(submenu); //submenu.setMnemonic( KeyEvent.VK_E ); SchemeExporter.makeSchemeExportMenu(submenu, getActionListener()); // Export window graphics submenu.add(GraphicsExporter.getExportMenu()); menu.addSeparator(); menuItem = new JMenuItem(Menu.PRINT, KeyEvent.VK_P); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.EXIT, KeyEvent.VK_X); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu = new JMenu(Menu.MENU_EDIT); menu.setMnemonic(KeyEvent.VK_E); menu.add(undoAction); menu.add(redoAction); menu.add(cloneAction); menuItem = new JMenuItem(Menu.SCHEME_FIND, KeyEvent.VK_F); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SELECT_ALL, KeyEvent.VK_A); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLEAR_ALL, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); final JCheckBoxMenuItem painterEnabled = new JCheckBoxMenuItem(Menu.CLASSPAINTER, true); painterEnabled.addActionListener(getActionListener()); menu.add(painterEnabled); menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas = Editor.getInstance().getCurrentCanvas(); if (canvas == null || !canvas.getPackage().hasPainters()) { painterEnabled.setVisible(false); } else { painterEnabled.setVisible(true); painterEnabled.setSelected(canvas.isEnableClassPainter()); } } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_VIEW); menu.setMnemonic(KeyEvent.VK_V); gridCheckBox = new JCheckBoxMenuItem(Menu.GRID, RuntimeProperties.isShowGrid()); gridCheckBox.setMnemonic('G'); gridCheckBox.addActionListener(getActionListener()); menu.add(gridCheckBox); ctrlCheckBox = new JCheckBoxMenuItem(Menu.CONTROL_PANEL, RuntimeProperties.isShowControls()); ctrlCheckBox.setMnemonic('C'); ctrlCheckBox.addActionListener(getActionListener()); menu.add(ctrlCheckBox); showPortCheckBox = new JCheckBoxMenuItem(Menu.SHOW_PORTS, true); showPortCheckBox.addActionListener(getActionListener()); menu.add(showPortCheckBox); showObjectNamesCheckBox = new JCheckBoxMenuItem(Menu.SHOW_NAMES, false); showObjectNamesCheckBox.addActionListener(getActionListener()); menu.add(showObjectNamesCheckBox); //sync View with current canvas menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas; if ((canvas = getCurrentCanvas()) == null) return; gridCheckBox.setSelected(canvas.isGridVisible()); ctrlCheckBox.setSelected(canvas.isCtrlPanelVisible()); showPortCheckBox.setSelected(canvas.isDrawPorts()); showObjectNamesCheckBox.setSelected(canvas.isShowObjectNames()); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_PACKAGE); menu.setMnemonic(KeyEvent.VK_P); menuItem = new JMenuItem(Menu.LOAD, KeyEvent.VK_L); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.INFO, KeyEvent.VK_I); menuItem.addActionListener(getActionListener()); menu.add(menuItem); if (Desktop.isDesktopSupported()) { menuItem = new JMenuItem(Menu.BROWSE_PACKAGE, KeyEvent.VK_B); menuItem.addActionListener(getActionListener()); menu.add(menuItem); } menuItem = new JMenuItem(Menu.CLOSE, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLOSE_ALL); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu.add(new JSeparator()); final JMenu submenuRecent = new JMenu(Menu.RECENT); submenuRecent.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { final JMenuItem empty = new JMenuItem("Empty"); @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeRecentSubMenu(submenuRecent); if (submenuRecent.getMenuComponentCount() == 0) { submenuRecent.add(empty); empty.setEnabled(false); } else { if (!((submenuRecent.getMenuComponentCount() == 1) && (submenuRecent.getPopupMenu().getComponentIndex(empty) >= -1))) { submenuRecent.remove(empty); } } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menu.add(submenuRecent); final JMenu menuScheme = new JMenu(Menu.MENU_SCHEME); menuScheme.setMnemonic(KeyEvent.VK_S); makeSchemeMenu(menuScheme); menuScheme.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeSchemeMenu(menuScheme); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); /* * menuItem = new JMenuItem("Planner"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); * menuItem = new JMenuItem("Plan, compile, run"); * menuItem.setActionCommand("Run"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); */ // menuScheme.setMnemonic(KeyEvent.VK_A); menuBar.add(menuScheme); menu = new JMenu(Menu.MENU_OPTIONS); menu.setMnemonic(KeyEvent.VK_O); menuItem = new JMenuItem(Menu.SETTINGS, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.FONTS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SETTINGS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.MENU_LAF); submenu.setMnemonic(KeyEvent.VK_L); Look.getInstance().createMenuItems(submenu); menu.add(submenu); menuBar.add(menu); makeToolsMenu(menuBar); menu = new JMenu(Menu.MENU_HELP); menu.setMnemonic(KeyEvent.VK_H); menuBar.add(menu); menuItem = new JMenuItem(Menu.DOCS, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }