Example usage for javax.swing JPopupMenu JPopupMenu

List of usage examples for javax.swing JPopupMenu JPopupMenu

Introduction

In this page you can find the example usage for javax.swing JPopupMenu JPopupMenu.

Prototype

public JPopupMenu(String label) 

Source Link

Document

Constructs a JPopupMenu with the specified title.

Usage

From source file:pl.otros.logview.gui.LogViewPanel.java

private JPopupMenu initTableContextMenu() {
    JPopupMenu menu = new JPopupMenu("Menu");
    JMenuItem mark = new JMenuItem("Mark selected rows");
    mark.addActionListener(new MarkRowAction(otrosApplication));
    JMenuItem unmark = new JMenuItem("Unmark selected rows");
    unmark.addActionListener(new UnMarkRowAction(otrosApplication));

    JMenuItem autoResizeMenu = new JMenu("Table auto resize mode");
    autoResizeMenu.setIcon(Icons.TABLE_RESIZE);
    JMenuItem autoResizeSubsequent = new JMenuItem("Subsequent columns");
    autoResizeSubsequent/*from   w w  w  . ja va2s.c  o  m*/
            .addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS));
    JMenuItem autoResizeLast = new JMenuItem("Last column");
    autoResizeLast.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_LAST_COLUMN));
    JMenuItem autoResizeNext = new JMenuItem("Next column");
    autoResizeNext.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_NEXT_COLUMN));
    JMenuItem autoResizeAll = new JMenuItem("All columns");
    autoResizeAll.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_ALL_COLUMNS));
    JMenuItem autoResizeOff = new JMenuItem("Auto resize off");
    autoResizeOff.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_OFF));
    autoResizeMenu.add(autoResizeSubsequent);
    autoResizeMenu.add(autoResizeOff);
    autoResizeMenu.add(autoResizeNext);
    autoResizeMenu.add(autoResizeLast);
    autoResizeMenu.add(autoResizeAll);
    JMenu removeMenu = new JMenu("Remove log events");
    removeMenu.setFont(menuLabelFont);
    removeMenu.setIcon(Icons.BIN);
    JLabel removeLabel = new JLabel("Remove by:");
    removeLabel.setFont(menuLabelFont);
    removeMenu.add(removeLabel);

    Map<String, Set<String>> propKeyValue = getPropertiesOfSelectedLogEvents();
    for (AcceptCondition acceptCondition : acceptConditionList) {
        removeMenu.add(new JMenuItem(new RemoveByAcceptanceCriteria(acceptCondition, otrosApplication)));
    }
    for (String propertyKey : propKeyValue.keySet()) {
        for (String propertyValue : propKeyValue.get(propertyKey)) {
            PropertyAcceptCondition propAcceptCondition = new PropertyAcceptCondition(propertyKey,
                    propertyValue);
            removeMenu
                    .add(new JMenuItem(new RemoveByAcceptanceCriteria(propAcceptCondition, otrosApplication)));
        }
    }

    menu.add(new JSeparator());
    JLabel labelMarkingRows = new JLabel("Marking/unmarking rows");
    labelMarkingRows.setFont(menuLabelFont);
    menu.add(labelMarkingRows);
    menu.add(new JSeparator());
    menu.add(mark);
    menu.add(unmark);
    JMenu[] markersMenu = getAutomaticMarkersMenu();
    menu.add(markersMenu[0]);
    menu.add(markersMenu[1]);
    menu.add(new ClearMarkingsAction(otrosApplication));
    menu.add(new JSeparator());
    JLabel labelQuickFilters = new JLabel("Quick filters");
    labelQuickFilters.setFont(menuLabelFont);
    menu.add(labelQuickFilters);
    menu.add(new JSeparator());
    menu.add(focusOnThisThreadAction);
    menu.add(focusOnEventsAfter);
    menu.add(focusOnEventsBefore);
    menu.add(focusOnSelectedClassesAction);
    menu.add(ignoreSelectedEventsClasses);
    menu.add(focusOnSelectedLoggerNameAction);
    menu.add(showCallHierarchyAction);
    for (String propertyKey : propKeyValue.keySet()) {
        for (String propertyValue : propKeyValue.get(propertyKey)) {
            menu.add(new FocusOnSelectedPropertyAction(propertyFilter, propertyFilterPanel.getEnableCheckBox(),
                    otrosApplication, propertyKey, propertyValue));
        }
    }
    menu.add(new JSeparator());
    menu.add(removeMenu);
    menu.add(new JSeparator());
    JLabel labelTableOptions = new JLabel("Table options");
    labelTableOptions.setFont(menuLabelFont);
    menu.add(labelTableOptions);
    menu.add(new JSeparator());
    menu.add(autoResizeMenu);

    menu.add(new JSeparator());
    List<MenuActionProvider> menuActionProviders = otrosApplication.getLogViewPanelMenuActionProvider();
    for (MenuActionProvider menuActionProvider : menuActionProviders) {
        try {
            List<OtrosAction> actions = menuActionProvider.getActions(otrosApplication, this);
            if (actions == null) {
                continue;
            }
            for (OtrosAction action : actions) {
                menu.add(action);
            }
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Cant get action from from provider " + menuActionProvider, e);
        }
    }

    return menu;
}

From source file:pl.otros.logview.gui.LogViewPanel.java

private void showMessageFormatterOrColorizerPopupMenu(MouseEvent e, String menuTitle,
        PluginableElementsContainer<? extends PluginableElement> selectedPluginableElementsContainer,
        PluginableElementsContainer<? extends PluginableElement> pluginableElementsContainer) {
    final JPopupMenu popupMenu = new JPopupMenu(menuTitle);
    popupMenu.add(new JLabel(menuTitle));
    ArrayList<PluginableElement> elements = new ArrayList<PluginableElement>(
            pluginableElementsContainer.getElements());
    Collections.sort(elements, new PluginableElementNameComparator());
    for (final PluginableElement pluginableElement : elements) {
        addMessageFormatterOrColorizerToMenu(popupMenu, pluginableElement, selectedPluginableElementsContainer);
    }/*from   w ww .j  av a 2 s  .co  m*/
    popupMenu.show(e.getComponent(), e.getX(), e.getY());
}

From source file:tufts.vue.RichTextBox.java

private JPopupMenu getPopup(MouseEvent e) {
    if (m == null) {
        m = new JPopupMenu(VueResources.getString("richtextbox.menu.textboxmenu"));

        //copyItem.addActionListener(this);
        //pasteItem.addActionListener(this);
        //If you let this be focusable you'll loose the text box when
        //the menu gets raised.
        m.setFocusable(false);/*w w  w .  j ava  2  s  .  c  o m*/
        m.add(copyItem);
        m.add(pasteItem);

        copyItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                RichTextBox.this.copy();
            }
        });
        pasteItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                RichTextBox.this.paste();
                setSize(getPreferredSize());
            }
        });

    }

    return m;
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.QueryAuthoringTreePanel.java

/**
 * Creates the popup menus./*www  . ja va  2 s . co m*/
 */
private void createPopupMenus() {

    queryActionsMenu = new JPopupMenu("Query Actions");
    JMenuItem orMenuItem = new JMenuItem("ANY of the following");
    orMenuItem.setActionCommand("Add OR");
    orMenuItem.addActionListener(this);

    JMenuItem andMenuItem = new JMenuItem("ALL of the following");
    andMenuItem.setActionCommand("Add And");
    andMenuItem.addActionListener(this);
    // add submenu to group logical relationships
    JMenu logicalSubMenu = new JMenu("Add Logical query");
    logicalSubMenu.add(andMenuItem);
    logicalSubMenu.add(orMenuItem);

    JMenuItem afterMenuItem = new JMenuItem("After");
    afterMenuItem.setActionCommand("After");
    afterMenuItem.addActionListener(this);
    JMenuItem beforeMenuItem = new JMenuItem("Before");
    beforeMenuItem.setActionCommand("Before");
    beforeMenuItem.addActionListener(this);
    // add submenu to group temporal relationships
    JMenu temporalSubMenu = new JMenu("Add Temporal query");
    temporalSubMenu.add(beforeMenuItem);
    temporalSubMenu.add(afterMenuItem);

    JMenuItem addCriterionMenuItem = new JMenuItem("Add Query criterion");
    addCriterionMenuItem.setActionCommand("Add Query criterion");
    addCriterionMenuItem.addActionListener(this);

    JMenuItem removeMenuItem1 = new JMenuItem("Remove criterion");
    removeMenuItem1.setActionCommand("Remove Expression");
    removeMenuItem1.addActionListener(this);

    queryActionsMenu.add(logicalSubMenu);
    queryActionsMenu.add(temporalSubMenu);
    queryActionsMenu.add(addCriterionMenuItem);
    queryActionsMenu.add(removeMenuItem1);

    queryActionsMenu.add(new AbstractAction("Toggle execution") {

        public void actionPerformed(ActionEvent arg0) {

            // get currently selected expression and toggle run time status between SKIP and EXECUTE
            QueryExpression.QueryRunTimeStatus status = selectedExpression.getRunTimeStatus();
            if (status == QueryExpression.QueryRunTimeStatus.EXECUTE) {
                selectedExpression.setRunTimeStatus(QueryExpression.QueryRunTimeStatus.SKIP);
            } else {
                selectedExpression.setRunTimeStatus(QueryExpression.QueryRunTimeStatus.EXECUTE);
            }
            // hide queryActionsMenu
            queryActionsMenu.setVisible(false);
            // revalidate tree
            queryInterfaceTree.revalidate();
        }
    });

    toggleStatusMenu = new JPopupMenu();
    JMenuItem removeMenuItem2 = new JMenuItem("Remove criterion");
    removeMenuItem2.setActionCommand("Remove Expression");
    removeMenuItem2.addActionListener(this);
    toggleStatusMenu.add(removeMenuItem2);
    toggleStatusMenu.add(new AbstractAction("Toggle execution") {

        public void actionPerformed(ActionEvent arg0) {

            // get currently selected expresion and toggle run time status between SKIP and EXECUTE
            QueryExpression.QueryRunTimeStatus status = selectedExpression.getRunTimeStatus();
            if (status == QueryExpression.QueryRunTimeStatus.EXECUTE) {
                selectedExpression.setRunTimeStatus(QueryExpression.QueryRunTimeStatus.SKIP);
            } else {
                selectedExpression.setRunTimeStatus(QueryExpression.QueryRunTimeStatus.EXECUTE);
            }

            // hide toggleStatusMenu
            toggleStatusMenu.setVisible(false);
            // revalidate tree
            queryInterfaceTree.revalidate();
            // notify listeners
            queryService.queryChanged(activeQuery, QueryAuthoringTreePanel.this);
        }
    });
}