List of usage examples for javax.swing JMenuItem JMenuItem
public JMenuItem(Action a)
Action
. From source file:io.github.jeddict.jpa.modeler.widget.attribute.AttributeWidget.java
@Override protected List<JMenuItem> getPopupMenuItemList() { List<JMenuItem> menuList = super.getPopupMenuItemList(); JMenuItem delete;/*from w ww . j a v a2 s. c om*/ delete = new JMenuItem("Delete"); delete.setIcon(DELETE_ICON); delete.addActionListener(e -> AttributeWidget.this.remove(true)); menuList.add(0, delete); return menuList; }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
private void showIconMenu(MouseEvent e) { try {//from w w w . j a v a 2s . c o m iconMenu = new JPopupMenu(); JMenuItem loadItem = new JMenuItem("Load"); iconMenu.add(loadItem); loadItem.setHorizontalTextPosition(JMenuItem.RIGHT); loadItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String favicon$ = "http://www.google.com/s2/favicons?domain=" + addressField.getText(); URL url = new URL(favicon$); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); ImageIcon icon = new ImageIcon(ImageIO.read(input)); int type = BufferedImage.TYPE_INT_RGB; BufferedImage out = new BufferedImage(24, 24, type); Color background = JWeblinkEditor.this.getBackground(); Graphics2D g2 = out.createGraphics(); g2.setBackground(background); g2.clearRect(0, 0, 24, 24); Image image = icon.getImage(); g2.drawImage(image, 4, 4, null); g2.dispose(); icon = new ImageIcon(out); iconIcon.setIcon(icon); input.close(); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); JMenuItem setItem = new JMenuItem("Set"); iconMenu.add(setItem); setItem.setHorizontalTextPosition(JMenuItem.RIGHT); setItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("WeblinkEditor:set icon"); JIconSelector is = new JIconSelector(); String isLocator$ = is.getLocator(); if (entihome$ != null) isLocator$ = Locator.append(isLocator$, Entigrator.ENTIHOME, entihome$); if (entityKey$ != null) isLocator$ = Locator.append(isLocator$, EntityHandler.ENTITY_KEY, entityKey$); String responseLocator$ = getLocator(); responseLocator$ = Locator.append(responseLocator$, JRequester.REQUESTER_ACTION, ACTION_SET_ICON); responseLocator$ = Locator.append(responseLocator$, BaseHandler.HANDLER_METHOD, "response"); isLocator$ = Locator.append(isLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(responseLocator$)); JConsoleHandler.execute(console, isLocator$); } }); iconMenu.show(e.getComponent(), e.getX(), e.getY()); } catch (Exception ee) { Logger.getLogger(getClass().getName()).severe(ee.toString()); } }
From source file:com.raceup.fsae.test.TesterGui.java
/** * Creates new edit menu/*from w w w . ja v a 2 s .c o m*/ * * @return edit menu */ private JMenu createEditMenu() { JMenu menu = new JMenu("Edit"); // file menu JMenuItem item = new JMenuItem("Test submissions seconds wait"); item.addActionListener(e -> { String userInput = JOptionPane.showInputDialog("Test submissions seconds wait", SECONDS_WAIT_BETWEEN_SUBMISSIONS); SECONDS_WAIT_BETWEEN_SUBMISSIONS = Integer.parseInt(userInput); // update }); menu.add(item); return menu; }
From source file:gdt.jgui.entity.JEntityFacetPanel.java
/** *Get the context menu./* w w w .j a v a 2 s .c om*/ *@return the context menu. */ @Override public JMenu getContextMenu() { menu = super.getContextMenu(); menu.addSeparator(); JMenuItem showStructure = new JMenuItem("Structure"); showStructure.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String locator$ = getLocator(); JEntityStructurePanel esp = new JEntityStructurePanel(); esp.instantiate(console, locator$); String espLocator$ = esp.getLocator(); espLocator$ = Locator.append(espLocator$, Entigrator.ENTIHOME, entihome$); espLocator$ = Locator.append(espLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, espLocator$); } }); menu.add(showStructure); JMenuItem showDigest = new JMenuItem("Digest"); showDigest.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String locator$ = getLocator(); JEntityDigestDisplay edd = new JEntityDigestDisplay(); edd.instantiate(console, locator$); String eddLocator$ = edd.getLocator(); eddLocator$ = Locator.append(eddLocator$, Entigrator.ENTIHOME, entihome$); eddLocator$ = Locator.append(eddLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, eddLocator$); } }); menu.add(showDigest); menu.addSeparator(); addFacets = new JMenuItem("Add facets"); addFacets.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String locator$ = getLocator(); JEntityAddFacets addFacets = new JEntityAddFacets(); addFacets.instantiate(console, locator$); String facetSelector$ = addFacets.getLocator(); facetSelector$ = Locator.append(facetSelector$, Entigrator.ENTIHOME, entihome$); facetSelector$ = Locator.append(facetSelector$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, facetSelector$); } }); menu.add(addFacets); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String locator$ = getLocator(); String requesterResponseLocator$ = Locator.getProperty(locator$, JRequester.REQUESTER_RESPONSE_LOCATOR); if (requesterResponseLocator$ == null) console.back(); else { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); // System.out.println("EntityfacetPanel:done:response locator="+responseLocator$); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { LOGGER.info(ee.toString()); } } } }); menu.add(doneItem); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { //System.out.println("EntityEditor:getConextMenu:menu selected"); if (removeFacets != null) menu.remove(removeFacets); if (copyFacets != null) menu.remove(copyFacets); if (hasSelectedItems()) { copyFacets = new JMenuItem("Copy facets"); copyFacets.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copyFacets(); } }); menu.add(copyFacets); } if (hasSelectedRemovableFacets()) { removeFacets = new JMenuItem("Remove facets"); removeFacets.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeFacets(); } }); menu.add(removeFacets); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu; }
From source file:medsavant.enrichment.app.OntologyAggregatePanel.java
private JPopupMenu createPopup() { JPopupMenu menu = new JPopupMenu(); SortableTreeTableModel model = (SortableTreeTableModel) tree.getModel(); final int[] selRows = tree.getSelectedRows(); JMenuItem posItem = new JMenuItem(String.format("<html>Filter by %s</html>", selRows.length == 1 ? "Ontology Term <i>" + model.getValueAt(selRows[0], 0) + "</i>" : "Selected Ontology Terms")); posItem.addActionListener(new ActionListener() { @Override//from www . j a v a2 s .c om public void actionPerformed(ActionEvent ae) { ThreadController.getInstance().cancelWorkers(pageName); List<OntologyTerm> terms = new ArrayList<OntologyTerm>(); SortableTreeTableModel model = (SortableTreeTableModel) tree.getModel(); for (int r : selRows) { OntologyNode rowNode = (OntologyNode) model.getRowAt(r); terms.add(rowNode.term); } OntologyType ont = terms.get(0).getOntology(); GeneticsFilterPage.getSearchBar().loadFilters( OntologyFilterView.wrapState(OntologyFilter.ontologyToTitle(ont), ont, terms, false)); } }); menu.add(posItem); return menu; }
From source file:biz.wolschon.finance.jgnucash.accountProperties.AccountProperties.java
private JPopupMenu createAccountIDPopupMenu() { final JPopupMenu accountIDPopupMenu = new JPopupMenu(); JMenuItem copyAccountIDMenuItem = new JMenuItem("copy"); copyAccountIDMenuItem.addActionListener(new ActionListener() { @Override//from w ww . jav a2s . c o m public void actionPerformed(final ActionEvent arg0) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(myAccount.getId()), AccountProperties.this); } }); accountIDPopupMenu.add(copyAccountIDMenuItem); return accountIDPopupMenu; }
From source file:org.rdv.viz.chart.ChartViz.java
/** * Create the chart and setup it's UI./*from www .j a v a 2s . c o m*/ */ private void initChart() { XYToolTipGenerator toolTipGenerator; if (xyMode) { dataCollection = new XYTimeSeriesCollection(); NumberAxis domainAxis = new NumberAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.addChangeListener(new AxisChangeListener() { public void axisChanged(AxisChangeEvent ace) { boundsChanged(); } }); this.domainAxis = domainAxis; toolTipGenerator = new StandardXYToolTipGenerator("{0}: {1} , {2}", new DecimalFormat(), new DecimalFormat()); } else { dataCollection = new TimeSeriesCollection(); domainAxis = new FixedAutoAdjustRangeDateAxis(); domainAxis.setLabel("Time"); domainAxis.setAutoRange(false); toolTipGenerator = new StandardXYToolTipGenerator("{0}: {1} , {2}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"), new DecimalFormat()); } rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.addChangeListener(new AxisChangeListener() { public void axisChanged(AxisChangeEvent ace) { boundsChanged(); } }); FastXYItemRenderer renderer = new FastXYItemRenderer(StandardXYItemRenderer.LINES, toolTipGenerator); renderer.setBaseCreateEntities(false); renderer.setBaseStroke(new BasicStroke(0.5f)); if (xyMode) { renderer.setCursorVisible(true); } xyPlot = new XYPlot(dataCollection, domainAxis, rangeAxis, renderer); chart = new JFreeChart(xyPlot); chart.setAntiAlias(false); seriesLegend = chart.getLegend(); chart.removeLegend(); chartPanel = new ChartPanel(chart, true); chartPanel.setInitialDelay(0); // get the chart panel standard popup menu JPopupMenu popupMenu = chartPanel.getPopupMenu(); // create a popup menu item to copy an image to the clipboard final JMenuItem copyChartMenuItem = new JMenuItem("Copy"); copyChartMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { copyChart(); } }); popupMenu.insert(copyChartMenuItem, 2); popupMenu.insert(new JPopupMenu.Separator(), 3); popupMenu.add(new JPopupMenu.Separator()); showLegendMenuItem = new JCheckBoxMenuItem("Show Legend", true); showLegendMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setShowLegend(showLegendMenuItem.isSelected()); } }); popupMenu.add(showLegendMenuItem); if (xyMode) { popupMenu.add(new JPopupMenu.Separator()); JMenuItem addLocalSeriesMenuItem = new JMenuItem("Add local series..."); addLocalSeriesMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { addLocalSeries(); } }); popupMenu.add(addLocalSeriesMenuItem); } chartPanelPanel = new JPanel(); chartPanelPanel.setLayout(new BorderLayout()); chartPanelPanel.add(chartPanel, BorderLayout.CENTER); }
From source file:edu.brown.gui.CatalogViewer.java
/** * //from w w w. j a v a 2 s . c o m */ 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:gda.gui.mca.McaGUI.java
private SimplePlot getSimplePlot() { if (simplePlot == null) { simplePlot = new SimplePlot(); simplePlot.setYAxisLabel("Values"); simplePlot.setTitle("MCA"); /*//from ww w .j a va 2 s .c o m * do not attempt to get calibration until the analyser is available getEnergyCalibration(); */ simplePlot.setXAxisLabel("Channel Number"); simplePlot.setTrackPointer(true); JPopupMenu menu = simplePlot.getPopupMenu(); JMenuItem item = new JMenuItem("Add Region Of Interest"); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "To add a region of interest, please click on region low" + " and region high channels\n" + "in the graph and set the index\n"); regionClickCount = 0; } }); JMenuItem calibitem = new JMenuItem("Calibrate Energy"); /* * Comment out as calibration is to come from the analyser directly menu.add(calibitem); */ calibitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { // regionClickCount = 0; int[] data = (int[]) analyser.getData(); double[] dData = new double[data.length]; for (int i = 0; i < dData.length; i++) { dData[i] = data[i]; } if (energyCalibrationDialog == null) { energyCalibrationDialog = new McaCalibrationPanel( (EpicsMCARegionOfInterest[]) analyser.getRegionsOfInterest(), dData, mcaName); energyCalibrationDialog.addIObserver(McaGUI.this); } energyCalibrationDialog.setVisible(true); } catch (DeviceException e1) { logger.error("Exception: " + e1.getMessage()); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); ex.printStackTrace(); } } }); simplePlot.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { // /////////System.out.println("Mouse clicked " + // me.getX() + " " // /////// + me.getY()); SimpleDataCoordinate coordinates = simplePlot.convertMouseEvent(me); if (simplePlot.getScreenDataArea().contains(me.getX(), me.getY()) && regionClickCount == 0) { regionLow = coordinates.toArray(); regionClickCount++; } else if (simplePlot.getScreenDataArea().contains(me.getX(), me.getY()) && regionClickCount == 1) { regionHigh = coordinates.toArray(); regionClickCount++; if (regionValid(regionLow[0], regionHigh[0])) { final String s = (String) JOptionPane.showInputDialog(null, "Please select the Region Index:\n", "Region Of Interest", JOptionPane.PLAIN_MESSAGE, null, null, String.valueOf(getNextRegion())); Thread t1 = uk.ac.gda.util.ThreadManager.getThread(new Runnable() { @Override public void run() { try { if (s != null) { int rIndex = Integer.parseInt(s); EpicsMCARegionOfInterest[] epc = { new EpicsMCARegionOfInterest() }; epc[0].setRegionLow(regionLow[0]); epc[0].setRegionHigh(regionHigh[0]); epc[0].setRegionIndex(rIndex); epc[0].setRegionName("region " + rIndex); analyser.setRegionsOfInterest(epc); addRegionMarkers(rIndex, regionLow[0], regionHigh[0]); } } catch (DeviceException e) { logger.error("Unable to set the table values"); } } }); t1.start(); } } } }); // TODO note that selectePlot cannot be changed runtime simplePlot.initializeLine(selectedPlot); simplePlot.setLineName(selectedPlot, getSelectedPlotString()); simplePlot.setLineColor(selectedPlot, getSelectedPlotColor()); simplePlot.setLineType(selectedPlot, "LineOnly"); } return simplePlot; }
From source file:com.limegroup.gnutella.gui.library.LibraryTableMediator.java
private JMenu createAdvancedMenu(LibraryTableDataLine dl) { JMenu menu = new JMenu(GUIMediator.getStringResource("GENERAL_ADVANCED_SUB_MENU")); if (dl != null) { menu.add(new JMenuItem(LICENSE_ACTION)); menu.add(new JMenuItem(BITZI_LOOKUP_ACTION)); menu.add(new JMenuItem(MAGNET_LOOKUP_ACTION)); menu.add(new JMenuItem(COPY_MAGNET_TO_CLIPBOARD_ACTION)); File file = getFile(TABLE.getSelectedRow()); menu.setEnabled(RouterService.getFileManager().isFileShared(file)); }/* ww w.j a va 2 s. c om*/ if (menu.getItemCount() == 0) menu.setEnabled(false); return menu; }