Search in sources :

Example 66 with ItemEvent

use of java.awt.event.ItemEvent 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 67 with ItemEvent

use of java.awt.event.ItemEvent in project knime-core by knime.

the class ColumnRowFilterPanel method instantiateComponents.

@SuppressWarnings("unchecked")
private void instantiateComponents(final RowFilterNodeDialogPane parentPane, final DataTableSpec tSpec) throws NotConfigurableException {
    /* instantiate the col idx selector, depending on the table spec */
    assert ((tSpec != null) && (tSpec.getNumColumns() > 0));
    Vector<String> colNames = new Vector<String>();
    for (int c = 0; c < tSpec.getNumColumns(); c++) {
        colNames.add(tSpec.getColumnSpec(c).getName());
    }
    m_colCombo = new ColumnSelectionComboxBox((Border) null, DataValue.class);
    m_colCombo.update(tSpec, null);
    m_colCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            selectedColChanged();
        }
    });
    m_deepFiltering = new JCheckBox("filter based on collection elements");
    /* the selectors for what kind of checking will be done */
    m_useRange = new JRadioButton("use range checking");
    m_useRegExpr = new JRadioButton("use pattern matching");
    m_useMissValue = new JRadioButton("only missing values match");
    m_useRange.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            radiosChanged();
        }
    });
    m_useRegExpr.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            radiosChanged();
        }
    });
    m_useMissValue.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            radiosChanged();
        }
    });
    m_radios = new ButtonGroup();
    m_radios.add(m_useRange);
    m_radios.add(m_useRegExpr);
    m_radios.add(m_useMissValue);
    /* the bound edit fields */
    m_lowerLabel = new JLabel("lower bound:");
    m_lowerLabel.setToolTipText("Smallest value of the range to be filtered.");
    m_lowerBound = new JTextField();
    m_upperLabel = new JLabel("upper bound:");
    m_upperLabel.setToolTipText("Largest value of the range to be filtered.");
    m_upperBound = new JTextField();
    m_lowerBound.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(final DocumentEvent e) {
            boundsChanged();
        }

        @Override
        public void removeUpdate(final DocumentEvent e) {
            boundsChanged();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            boundsChanged();
        }
    });
    m_upperBound.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(final DocumentEvent e) {
            boundsChanged();
        }

        @Override
        public void removeUpdate(final DocumentEvent e) {
            boundsChanged();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            boundsChanged();
        }
    });
    /* the regular expression stuff */
    m_regLabel = new JLabel("pattern:");
    // it's important that the column selection is created before!
    m_regExpr = new JComboBox(getPossibleValuesOfSelectedColumn());
    m_regExpr.setEditable(true);
    m_regExpr.setSelectedItem("");
    m_regExpr.setMinimumSize(new Dimension(50, m_regExpr.getPreferredSize().height));
    // m_regExpr.setPreferredSize(new Dimension(200, 50));
    m_regExpr.setMaximumSize(new Dimension(300, 50));
    JTextField ed = (JTextField) m_regExpr.getEditor().getEditorComponent();
    ed.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(final DocumentEvent e) {
            regExprChanged();
        }

        @Override
        public void removeUpdate(final DocumentEvent e) {
            regExprChanged();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            regExprChanged();
        }
    });
    m_regExpr.addItemListener(this);
    /* add flow variable button for the pattern/regexpr */
    FlowVariableModel fvm = parentPane.createFlowVariableModel(new String[] { RowFilterNodeModel.CFGFILTER, StringCompareRowFilter.CFGKEY_PATTERN }, FlowVariable.Type.STRING);
    fvm.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent evt) {
            FlowVariableModel fvm = (FlowVariableModel) (evt.getSource());
            m_regExpr.setEnabled(!fvm.isVariableReplacementEnabled());
            if (fvm.isVariableReplacementEnabled() && m_regExpr.getSelectedItem().equals("")) {
                // TODO: replace with more meaningful default - empty
                // pattern are rejected by dialog.
                m_regExpr.setSelectedItem(fvm.getInputVariableName());
            }
        }
    });
    m_regExprVarButton = new FlowVariableModelButton(fvm);
    m_caseSensitive = new JCheckBox("case sensitive match");
    m_isRegExpr = new JCheckBox("regular expression");
    m_hasWildCards = new JCheckBox("contains wild cards");
    m_hasWildCards.setToolTipText("insert '?' or '*' to match any one " + "character or any sequence (including none) of characters.");
    m_isRegExpr.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            wildRegExprChanged(e);
            // also trigger regular expression recompile
            regExprChanged();
        }
    });
    m_hasWildCards.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            wildRegExprChanged(e);
            // also trigger regular expression recompile
            regExprChanged();
        }
    });
    /* and a label to display errors/warnings */
    m_errText = new JTextArea();
    m_errText.setEditable(false);
    m_errText.setLineWrap(true);
    m_errText.setWrapStyleWord(true);
    m_errText.setBackground(getBackground());
    m_errText.setFont(new Font(m_errText.getFont().getName(), Font.BOLD, m_errText.getFont().getSize()));
    m_errText.setMinimumSize(new Dimension(350, 50));
    m_errText.setMaximumSize(new Dimension(350, 100));
    m_errText.setForeground(Color.RED);
    /* set the default values */
    m_useRegExpr.setSelected(true);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) ItemEvent(java.awt.event.ItemEvent) JRadioButton(javax.swing.JRadioButton) JTextArea(javax.swing.JTextArea) DataValue(org.knime.core.data.DataValue) ColumnSelectionComboxBox(org.knime.core.node.util.ColumnSelectionComboxBox) JTextField(javax.swing.JTextField) Font(java.awt.Font) FlowVariableModel(org.knime.core.node.FlowVariableModel) ChangeListener(javax.swing.event.ChangeListener) Vector(java.util.Vector) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) JCheckBox(javax.swing.JCheckBox) ChangeEvent(javax.swing.event.ChangeEvent) ButtonGroup(javax.swing.ButtonGroup) FlowVariableModelButton(org.knime.core.node.FlowVariableModelButton) ItemListener(java.awt.event.ItemListener) Border(javax.swing.border.Border)

Example 68 with ItemEvent

use of java.awt.event.ItemEvent in project knime-core by knime.

the class NormalizerNodeDialog method generateContent.

/*
     * Generates the radio buttons and text fields
     */
private JPanel generateContent() {
    JPanel panel = new JPanel();
    // min-max
    JPanel panel1 = new JPanel();
    GridLayout gl = new GridLayout(2, 4);
    panel1.setLayout(gl);
    m_minmaxButton = new JRadioButton("Min-Max Normalization");
    m_minmaxButton.setSelected(true);
    JLabel nmin = new JLabel("Min: ");
    JPanel spanel1 = new JPanel();
    spanel1.setLayout(new BorderLayout());
    spanel1.add(nmin, BorderLayout.EAST);
    spanel1.setMaximumSize(new Dimension(30, 10));
    m_newminTextField = new JTextField(2);
    JLabel nmax = new JLabel("Max: ");
    JPanel spanel2 = new JPanel();
    spanel2.setLayout(new BorderLayout());
    spanel2.add(nmax, BorderLayout.EAST);
    spanel2.setMaximumSize(new Dimension(30, 10));
    m_newmaxTextField = new JTextField(2);
    panel1.add(m_minmaxButton);
    panel1.add(spanel1);
    panel1.add(m_newminTextField);
    panel1.add(Box.createHorizontalGlue());
    panel1.add(new JPanel());
    panel1.add(spanel2);
    panel1.add(m_newmaxTextField);
    panel1.add(Box.createHorizontalGlue());
    // z-score
    JPanel panel2 = new JPanel();
    panel2.setLayout(new BorderLayout());
    m_zscoreButton = new JRadioButton("Z-Score Normalization");
    panel2.add(m_zscoreButton, BorderLayout.WEST);
    // decimal scaling
    JPanel panel3 = new JPanel();
    panel3.setLayout(new BorderLayout());
    m_decButton = new JRadioButton("Normalization by Decimal Scaling");
    panel3.add(m_decButton, BorderLayout.WEST);
    // Group the radio buttons.
    ButtonGroup group = new ButtonGroup();
    group.add(m_minmaxButton);
    group.add(m_zscoreButton);
    group.add(m_decButton);
    m_minmaxButton.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (m_minmaxButton.isSelected()) {
                m_filterpanel.setEnabled(true);
                m_newminTextField.setEnabled(true);
                m_newmaxTextField.setEnabled(true);
            }
        }
    });
    m_zscoreButton.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (m_zscoreButton.isSelected()) {
                m_filterpanel.setEnabled(true);
                m_newminTextField.setEnabled(false);
                m_newmaxTextField.setEnabled(false);
            }
        }
    });
    m_decButton.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (m_decButton.isSelected()) {
                m_filterpanel.setEnabled(true);
                m_newminTextField.setEnabled(false);
                m_newmaxTextField.setEnabled(false);
            }
        }
    });
    BoxLayout bly = new BoxLayout(panel, BoxLayout.Y_AXIS);
    panel.setLayout(bly);
    panel.add(panel1);
    panel.add(panel2);
    panel.add(panel3);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) ItemEvent(java.awt.event.ItemEvent) JRadioButton(javax.swing.JRadioButton) BorderLayout(java.awt.BorderLayout) ButtonGroup(javax.swing.ButtonGroup) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) ItemListener(java.awt.event.ItemListener) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField)

Example 69 with ItemEvent

use of java.awt.event.ItemEvent in project knime-core by knime.

the class ConstantValueColumnNodeDialogPane method connectRadioAndComponent.

/**
 * @param replaceColumnRadio
 */
private void connectRadioAndComponent(final JRadioButton replaceColumnRadio, final Component panel) {
    replaceColumnRadio.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            panel.setEnabled(replaceColumnRadio.isSelected());
        }
    });
    panel.addPropertyChangeListener("enabled", new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            replaceColumnRadio.setSelected(panel.isEnabled());
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ItemListener(java.awt.event.ItemListener)

Example 70 with ItemEvent

use of java.awt.event.ItemEvent in project knime-core by knime.

the class DomainDialog method createValuesPanel.

/*
     * create a panel to enter possible values. Depending on the stringValues
     * parameter it will create one to enter integers or strings. The integer
     * panel will also have an additional checkbox to decide whether the integer
     * column has nominal values at all.
     *
     * @param stringValues the flag indicating that the panel should be for
     * entering possible values of type string. Otherwise (if set false) it will
     * allow only integer values to be entered.
     */
private JPanel createValuesPanel(final boolean stringValues) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "poss. Values"));
    if (!stringValues) {
        // the checkbox to tell if this columns contains nominal values
        m_containsVals = new JCheckBox("this integer column contains nominal values");
        m_containsVals.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                containsValsChanged();
            }
        });
        Box checkBox = Box.createHorizontalBox();
        checkBox.add(m_containsVals);
        checkBox.add(Box.createHorizontalGlue());
        panel.add(checkBox);
        panel.add(Box.createVerticalStrut(3));
    }
    // the box to manually add/remove possible values
    m_editField = new JTextField(10);
    m_editField.setMaximumSize(new Dimension(100, 25));
    m_editField.setMinimumSize(new Dimension(100, 25));
    m_editField.setPreferredSize(new Dimension(100, 25));
    m_valueList = new JList<>();
    m_valueList.setMinimumSize(new Dimension(100, 150));
    m_valueList.setMaximumSize(new Dimension(100, 150));
    m_valueList.setPreferredSize(new Dimension(100, 150));
    m_errorLabel = new JLabel("");
    m_addButton = new JButton("Add");
    if (stringValues) {
        m_addButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                addStringPosValue();
            }
        });
    } else {
        m_addButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                addIntPosValue();
            }
        });
    }
    m_remButton = new JButton("Remove");
    m_remButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            remSelPosValues();
        }
    });
    Box buttonBox = Box.createVerticalBox();
    buttonBox.add(m_addButton);
    buttonBox.add(Box.createVerticalStrut(3));
    buttonBox.add(m_remButton);
    buttonBox.add(Box.createVerticalGlue());
    Box fieldBox = Box.createVerticalBox();
    fieldBox.add(m_editField);
    fieldBox.add(Box.createVerticalGlue());
    Box editBox = Box.createHorizontalBox();
    editBox.add(fieldBox);
    editBox.add(Box.createHorizontalStrut(3));
    editBox.add(buttonBox);
    // now this contains the textfield and the buttons arranged nicely
    // a box for the error label to ensure a certain height - even if empty
    Box errBox = Box.createHorizontalBox();
    errBox.add(Box.createVerticalStrut(25));
    errBox.add(m_errorLabel);
    errBox.add(Box.createHorizontalGlue());
    Box leftBox = Box.createVerticalBox();
    leftBox.add(editBox);
    leftBox.add(Box.createVerticalStrut(6));
    leftBox.add(errBox);
    leftBox.add(Box.createVerticalGlue());
    Box rightBox = Box.createHorizontalBox();
    rightBox.add(new JScrollPane(m_valueList));
    rightBox.add(Box.createVerticalStrut(150));
    // the over all nominal values boss box
    Box valsEditBox = Box.createHorizontalBox();
    valsEditBox.add(leftBox);
    valsEditBox.add(Box.createHorizontalStrut(3));
    valsEditBox.add(rightBox);
    valsEditBox.add(Box.createHorizontalGlue());
    panel.add(valsEditBox);
    return panel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener)

Aggregations

ItemEvent (java.awt.event.ItemEvent)339 ItemListener (java.awt.event.ItemListener)313 ActionEvent (java.awt.event.ActionEvent)120 ActionListener (java.awt.event.ActionListener)110 JPanel (javax.swing.JPanel)106 JLabel (javax.swing.JLabel)84 JCheckBox (javax.swing.JCheckBox)72 JComboBox (javax.swing.JComboBox)65 Dimension (java.awt.Dimension)59 JButton (javax.swing.JButton)53 BorderLayout (java.awt.BorderLayout)48 JTextField (javax.swing.JTextField)46 ButtonGroup (javax.swing.ButtonGroup)35 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)33 GridLayout (java.awt.GridLayout)30 ChangeEvent (javax.swing.event.ChangeEvent)30 GridBagConstraints (java.awt.GridBagConstraints)29 JMenu (javax.swing.JMenu)29 ChangeListener (javax.swing.event.ChangeListener)29 GridBagLayout (java.awt.GridBagLayout)28