List of usage examples for javax.swing JPopupMenu add
public JMenuItem add(Action a)
Action
object. From source file:net.sourceforge.jasa.view.OrderBookView.java
@Override public void afterPropertiesSet() throws Exception { this.setModel(this); this.setPreferredSize(new Dimension(400, 200)); JPopupMenu popup = new JPopupMenu(); popup.add(new AbstractAction("Inspect order") { @Override//from w w w. j av a 2 s .c o m public void actionPerformed(ActionEvent e) { int row = getSelectedRow(); int column = getSelectedColumn(); Order order = null; if (column > 1) { order = asks.get(row); } else { order = bids.get(row); } if (order != null) { Inspector.inspect(order); } } }); setComponentPopupMenu(popup); }
From source file:Main.java
protected void showMenu(int x, int y) { JPopupMenu popup = new JPopupMenu(); JMenuItem mi = new JMenuItem("Delete"); TreePath path = tree.getSelectionPath(); Object node = path.getLastPathComponent(); if (node == tree.getModel().getRoot()) { mi.setEnabled(false);//from w w w. j a v a2 s . c o m } popup.add(mi); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { deleteSelectedItems(); } }); popup.show(tree, x, y); }
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithChart.java
public void addItemToPopupMenu(JMenuItem item) { JPopupMenu popup = _chartPanel.getPopupMenu(); popup.add(item); }
From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java
public HistoChartPanel(final JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips, final ModelMaker modelMaker) { super(chart, properties, save, print, zoom, tooltips); this.modelMaker = modelMaker; // horizontal zoom doesn't work, by setting false we don't get bogus menu item // setHorizontalZoom(false); // setVerticalZoom(true); final JCheckBoxMenuItem logYScale = new JCheckBoxMenuItem( ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.test.logscale.y")); logYScale.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { CategoryPlot p = (CategoryPlot) chart.getPlot(); Axis oldAxis = p.getRangeAxis(); if (logYScale.isSelected()) { LogarithmicAxis yAxis = new LogarithmicAxis(ChoiceMakerCoreMessages.m .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs")); yAxis.setStrictValuesFlag(false); p.setRangeAxis(yAxis);/*ww w .j a v a 2 s.c o m*/ } else { p.setRangeAxis(new NumberAxis(ChoiceMakerCoreMessages.m .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"))); } oldAxis.setPlot(null); chartChanged(new ChartChangeEvent(this)); } }); JPopupMenu popup = getPopupMenu(); popup.addSeparator(); popup.add(logYScale); popup.addSeparator(); select = new JMenu("Select"); final JMenuItem all = new JMenuItem("All"); select.add(all); final JMenuItem cmDiffer = new JMenuItem("Human marked differ"); select.add(cmDiffer); final JMenuItem cmHold = new JMenuItem("Human marked hold"); select.add(cmHold); final JMenuItem cmMatch = new JMenuItem("Human marked match"); select.add(cmMatch); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent ev) { ListeningMarkedRecordPairFilter filter = modelMaker.getFilter(); filter.reset(); filter.setFromPercentage(rangeFrom); filter.setToPercentage(rangeTo); Object src = ev.getSource(); if (src != all) { boolean[] b = new boolean[Decision.NUM_DECISIONS]; if (src == cmDiffer) { b[Decision.DIFFER.toInt()] = true; } else if (src == cmHold) { b[Decision.HOLD.toInt()] = true; } else if (src == cmMatch) { b[Decision.MATCH.toInt()] = true; } filter.setHumanDecision(b); } modelMaker.filterMarkedRecordPairList(); } }; all.addActionListener(l); cmDiffer.addActionListener(l); cmHold.addActionListener(l); cmMatch.addActionListener(l); popup.add(select); addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent evt) { ChartEntity e = evt.getEntity(); if (e instanceof CategoryItemEntity) { CategoryItemEntity c = (CategoryItemEntity) e; int cat = c.getCategoryIndex(); HistoCategoryDataset data = (HistoCategoryDataset) ((CategoryPlot) getChart().getPlot()) .getDataset(); int len = data.getColumnCount(); float step = 1f / len; rangeFrom = cat * step; rangeTo = rangeFrom + step; ListeningMarkedRecordPairFilter filter = modelMaker.getFilter(); filter.reset(); filter.setFromPercentage(rangeFrom); filter.setToPercentage(rangeTo); boolean[] b = new boolean[Decision.NUM_DECISIONS]; int series = c.getSeries(); if (data.isIncludeHolds() && series != 0) { if (series == 1) { series = 2; } else { series = 1; } } b[series] = true; filter.setHumanDecision(b); modelMaker.filterMarkedRecordPairList(); } } public void chartMouseMoved(ChartMouseEvent arg0) { } }); }
From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java
private void showPopup(final MouseEvent ev) { final JMenuItem open = new JMenuItem("Anzeigen"); open.addActionListener(new ActionListener() { @Override//from ww w.j av a2 s . co m public void actionPerformed(final ActionEvent e) { DocumentTable.this.openSelectedRows(); } }); final JMenuItem export = new JMenuItem("Exportieren"); export.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { DocumentTable.this.exportSelectedRows(); } }); final JPopupMenu menu = new JPopupMenu(); menu.add(open); menu.add(export); menu.show(ev.getComponent(), ev.getX(), ev.getY()); }
From source file:components.PopupMenuDemo.java
public void createPopupMenu() { JMenuItem menuItem;/*from w w w .j a va 2s . co m*/ //Create the popup menu. JPopupMenu popup = new JPopupMenu(); menuItem = new JMenuItem("A popup menu item"); menuItem.addActionListener(this); popup.add(menuItem); menuItem = new JMenuItem("Another popup menu item"); menuItem.addActionListener(this); popup.add(menuItem); //Add listener to the text area so the popup menu can come up. MouseListener popupListener = new PopupListener(popup); output.addMouseListener(popupListener); }
From source file:net.sf.mzmine.modules.visualization.twod.TwoDPlot.java
TwoDPlot(RawDataFile rawDataFile, TwoDVisualizerWindow visualizer, TwoDDataSet dataset, Range rtRange, Range mzRange) {// ww w .jav a 2 s . c om super(null, true); this.rawDataFile = rawDataFile; this.rtRange = rtRange; this.mzRange = mzRange; setBackground(Color.white); setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); // set the X axis (retention time) properties xAxis = new NumberAxis("Retention time"); xAxis.setAutoRangeIncludesZero(false); xAxis.setNumberFormatOverride(rtFormat); xAxis.setUpperMargin(0); xAxis.setLowerMargin(0); // set the Y axis (intensity) properties yAxis = new NumberAxis("m/z"); yAxis.setAutoRangeIncludesZero(false); yAxis.setNumberFormatOverride(mzFormat); yAxis.setUpperMargin(0); yAxis.setLowerMargin(0); // set the plot properties plot = new TwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); // 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); chartSubTitle = new TextTitle(); chartSubTitle.setFont(subTitleFont); chartSubTitle.setMargin(5, 0, 0, 0); chart.addSubtitle(chartSubTitle); // disable maximum size (we don't want scaling) setMaximumDrawWidth(Integer.MAX_VALUE); setMaximumDrawHeight(Integer.MAX_VALUE); // set crosshair (selection) properties plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairPaint(crossHairColor); plot.setDomainCrosshairStroke(crossHairStroke); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); peakDataRenderer = new PeakDataRenderer(); JMenuItem plotTypeMenuItem = new JMenuItem("Toggle centroid/continuous mode"); plotTypeMenuItem.addActionListener(visualizer); plotTypeMenuItem.setActionCommand("SWITCH_PLOTMODE"); add(plotTypeMenuItem); JPopupMenu popupMenu = getPopupMenu(); popupMenu.addSeparator(); popupMenu.add(plotTypeMenuItem); }
From source file:CubaHSQLDBServer.java
private void addCopyPopup(final JTextArea source) { final JPopupMenu popup = new JPopupMenu(); popup.add(new AbstractAction("Copy to clipboard") { @Override/*from w ww.j a v a 2 s . c o m*/ public void actionPerformed(ActionEvent e) { StringSelection contents = new StringSelection(source.getText()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, contents); } }); source.add(popup); source.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(source, e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(source, e.getX(), e.getY()); } } }); }
From source file:com.eviware.soapui.impl.wsdl.panels.teststeps.WsdlTestRequestDesktopPanel.java
protected SoapMessageXmlEditor buildRequestEditor() { SoapMessageXmlEditor editor = super.buildRequestEditor(); XmlOutlineEditor outlineEditor = editor.getOutlineEditor(); if (outlineEditor != null) { JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new TransferFromPropertyAction(getRequest(), outlineEditor)); outlineEditor.getOutlineTable().setComponentPopupMenu(popupMenu); XmlSourceEditor sourceEditor = editor.getSourceEditor(); if (sourceEditor != null) { JPopupMenu editorPopup = sourceEditor.getEditorPopup(); editorPopup.insert(new TransferFromPropertyFromSource(getRequest(), sourceEditor, outlineEditor), 0);//from ww w .ja v a2 s .co m } } return editor; }
From source file:com.eviware.soapui.impl.wsdl.panels.teststeps.WsdlTestRequestDesktopPanel.java
protected SoapMessageXmlEditor buildResponseEditor() { SoapMessageXmlEditor editor = super.buildResponseEditor(); XmlOutlineEditor outlineEditor = editor.getOutlineEditor(); if (outlineEditor != null) { JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new AddXPathContentAssertionAction(getRequest(), outlineEditor)); popupMenu.add(new TransferToPropertyAction(getRequest(), outlineEditor)); outlineEditor.getOutlineTable().setComponentPopupMenu(popupMenu); XmlSourceEditor sourceEditor = editor.getSourceEditor(); if (sourceEditor != null) { JPopupMenu editorPopup = sourceEditor.getEditorPopup(); editorPopup.insert(/*w ww . j a v a 2 s .c o m*/ new AddXPathContentAssertionFromSource(getRequest(), sourceEditor, outlineEditor), 0); editorPopup.insert(new TransferToPropertyFromSource(getRequest(), sourceEditor, outlineEditor), 0); } } return editor; }