Java Code Examples for javax.swing.JPopupMenu#getSubElements()
The following examples show how to use
javax.swing.JPopupMenu#getSubElements() .
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: DockableMenu.java From rapidminer-studio with GNU Affero General Public License v3.0 | 7 votes |
/** * Ensures that the correct maximum height is set for the popup menu and sets the scroll increment. * Will only take effect with the first item added. Makes sure the height is set to {@link #MAX_SHOWN_ITEMS}*itemHeight. * * @since 8.2 */ private void ensurePopupHeight() { JPopupMenu popupMenu = getPopupMenu(); if (popupMenu.getSubElements().length != 1 || !(popupMenu instanceof ScrollableJPopupMenu)) { return; } ScrollableJPopupMenu scrollablePopup = (ScrollableJPopupMenu) popupMenu; int itemHeight = scrollablePopup.getComponentsInsideScrollpane()[0].getPreferredSize().height; int maxHeight = MAX_SHOWN_ITEMS * itemHeight; maxHeight = Math.min(maxHeight, ScrollableJPopupMenu.SIZE_HUGE); scrollablePopup.setMaxHeight(maxHeight); JScrollPane scrollPane = scrollablePopup.getScrollPane(); JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); verticalScrollBar.setUnitIncrement(itemHeight); verticalScrollBar.setBlockIncrement(maxHeight); }
Example 2
Source File: OutlineView.java From netbeans with Apache License 2.0 | 6 votes |
/** * Find relevant actions and call the factory to create a popup. */ private JPopupMenu createPopup(Point p) { int[] selRows = outline.getSelectedRows(); ArrayList<Node> al = new ArrayList<Node> (selRows.length); for (int i = 0; i < selRows.length; i++) { Node n = getNodeFromRow(selRows[i]); if (n != null) { al.add(n); } } Node[] arr = al.toArray (new Node[al.size ()]); if (arr.length == 0) { if (manager.getRootContext() != null) { // display the context menu of the root node JPopupMenu popup = manager.getRootContext().getContextMenu(); if (popup != null && popup.getSubElements().length > 0) { popupFactory.addNoFilterItem(outline, popup); return popup; } } // we'll have an empty popup } p = SwingUtilities.convertPoint(this, p, outline); int column = outline.columnAtPoint(p); int row = outline.rowAtPoint(p); return popupFactory.createPopupMenu(row, column, arr, outline); }
Example 3
Source File: MenuChecker.java From netbeans with Apache License 2.0 | 6 votes |
/** Get PopupMenu and transfer it to ArrayList. * @param popup menu to be tranfered * @return transfered menu - !separator is ignored */ public static ArrayList<NbMenuItem> getPopupMenuArrayList(JPopupMenu popup) { //System.out.print("getPopupMenuArrayList: "); popup.list(); //DEBUG MenuElement[] elements = popup.getSubElements(); ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>(); for (MenuElement menuElement : elements) { //System.out.print("getPopupMenuArrayList: "); // ((JComponent) menuElement).list(); if (menuElement instanceof JSeparator) { //System.out.println("adding separator");//DEBUG NbMenuItem separator = new NbMenuItem(); separator.setSeparator(true); list.add(separator); } else { if (menuElement instanceof JMenu) { NbMenuItem mitem = new NbMenuItem((JMenuItem) menuElement); mitem.setName(mitem.getName()); mitem.setSubmenu (getMenuArrayList((JMenu) menuElement)); list.add(mitem); } else if (menuElement instanceof JMenuItem) //if() { if (!((JMenuItem) menuElement).isVisible()) { continue; } NbMenuItem item = new NbMenuItem((JMenuItem) menuElement); item.setName(item.getName()); list.add(item); } else { System.out.println("getPopup unknown:" + menuElement.toString()); } } } return list; }
Example 4
Source File: MenuChecker.java From netbeans with Apache License 2.0 | 6 votes |
/** Get PopupMenu and transfer it to ArrayList. * @param popup menu to be tranfered * @return transfered menu - !separator is ignored */ public static ArrayList<NbMenuItem> getPopupMenuArrayList(JPopupMenu popup) { //System.out.print("getPopupMenuArrayList: "); popup.list(); //DEBUG MenuElement[] elements = popup.getSubElements(); ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>(); for (MenuElement menuElement : elements) { //System.out.print("getPopupMenuArrayList: "); // ((JComponent) menuElement).list(); if (menuElement instanceof JSeparator) { //System.out.println("adding separator");//DEBUG NbMenuItem separator = new NbMenuItem(); separator.setSeparator(true); list.add(separator); } else { if (menuElement instanceof JMenu) { NbMenuItem mitem = new NbMenuItem((JMenuItem) menuElement); mitem.setName(mitem.getName()); mitem.setSubmenu (getMenuArrayList((JMenu) menuElement)); list.add(mitem); } else if (menuElement instanceof JMenuItem) //if() { if (!((JMenuItem) menuElement).isVisible()) { continue; } NbMenuItem item = new NbMenuItem((JMenuItem) menuElement); item.setName(item.getName()); list.add(item); } else { System.out.println("getPopup unknown:" + menuElement.toString()); } } } return list; }
Example 5
Source File: RightClickMouseAdapter.java From RobotBuilder with BSD 3-Clause "New" or "Revised" License | 6 votes |
private JPopupMenu generatePopupMenu(RobotComponent component) { JPopupMenu menu = new JPopupMenu(); List<JMenu> submenus = new LinkedList<>(); TreeModel model = Palette.getInstance().getPaletteModel(); Enumeration children = ((DefaultMutableTreeNode) model.getRoot()).children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); JMenu submenu = generateMenu(new JMenu("Add " + child.getUserObject()), child, component); if (submenu.getSubElements().length > 0) { submenus.add(submenu); } } if (submenus.size() > 1) { submenus.forEach(menu::add); } else if (submenus.size() == 1) { for (Component element : submenus.get(0).getMenuComponents()) { menu.add(element); } } if (isDeletable(component)) { if (menu.getSubElements().length > 0) { menu.addSeparator(); } menu.add(new DeleteItemAction("Delete", component)); } return menu; }
Example 6
Source File: BaseChartPanel.java From nmonvisualizer with Apache License 2.0 | 6 votes |
@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 7
Source File: ListView.java From netbeans with Apache License 2.0 | 5 votes |
void createPopup(int xpos, int ypos, boolean contextMenu) { if (manager == null) { return; } if (!popupAllowed) { return; } if (!isShowing()) { return; } JPopupMenu popup; if (contextMenu) { popup = Utilities.actionsToPopup(manager.getExploredContext().getActions(true), this); } else { Action[] actions = NodeOp.findActions(manager.getSelectedNodes()); popup = Utilities.actionsToPopup(actions, this); } if ((popup != null) && (popup.getSubElements().length > 0)) { Point p = getViewport().getViewPosition(); p.x = xpos - p.x; p.y = ypos - p.y; SwingUtilities.convertPointToScreen(p, ListView.this); Dimension popupSize = popup.getPreferredSize(); Rectangle screenBounds = Utilities.getUsableScreenBounds(getGraphicsConfiguration()); if ((p.x + popupSize.width) > (screenBounds.x + screenBounds.width)) { p.x = (screenBounds.x + screenBounds.width) - popupSize.width; } if ((p.y + popupSize.height) > (screenBounds.y + screenBounds.height)) { p.y = (screenBounds.y + screenBounds.height) - popupSize.height; } SwingUtilities.convertPointFromScreen(p, ListView.this); popup.show(this, p.x, p.y); } }
Example 8
Source File: TreeView.java From netbeans with Apache License 2.0 | 5 votes |
private void createPopup(int xpos, int ypos, JPopupMenu popup) { if (popup.getSubElements().length > 0) { popup.show(TreeView.this, xpos, ypos); } }
Example 9
Source File: ContextMenuUtility.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public static JPopupMenu getMenu( final ReportDesignerContext context, final Object selectedElement ) { ReportDesignerView view = context.getView(); if ( selectedElement == null || selectedElement instanceof MasterReport ) { // This check assumes that we've click on a report band see JIRA // PRD-1076 return view.getPopupMenu( "popup-ReportDefinition" ); // NON-NLS } final ReportDesignerDocumentContext activeContext = context.getActiveContext(); ReportRenderContext doc = null; if ( activeContext instanceof ReportRenderContext ) { doc = (ReportRenderContext) activeContext; if ( selectedElement == doc.getReportDefinition() ) { if ( selectedElement instanceof CrosstabElement ) { return view.getPopupMenu( "popup-CrosstabElement" ); // NON-NLS } return view.getPopupMenu( "popup-ReportDefinition" ); // NON-NLS } } if ( selectedElement instanceof SubReport ) { return view.getPopupMenu( "popup-SubReport" ); // NON-NLS } if ( selectedElement instanceof CompoundDataFactory ) { return createDataSourcePopup( context ); } if ( selectedElement instanceof DataFactory ) { return view.getPopupMenu( "popup-DataSource" ); // NON-NLS } if ( selectedElement instanceof ReportFunctionNode ) { return view.getPopupMenu( "popup-Expressions" ); // NON-NLS } if ( selectedElement instanceof ReportQueryNode ) { final ReportQueryNode rqn = (ReportQueryNode) selectedElement; JPopupMenu popupMenu; if ( rqn.isAllowEdit() ) { popupMenu = view.getPopupMenu( "popup-Query" ); // NON-NLS } else { popupMenu = view.getPopupMenu( "popup-Inherited-Query" ); // NON-NLS } final MenuElement activationItem = popupMenu.getSubElements()[0]; toggleActivationItem( doc, rqn, activationItem ); return popupMenu; } if ( selectedElement instanceof Expression ) { return view.getPopupMenu( "popup-Expression" ); // NON-NLS } if ( selectedElement instanceof RootLevelBand ) { return view.getPopupMenu( "popup-RootLevelBand" ); // NON-NLS } if ( selectedElement instanceof RelationalGroup ) { return view.getPopupMenu( "popup-RelationalGroup" ); // NON-NLS } if ( selectedElement instanceof CrosstabGroup ) { return view.getPopupMenu( "popup-CrosstabGroup" ); // NON-NLS } if ( selectedElement instanceof CrosstabOtherGroup ) { return view.getPopupMenu( "popup-CrosstabOtherGroup" ); // NON-NLS } if ( selectedElement instanceof CrosstabRowGroup ) { return view.getPopupMenu( "popup-CrosstabRowGroup" ); // NON-NLS } if ( selectedElement instanceof CrosstabColumnGroup ) { return view.getPopupMenu( "popup-CrosstabColumnGroup" ); // NON-NLS } if ( selectedElement instanceof CrosstabCellBody ) { return view.getPopupMenu( "popup-CrosstabCellBody" ); // NON-NLS } if ( selectedElement instanceof Group ) { return view.getPopupMenu( "popup-Group" ); // NON-NLS } if ( selectedElement instanceof Band ) { return view.getPopupMenu( "popup-Band" ); // NON-NLS } if ( selectedElement instanceof Element ) { final Element element = (Element) selectedElement; final JPopupMenu popup = view.getPopupMenu( "popup-" + element.getElementTypeName() ); // NON-NLS if ( popup != null ) { return popup; } return view.getPopupMenu( "popup-Element" ); // NON-NLS } if ( selectedElement instanceof ReportParameterDefinition ) { return view.getPopupMenu( "popup-Parameters" ); // NON-NLS } if ( selectedElement instanceof ParameterDefinitionEntry ) { return view.getPopupMenu( "popup-Parameter" ); // NON-NLS } if ( selectedElement instanceof ReportParametersNode ) { return view.getPopupMenu( "popup-Parameters" ); // NON-NLS } if ( selectedElement instanceof SubReportParametersNode ) { return view.getPopupMenu( "popup-SubReportParameters" ); // NON-NLS } return null; }