Search in sources :

Example 66 with ItemListener

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

the class DialogComponentTime method createTimePanel.

private JPanel createTimePanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    JPanel timePanel = new JPanel();
    timePanel.setLayout(new BoxLayout(timePanel, BoxLayout.X_AXIS));
    m_hourUI = new JTextField(2);
    m_hourUI.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            m_hourUI.selectAll();
        }
    });
    m_hourUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {

        @Override
        protected void validate() {
            try {
                updateHour();
            } catch (InvalidSettingsException e) {
                showError(m_hourUI);
            }
        }
    });
    timePanel.add(new JLabel("Hour:"));
    timePanel.add(m_hourUI);
    timePanel.add(Box.createHorizontalStrut(WIDTH));
    m_minuteUI = new JTextField(2);
    m_minuteUI.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            m_minuteUI.selectAll();
        }
    });
    m_minuteUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {

        @Override
        protected void validate() {
            try {
                updateMinute();
            } catch (InvalidSettingsException e) {
                showError(m_minuteUI);
            }
        }
    });
    timePanel.add(new JLabel("Minute:"));
    timePanel.add(m_minuteUI);
    timePanel.add(Box.createHorizontalStrut(WIDTH));
    m_secondUI = new JTextField(2);
    m_secondUI.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            m_secondUI.selectAll();
        }
    });
    m_secondUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {

        @Override
        protected void validate() {
            try {
                updateSecond();
            } catch (InvalidSettingsException e) {
                showError(m_secondUI);
            }
        }
    });
    timePanel.add(new JLabel("Second:"));
    timePanel.add(m_secondUI);
    timePanel.add(Box.createHorizontalStrut(WIDTH));
    m_useMillis = new JCheckBox();
    m_useMillis.setSelected(false);
    m_milliUI = new JTextField(3);
    m_milliUI.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            m_milliUI.selectAll();
        }
    });
    m_milliUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {

        @Override
        protected void validate() {
            try {
                updateMillisecond();
            } catch (InvalidSettingsException e) {
                showError(m_milliUI);
            }
        }
    });
    m_useMillis.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            boolean enable = m_useMillis.isSelected();
            if (!enable) {
                // if we are disabled -> clear all errors
                // DialogComponent sets default (active!) colors
                clearError(m_milliUI);
            }
            // now enable or disable the text field (in order to get the
            // inactive default colors
            m_milliUI.setEnabled(enable);
            // immediately update the model
            SettingsModelCalendar model = (SettingsModelCalendar) getModel();
            model.setUseMilliseconds(enable);
            if (enable) {
                // into the model: if !useMillis it is not validated
                try {
                    // call update milliseconds in order to set error
                    updateMillisecond();
                } catch (InvalidSettingsException ise) {
                    showError(m_milliUI);
                }
            }
        }
    });
    timePanel.add(m_useMillis);
    timePanel.add(new JLabel("Milli:"));
    timePanel.add(m_milliUI);
    panel.add(timePanel);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) FocusAdapter(java.awt.event.FocusAdapter) ItemEvent(java.awt.event.ItemEvent) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) JCheckBox(javax.swing.JCheckBox) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ItemListener(java.awt.event.ItemListener)

Example 67 with ItemListener

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

the class DialogComponentDate method createDatePanel.

private JPanel createDatePanel() {
    // add the check box on top of the horizontal date panel
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    JPanel datePanel = new JPanel();
    // one text input field (year)
    m_yearUI = new JTextField(4);
    m_yearUI.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            m_yearUI.selectAll();
        }
    });
    m_yearUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {

        @Override
        protected void validate() {
            try {
                // if it is an integer it is a valid year
                updateModel();
            } catch (Exception e) {
                // else show error
                showError(m_yearUI);
            }
        }
    });
    datePanel.add(new JLabel("Year:"));
    datePanel.add(m_yearUI);
    // select boxes month
    Integer[] months = new Integer[12];
    for (int i = 0; i < 12; i++) {
        months[i] = Integer.valueOf(i + 1);
    }
    m_monthUI = new JComboBox(months);
    m_monthUI.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            try {
                updateModel();
            } catch (Exception ex) {
            // year may be invalid -> month is anyway a select box
            }
        }
    });
    datePanel.add(new JLabel("Month:"));
    datePanel.add(m_monthUI);
    // select box day
    Integer[] days = new Integer[31];
    for (int i = 0; i < 31; i++) {
        days[i] = Integer.valueOf(i + 1);
    }
    m_dayUI = new JComboBox(days);
    m_dayUI.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            try {
                updateModel();
            } catch (Exception ex) {
            // year may be invalid -> day is anyway a select box
            }
        }
    });
    datePanel.add(new JLabel("Day:"));
    datePanel.add(m_dayUI);
    panel.add(datePanel);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) FocusAdapter(java.awt.event.FocusAdapter) ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) ItemListener(java.awt.event.ItemListener)

Example 68 with ItemListener

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

the class LogRegLearnerNodeDialogPane method createTargetOptionsPanel.

/**
 * Create options panel for the target.
 */
private JPanel createTargetOptionsPanel() {
    JPanel p = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.BASELINE_LEADING;
    c.insets = new Insets(5, 5, 0, 0);
    p.add(new JLabel("Target Column:"), c);
    c.gridx++;
    m_selectionPanel = new ColumnSelectionPanel(new EmptyBorder(0, 0, 0, 0), NominalValue.class);
    m_selectionPanel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            updateTargetCategories((DataCell) m_targetReferenceCategory.getSelectedItem());
        }
    });
    p.add(m_selectionPanel, c);
    c.gridx = 0;
    c.gridy++;
    p.add(new JLabel("Reference Category:"), c);
    c.gridx++;
    m_targetReferenceCategory = new JComboBox();
    p.add(m_targetReferenceCategory, c);
    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 3;
    c.weightx = 1;
    m_notSortTarget = new JCheckBox("Use order from target column domain (only relevant for output representation)");
    p.add(m_notSortTarget, c);
    m_selectionPanel.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            Object selected = e.getItem();
            if (selected instanceof DataColumnSpec) {
                m_filterPanel.resetHiding();
                m_filterPanel.hideColumns((DataColumnSpec) selected);
            }
        }
    });
    return p;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) NominalValue(org.knime.core.data.NominalValue) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) DataCell(org.knime.core.data.DataCell) ItemListener(java.awt.event.ItemListener) ColumnSelectionPanel(org.knime.core.node.util.ColumnSelectionPanel) EmptyBorder(javax.swing.border.EmptyBorder)

Example 69 with ItemListener

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

the class LinRegLinePlotterProperties method update.

/**
 * Updates the selection boxes with the new
 * {@link org.knime.core.data.DataTableSpec} and selects the passed indices.
 * Takes care, that the x column selection box only contains the columns
 * used for model calculation. For this purpose the ItemListeners of this
 * box are removed and afterwards added again in order to avoid event loops.
 *
 * @param spec the new data table spec.
 * @param xPreSelect the x column index (-1 if unknown)
 * @param yPreSelect the y column (-1 if unknown)
 */
@Override
public void update(final DataTableSpec spec, final int xPreSelect, final int yPreSelect) {
    try {
        m_xSelector.update(spec, spec.getColumnSpec(xPreSelect).getName(), true);
        m_ySelector.update(spec, spec.getColumnSpec(yPreSelect).getName(), true);
        // store the old selected one
        Object oldSelected = m_xSelector.getSelectedItem();
        // suppress events
        ItemListener[] listeners = m_xSelector.getItemListeners();
        for (ItemListener listener : listeners) {
            m_xSelector.removeItemListener(listener);
        }
        if (m_includs != null) {
            // cleanup -> remove all items and add only the included
            m_xSelector.removeAllItems();
            List<String> survivors = Arrays.asList(m_includs);
            for (DataColumnSpec colSpec : spec) {
                if (!colSpec.getName().equals(m_targetColumn) && survivors.contains(colSpec.getName())) {
                    m_xSelector.addItem(colSpec);
                }
            }
            // restore the previously selected
            m_xSelector.setSelectedItem(oldSelected);
            for (ItemListener listener : listeners) {
                m_xSelector.addItemListener(listener);
            }
        }
    } catch (NotConfigurableException e) {
        LOGGER.warn(e.getMessage(), e);
    }
    DataColumnSpec x = (DataColumnSpec) m_xSelector.getSelectedItem();
    DataColumnSpec y = (DataColumnSpec) m_ySelector.getSelectedItem();
    m_ySelector.setEnabled(false);
    updateRangeSpinner(x, y);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataColumnSpec(org.knime.core.data.DataColumnSpec) ItemListener(java.awt.event.ItemListener)

Example 70 with ItemListener

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

the class LogRegLearnerNodeDialogPane method createTargetOptionsPanel.

/**
 * Create options panel for the target.
 */
private JPanel createTargetOptionsPanel() {
    JPanel p = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.BASELINE_LEADING;
    c.insets = new Insets(5, 5, 0, 0);
    p.add(new JLabel("Target Column:"), c);
    c.gridx++;
    @SuppressWarnings("unchecked") final ColumnSelectionPanel columnSelectionPanel = new ColumnSelectionPanel(new EmptyBorder(0, 0, 0, 0), NominalValue.class);
    m_selectionPanel = columnSelectionPanel;
    m_selectionPanel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            updateTargetCategories((DataCell) m_targetReferenceCategory.getSelectedItem());
        }
    });
    p.add(m_selectionPanel, c);
    c.gridx = 0;
    c.gridy++;
    p.add(new JLabel("Reference Category:"), c);
    c.gridx++;
    m_targetReferenceCategory = new JComboBox<>();
    p.add(m_targetReferenceCategory, c);
    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 3;
    c.weightx = 1;
    m_notSortTarget = new JCheckBox("Use order from target column domain (only relevant for output representation)");
    p.add(m_notSortTarget, c);
    m_selectionPanel.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            Object selected = e.getItem();
            if (selected instanceof DataColumnSpec) {
                m_filterPanel.resetHiding();
                m_filterPanel.hideNames((DataColumnSpec) selected);
            }
        }
    });
    return p;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) DataCell(org.knime.core.data.DataCell) ItemListener(java.awt.event.ItemListener) ColumnSelectionPanel(org.knime.core.node.util.ColumnSelectionPanel) EmptyBorder(javax.swing.border.EmptyBorder)

Aggregations

ItemListener (java.awt.event.ItemListener)162 ItemEvent (java.awt.event.ItemEvent)154 ActionEvent (java.awt.event.ActionEvent)45 ActionListener (java.awt.event.ActionListener)43 JCheckBox (javax.swing.JCheckBox)33 JPanel (javax.swing.JPanel)27 JLabel (javax.swing.JLabel)23 JComboBox (javax.swing.JComboBox)18 BoxLayout (javax.swing.BoxLayout)15 JTextField (javax.swing.JTextField)14 DocumentEvent (javax.swing.event.DocumentEvent)13 JButton (javax.swing.JButton)12 ChangeEvent (javax.swing.event.ChangeEvent)12 Dimension (java.awt.Dimension)11 ChangeListener (javax.swing.event.ChangeListener)11 GridBagConstraints (java.awt.GridBagConstraints)10 GridLayout (java.awt.GridLayout)10 Box (javax.swing.Box)10 GridBagLayout (java.awt.GridBagLayout)9 BorderLayout (java.awt.BorderLayout)8