Search in sources :

Example 91 with ChangeListener

use of javax.swing.event.ChangeListener in project knime-core by knime.

the class ModifyTimeZoneNodeModel method createSuffixModel.

/**
 * @param replaceOrAppendModel model for the replace/append button group
 * @return the string model, used in both dialog and model.
 */
public static SettingsModelString createSuffixModel(final SettingsModelString replaceOrAppendModel) {
    final SettingsModelString suffixModel = new SettingsModelString("suffix", "(modified time zone)");
    replaceOrAppendModel.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            if (replaceOrAppendModel.getStringValue().equals(OPTION_APPEND)) {
                suffixModel.setEnabled(true);
            } else {
                suffixModel.setEnabled(false);
            }
        }
    });
    suffixModel.setEnabled(false);
    return suffixModel;
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 92 with ChangeListener

use of javax.swing.event.ChangeListener in project knime-core by knime.

the class OptionsPanel method newTargetSelected.

/**
 * @param item
 */
private void newTargetSelected(final DataColumnSpec item) {
    String col = m_targetColumnBox.getSelectedColumn();
    if (m_lastTableSpec == null || col == null) {
        return;
    }
    DataTableSpec filtered = getCurrentAttributeSpec();
    // Set<String> prevIn = m_includeColumnsFilterPanel.getIncludedColumnSet();
    // m_includeColumnsFilterPanel.update(filtered, false, prevIn);
    Set<String> prevIn = m_includeColumnsFilterPanel2.getIncludedNamesAsSet();
    String[] prevInArray = prevIn.toArray(new String[prevIn.size()]);
    Set<String> prevEx = m_includeColumnsFilterPanel2.getExcludedNamesAsSet();
    String[] prevExArray = prevEx.toArray(new String[prevEx.size()]);
    DataColumnSpecFilterConfiguration conf = TreeEnsembleLearnerConfiguration.createColSpecFilterConfig();
    m_includeColumnsFilterPanel2.saveConfiguration(conf);
    EnforceOption prevEnforceOption = conf.isEnforceInclusion() ? EnforceOption.EnforceInclusion : EnforceOption.EnforceExclusion;
    String[] prevExWithFormerTarget = Arrays.copyOf(prevExArray, prevEx.size() + 1);
    prevExWithFormerTarget[prevEx.size()] = getMissingColSpecName(filtered, prevInArray, prevExArray);
    conf.loadDefaults(prevInArray, prevExWithFormerTarget, prevEnforceOption);
    m_includeColumnsFilterPanel2.loadConfiguration(conf, filtered);
    ChangeEvent e = new ChangeEvent(this);
    for (ChangeListener l : m_changeListenerList) {
        l.stateChanged(e);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ChangeEvent(javax.swing.event.ChangeEvent) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration) EnforceOption(org.knime.core.node.util.filter.NameFilterConfiguration.EnforceOption) ChangeListener(javax.swing.event.ChangeListener)

Example 93 with ChangeListener

use of javax.swing.event.ChangeListener in project knime-core by knime.

the class OptionsPanel method newTargetSelected.

/**
 * @param item
 */
private void newTargetSelected(final DataColumnSpec item) {
    String col = m_targetColumnBox.getSelectedColumn();
    if (m_lastTableSpec == null || col == null) {
        return;
    }
    DataTableSpec filtered = getCurrentAttributeSpec();
    // Set<String> prevIn = m_includeColumnsFilterPanel.getIncludedColumnSet();
    // m_includeColumnsFilterPanel.update(filtered, false, prevIn);
    Set<String> prevIn = m_includeColumnsFilterPanel2.getIncludedNamesAsSet();
    String[] prevInArray = prevIn.toArray(new String[prevIn.size()]);
    Set<String> prevEx = m_includeColumnsFilterPanel2.getExcludedNamesAsSet();
    String[] prevExArray = prevEx.toArray(new String[prevEx.size()]);
    DataColumnSpecFilterConfiguration conf = TreeEnsembleLearnerConfiguration.createColSpecFilterConfig();
    m_includeColumnsFilterPanel2.saveConfiguration(conf);
    EnforceOption prevEnforceOption = conf.isEnforceInclusion() ? EnforceOption.EnforceInclusion : EnforceOption.EnforceExclusion;
    String[] prevExWithFormerTarget = Arrays.copyOf(prevExArray, prevEx.size() + 1);
    prevExWithFormerTarget[prevEx.size()] = getMissingColSpecName(filtered, prevInArray, prevExArray);
    conf.loadDefaults(prevInArray, prevExWithFormerTarget, prevEnforceOption);
    m_includeColumnsFilterPanel2.loadConfiguration(conf, filtered);
    ChangeEvent e = new ChangeEvent(this);
    for (ChangeListener l : m_changeListenerList) {
        l.stateChanged(e);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ChangeEvent(javax.swing.event.ChangeEvent) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration) EnforceOption(org.knime.core.node.util.filter.NameFilterConfiguration.EnforceOption) ChangeListener(javax.swing.event.ChangeListener)

Example 94 with ChangeListener

use of javax.swing.event.ChangeListener in project knime-core by knime.

the class RuleEngineNodeDialog method createEditorPart.

/*
     * Editor part (from top to bottom, from left to right): default label
     * (label, text field) new column name (label, text field) rule editor (rule
     * text field, outcome text field, add button, clear button) error text
     * field
     */
private Box createEditorPart() {
    /*
         * Default label box
         */
    m_defaultLabelEditor = new JTextField(10);
    m_defaultLabelEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
    m_defaultLabelEditor.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            if (m_defaultLabelEditor.getText().equals(DEFAULT_LABEL)) {
                m_defaultLabelEditor.setText("");
            }
            m_lastUsedTextfield = m_defaultLabelEditor;
        }
    });
    JPanel defaultLabelBox = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.1;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 20, 0, 0);
    defaultLabelBox.add(new JLabel("Default label (if no rule matches): "), c);
    c.insets = new Insets(0, 0, 0, 0);
    c.gridx++;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    defaultLabelBox.add(m_defaultLabelEditor, c);
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.1;
    // also add a variable Model + corresponding icon to make this
    // option controllable via a variable
    FlowVariableModel fvm = createFlowVariableModel(RuleEngineSettings.CFG_DEFAULT_LABEL, FlowVariable.Type.STRING);
    fvm.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent evt) {
            FlowVariableModel svm = (FlowVariableModel) (evt.getSource());
            m_defaultLabelEditor.setEnabled(!svm.isVariableReplacementEnabled());
        }
    });
    c.gridx++;
    defaultLabelBox.add(new FlowVariableModelButton(fvm), c);
    c.gridx++;
    defaultLabelBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
    c.gridy++;
    c.gridx = 1;
    m_defaultLabelIsColumn = new JCheckBox("is a column reference");
    defaultLabelBox.add(m_defaultLabelIsColumn, c);
    /*
         * New column name box
         */
    m_newColumnName = new JTextField(10);
    m_newColumnName.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
    m_newColumnName.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            if (m_newColumnName.getText().equals(NEW_COL_NAME)) {
                m_newColumnName.setText("");
            }
        }
    });
    Box newColNameBox = Box.createHorizontalBox();
    newColNameBox.add(Box.createHorizontalStrut(20));
    newColNameBox.add(new JLabel("Appended column name: "));
    newColNameBox.add(Box.createHorizontalGlue());
    newColNameBox.add(m_newColumnName);
    newColNameBox.add(Box.createHorizontalGlue());
    newColNameBox.add(Box.createHorizontalStrut(10));
    newColNameBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
    /*
         * Rule Box
         */
    JPanel ruleBox = new JPanel(new GridBagLayout());
    m_ruleEditor = new JTextField(RULE_LABEL, 35);
    m_ruleEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
    m_ruleEditor.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            if (m_ruleEditor.getText().equals(RULE_LABEL)) {
                m_ruleEditor.setText("");
            }
            m_lastUsedTextfield = m_ruleEditor;
        }
    });
    m_ruleLabelEditor = new JTextField(OUTCOME_LABEL, 10);
    m_ruleLabelEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
    m_ruleLabelEditor.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            if (m_ruleLabelEditor.getText().equals(OUTCOME_LABEL)) {
                m_ruleLabelEditor.setText("");
            }
            m_lastUsedTextfield = m_ruleLabelEditor;
        }
    });
    m_lastUsedTextfield = m_ruleEditor;
    /*
         * Add Button
         */
    JButton add = new JButton("Add");
    add.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent arg0) {
            LOGGER.debug("adding: " + m_ruleEditor.getText() + "=>" + m_ruleLabelEditor.getText());
            addRule();
            m_lastUsedTextfield = m_ruleEditor;
        }
    });
    /*
         * Clear Button
         */
    JButton clear = new JButton("Clear");
    clear.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent arg0) {
            m_ruleEditor.setText("");
            m_ruleLabelEditor.setText("");
        }
    });
    m_outcomeIsColumn = new JCheckBox("is a column reference");
    /*
         * Putting the rule editor together (rule, outcome, add, clear)
         */
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(0, 20, 0, 0);
    c.weightx = 0.8;
    c.fill = GridBagConstraints.HORIZONTAL;
    ruleBox.add(new JLabel("Condition"), c);
    c.gridx++;
    c.weightx = 0.1;
    c.insets = new Insets(0, 5, 0, 0);
    ruleBox.add(new JLabel("Outcome"), c);
    c.gridx = 0;
    c.gridy++;
    c.insets = new Insets(0, 20, 0, 0);
    ruleBox.add(m_ruleEditor, c);
    c.insets = new Insets(0, 5, 0, 0);
    c.gridx++;
    c.weightx = 0.1;
    ruleBox.add(m_ruleLabelEditor, c);
    c.insets = new Insets(0, 10, 0, 0);
    c.fill = GridBagConstraints.NONE;
    c.gridx++;
    ruleBox.add(add, c);
    c.gridx++;
    ruleBox.add(clear, c);
    c.gridy++;
    c.gridx = 1;
    c.insets = new Insets(0, 5, 0, 0);
    ruleBox.add(m_outcomeIsColumn, c);
    /*
         * Putting it all together
         */
    Box editorBox = Box.createVerticalBox();
    editorBox.add(newColNameBox);
    editorBox.add(Box.createVerticalStrut(20));
    editorBox.add(defaultLabelBox);
    editorBox.add(Box.createVerticalStrut(20));
    editorBox.add(ruleBox);
    editorBox.add(Box.createVerticalStrut(20));
    m_error = new JLabel(" ");
    m_error.setForeground(Color.RED);
    editorBox.add(m_error);
    editorBox.setBorder(BorderFactory.createEtchedBorder());
    return editorBox;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) FlowVariableModel(org.knime.core.node.FlowVariableModel) JCheckBox(javax.swing.JCheckBox) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) FlowVariableModelButton(org.knime.core.node.FlowVariableModelButton) ChangeListener(javax.swing.event.ChangeListener)

Example 95 with ChangeListener

use of javax.swing.event.ChangeListener in project knime-core by knime.

the class OptionsPanel method newTargetSelected.

/**
 * @param item
 */
private void newTargetSelected(final DataColumnSpec item) {
    String col = m_targetColumnBox.getSelectedColumn();
    if (m_lastTableSpec == null || col == null) {
        return;
    }
    DataTableSpec filtered = getCurrentAttributeSpec();
    // Set<String> prevIn = m_includeColumnsFilterPanel.getIncludedColumnSet();
    // m_includeColumnsFilterPanel.update(filtered, false, prevIn);
    Set<String> prevIn = m_includeColumnsFilterPanel2.getIncludedNamesAsSet();
    String[] prevInArray = prevIn.toArray(new String[prevIn.size()]);
    Set<String> prevEx = m_includeColumnsFilterPanel2.getExcludedNamesAsSet();
    String[] prevExArray = prevEx.toArray(new String[prevEx.size()]);
    DataColumnSpecFilterConfiguration conf = TreeEnsembleLearnerConfiguration.createColSpecFilterConfig();
    m_includeColumnsFilterPanel2.saveConfiguration(conf);
    EnforceOption prevEnforceOption = conf.isEnforceInclusion() ? EnforceOption.EnforceInclusion : EnforceOption.EnforceExclusion;
    String[] prevExWithFormerTarget = Arrays.copyOf(prevExArray, prevEx.size() + 1);
    prevExWithFormerTarget[prevEx.size()] = getMissingColSpecName(filtered, prevInArray, prevExArray);
    conf.loadDefaults(prevInArray, prevExWithFormerTarget, prevEnforceOption);
    m_includeColumnsFilterPanel2.loadConfiguration(conf, filtered);
    ChangeEvent e = new ChangeEvent(this);
    for (ChangeListener l : m_changeListenerList) {
        l.stateChanged(e);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ChangeEvent(javax.swing.event.ChangeEvent) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration) EnforceOption(org.knime.core.node.util.filter.NameFilterConfiguration.EnforceOption) ChangeListener(javax.swing.event.ChangeListener)

Aggregations

ChangeListener (javax.swing.event.ChangeListener)218 ChangeEvent (javax.swing.event.ChangeEvent)205 JPanel (javax.swing.JPanel)54 ActionEvent (java.awt.event.ActionEvent)47 ActionListener (java.awt.event.ActionListener)46 JLabel (javax.swing.JLabel)34 Dimension (java.awt.Dimension)29 GridBagConstraints (java.awt.GridBagConstraints)27 GridBagLayout (java.awt.GridBagLayout)24 JCheckBox (javax.swing.JCheckBox)24 Insets (java.awt.Insets)21 JSlider (javax.swing.JSlider)20 PropertyChangeListener (java.beans.PropertyChangeListener)19 JButton (javax.swing.JButton)19 BorderLayout (java.awt.BorderLayout)17 PropertyChangeEvent (java.beans.PropertyChangeEvent)17 IOException (java.io.IOException)14 BoxLayout (javax.swing.BoxLayout)14 ButtonGroup (javax.swing.ButtonGroup)14 JSpinner (javax.swing.JSpinner)13