List of usage examples for javax.swing JPopupMenu addSeparator
public void addSeparator()
From source file:io.heming.accountbook.ui.MainFrame.java
private void initTablePopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteMenuItem = new JMenuItem("(D)", new ImageIcon(getClass().getResource("edit-delete-6.png"))); deleteMenuItem.setMnemonic('D'); popupMenu.add(deleteMenuItem);/* ww w. ja v a2 s .c o m*/ deleteMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteRecord(); } }); popupMenu.addSeparator(); JMenuItem editMenuItem = new JMenuItem("(E)", new ImageIcon(getClass().getResource("edit-4.png"))); editMenuItem.setMnemonic('E'); popupMenu.add(editMenuItem); editMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Record record = model.getRecord(table.convertRowIndexToModel(table.getSelectedRow())); showUpdateRecordDialog(record); } }); // ??popup menu table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (disable) return; JTable table = (JTable) e.getSource(); Point point = e.getPoint(); int row = table.rowAtPoint(point); int col = table.columnAtPoint(e.getPoint()); if (SwingUtilities.isRightMouseButton(e)) { if (row >= 0 && col >= 0) { table.setRowSelectionInterval(row, row); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } else if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() == 2) { if (row >= 0 && col >= 0) { // Record record = model.getRecord(table.convertRowIndexToModel(row)); // showUpdateRecordDialog(record); } } } } }); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); table.getActionMap().put("Enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { if (disable) return; //do something on JTable enter pressed int row = table.getSelectedRow(); if (row >= 0) { Record record = model.getRecord(table.convertRowIndexToModel(row)); showUpdateRecordDialog(record); } } }); }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Creates a popup menu for the panel./*from w w w . ja v a 2 s .c o m*/ * * @param properties include a menu item for the chart property editor. * @param save include a menu item for saving the chart. * @param print include a menu item for printing the chart. * @param zoom include menu items for zooming. * * @return The popup menu. */ protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) { JPopupMenu result = new JPopupMenu("Chart:"); boolean separator = false; JMenuItem newClassItem = new JMenuItem(PluginServices.getText(this, "new_class")); newClassItem.setActionCommand(NEW_CLASS_COMMAND); newClassItem.addActionListener(this); result.add(newClassItem); separator = true; if (properties) { } if (save) { if (separator) { result.addSeparator(); separator = false; } JMenuItem saveItem = new JMenuItem(localizationResources.getString("Save_as...")); saveItem.setActionCommand(SAVE_COMMAND); saveItem.addActionListener(this); result.add(saveItem); separator = true; } if (print) { if (separator) { result.addSeparator(); separator = false; } JMenuItem printItem = new JMenuItem(localizationResources.getString("Print...")); printItem.setActionCommand(PRINT_COMMAND); printItem.addActionListener(this); result.add(printItem); separator = true; } if (zoom) { if (separator) { result.addSeparator(); separator = false; } } return result; }
From source file:de.erdesignerng.visual.common.OutlineComponent.java
/** * Create the PopupMenu actions correlating to a specific tree node. * * @param aNode - the node// w w w .ja va 2s .co m * @param aMenu - the menu to add the actions to * @param aRecursive - recursive */ private void initializeActionsFor(final DefaultMutableTreeNode aNode, JPopupMenu aMenu, boolean aRecursive) { Object theUserObject = aNode.getUserObject(); if (!aRecursive) { JMenuItem theExpandAllItem = new JMenuItem(); theExpandAllItem.setText(getResourceHelper().getFormattedText(ERDesignerBundle.EXPANDALL)); theExpandAllItem .addActionListener(e -> expandOrCollapseAllChildrenOfNode(new TreePath(aNode.getPath()), true)); aMenu.add(theExpandAllItem); JMenuItem theCollapseAllItem = new JMenuItem(); theCollapseAllItem.setText(getResourceHelper().getFormattedText(ERDesignerBundle.COLLAPSEALL)); theCollapseAllItem.addActionListener( e -> expandOrCollapseAllChildrenOfNode(new TreePath(aNode.getPath()), false)); aMenu.add(theCollapseAllItem); aMenu.addSeparator(); } List<ModelItem> theItemList = new ArrayList<>(); if (theUserObject instanceof ModelItem) { theItemList.add((ModelItem) theUserObject); ContextMenuFactory.addActionsToMenu(ERDesignerComponent.getDefault().getEditor(), aMenu, theItemList); } if (aNode.getParent() != null) { initializeActionsFor((DefaultMutableTreeNode) aNode.getParent(), aMenu, true); } }
From source file:com.mirth.connect.client.ui.components.MirthTable.java
private JPopupMenu getColumnMenu() { JPopupMenu columnMenu = new JPopupMenu(); DefaultTableModel model = (DefaultTableModel) getModel(); for (int i = 0; i < model.getColumnCount(); i++) { final String columnName = model.getColumnName(i); // Get the column object by name. Using an index may not return the column object if the column is hidden TableColumnExt column = getColumnExt(columnName); // Create the menu item final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(columnName); // Show or hide the checkbox menuItem.setSelected(column.isVisible()); menuItem.addActionListener(new ActionListener() { @Override/*from w ww .jav a 2 s . c om*/ public void actionPerformed(ActionEvent evt) { TableColumnExt column = getColumnExt(menuItem.getText()); // Determine whether to show or hide the selected column boolean enable = !column.isVisible(); // Do not hide a column if it is the last remaining visible column if (enable || getColumnCount() > 1) { column.setVisible(enable); saveColumnOrder(); } } }); columnMenu.add(menuItem); } columnMenu.addSeparator(); JMenuItem menuItem = new JMenuItem("Restore Default"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { restoreDefaultColumnPreferences(); } }); columnMenu.add(menuItem); return columnMenu; }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override protected JPopupMenu createPopupMenu(boolean properties, boolean copy, boolean save, boolean print, boolean zoom) { JPopupMenu menu = super.createPopupMenu(properties, copy, save, print, zoom); menu.addSeparator(); legendMenu = new JMenu("Legend Position"); menu.add(legendMenu);/*from w w w. j a va 2 s . c o m*/ legendNone = new JRadioButtonMenuItem("None"); legendNone.setActionCommand(LEGEND_NONE_COMMAND); legendNone.addActionListener(this); legendMenu.add(legendNone); legendInternal = new JRadioButtonMenuItem("Internal"); legendInternal.setActionCommand(LEGEND_INTERNAL_COMMAND); legendInternal.addActionListener(this); legendMenu.add(legendInternal); legendBottom = new JRadioButtonMenuItem("Bottom"); legendBottom.setActionCommand(LEGEND_BOTTOM_COMMAND); legendBottom.addActionListener(this); legendMenu.add(legendBottom); legendRight = new JRadioButtonMenuItem("Right"); legendRight.setActionCommand(LEGEND_RIGHT_COMMAND); legendRight.addActionListener(this); legendMenu.add(legendRight); menu.addSeparator(); curveManagementMenu = new JMenu("Focus on Curve"); menu.add(curveManagementMenu); // this.removeSelectedMaskMenuItem = new JMenuItem(); // this.removeSelectedMaskMenuItem.setActionCommand(REMOVE_SELECTED_MASK_COMMAND); // this.removeSelectedMaskMenuItem.addActionListener(this); // menu.addSeparator(); // menu.add(removeSelectedMaskMenuItem); // maskManagementMenu = new JMenu("Mask Management"); // menu.add(maskManagementMenu); return menu; }
From source file:net.panthema.BispanningGame.GamePanel.java
public GamePanel() throws IOException { makeActions();/* ww w . ja v a 2 s .c o m*/ setBackground(Color.WHITE); ImageAlice = ImageIO.read( getClass().getClassLoader().getResourceAsStream("net/panthema/BispanningGame/images/Alice.png")); ImageBob = ImageIO.read( getClass().getClassLoader().getResourceAsStream("net/panthema/BispanningGame/images/Bob.png")); logTextArea = new JTextArea(); makeNewRandomGraph(8); mLayout = MyGraphLayoutFactory(mGraph); mVV = new VisualizationViewer<Integer, MyEdge>(mLayout); mVV.setSize(new Dimension(1000, 800)); mVV.setBackground(Color.WHITE); // Bob's play does not repeat. mPlayBob.setRepeats(false); // set up mouse handling PluggableGraphMouse gm = new PluggableGraphMouse(); gm.add(new MyEditingGraphMousePlugin<Integer, MyEdge>(MouseEvent.CTRL_MASK, new MyVertexFactory(), new MyEdgeFactory())); gm.add(new TranslatingGraphMousePlugin(MouseEvent.BUTTON3_MASK)); gm.add(new MyGraphMousePlugin(MouseEvent.BUTTON1_MASK | MouseEvent.BUTTON3_MASK)); gm.add(new PickingGraphMousePlugin<Integer, MyEdge>()); gm.add(new ScalingGraphMousePlugin(new LayoutScalingControl(), 0, 1.1f, 0.9f)); mVV.setGraphMouse(gm); // set vertex and label drawing mVV.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.black)); mVV.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() { public String transform(Integer v) { return "v" + v; } }); mVV.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>()); mVV.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); mVV.getRenderer().setEdgeRenderer(new MyEdgeRenderer()); mVV.getRenderContext().setVertexDrawPaintTransformer(new MyVertexDrawPaintTransformer<Integer>()); mVV.getRenderContext().setVertexFillPaintTransformer(new MyVertexFillPaintTransformer()); mVV.getRenderContext().setEdgeStrokeTransformer(new MyEdgeStrokeTransformer()); MyQuadCurve<Integer, MyEdge> quadcurve = new MyQuadCurve<Integer, MyEdge>(); mVV.getRenderContext().setEdgeShapeTransformer(quadcurve); mVV.getRenderContext().setParallelEdgeIndexFunction(quadcurve); mVV.getRenderContext().setEdgeDrawPaintTransformer(new MyEdgeDrawPaintTransformer()); mVV.getRenderContext().setEdgeFillPaintTransformer(new MyEdgeFillPaintTransformer()); mVV.getRenderContext().setEdgeArrowStrokeTransformer(new MyEdgeInnerStrokeTransformer()); mVV.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.black)); mVV.getRenderContext().setEdgeLabelTransformer(new Transformer<MyEdge, String>() { public String transform(MyEdge e) { return e.toString(); } }); mVV.getRenderContext().setLabelOffset(6); // create pick support to select closest nodes and edges mPickSupport = new ShapePickSupport<Integer, MyEdge>(mVV, mPickDistance); // add pre renderer to draw Alice and Bob mVV.addPreRenderPaintable(new MyGraphPreRenderer()); // add post renderer to show error messages in background mVV.addPostRenderPaintable(new MyGraphPostRenderer()); setLayout(new BorderLayout()); add(mVV, BorderLayout.CENTER); JPanel panelSouth = new JPanel(); add(panelSouth, BorderLayout.SOUTH); panelSouth.setLayout(new GridLayout(0, 2, 0, 0)); JPanel panelButtons = new JPanel(); panelSouth.add(panelButtons); panelButtons.setLayout(new GridLayout(2, 2, 0, 0)); panelSouth.setPreferredSize(new Dimension(800, 60)); final JButton btnNewRandomGraph = new JButton("New Random Graph"); btnNewRandomGraph.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JPopupMenu popup = new JPopupMenu(); for (int i = 0; i < actionRandomGraph.length; ++i) { if (actionRandomGraph[i] != null) popup.add(actionRandomGraph[i]); } popup.addSeparator(); popup.add(getActionNewGraphType()); popup.show(btnNewRandomGraph, e.getX(), e.getY()); } }); panelButtons.add(btnNewRandomGraph); final JButton btnNewNamedGraph = new JButton("New Named Graph"); btnNewNamedGraph.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JPopupMenu popup = new JPopupMenu(); for (int i = 0; i < actionNamedGraph.size(); ++i) { if (actionNamedGraph.get(i) != null) popup.add(actionNamedGraph.get(i)); } popup.show(btnNewNamedGraph, e.getX(), e.getY()); } }); panelButtons.add(btnNewNamedGraph); final JButton btnRelayout = new JButton("Relayout"); btnRelayout.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { relayoutGraph(); } }); panelButtons.add(btnRelayout); final JButton btnOptions = new JButton("Options"); btnOptions.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JPopupMenu popup = new JPopupMenu(); addPopupActions(popup); popup.addSeparator(); popup.show(btnOptions, e.getX(), e.getY()); } }); panelButtons.add(btnOptions); JScrollPane scrollPane = new JScrollPane(logTextArea); panelSouth.add(scrollPane); logTextArea.setEditable(false); setSize(new Dimension(1000, 800)); relayoutGraph(); }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
@Override protected JPopupMenu createPopupMenu(boolean properties, boolean copy, boolean save, boolean print, boolean zoom) { JPopupMenu menu = super.createPopupMenu(properties, copy, save, print, zoom); this.resetColorScaleMenuItem = new JMenuItem("Reset Color Scale"); this.resetColorScaleMenuItem.setActionCommand(RESET_COLOR_SCALE_COMMAND); this.resetColorScaleMenuItem.addActionListener(this); menu.addSeparator(); menu.add(resetColorScaleMenuItem);//from w ww. j a v a 2 s.com return menu; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
private JPopupMenu createPopupMenu(boolean over_peak) { JPopupMenu menu = new JPopupMenu(); if (over_peak) { updatePeakActions();//from www. j ava 2 s . c om ButtonGroup group = new ButtonGroup(); if (shown_mslevel.equals("ms")) { for (GlycanAction a : theApplication.getPluginManager().getMsPeakActions()) { JRadioButtonMenuItem last = new JRadioButtonMenuItem( new GlycanAction(a, "annotatepeaks", -1, "", this)); menu.add(last); last.setSelected(a == ms_action); group.add(last); } } else { for (GlycanAction a : theApplication.getPluginManager().getMsMsPeakActions()) { JRadioButtonMenuItem last = new JRadioButtonMenuItem( new GlycanAction(a, "annotatepeaks", -1, "", this)); menu.add(last); last.setSelected(a == msms_action); group.add(last); } } menu.addSeparator(); } menu.add(theActionManager.get("zoomnone")); menu.add(theActionManager.get("zoomin")); menu.add(theActionManager.get("zoomout")); return menu; }
From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java
private void showSettingsPopup() { JPopupMenu menu = new JPopupMenu(); final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem( Localization.lang("Automatically sync bibliography when inserting citations"), preferences.syncWhenCiting()); final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem( Localization.lang("Look up BibTeX entries in the active tab only")); final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem( Localization.lang("Look up BibTeX entries in all open databases")); final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings")); ButtonGroup bg = new ButtonGroup(); bg.add(useActiveBase);/* w ww. ja v a 2 s . c o m*/ bg.add(useAllBases); if (preferences.useAllDatabases()) { useAllBases.setSelected(true); } else { useActiveBase.setSelected(true); } autoSync.addActionListener(e -> preferences.setSyncWhenCiting(autoSync.isSelected())); useAllBases.addActionListener(e -> preferences.setUseAllDatabases(useAllBases.isSelected())); useActiveBase.addActionListener(e -> preferences.setUseAllDatabases(!useActiveBase.isSelected())); clearConnectionSettings.addActionListener(e -> frame.output(preferences.clearConnectionSettings())); menu.add(autoSync); menu.addSeparator(); menu.add(useActiveBase); menu.add(useAllBases); menu.addSeparator(); menu.add(clearConnectionSettings); menu.show(settingsB, 0, settingsB.getHeight()); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Creates a popup menu for the panel.//from ww w .j a va 2 s. co m * * @param properties include a menu item for the chart property editor. * @param save include a menu item for saving the chart. * @param print include a menu item for printing the chart. * @param zoom include menu items for zooming. * * @return The popup menu. */ protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) { JPopupMenu result = new JPopupMenu("Chart:"); boolean separator = false; if (properties) { JMenuItem propertiesItem = new JMenuItem(localizationResources.getString("Properties...")); propertiesItem.setActionCommand(PROPERTIES_ACTION_COMMAND); propertiesItem.addActionListener(this); result.add(propertiesItem); separator = true; } if (save) { if (separator) { result.addSeparator(); separator = false; } JMenuItem saveItem = new JMenuItem(localizationResources.getString("Save_as...")); saveItem.setActionCommand(SAVE_ACTION_COMMAND); saveItem.addActionListener(this); result.add(saveItem); separator = true; } if (print) { if (separator) { result.addSeparator(); separator = false; } JMenuItem printItem = new JMenuItem(localizationResources.getString("Print...")); printItem.setActionCommand(PRINT_ACTION_COMMAND); printItem.addActionListener(this); result.add(printItem); separator = true; } if (zoom) { if (separator) { result.addSeparator(); separator = false; } JMenu zoomInMenu = new JMenu(localizationResources.getString("Zoom_In")); zoomInBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_ACTION_COMMAND); zoomInBothMenuItem.addActionListener(this); zoomInMenu.add(zoomInBothMenuItem); zoomInMenu.addSeparator(); zoomInHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis")); zoomInHorizontalMenuItem.setActionCommand(ZOOM_IN_HORIZONTAL_ACTION_COMMAND); zoomInHorizontalMenuItem.addActionListener(this); zoomInMenu.add(zoomInHorizontalMenuItem); zoomInVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis")); zoomInVerticalMenuItem.setActionCommand(ZOOM_IN_VERTICAL_ACTION_COMMAND); zoomInVerticalMenuItem.addActionListener(this); zoomInMenu.add(zoomInVerticalMenuItem); result.add(zoomInMenu); JMenu zoomOutMenu = new JMenu(localizationResources.getString("Zoom_Out")); zoomOutBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); zoomOutBothMenuItem.setActionCommand(ZOOM_OUT_BOTH_ACTION_COMMAND); zoomOutBothMenuItem.addActionListener(this); zoomOutMenu.add(zoomOutBothMenuItem); zoomOutMenu.addSeparator(); zoomOutHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis")); zoomOutHorizontalMenuItem.setActionCommand(ZOOM_OUT_HORIZONTAL_ACTION_COMMAND); zoomOutHorizontalMenuItem.addActionListener(this); zoomOutMenu.add(zoomOutHorizontalMenuItem); zoomOutVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis")); zoomOutVerticalMenuItem.setActionCommand(ZOOM_OUT_VERTICAL_ACTION_COMMAND); zoomOutVerticalMenuItem.addActionListener(this); zoomOutMenu.add(zoomOutVerticalMenuItem); result.add(zoomOutMenu); JMenu autoRangeMenu = new JMenu(localizationResources.getString("Auto_Range")); autoRangeBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); autoRangeBothMenuItem.setActionCommand(AUTO_RANGE_BOTH_ACTION_COMMAND); autoRangeBothMenuItem.addActionListener(this); autoRangeMenu.add(autoRangeBothMenuItem); autoRangeMenu.addSeparator(); autoRangeHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis")); autoRangeHorizontalMenuItem.setActionCommand(AUTO_RANGE_HORIZONTAL_ACTION_COMMAND); autoRangeHorizontalMenuItem.addActionListener(this); autoRangeMenu.add(autoRangeHorizontalMenuItem); autoRangeVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis")); autoRangeVerticalMenuItem.setActionCommand(AUTO_RANGE_VERTICAL_ACTION_COMMAND); autoRangeVerticalMenuItem.addActionListener(this); autoRangeMenu.add(autoRangeVerticalMenuItem); result.addSeparator(); result.add(autoRangeMenu); } return result; }