List of usage examples for javax.swing JPopupMenu add
public JMenuItem add(Action a)
Action
object. From source file:com.mirth.connect.client.ui.components.rsta.MirthRSyntaxTextArea.java
@Override protected JPopupMenu createPopupMenu() { JPopupMenu menu = new JPopupMenu(); menu.add(undoMenuItem); menu.add(redoMenuItem);//from w ww. ja v a 2 s. c om menu.addSeparator(); menu.add(cutMenuItem); menu.add(copyMenuItem); menu.add(pasteMenuItem); menu.add(deleteMenuItem); menu.addSeparator(); menu.add(selectAllMenuItem); menu.add(findReplaceMenuItem); menu.add(findNextMenuItem); menu.add(clearMarkedOccurrencesMenuItem); menu.addSeparator(); foldingMenu.add(collapseFoldMenuItem); foldingMenu.add(expandFoldMenuItem); foldingMenu.add(collapseAllFoldsMenuItem); foldingMenu.add(collapseAllCommentFoldsMenuItem); foldingMenu.add(expandAllFoldsMenuItem); menu.add(foldingMenu); menu.addSeparator(); displayMenu.add(showTabLinesMenuItem); displayMenu.add(showWhitespaceMenuItem); displayMenu.add(showLineEndingsMenuItem); displayMenu.add(wrapLinesMenuItem); menu.add(displayMenu); menu.addSeparator(); macroMenu.add(beginMacroMenuItem); macroMenu.add(endMacroMenuItem); macroMenu.add(playbackMacroMenuItem); menu.add(macroMenu); menu.addSeparator(); menu.add(viewUserAPIMenuItem); return menu; }
From source file:net.sf.mzmine.modules.visualization.neutralloss.NeutralLossPlot.java
NeutralLossPlot(NeutralLossVisualizerWindow visualizer, NeutralLossDataSet dataset, Object xAxisType) { super(null, true); this.visualizer = visualizer; setBackground(Color.white);//from w w w. j av a2s. c o m setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat(); NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); // set the X axis (retention time) properties NumberAxis xAxis; if (xAxisType.equals(NeutralLossParameters.xAxisPrecursor)) { xAxis = new NumberAxis("Precursor m/z"); xAxis.setNumberFormatOverride(mzFormat); } else { xAxis = new NumberAxis("Retention time"); xAxis.setNumberFormatOverride(rtFormat); } xAxis.setUpperMargin(0); xAxis.setLowerMargin(0); xAxis.setAutoRangeIncludesZero(false); // set the Y axis (intensity) properties NumberAxis yAxis = new NumberAxis("Neutral loss (Da)"); yAxis.setAutoRangeIncludesZero(false); yAxis.setNumberFormatOverride(mzFormat); yAxis.setUpperMargin(0); yAxis.setLowerMargin(0); // set the renderer properties defaultRenderer = new NeutralLossDataPointRenderer(false, true); defaultRenderer.setTransparency(0.4f); setSeriesColorRenderer(0, pointColor, dataPointsShape); setSeriesColorRenderer(1, searchPrecursorColor, dataPointsShape2); setSeriesColorRenderer(2, searchNeutralLossColor, dataPointsShape2); // tooltips defaultRenderer.setBaseToolTipGenerator(dataset); // set the plot properties plot = new XYPlot(dataset, xAxis, yAxis, defaultRenderer); plot.setBackgroundPaint(Color.white); plot.setRenderer(defaultRenderer); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); // chart properties chart = new JFreeChart("", titleFont, plot, false); chart.setBackgroundPaint(Color.white); setChart(chart); // title chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); // disable maximum size (we don't want scaling) setMaximumDrawWidth(Integer.MAX_VALUE); setMaximumDrawHeight(Integer.MAX_VALUE); // set crosshair (selection) properties plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.setDomainCrosshairPaint(crossHairColor); plot.setRangeCrosshairPaint(crossHairColor); plot.setDomainCrosshairStroke(crossHairStroke); plot.setRangeCrosshairStroke(crossHairStroke); plot.addRangeMarker(new ValueMarker(0)); // set focusable state to receive key events setFocusable(true); // register key handlers GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("SPACE"), visualizer, "SHOW_SPECTRUM"); // add items to popup menu JPopupMenu popupMenu = getPopupMenu(); popupMenu.addSeparator(); JMenuItem highLightPrecursorRange = new JMenuItem("Highlight precursor m/z range..."); highLightPrecursorRange.addActionListener(visualizer); highLightPrecursorRange.setActionCommand("HIGHLIGHT_PRECURSOR"); popupMenu.add(highLightPrecursorRange); JMenuItem highLightNeutralLossRange = new JMenuItem("Highlight neutral loss m/z range..."); highLightNeutralLossRange.addActionListener(visualizer); highLightNeutralLossRange.setActionCommand("HIGHLIGHT_NEUTRALLOSS"); popupMenu.add(highLightNeutralLossRange); }
From source file:de.tntinteractive.portalsammler.gui.MainDialog.java
private JPopupMenu createConfigMenu() { final JPopupMenu menu = new JPopupMenu(); final JMenuItem sourceConfig = new JMenuItem("Quellen verwalten..."); sourceConfig.addActionListener(new ActionListener() { @Override/* w w w . jav a 2 s .com*/ public void actionPerformed(final ActionEvent e) { MainDialog.this.gui.showConfigGui(MainDialog.this.getStore()); } }); menu.add(sourceConfig); final JMenuItem changePassword = new JMenuItem("Neues Passwort..."); changePassword.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { MainDialog.this.changePassword(); } catch (final GeneralSecurityException ex) { MainDialog.this.gui.showError(ex); } catch (final IOException ex) { MainDialog.this.gui.showError(ex); } } }); menu.add(changePassword); return menu; }
From source file:org.cds06.speleograph.graph.SeriesMenu.java
private JPopupMenu createPopupMenuForSeries(final Series series) { if (series == null) return new JPopupMenu(); final JPopupMenu menu = new JPopupMenu(series.getName()); menu.removeAll();//from w w w . j a v a 2 s. co m menu.add(new AbstractAction() { { putValue(NAME, "Renommer la srie"); } @Override public void actionPerformed(ActionEvent e) { menu.setVisible(false); String newName = ""; while (newName == null || newName.equals("")) { newName = (String) JOptionPane.showInputDialog(application, "Entrez un nouveau nom pour la srie", null, JOptionPane.QUESTION_MESSAGE, null, null, series.getName()); } series.setName(newName); } }); if (series.hasOwnAxis()) { menu.add(new AbstractAction() { { putValue(NAME, "Supprimer l'axe spcifique"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes vous sr de vouloir supprimer cet axe ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { series.setAxis(null); } } }); } else { menu.add(new JMenuItem(new AbstractAction() { { putValue(NAME, "Crer un axe spcifique pour la srie"); } @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(application, "Quel titre pour cet axe ?", series.getAxis().getLabel()); if (name == null || "".equals(name)) return; // User has canceled series.setAxis(new NumberAxis(name)); } })); } menu.add(new SetTypeMenu(series)); if (series.isWater()) { menu.addSeparator(); menu.add(new SumOnPeriodAction(series)); menu.add(new CreateCumulAction(series)); } if (series.isWaterCumul()) { menu.addSeparator(); menu.add(new SamplingAction(series)); } if (series.isPressure()) { menu.addSeparator(); menu.add(new CorrelateAction(series)); menu.add(new WaterHeightAction(series)); } menu.addSeparator(); menu.add(new AbstractAction() { { String name; if (series.canUndo()) name = "Annuler " + series.getItemsName(); else name = series.getLastUndoName(); putValue(NAME, name); if (series.canUndo()) setEnabled(true); else { setEnabled(false); } } @Override public void actionPerformed(ActionEvent e) { series.undo(); } }); menu.add(new AbstractAction() { { String name; if (series.canRedo()) { name = "Refaire " + series.getNextRedoName(); setEnabled(true); } else { name = series.getNextRedoName(); setEnabled(false); } putValue(NAME, name); } @Override public void actionPerformed(ActionEvent e) { series.redo(); } }); menu.add(new AbstractAction() { { putValue(NAME, I18nSupport.translate("menus.serie.resetSerie")); if (series.canUndo()) setEnabled(true); else setEnabled(false); } @Override public void actionPerformed(ActionEvent e) { series.reset(); } }); menu.add(new LimitDateRangeAction(series)); menu.add(new HourSettingAction(series)); menu.addSeparator(); { JMenuItem deleteItem = new JMenuItem("Supprimer la srie"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir supprimer cette srie ?\n" + "Cette action est dfinitive.", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { series.delete(); } } }); menu.add(deleteItem); } menu.addSeparator(); { final JMenuItem up = new JMenuItem("Remonter dans la liste"), down = new JMenuItem("Descendre dans la liste"); ActionListener listener = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(up)) { series.upSeriesInList(); } else { series.downSeriesInList(); } } }; up.addActionListener(listener); down.addActionListener(listener); if (series.isFirst()) { menu.add(down); } else if (series.isLast()) { menu.add(up); } else { menu.add(up); menu.add(down); } } menu.addSeparator(); { menu.add(new SeriesInfoAction(series)); } { JMenuItem colorItem = new JMenuItem("Couleur de la srie"); colorItem.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { series.setColor(JColorChooser.showDialog(application, I18nSupport.translate("actions.selectColorForSeries"), series.getColor())); } }); menu.add(colorItem); } { JMenu plotRenderer = new JMenu("Affichage de la srie"); final ButtonGroup modes = new ButtonGroup(); java.util.List<DrawStyle> availableStyles; if (series.isMinMax()) { availableStyles = DrawStyles.getDrawableStylesForHighLow(); } else { availableStyles = DrawStyles.getDrawableStyles(); } for (final DrawStyle s : availableStyles) { final JRadioButtonMenuItem item = new JRadioButtonMenuItem(DrawStyles.getHumanCheckboxText(s)); item.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (item.isSelected()) series.setStyle(s); } }); modes.add(item); if (s.equals(series.getStyle())) { modes.setSelected(item.getModel(), true); } plotRenderer.add(item); } menu.add(plotRenderer); } menu.addSeparator(); menu.add(new AbstractAction() { { putValue(Action.NAME, "Fermer le fichier"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir fermer toutes les sries du fichier ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { final File f = series.getOrigin(); for (final Series s : Series.getInstances().toArray(new Series[Series.getInstances().size()])) { if (s.getOrigin().equals(f)) s.delete(); } } } }); return menu; }
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; }//from ww w. j a va 2s.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.jabref.gui.maintable.MainTableSelectionListener.java
/** * Method to handle a single left click on one the special fields (e.g., ranking, quality, ...) * Shows either a popup to select/clear a value or simply toggles the functionality to set/unset the special field * * @param e MouseEvent used to determine the position of the popups * @param columnName the name of the specialfield column *//* w w w . j av a 2s . co m*/ private void handleSpecialFieldLeftClick(MouseEvent e, String columnName) { if ((e.getClickCount() == 1)) { SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(columnName).ifPresent(field -> { // special field found if (field.isSingleValueField()) { // directly execute toggle action instead of showing a menu with one action field.getValues().get(0).getAction(panel.frame()).action(); } else { JPopupMenu menu = new JPopupMenu(); for (SpecialFieldValue val : field.getValues()) { menu.add(val.getMenuAction(panel.frame())); } menu.show(table, e.getX(), e.getY()); } }); } }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
protected void displaySeriesPopup(final JFreeChart chart, final String label, final int series, final ColorButton button) { JPopupMenu p = new JPopupMenu(); JMenuItem color = new JMenuItem("Color..."); p.add(color); color.addActionListener(new ActionListener() { @Override//from w w w .j a v a 2s. co m public void actionPerformed(ActionEvent e) { displayColorPicker(chart, label, series, button); } }); JMenuItem remove = new JMenuItem("Remove"); p.add(remove); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeSeries(chart, series); } }); p.show(button, 4, 4); }
From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java
/** * Helper method to add a contextual menu on a text component that will allow for Copy & Select All text actions. *//*w ww.ja v a 2 s . c o m*/ protected void addCopyMenu(final JTextComponent component) { Preconditions.checkNotNull(component); if (!component.isEditable()) { component.setCursor(new Cursor(Cursor.TEXT_CURSOR)); } final JPopupMenu contextMenu = new JPopupMenu(); JMenuItem copy = new JMenuItem(component.getActionMap().get(DefaultEditorKit.copyAction)); copy.setText(i18n.getString(I18n.TEXT_COPY_ID)); contextMenu.add(copy); contextMenu.addSeparator(); JMenuItem selectAll = new JMenuItem(component.getActionMap().get(DefaultEditorKit.selectAllAction)); selectAll.setText(i18n.getString(I18n.TEXT_SELECT_ALL_ID)); contextMenu.add(selectAll); component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { contextMenu.show(component, e.getX(), e.getY()); } } }); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.AnnotationReportApplet.java
protected JPopupMenu createPopupMenu() { JPopupMenu menu = new JPopupMenu(); menu.add(theActionManager.get("zoomnone")); menu.add(theActionManager.get("zoomin")); menu.add(theActionManager.get("zoomout")); menu.addSeparator();//w w w .j av a2 s . com menu.add(theActionManager.get("cut")); menu.add(theActionManager.get("copy")); menu.add(theActionManager.get("delete")); menu.addSeparator(); menu.add(theActionManager.get("enlarge")); menu.add(theActionManager.get("resetsize")); menu.add(theActionManager.get("shrink")); menu.addSeparator(); menu.add(theActionManager.get("group")); menu.add(theActionManager.get("ungroup")); return menu; }
From source file:lu.lippmann.cdb.ext.hydviga.ui.SimilarCasesFrame.java
/** * Constructor./* w ww . jav a 2 s .c o m*/ */ SimilarCasesFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp, String attrname, final int gapsize, final int position, final double x, final double y, final int year, final String season, final boolean isDuringRising) throws Exception { LogoHelper.setLogo(this); this.setTitle("KnowledgeDB: Suggested configurations / similar cases"); this.inputCaseTablePanel = new JXPanel(); this.inputCaseTablePanel.setBorder(new TitledBorder("Present case")); this.inputCaseChartPanel = new JXPanel(); this.inputCaseChartPanel.setBorder(new TitledBorder("Profile of the present case")); this.outputCasesTablePanel = new JXPanel(); this.outputCasesTablePanel.setBorder(new TitledBorder("Suggested cases")); this.outputCasesChartPanel = new JXPanel(); this.outputCasesChartPanel.setBorder(new TitledBorder("Profile of the selected suggested case")); getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS)); getContentPane().add(inputCaseTablePanel); getContentPane().add(inputCaseChartPanel); getContentPane().add(outputCasesTablePanel); getContentPane().add(outputCasesChartPanel); final Instances res = GapFillingKnowledgeDB.findSimilarCases(attrname, x, y, year, season, gapsize, position, isDuringRising, gcp.findDownstreamStation(attrname) != null, gcp.findUpstreamStation(attrname) != null, GapsUtil.measureHighMiddleLowInterval(ds, ds.attribute(attrname).index(), position - 1)); final Instances inputCase = new Instances(res); while (inputCase.numInstances() > 1) inputCase.remove(1); final JXTable inputCaseTable = buidJXTable(inputCase); final JScrollPane inputScrollPane = new JScrollPane(inputCaseTable); //System.out.println(inputScrollPane.getPreferredSize()); inputScrollPane.setPreferredSize( new Dimension(COMPONENT_WIDTH, (int) (50 + inputScrollPane.getPreferredSize().getHeight()))); this.inputCaseTablePanel.add(inputScrollPane); final ChartPanel inputcp = GapsUIUtil.buildGapChartPanel(ds, dateIdx, ds.attribute(attrname), gapsize, position); inputcp.getChart().removeLegend(); inputcp.setPreferredSize(CHART_DIMENSION); this.inputCaseChartPanel.add(inputcp); final Instances outputCases = new Instances(res); outputCases.remove(0); final JXTable outputCasesTable = buidJXTable(outputCases); final JScrollPane outputScrollPane = new JScrollPane(outputCasesTable); outputScrollPane.setPreferredSize( new Dimension(COMPONENT_WIDTH, (int) (50 + outputScrollPane.getPreferredSize().getHeight()))); this.outputCasesTablePanel.add(outputScrollPane); outputCasesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); outputCasesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final int modelRow = outputCasesTable.getSelectedRow(); final String attrname = outputCasesTable.getModel().getValueAt(modelRow, 1).toString(); final int gapsize = (int) Double .valueOf(outputCasesTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue(); final int position = (int) Double .valueOf(outputCasesTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue(); try { final ChartPanel cp = GapsUIUtil.buildGapChartPanel(ds, dateIdx, ds.attribute(attrname), gapsize, position); cp.getChart().removeLegend(); cp.setPreferredSize(CHART_DIMENSION); outputCasesChartPanel.removeAll(); outputCasesChartPanel.add(cp); getContentPane().repaint(); pack(); } catch (Exception e1) { e1.printStackTrace(); } } } }); outputCasesTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { final InstanceTableModel instanceTableModel = (InstanceTableModel) outputCasesTable.getModel(); final int row = outputCasesTable.rowAtPoint(e.getPoint()); final int modelRow = outputCasesTable.convertRowIndexToModel(row); final String attrname = instanceTableModel.getValueAt(modelRow, 1).toString(); final int gapsize = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 4).toString()) .doubleValue(); final int position = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); if (e.isPopupTrigger()) { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); final JMenuItem mi = new JMenuItem("Use this configuration"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { System.out.println("not implemented!"); } }); jPopupMenu.add(mi); jPopupMenu.show(outputCasesTable, e.getX(), e.getY()); } else { // nothing? } } }); setPreferredSize(new Dimension(FRAME_WIDTH, 900)); pack(); setVisible(true); /* select the first row */ outputCasesTable.setRowSelectionInterval(0, 0); }