Java Code Examples for javax.swing.JMenuItem#addActionListener()

The following examples show how to use javax.swing.JMenuItem#addActionListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OSPCombo.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Shows the popup immediately below the specified field. If item is selected,
 * sets the field text and fires property change.
 *
 * @param field the field that displays the selected string
 */
public void showPopup(final JTextField display) {
  //display = field;
  Action selectAction = new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
      int prev = selected;
      selected = Integer.parseInt(e.getActionCommand());
      display.setText(items[selected]);
      OSPCombo.this.firePropertyChange("index", prev, -1); //$NON-NLS-1$        
    }

  };
  removeAll();
  for(int i = 0; i<items.length; i++) {
    String next = items[i].toString();
    JMenuItem item = new JMenuItem(next);
    item.setFont(display.getFont());
    item.addActionListener(selectAction);
    item.setActionCommand(String.valueOf(i));
    add(item);
  }
  int popupHeight = 8+getComponentCount()*display.getHeight();
  setPopupSize(display.getWidth(), popupHeight);
  show(display, 0, display.getHeight());
}
 
Example 2
Source File: GeoServerInput.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate workspace list.
 *
 * @param client the client
 * @param parentMenu the parent menu
 */
private void populateWorkspaceList(GeoServerClientInterface client, JMenu parentMenu) {
    for (String workspaceName : client.getWorkspaceList()) {
        JMenuItem workspaceMenuItem = new JMenuItem(workspaceName);
        workspaceMenuItem.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();

                        StyleWrapper styleWrapper = sldData.getStyle();

                        removeStyleFileExtension(styleWrapper);

                        styleWrapper.setWorkspace(workspaceName);
                        client.uploadSLD(styleWrapper, sldData.getSld());
                        client.refreshWorkspace(workspaceName);
                    }
                });
        parentMenu.add(workspaceMenuItem);
    }
}
 
Example 3
Source File: MapMenu.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
private JMenuItem createClubJMenuItem(String clubName, int clubNumber) {
    JMenuItem item = new JMenuItem(clubName);

    item.setActionCommand(Integer.toString(clubNumber));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Mounted club = myEntity.getClubs().get(
                        Integer.parseInt(e.getActionCommand()));
                ((PhysicalDisplay) currentPanel).club(club);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    return item;
}
 
Example 4
Source File: MetalworksFrame.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected JMenu buildViewsMenu() {
    JMenu views = new JMenu("Views");

    JMenuItem inBox = new JMenuItem("Open In-Box");
    JMenuItem outBox = new JMenuItem("Open Out-Box");
    outBox.setEnabled(false);

    inBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openInBox();
        }
    });

    views.add(inBox);
    views.add(outBox);
    return views;
}
 
Example 5
Source File: MetalworksFrame.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected JMenu buildViewsMenu() {
    JMenu views = new JMenu("Views");

    JMenuItem inBox = new JMenuItem("Open In-Box");
    JMenuItem outBox = new JMenuItem("Open Out-Box");
    outBox.setEnabled(false);

    inBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openInBox();
        }
    });

    views.add(inBox);
    views.add(outBox);
    return views;
}
 
Example 6
Source File: MetalworksFrame.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected JMenu buildViewsMenu() {
    JMenu views = new JMenu("Views");

    JMenuItem inBox = new JMenuItem("Open In-Box");
    JMenuItem outBox = new JMenuItem("Open Out-Box");
    outBox.setEnabled(false);

    inBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openInBox();
        }
    });

    views.add(inBox);
    views.add(outBox);
    return views;
}
 
Example 7
Source File: MainMenu.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void addMenuItemForModule(MZmineRunnableModule module) {
  MZmineModuleCategory parentMenu = module.getModuleCategory();
  String menuItemText = module.getName();
  String menuItemToolTip = module.getDescription();

  JMenuItem newItem = new JMenuItem(menuItemText);
  newItem.setToolTipText(menuItemToolTip);
  newItem.addActionListener(this);

  /*
   * Shortcuts keys to open, save and close a project. Implementation will be changed with JavaFX.
   */
  if (menuItemText == "Open project") {
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
  }
  if (menuItemText == "Save project") {
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
  }
  if (menuItemText == "Close project") {
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));
  }

  moduleMenuItems.put(newItem, module);

  addMenuItem(parentMenu, newItem);
}
 
Example 8
Source File: BaseChartPanel.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
@Override
protected JPopupMenu createPopupMenu(boolean properties, boolean copy, boolean save, boolean print, boolean zoom) {
    JPopupMenu popup = super.createPopupMenu(properties, copy, save, print, zoom);
    int n = 0;

    // find the existing 'Copy' menu item and add an option to copy chart data after that
    for (MenuElement element : popup.getSubElements()) {
        JMenuItem item = (JMenuItem) element;

        if (item.getText().equals("Copy")) {
            JMenuItem copyData = new JMenuItem("Copy Chart Data");
            copyData.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    doCopyDataset();
                }
            });

            // after separator, after copy => + 2
            popup.add(copyData, n + 2);
            popup.add(new JPopupMenu.Separator(), n + 3);
        }

        n++;
    }

    // create Save Chart item
    // note that the default 'Save as' item is no present since false was passed into the
    // BaseChartPanel constructor when creating this class' instance
    JMenuItem savePNG = new JMenuItem("Save Chart...");
    savePNG.setActionCommand("SAVE_AS_PNG");
    savePNG.addActionListener(this);

    popup.add(savePNG);

    return popup;
}
 
Example 9
Source File: MainFrame.java    From FCMFrame with Apache License 2.0 5 votes vote down vote up
public JMenuItem createMenuItem(JMenu menu, String label, String mnemonic, String accessibleDescription, Action action) {
	JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(label));
	mi.addActionListener(action);
	if(action == null) {
		mi.setEnabled(false);
	}
	return mi;
}
 
Example 10
Source File: MsgTextAreaJPopupMenu.java    From talent-aio with GNU Lesser General Public License v2.1 5 votes vote down vote up
private JMenuItem getCopyMenuItem()
{
	JMenuItem copyMenuItem = new JMenuItem();
	copyMenuItem.setText("copy");
	copyMenuItem.addActionListener(this);
	return copyMenuItem;
}
 
Example 11
Source File: VideoDownloadWindow.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void createQueueItems(JMenuItem queueMenuItem) {
	ArrayList<DownloadQueue> queues = XDMApp.getInstance().getQueueList();
	for (int i = 0; i < queues.size(); i++) {
		DownloadQueue q = queues.get(i);
		JMenuItem mItem = new JMenuItem(q.getName().length() < 1 ? "Default queue" : q.getName());
		mItem.setName("QUEUE:" + q.getQueueId());
		mItem.setForeground(Color.WHITE);
		mItem.addActionListener(this);
		queueMenuItem.add(mItem);
	}
}
 
Example 12
Source File: VizGUI.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that repopulates the Porjection popup menu.
 */
private void repopulateProjectionPopup() {
    int num = 0;
    String label = "Projection: none";
    if (myState == null) {
        projectionButton.setEnabled(false);
        return;
    }
    projectionButton.setEnabled(true);
    projectionPopup.removeAll();
    final Set<AlloyType> projected = myState.getProjectedTypes();
    for (final AlloyType t : myState.getOriginalModel().getTypes())
        if (myState.canProject(t)) {
            final boolean on = projected.contains(t);
            final JMenuItem m = new JMenuItem(t.getName(), on ? OurCheckbox.ON : OurCheckbox.OFF);
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (on)
                        myState.deproject(t);
                    else
                        myState.project(t);
                    updateDisplay();
                }
            });
            projectionPopup.add(m);
            if (on) {
                num++;
                if (num == 1)
                    label = "Projected over " + t.getName();
            }
        }
    projectionButton.setText(num > 1 ? ("Projected over " + num + " sigs") : label);
}
 
Example 13
Source File: MapMenu.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
private JMenuItem createModeJMenuItem(Mounted mounted, int position) {
    JMenuItem item = new JMenuItem();

    EquipmentMode mode = mounted.getType().getMode(position);

    if (mode.equals(mounted.curMode())) {
        item.setText("* " + mode.getDisplayableName());
    } else {
        item.setText(mode.getDisplayableName());
    }

    item.setActionCommand(Integer.toString(position));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                int modePosition = Integer.parseInt(e.getActionCommand());
                int weaponNum = gui.mechD.wPan.getSelectedWeaponNum();
                Mounted equip = myEntity.getEquipment(weaponNum);
                equip.setMode(modePosition);
                client.sendModeChange(myEntity.getId(), weaponNum,
                                      modePosition);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    return item;

}
 
Example 14
Source File: FilterActions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JMenuItem[] createMenuItems () {
    FiltersDescription filtersDesc = filters.getDescription();
    ArrayList menuItems = new ArrayList();
    for (int i = 0; i < filtersDesc.getFilterCount(); i++) {
        String filterName = filtersDesc.getName(i);
        JMenuItem menuItem = new JCheckBoxMenuItem(
                filtersDesc.getDisplayName(i), filters.isSelected(filterName)); 
        menuItem.addActionListener(this);
        menuItem.putClientProperty(PROP_FILTER_NAME, filterName);
        menuItems.add(menuItem);
    }
    return (JMenuItem[])menuItems.toArray(new JMenuItem[]{});
}
 
Example 15
Source File: MapWindow.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
BBoxPopupMenu(JPopupMenu popupMenu, boolean addSeparator) {
	copy = new JMenuItem();	
	paste = new JMenuItem();

	copy.setEnabled(false);
	paste.setEnabled(clipboardHandler.containsPossibleBoundingBox());

	if (addSeparator) popupMenu.addSeparator();
	popupMenu.add(copy);
	popupMenu.add(paste);

	copy.addActionListener(e -> copyBoundingBoxToClipboard());
	paste.addActionListener(e -> pasteBoundingBoxFromClipboard());
}
 
Example 16
Source File: ImportFromAbstractDialog.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private static void setContextMenu(JTextField field) {
    JMenuItem paste =
            new JMenuItem(Constant.messages.getString(MESSAGE_PREFIX + "pasteaction"));
    paste.addActionListener(e -> field.paste());

    JPopupMenu jPopupMenu = new JPopupMenu();
    jPopupMenu.add(paste);
    field.setComponentPopupMenu(jPopupMenu);
}
 
Example 17
Source File: MetalworksFrame.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected JMenu buildEditMenu() {
    JMenu edit = new JMenu("Edit");
    JMenuItem undo = new JMenuItem("Undo");
    JMenuItem copy = new JMenuItem("Copy");
    JMenuItem cut = new JMenuItem("Cut");
    JMenuItem paste = new JMenuItem("Paste");
    JMenuItem prefs = new JMenuItem("Preferences...");

    undo.setEnabled(false);
    copy.setEnabled(false);
    cut.setEnabled(false);
    paste.setEnabled(false);

    prefs.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openPrefsWindow();
        }
    });

    edit.add(undo);
    edit.addSeparator();
    edit.add(cut);
    edit.add(copy);
    edit.add(paste);
    edit.addSeparator();
    edit.add(prefs);
    return edit;
}
 
Example 18
Source File: VizPanel.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Creates association styles menu items.
 */
protected void createAssociationStylesMenuItem() {
  associationStylesMenuItem = new JMenuItem(Messages
      .getString("Viz.AssociationTypeConfiguration"));
  associationStylesMenuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent action) {
      menuOpenAssociationConfig();
    }
  });
  add(glPopup, associationStylesMenuItem, ITEM_ID_ASSOCIATION_STYLES);
}
 
Example 19
Source File: EnhancementRequestHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
public JMenuItem getComponent() {
    JMenuItem twitterShare = new JMenuItem("Enhancement/Bugs ?", ENHANCEMENT_ICON);
    twitterShare.addActionListener((ActionEvent e) -> {
        SharingHelper.openWebpage(ExceptionUtils.ISSUES_URL);
    });
    return twitterShare;
}
 
Example 20
Source File: TableViewTopComponent.java    From constellation with Apache License 2.0 4 votes vote down vote up
/**
 * Initialise context menu and menu items.
 */
private void initTableContextMenu() {
    // Right click context model initialisation.
    final JMenu copyAllMenu = new JMenu(Bundle.MSG_CopyAllRows());

    final JMenuItem copyAllCommasItem = new JMenuItem(Bundle.MSG_Commas());
    copyAllCommasItem.setActionCommand(ALL_PREFIX + Bundle.MSG_Commas());
    copyAllCommasItem.addActionListener(copyClipboard);

    final JMenuItem copyAllTabsItem = new JMenuItem(Bundle.MSG_Tabs());
    copyAllTabsItem.setActionCommand(ALL_PREFIX + Bundle.MSG_Tabs());
    copyAllTabsItem.addActionListener(copyClipboard);

    copyAllMenu.add(copyAllCommasItem);
    copyAllMenu.add(copyAllTabsItem);

    final JMenu copySelectedMenu = new JMenu(Bundle.MSG_CopySelectedRows());

    final JMenuItem copySelectedCommasItem = new JMenuItem(Bundle.MSG_Commas());
    copySelectedCommasItem.setActionCommand(SEL_PREFIX + Bundle.MSG_Commas());
    copySelectedCommasItem.addActionListener(copyClipboard);

    final JMenuItem copySelectedTabsItem = new JMenuItem(Bundle.MSG_Tabs());
    copySelectedTabsItem.setActionCommand(SEL_PREFIX + Bundle.MSG_Tabs());
    copySelectedTabsItem.addActionListener(copyClipboard);

    copySelectedMenu.add(copySelectedCommasItem);
    copySelectedMenu.add(copySelectedTabsItem);

    final JMenuItem copyCellItem = new JMenuItem(Bundle.MSG_CopyCell());
    copyCellItem.addActionListener(copyClipboard);

    final JMenuItem copyTableItem = new JMenuItem(Bundle.MSG_CopyTable());
    copyTableItem.addActionListener(copyClipboard);

    final JMenuItem copyColumn = new JMenuItem(Bundle.MSG_CopyColumn());
    copyColumn.addActionListener(copyClipboard);

    final JMenuItem copyColumnItem = new JMenuItem(Bundle.MSG_CopyColumns());
    copyColumnItem.addActionListener((final ActionEvent e) -> {
        createSelectColumnDialog();
    });

    final JMenuItem csvAllItem = new JMenuItem(Bundle.MSG_AllCSV());
    csvAllItem.addActionListener(copyClipboard);

    final JMenuItem csvSelectedItem = new JMenuItem(Bundle.MSG_SelectedCSV());
    csvSelectedItem.addActionListener(copyClipboard);

    final JMenuItem excelAllItem = new JMenuItem(Bundle.MSG_AllExcel());
    excelAllItem.addActionListener(copyExcel);

    final JMenuItem excelSelectedItem = new JMenuItem(Bundle.MSG_SelectedExcel());
    excelSelectedItem.addActionListener(copyExcel);

    rightClickMenu.add(copyAllMenu);
    rightClickMenu.add(copySelectedMenu);
    rightClickMenu.add(copyCellItem);
    rightClickMenu.add(copyTableItem);
    rightClickMenu.add(copyColumn);
    rightClickMenu.add(copyColumnItem);

    //combine into a single "export" menu
    final JMenu exportMenu = new JMenu(Bundle.MSG_ExportRows());

    final JMenu exportAllMenu = new JMenu(Bundle.MSG_AllRows());
    exportAllMenu.add(csvAllItem);
    exportAllMenu.add(excelAllItem);

    final JMenu exportSelectedMenu = new JMenu(Bundle.MSG_SelectedRows());
    exportSelectedMenu.add(csvSelectedItem);
    exportSelectedMenu.add(excelSelectedItem);

    exportMenu.add(exportAllMenu);
    exportMenu.add(exportSelectedMenu);

    rightClickMenu.add(exportMenu);

}