Search in sources :

Example 76 with JPopupMenu

use of javax.swing.JPopupMenu in project knime-core by knime.

the class AbstractPlotter method showPopupMenu.

/* ---------- relevant mouse methods ----------- */
/**
 * Calls the {@link #fillPopupMenu(JPopupMenu)} and then shows the popup
 * menu at the position of the mouse click.
 */
private void showPopupMenu(final Point at) {
    m_drawingPane.setMouseDown(false);
    m_isDragged = false;
    JPopupMenu menu = new JPopupMenu();
    fillPopupMenu(menu);
    if (menu.isEnabled()) {
        menu.show(m_drawingPane, (int) at.getX(), (int) at.getY());
    }
    return;
}
Also used : JPopupMenu(javax.swing.JPopupMenu)

Example 77 with JPopupMenu

use of javax.swing.JPopupMenu in project knime-core by knime.

the class Axis method createPopupMenu.

private JPopupMenu createPopupMenu() {
    if (getCoordinate() == null) {
        return null;
    }
    m_currFormat = NORMAL;
    JPopupMenu popupMenu = new JPopupMenu();
    createNotationMenu(popupMenu);
    // policies
    if (m_coordinate != null) {
        List<PolicyStrategy> strategies = new LinkedList<PolicyStrategy>();
        Set<PolicyStrategy> policies = m_coordinate.getCompatiblePolicies();
        if (policies != null) {
            strategies.addAll(policies);
            Collections.sort(strategies, new Comparator<PolicyStrategy>() {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public int compare(final PolicyStrategy o1, final PolicyStrategy o2) {
                    return o1.getDisplayName().compareTo(o2.getDisplayName());
                }
            });
        }
        JMenu tickPolicyMenu = new JMenu("Tick policies");
        ButtonGroup tickPolicyButtons = new ButtonGroup();
        if (strategies.size() > 0) {
            popupMenu.add(tickPolicyMenu);
            for (PolicyStrategy strategy : strategies) {
                final PolicyStrategy tempStrategy = strategy;
                JRadioButtonMenuItem tickPolicy = new JRadioButtonMenuItem(strategy.getDisplayName());
                tickPolicyButtons.add(tickPolicy);
                tickPolicyMenu.add(tickPolicy);
                if (strategy.equals(m_coordinate.getCurrentPolicy())) {
                    tickPolicy.setSelected(true);
                }
                tickPolicy.addItemListener(new ItemListener() {

                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    public void itemStateChanged(final ItemEvent e) {
                        if (e.getStateChange() == ItemEvent.SELECTED) {
                            m_coordinate.setPolicy(tempStrategy);
                            // recreate popup menu
                            setComponentPopupMenu(createPopupMenu());
                            if (tempStrategy.isMappingAllowed()) {
                                m_mappingMethodMenu.setEnabled(true);
                                m_notationsMenu.setEnabled(true);
                            } else {
                                // hide mapping methods
                                m_mappingMethodMenu.setEnabled(false);
                                m_notationsMenu.setEnabled(false);
                                if (getCoordinate() != null) {
                                    getCoordinate().setActiveMappingMethod(null);
                                }
                            }
                            notifyChangeListeners();
                        }
                    }
                });
            }
        }
        // add strategies
        Set<MappingMethod> mappingMethods = m_coordinate.getCompatibleMappingMethods();
        m_mappingMethodMenu = new JMenu("Mapping Methods");
        if (mappingMethods != null && mappingMethods.size() > 0) {
            popupMenu.add(m_mappingMethodMenu);
            ButtonGroup buttons = new ButtonGroup();
            final Map<MappingMethod, JRadioButtonMenuItem> checkboxes = new HashMap<MappingMethod, JRadioButtonMenuItem>();
            JRadioButtonMenuItem none = new JRadioButtonMenuItem("none", true);
            buttons.add(none);
            none.addItemListener(new ItemListener() {

                @Override
                public void itemStateChanged(final ItemEvent e) {
                    if (e.getStateChange() == ItemEvent.SELECTED) {
                        m_coordinate.setActiveMappingMethod(null);
                        notifyChangeListeners();
                    }
                }
            });
            m_mappingMethodMenu.add(none);
            for (MappingMethod method : mappingMethods) {
                // final needed
                final MappingMethod tempMethod = method;
                JRadioButtonMenuItem checkbox = new JRadioButtonMenuItem(method.getDisplayName(), false);
                checkbox.setEnabled(method.isCompatibleWithDomain(getCoordinate().getDomain()));
                checkboxes.put(method, checkbox);
                buttons.add(checkbox);
                if (method.equals(m_coordinate.getActiveMappingMethod())) {
                    checkbox.setSelected(true);
                }
                checkbox.addItemListener(new ItemListener() {

                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    public void itemStateChanged(final ItemEvent e) {
                        if (e.getStateChange() == ItemEvent.SELECTED) {
                            m_coordinate.setActiveMappingMethod(tempMethod);
                        }
                        notifyChangeListeners();
                    }
                });
                m_mappingMethodMenu.add(checkbox);
            }
            for (Map.Entry<MappingMethod, JRadioButtonMenuItem> entry : checkboxes.entrySet()) {
                if (entry.getKey().isCompatibleWithDomain(getCoordinate().getDomain())) {
                    entry.getValue().setEnabled(true);
                }
            }
        }
    }
    if (popupMenu.getComponentCount() < 1) {
        return null;
    }
    return popupMenu;
}
Also used : PolicyStrategy(org.knime.base.util.coordinate.PolicyStrategy) ItemEvent(java.awt.event.ItemEvent) HashMap(java.util.HashMap) MappingMethod(org.knime.base.util.coordinate.MappingMethod) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JPopupMenu(javax.swing.JPopupMenu) LinkedList(java.util.LinkedList) ButtonGroup(javax.swing.ButtonGroup) ItemListener(java.awt.event.ItemListener) HashMap(java.util.HashMap) Map(java.util.Map) JMenu(javax.swing.JMenu)

Example 78 with JPopupMenu

use of javax.swing.JPopupMenu in project knime-core by knime.

the class ClusterNodeView method openPopupMenu.

private void openPopupMenu(final MouseEvent e) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem item = new JMenuItem(HILITE);
    item.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void actionPerformed(final ActionEvent arg0) {
            getNodeModel().getHiLiteHandler().fireHiLiteEvent(m_selected);
        }
    });
    menu.add(item);
    item = new JMenuItem(UNHILITE);
    item.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void actionPerformed(final ActionEvent arg0) {
            getNodeModel().getHiLiteHandler().fireUnHiLiteEvent(m_selected);
        }
    });
    menu.add(item);
    item = new JMenuItem(UNHILITE_ALL);
    item.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void actionPerformed(final ActionEvent arg0) {
            getNodeModel().getHiLiteHandler().fireClearHiLiteEvent();
        }
    });
    menu.add(item);
    menu.show(e.getComponent(), e.getX(), e.getY());
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 79 with JPopupMenu

use of javax.swing.JPopupMenu in project knime-core by knime.

the class DnDColumnSelectionSearchableListPanel method enableDragAndDropSupport.

/**
 * Convenient method to enable the drag and drop support of the list view at the left side.
 *
 * @param dndStateListener notified if drag is started and finished
 * @since 2.11
 */
public void enableDragAndDropSupport(final DnDStateListener dndStateListener) {
    ColumnSelectionList columnList = getColumnList();
    columnList.setDragEnabled(true);
    JPopupMenu popup = new JPopupMenu();
    final JMenuItem jMenuItem = new JMenuItem("New Configuration", DnDConfigurationPanel.ADD_ICON_16);
    popup.add(jMenuItem);
    popup.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
            boolean enable = true;
            for (DataColumnSpec col : getSelectedColumns()) {
                if (m_configuredColumnDeterminer.isConfiguredColumn(col)) {
                    enable = false;
                    break;
                }
            }
            jMenuItem.setEnabled(enable);
        }

        @Override
        public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(final PopupMenuEvent e) {
        }
    });
    jMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            fireConfigurationRequested(Type.CREATION);
        }
    });
    columnList.setComponentPopupMenu(popup);
    final TransferHandler handler = columnList.getTransferHandler();
    columnList.setTransferHandler(new DnDColumnSpecSourceTransferHandler(handler, dndStateListener) {

        @Override
        protected List<DataColumnSpec> getColumnsSpecsToDrag() {
            return getSelectedColumns();
        }
    });
}
Also used : ColumnSelectionList(org.knime.core.node.util.ColumnSelectionList) DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) TransferHandler(javax.swing.TransferHandler) List(java.util.List) ColumnSelectionList(org.knime.core.node.util.ColumnSelectionList) JMenuItem(javax.swing.JMenuItem) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JPopupMenu(javax.swing.JPopupMenu)

Example 80 with JPopupMenu

use of javax.swing.JPopupMenu in project knime-core by knime.

the class DBDataTypeAggregationFunctionPanel method createTablePopupMenu.

/**
 * {@inheritDoc}
 */
@Override
protected JPopupMenu createTablePopupMenu() {
    final JPopupMenu menu = new JPopupMenu();
    final JMenuItem invalidRowsMenu = createInvalidRowsSelectionMenu();
    if (invalidRowsMenu != null) {
        menu.add(invalidRowsMenu);
        menu.addSeparator();
    }
    createColumnSelectionMenu(menu);
    menu.addSeparator();
    createAggregationSection(menu);
    return menu;
}
Also used : JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)203 JMenuItem (javax.swing.JMenuItem)105 ActionEvent (java.awt.event.ActionEvent)61 ActionListener (java.awt.event.ActionListener)46 JMenu (javax.swing.JMenu)28 Point (java.awt.Point)24 Component (java.awt.Component)20 JLabel (javax.swing.JLabel)20 JSeparator (javax.swing.JSeparator)19 JScrollPane (javax.swing.JScrollPane)18 MouseEvent (java.awt.event.MouseEvent)17 JButton (javax.swing.JButton)16 AbstractAction (javax.swing.AbstractAction)15 BorderLayout (java.awt.BorderLayout)13 JPanel (javax.swing.JPanel)13 JTable (javax.swing.JTable)13 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)12 MouseAdapter (java.awt.event.MouseAdapter)11 ArrayList (java.util.ArrayList)11 Icon (javax.swing.Icon)11