Java Code Examples for org.openide.util.Utilities#actionsToPopup()

The following examples show how to use org.openide.util.Utilities#actionsToPopup() . 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: PopupHandler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void mousePressed(MouseEvent ev) {
    if (ev.isPopupTrigger()) {
        int x = ev.getX();
        int y = ev.getY();
        TreePath path = view.getClosestPathForLocation(x, y);
        if (path != null) {
            LookTreeNode n = (LookTreeNode)path.getLastPathComponent();
            clicked = new WeakReference<LookTreeNode>(n);
            @SuppressWarnings("unchecked")
            Action[] actions = n.getLook().getActions(n.getData(), n.getLookup() );
            // XXX handle multiselects...
            Node selection = makeNode( n );
            Lookup context = Lookups.fixed(new Object[] {selection, actionMap});
            JPopupMenu menu = Utilities.actionsToPopup(actions, context);
            menu.show(view, x, y);
            // XXX selection does not appear to be collected... do we need to
            // also destroy the popup menu?
        }
    }
}
 
Example 2
Source File: TerminalContainerTabbed.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void showPopup(MouseEvent e) {
    Terminal selected = (Terminal) getSelected();
    
    Action close = ActionFactory.forID(ActionFactory.CLOSE_ACTION_ID);
    Action setTitle = ActionFactory.forID(ActionFactory.SET_TITLE_ACTION_ID);
    Action pin = ActionFactory.forID(ActionFactory.PIN_TAB_ACTION_ID);
    pin.putValue("Name", PinTabAction.getMessage(selected.isPinned())); //NOI18N
    Action closeAll = new CloseAll();
    Action closeAllBut = new CloseAllButCurrent();
	    
    JPopupMenu menu = Utilities.actionsToPopup(
	    new Action[]{
		close,
		closeAll,
		closeAllBut,
		null,
		setTitle,
		pin
	    }, Lookups.fixed(getSelected())
    );
    menu.show(TerminalContainerTabbed.this, e.getX(), e.getY());
}
 
Example 3
Source File: CategoryDescriptor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private MouseListener createMouseListener() {
    return new MouseAdapter() {
        public void mouseClicked(MouseEvent event) {
            if (SwingUtilities.isRightMouseButton(event)) {
                JComponent comp = (JComponent)event.getSource();
                Item item = null;
                if (comp instanceof JList) {
                    JList list = (JList)comp;
                    Point p = event.getPoint();
                    int index = list.locationToIndex(p);
                    if (index >= 0 && !list.getCellBounds(index, index).contains(p)) {
                        index = -1;
                    }
                    if (index >= 0) {
                        item = (Item)list.getModel().getElementAt(index);
                    }
                }
                Action[] actions = null == item ? category.getActions() : item.getActions();
                JPopupMenu popup = Utilities.actionsToPopup( actions, getComponent() );
                Utils.addCustomizationMenuItems( popup, getPalettePanel().getController(), getPalettePanel().getSettings() );
                popup.show(comp, event.getX(), event.getY());
            }
        }
    };
}
 
Example 4
Source File: TreeList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Show popup menu from actions provided by node at given index (if any).
 *
 * @param rowIndex
 * @param location
 */
void showPopupMenuAt(int rowIndex, Point location) {
    TreeListNode node = (TreeListNode) getModel().getElementAt(rowIndex);
    boolean popupForSelected = false;
    if (getSelectionMode() != ListSelectionModel.SINGLE_SELECTION) {
        popupForSelected = isPopupForSelected(node);
    }
    if (!popupForSelected) {
        setSelectedIndex(rowIndex);
    }
    Action[] actions = node.getPopupActions();

    if (null == actions || actions.length == 0) {
        return;
    }
    JPopupMenu popup = Utilities.actionsToPopup(actions, this);
    popup.show(this, location.x, location.y);
}
 
Example 5
Source File: NodePopupFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a popup menu with entries from the selected nodes
 * related to the given component (usually a ETable subclass). The popup
 * is created for the table element in given column and row (column
 *  and row are in the view's coordinates (not the model's)).
 */
public JPopupMenu createPopupMenu(int row, int column, Node[] selectedNodes,
        Component component) {
    
    Action[] actions = NodeOp.findActions (selectedNodes);
    JPopupMenu res = Utilities.actionsToPopup(actions, component);
    if (showQuickFilter) {
        if ((component instanceof ETable) && (column >= 0)) {
            ETable et = (ETable)component;
            if (row >= 0) {
                Object val = et.getValueAt(row, column);
                val = et.transformValue(val);
                String s = NbBundle.getMessage(NodePopupFactory.class, "LBL_QuickFilter");
                res.add(et.getQuickFilterPopup(column, val, s));
            } else if (et.getQuickFilterColumn() == column) {
                addNoFilterItem(et, res);
            }
        }
    }
    return res;
}
 
Example 6
Source File: TreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void createExtendedPopup(int xpos, int ypos, JMenu newMenu) {
    Node[] ns = manager.getSelectedNodes();
    JPopupMenu popup = null;

    if (ns.length > 0) {
        // if any nodes are selected --> find theirs actions
        Action[] actions = NodeOp.findActions(ns);
        popup = Utilities.actionsToPopup(actions, this);
    } else {
        // if none node is selected --> get context actions from view's root
        if (manager.getRootContext() != null) {
            popup = manager.getRootContext().getContextMenu();
        }
    }

    int cnt = 0;

    if (popup == null) {
        popup = SystemAction.createPopupMenu(new SystemAction[] {  });
    }

    popup.add(newMenu);

    createPopup(xpos, ypos, popup);
}
 
Example 7
Source File: DataLoaderGetActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks whether the JSeparator added from the configuration
 * file is reflected in the resulting popup.
 * The tests performs following steps:
 * <OL><LI> Create an instance of ExtensibleNode with folder set to "test"
 *     <LI> No actions should be returned by getActions since the "test" folder
 *          is not there
 *     <LI> Create two actions in the testing folder separated by JSeparator
 *     <LI> getActions should return 3 elements - null element for the separator
 *     <LI> Popup is created from the actions array - the null element
 *              should be replaced by a JSeparator again
 * </OL>
 */
public void testAddingSeparators() throws Exception {
    Node en1 = node;
    assertEquals("No actions at the start", 0, en1.getActions(false).length);
    FileObject test = root;
    FileObject a1 = test.createData("1[org-openide-actions-PropertiesAction].instance");
    FileObject sep = test.createData("2[javax-swing-JSeparator].instance");
    FileObject a2 = test.createData("3[org-openide-actions-CutAction].instance");
    Action[] actions = en1.getActions(false);
    assertEquals("Actions array should contain 3 elements: "+Arrays.asList(actions), 3, actions.length);
    assertNull("separator should create null element in the array", actions[1]);
    javax.swing.JPopupMenu jp = Utilities.actionsToPopup(actions, Lookups.singleton(en1));
    assertEquals("Popup should contain 3 components", 3, jp.getComponentCount());
    assertTrue("Separator should be second", jp.getComponent(1) instanceof JSeparator);
}
 
Example 8
Source File: NodeOp.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Computes a common popup menu for the specified nodes.
 * Provides only those actions supplied by all nodes in the list.
 * <p>Component action maps are not taken into consideration.
 * {@link Utilities#actionsToPopup(Action[], Component)} is a better choice
 * if you want to use actions such as "Paste" which look at action maps.
* @param nodes the nodes
* @return the menu for all nodes
*/
public static JPopupMenu findContextMenu(Node[] nodes) {
    Action[] arr = findActions(nodes);

    // prepare lookup representing all the selected nodes
    List<Lookup> allLookups = new ArrayList<Lookup>();

    for (Node n : nodes) {
        allLookups.add(n.getLookup());
    }

    Lookup lookup = new ProxyLookup(allLookups.toArray(new Lookup[allLookups.size()]));

    return Utilities.actionsToPopup(arr, lookup);
}
 
Example 9
Source File: UtilitiesActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDynamicMenuContent() {
    Action[] acts = new Action[] {
        new Act1(),
        new Act2()
        
    };
    JPopupMenu popup = Utilities.actionsToPopup(acts, Lookup.EMPTY);
    Component[] comp = popup.getComponents();
    boolean onepresent = false;
    boolean twopresent = false;
    boolean threepresent = false;
    boolean fourpresent = false;
    boolean zeropresent = false;
    for (int i = 0; i < comp.length; i++) {
        if ("0".equals(((JMenuItem)comp[i]).getText())) {
            zeropresent = true;
        }
        if ("2".equals(((JMenuItem)comp[i]).getText())) {
            twopresent = true;
        }
        if ("4".equals(((JMenuItem)comp[i]).getText())) {
            fourpresent = true;
        }
        if ("3".equals(((JMenuItem)comp[i]).getText())) {
            threepresent = true;
        }
        if ("1".equals(((JMenuItem)comp[i]).getText())) {
            onepresent = true;
        }
    }
    assertTrue(threepresent);
    assertTrue(fourpresent);
    assertTrue(onepresent);
    assertTrue(twopresent);
    assertTrue(zeropresent);
}
 
Example 10
Source File: ListView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 11
Source File: TreeList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ae) {
    TreeListNode node = getSelectedTreeListNode();
    TreeList tl = (TreeList) ae.getSource();
    JPopupMenu menu = Utilities.actionsToPopup(node.getPopupActions(), tl);
    Point p = tl.getUI().indexToLocation(tl, tl.getSelectedIndex());
    menu.show(tl, p.x + 22, p.y);
}
 
Example 12
Source File: SelectionList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Show popup menu from actions provided by node at given index (if any).
 *
 * @param rowIndex
 * @param location
 */
private void showPopupMenuAt(int rowIndex, Point location) {
    ListNode node = getModel().getElementAt(rowIndex);
    Action[] actions = node.getPopupActions();

    if (null == actions || actions.length == 0) {
        return;
    }
    JPopupMenu popup = Utilities.actionsToPopup(actions, this);
    popup.show(this, location.x, location.y);
}
 
Example 13
Source File: PalettePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private MouseListener mouseListener() {
    if( null == mouseListener ) {
        mouseListener = new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent event) {
                if( SwingUtilities.isRightMouseButton( event ) && null != model ) {
                    JPopupMenu popup = Utilities.actionsToPopup( model.getActions(), PalettePanel.this );
                    Utils.addCustomizationMenuItems( popup, getController(), getSettings() );
                    popup.show( (Component)event.getSource(), event.getX(), event.getY() );
                }
            }
        };
    }
    return mouseListener;
}
 
Example 14
Source File: CategoryList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    int posX = 0;
    int posY = 0;
    Item item = getItemAt( getSelectedIndex() );
    if( null != item ) {
        Rectangle rect = getCellBounds( getSelectedIndex(), getSelectedIndex() );
        posX = rect.x;
        posY = rect.y + rect.height;
    }
    Action[] actions = null == item ? category.getActions() : item.getActions();
    JPopupMenu popup = Utilities.actionsToPopup( actions, CategoryList.this );
    Utils.addCustomizationMenuItems( popup, palettePanel.getController(), palettePanel.getSettings() );
    popup.show( getParent(), posX, posY );
}
 
Example 15
Source File: ScreenshotComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void showPopupMenu(int x, int y) {
    Node[] activatedNodes = getActivatedNodes();
    if (activatedNodes.length == 1) {
        Action[] actions = activatedNodes[0].getActions(true);
        JPopupMenu contextMenu = Utilities.actionsToPopup(actions, ScreenshotComponent.this);
        contextMenu.show(ScreenshotComponent.this.canvas, x, y);
    }
}
 
Example 16
Source File: LinkLabel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void showPopup(Point p) {
    if (popupActions.length > 0) {
        JPopupMenu menu = Utilities.actionsToPopup(popupActions, this);
        menu.show(this, p.x, p.y);
    }
}
 
Example 17
Source File: DesignViewPopupProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public JPopupMenu getPopupMenu(Widget widget, Point point) {
    return Utilities.actionsToPopup(actions, 
            widget.getScene().getView().getComponentAt(point));
}
 
Example 18
Source File: ProjectTab.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void showPopup(int x, int y) {
    Action actions[] = rootNode.getActions(false);
    JPopupMenu popup = Utilities.actionsToPopup(actions, component);
    popup.show(component, x, y);
}
 
Example 19
Source File: CategoryButton.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    Action[] actions = category.getActions();
    JPopupMenu popup = Utilities.actionsToPopup( actions, CategoryButton.this );
    Utils.addCustomizationMenuItems( popup, descriptor.getPalettePanel().getController(), descriptor.getPalettePanel().getSettings() );
    popup.show( getParent(), 0, getHeight() );
}
 
Example 20
Source File: SystemAction.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/** Create the default popup menu representation of an array of actions.
* @param actions actions to show in the generated menu
* @return a popup menu displaying them
*
* @deprecated Use {@link org.openide.util.Utilities#actionsToPopup}
*/
@Deprecated
public static JPopupMenu createPopupMenu(SystemAction[] actions) {
    return Utilities.actionsToPopup(actions, Utilities.actionsGlobalContext());
}