public void mousePressed (MouseEvent e) { if (e.getComponent ().isEnabled ()) { // open the popup menu Node context = null; if (!root) { Node[] sel = explorerManager.getSelectedNodes (); if (sel.length > 0) { context = sel[0]; } } if (context == null) { context = explorerManager.getRootContext(); } Menu menu = new Menu (context, listener); JPopupMenu popupMenu = menu.getPopupMenu (); java.awt.Point p = new java.awt.Point (e.getX (), e.getY ()); p.x = e.getX() - p.x; p.y = e.getY() - p.y; SwingUtilities.convertPointToScreen (p, e.getComponent ()); Dimension popupSize = popupMenu.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, e.getComponent ()); popupMenu.show(e.getComponent (), p.x, p.y); } }
Menu menu = new Menu(context, listener); JPopupMenu popupMenu = menu.getPopupMenu(); java.awt.Point p = new java.awt.Point(e.getX(), e.getY()); p.x = e.getX() - p.x;
public void mousePressed (MouseEvent e) { if (e.getComponent ().isEnabled ()) { // open the popup menu Node context = null; if (!root) { Node[] sel = explorerManager.getSelectedNodes (); if (sel.length > 0) { context = sel[0]; } } if (context == null) { context = explorerManager.getRootContext(); } Menu menu = new Menu (context, listener); JPopupMenu popupMenu = menu.getPopupMenu (); java.awt.Point p = new java.awt.Point (e.getX (), e.getY ()); p.x = e.getX() - p.x; p.y = e.getY() - p.y; SwingUtilities.convertPointToScreen (p, e.getComponent ()); Dimension popupSize = popupMenu.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, e.getComponent ()); popupMenu.show(e.getComponent (), p.x, p.y); } }
private void fillSubmenu(JPopupMenu popup) { if (!filled) { filled = true; Helper h = new Helper(popup); Node[] nodes = node.getChildren().getNodes(true); // Fill in the popup. removeAll(); for (int i = 0; i < nodes.length; i++) add(createMenuItem(nodes[i])); // also work with empty element if (getMenuComponentCount() == 0) { add(createEmptyMenuItem()); } } }
/** Create a menu element for a node. The default implementation creates * {@link MenuView.MenuItem}s for leafs and <code>Menu</code> for other nodes. * * @param n node to create element for * @return the created node */ protected JMenuItem createMenuItem (Node n) { return n.isLeaf () ? (JMenuItem) new MenuItem (n, action) : (JMenuItem) new Menu (n, action); }
/** Create a menu element for a node. The default implementation creates * {@link MenuView.MenuItem}s for leafs and <code>Menu</code> for other nodes. * * @param n node to create element for * @return the created node */ protected JMenuItem createMenuItem (Node n) { return n.isLeaf () ? (JMenuItem) new MenuItem (n, action) : (JMenuItem) new Menu (n, action); }
public JPopupMenu getPopupMenu () { if (node == null) node = getTemplateRoot (n); return super.getPopupMenu (); } };
/** Overriden to fill the submenu with the real content lazily */ public JPopupMenu getPopupMenu() { final JPopupMenu popup = super.getPopupMenu(); fillSubmenu(popup); return popup; }
/** Create a menu element for a node. The default implementation creates * {@link MenuView.MenuItem}s for leafs and <code>Menu</code> for other nodes. * * @param n node to create element for * @return the created node */ protected JMenuItem createMenuItem(Node n) { return n.isLeaf() ? (JMenuItem) new MenuItem(n, action) : (JMenuItem) new Menu(n, action); }
/** Overriden to fill the submenu with the real content lazily */ public JPopupMenu getPopupMenu() { final JPopupMenu popup = super.getPopupMenu(); fillSubmenu(popup); return popup; }
private void fillSubmenu(JPopupMenu popup) { if (!filled) { filled = true; Helper h = new Helper(popup); Node[] nodes = node.getChildren().getNodes(true); // Fill in the popup. removeAll(); for(int i=0; i<nodes.length; i++) add(createMenuItem(nodes[i])); // also work with empty element if(getMenuComponentCount () == 0) add(createEmptyMenuItem()); } }
/** Overriden to fill the submenu with the real content lazily */ public JPopupMenu getPopupMenu() { final JPopupMenu popup = super.getPopupMenu(); fillSubmenu(popup); return popup; }
private void fillSubmenu(JPopupMenu popup) { if (!filled) { filled = true; Helper h = new Helper(popup); Node[] nodes = node.getChildren().getNodes(true); // Fill in the popup. removeAll(); for(int i=0; i<nodes.length; i++) add(createMenuItem(nodes[i])); // also work with empty element if(getMenuComponentCount () == 0) add(createEmptyMenuItem()); } }