Search in sources :

Example 46 with JRadioButtonMenuItem

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

the class TableContentView method getPopUpMenu.

/**
 * Create a custom popup menu when the mouse was clicked in a column header.
 * This popup menu will contain the possible values in that column (when
 * available) and a set of buttons which let the user change the renderer
 * (again: when available).
 *
 * @param column column for which to create the popup menu
 * @return a popup menu displaying these properties
 * @see #onMouseClickInHeader(MouseEvent)
 */
protected JPopupMenu getPopUpMenu(final int column) {
    final TableColumn tableColumn = getColumnModel().getColumn(column);
    Object value = tableColumn.getHeaderValue();
    if (!(value instanceof DataColumnSpec)) {
        // only occurs if someone overrides the addColumn method.
        return null;
    }
    final DataColumnSpec spec = (DataColumnSpec) value;
    JPopupMenu popup = new JPopupMenu("Column Context Menu");
    JMenuItem menuItem;
    // first menu item will allow to show all possible values
    final Set<DataCell> valueList = spec.getDomain().getValues();
    if (valueList != null && !valueList.isEmpty()) {
        menuItem = new JMenuItem("Show possible values");
        final String[] columnValues = new String[valueList.size()];
        int i = 0;
        for (DataCell cell : valueList) {
            columnValues[i++] = cell.toString();
        }
        menuItem.addActionListener(new ActionListener() {

            // TODO: must be put in a scroll pane?
            @Override
            public void actionPerformed(final ActionEvent action) {
                JOptionPane.showMessageDialog(TableContentView.this.getRootPane(), columnValues, "Possible Values", JOptionPane.INFORMATION_MESSAGE);
            }
        });
        popup.add(menuItem);
    }
    // try to figure out the set of available renderers
    TableCellRenderer curRen = tableColumn.getCellRenderer();
    String renderID = null;
    DataValueRendererFamily renFamily = null;
    // should always be true unless someone overrides addColumn
    if (curRen instanceof DataValueRendererFamily) {
        renFamily = (DataValueRendererFamily) curRen;
        renderID = renFamily.getDescription();
    }
    String[] availRender = getAvailableRenderers(column);
    if (availRender != null && availRender.length > 1) {
        JMenu subMenu = new JMenu("Available Renderers");
        popup.add(subMenu);
        // actionlistener which changes the renderer according to the
        // action command
        ActionListener actionListener = new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent action) {
                changeRenderer(column, action.getActionCommand());
            }
        };
        ButtonGroup buttonGroup = new ButtonGroup();
        for (int i = 0; i < availRender.length; i++) {
            String thisID = availRender[i];
            menuItem = new JRadioButtonMenuItem(thisID);
            menuItem.setEnabled(renFamily != null && renFamily.accepts(thisID, spec));
            buttonGroup.add(menuItem);
            menuItem.setActionCommand(thisID);
            menuItem.addActionListener(actionListener);
            menuItem.setSelected(thisID.equals(renderID));
            subMenu.add(menuItem);
        }
    }
    return popup;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) DataValueRendererFamily(org.knime.core.data.renderer.DataValueRendererFamily) DataCell(org.knime.core.data.DataCell) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 47 with JRadioButtonMenuItem

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

the class TableView method createHiLiteMenuItems.

// createHiLiteMenu()
/**
 * Helper function to create new JMenuItems that are in the hilite menu.
 *
 * @return all those items in an array
 */
Collection<JMenuItem> createHiLiteMenuItems() {
    ArrayList<JMenuItem> result = new ArrayList<JMenuItem>();
    JMenuItem hsitem = new JMenuItem("Hilite Selected");
    hsitem.setMnemonic('S');
    hsitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            hiliteSelected();
        }
    });
    hsitem.addPropertyChangeListener(new EnableListener(this, true, true));
    hsitem.setEnabled(hasData() && hasHiLiteHandler());
    result.add(hsitem);
    JMenuItem usitem = new JMenuItem("Unhilite Selected");
    usitem.setMnemonic('U');
    usitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            unHiliteSelected();
        }
    });
    usitem.addPropertyChangeListener(new EnableListener(this, true, true));
    usitem.setEnabled(hasData() && hasHiLiteHandler());
    result.add(usitem);
    JMenuItem chitem = new JMenuItem("Clear Hilite");
    chitem.setMnemonic('C');
    chitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            resetHilite();
        }
    });
    chitem.addPropertyChangeListener(new EnableListener(this, true, true));
    chitem.setEnabled(hasData() && hasHiLiteHandler());
    result.add(chitem);
    JMenu filterSubMenu = new JMenu("Filter");
    JRadioButtonMenuItem showAllItem = new JRadioButtonMenuItem("Show All");
    showAllItem.addPropertyChangeListener("ancestor", new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            boolean selected = getContentModel().getTableContentFilter().equals(TableContentFilter.All);
            ((AbstractButton) evt.getSource()).setSelected(selected);
        }
    });
    showAllItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            getContentModel().setTableContentFilter(TableContentFilter.All);
        }
    });
    showAllItem.addPropertyChangeListener(new EnableListener(this, true, false));
    showAllItem.setEnabled(hasData());
    filterSubMenu.add(showAllItem);
    JRadioButtonMenuItem showHiliteItem = new JRadioButtonMenuItem("Show Hilited Only");
    showHiliteItem.addPropertyChangeListener("ancestor", new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            boolean selected = getContentModel().getTableContentFilter().equals(TableContentFilter.HiliteOnly);
            ((AbstractButton) evt.getSource()).setSelected(selected);
        }
    });
    showHiliteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            getContentModel().setTableContentFilter(TableContentFilter.HiliteOnly);
        }
    });
    showHiliteItem.addPropertyChangeListener(new EnableListener(this, true, true));
    showHiliteItem.setEnabled(hasData() && hasHiLiteHandler());
    filterSubMenu.add(showHiliteItem);
    JRadioButtonMenuItem showUnHiliteItem = new JRadioButtonMenuItem("Show UnHilited Only");
    showUnHiliteItem.addPropertyChangeListener("ancestor", new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            boolean selected = getContentModel().getTableContentFilter().equals(TableContentFilter.UnHiliteOnly);
            ((AbstractButton) evt.getSource()).setSelected(selected);
        }
    });
    showUnHiliteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            getContentModel().setTableContentFilter(TableContentFilter.UnHiliteOnly);
        }
    });
    showUnHiliteItem.addPropertyChangeListener(new EnableListener(this, true, true));
    showUnHiliteItem.setEnabled(hasData() && hasHiLiteHandler());
    filterSubMenu.add(showUnHiliteItem);
    result.add(filterSubMenu);
    return result;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) ActionListener(java.awt.event.ActionListener) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 48 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project MassBank-web by MassBank.

the class DrawPane method fillRadioMenu.

private JMenu fillRadioMenu(String title, char mnemonic, Action[] actions) {
    JMenu menu = new JMenu(title);
    menu.setMnemonic(mnemonic);
    ButtonGroup bg = new ButtonGroup();
    if (actions != null)
        for (int i = 0; i < actions.length; i++) {
            JRadioButtonMenuItem rb = new JRadioButtonMenuItem(actions[i]);
            bg.add(rb);
            menu.add(rb);
            if (i == 0)
                rb.setSelected(true);
        }
    return menu;
}
Also used : ButtonGroup(javax.swing.ButtonGroup) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenu(javax.swing.JMenu)

Example 49 with JRadioButtonMenuItem

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

the class ScatterPlotter method getHiLiteMenu.

/**
 * Creates a menue entry for Hiliting if not done so far.
 *
 * @return a JMenu entry handling the hiliting of objects
 */
@Override
public JMenu getHiLiteMenu() {
    // if the menu was already created
    // if (m_hiliteMenu != null) {
    // return m_hiliteMenu;
    // }
    // else create it
    JMenu menu = new JMenu(HiLiteHandler.HILITE);
    menu.setMnemonic('H');
    boolean selected = getDrawingPane().getNumberSelectedElements() > 0;
    // create the entries. by default all entries are disabled first
    m_hilite = new JMenuItem(POPUP_HILITE_SELECTED);
    m_hilite.addActionListener(this);
    m_hilite.setEnabled(selected);
    m_hilite.setMnemonic('H');
    menu.add(m_hilite);
    m_unhilite = new JMenuItem(POPUP_UNHILITE_SELECTED);
    m_unhilite.addActionListener(this);
    m_unhilite.setEnabled(selected);
    m_unhilite.setMnemonic('U');
    menu.add(m_unhilite);
    m_clearHilite = new JMenuItem(POPUP_CLEAR_HILITED);
    m_clearHilite.addActionListener(this);
    m_clearHilite.setEnabled(true);
    m_clearHilite.setMnemonic('E');
    menu.add(m_clearHilite);
    /* ------------------------------ */
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();
    /* --- "[ ] show unhilited" --- */
    m_show = new JRadioButtonMenuItem(POPUP_SHOW, (!getFadeUnHiLited() && !isHideUnHiLited()));
    m_show.addActionListener(this);
    group.add(m_show);
    menu.add(m_show);
    /* --- "[ ] fade unhilited" --- */
    m_fade = new JRadioButtonMenuItem(POPUP_FADE, getFadeUnHiLited());
    m_fade.addActionListener(this);
    group.add(m_fade);
    menu.add(m_fade);
    /* --- "[ ] hide unhilited" --- */
    m_hide = new JRadioButtonMenuItem(POPUP_HIDE, isHideUnHiLited());
    m_hide.addActionListener(this);
    group.add(m_hide);
    menu.add(m_hide);
    m_hiliteMenu = menu;
    return menu;
}
Also used : ButtonGroup(javax.swing.ButtonGroup) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Aggregations

JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)49 ActionEvent (java.awt.event.ActionEvent)28 JMenu (javax.swing.JMenu)25 ActionListener (java.awt.event.ActionListener)24 ButtonGroup (javax.swing.ButtonGroup)24 JMenuItem (javax.swing.JMenuItem)16 JPopupMenu (javax.swing.JPopupMenu)7 JSeparator (javax.swing.JSeparator)5 Color (java.awt.Color)4 ArrayList (java.util.ArrayList)4 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)4 ItemEvent (java.awt.event.ItemEvent)3 ItemListener (java.awt.event.ItemListener)3 AbstractAction (javax.swing.AbstractAction)3 JButton (javax.swing.JButton)3 Component (java.awt.Component)2 Preferences (java.util.prefs.Preferences)2 Action (javax.swing.Action)2 JCheckBox (javax.swing.JCheckBox)2 JMenuBar (javax.swing.JMenuBar)2