Search in sources :

Example 61 with ItemEvent

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

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

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

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

Example 65 with ItemEvent

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

the class PiePlotter method registerPropertiesChangeListener.

/**
 * Registers all histogram properties listener to the histogram
 * properties panel.
 */
private void registerPropertiesChangeListener() {
    m_props.addShowSectionOutlineChangedListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel != null) {
                vizModel.setDrawSectionOutline(e.getStateChange() == ItemEvent.SELECTED);
                final AbstractDrawingPane drawingPane = getPieDrawingPane();
                drawingPane.repaint();
            }
        }
    });
    m_props.addLabelDisplayListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel != null) {
                final P props = getPropertiesPanel();
                if (props != null) {
                    vizModel.setLabelDisplayPolicy(props.getLabelDisplayPolicy());
                    final AbstractDrawingPane drawingPane = getPieDrawingPane();
                    drawingPane.repaint();
                }
            }
        }
    });
    m_props.addValueScaleListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel != null) {
                final P props = getPropertiesPanel();
                if (props != null) {
                    vizModel.setValueScale(props.getValueScale());
                    final AbstractDrawingPane drawingPane = getPieDrawingPane();
                    drawingPane.repaint();
                }
            }
        }
    });
    m_props.addShowDetailsListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel != null) {
                if (vizModel.setShowDetails(e.getStateChange() == ItemEvent.SELECTED)) {
                    final AbstractDrawingPane drawingPane = getPieDrawingPane();
                    drawingPane.repaint();
                }
            }
        }
    });
    m_props.addPieSizeChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            final JSlider source = (JSlider) e.getSource();
            final int pieSize = source.getValue();
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            if (vizModel.setPieSize((pieSize / 100.0))) {
                updatePaintModel();
            }
        }
    });
    m_props.addExplodeSizeChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            final JSlider source = (JSlider) e.getSource();
            final int explodeSize = source.getValue();
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            if (vizModel.setExplodeSize((explodeSize / 100.0))) {
                updatePaintModel();
            }
        }
    });
    m_props.addAggrMethodListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            final String methodName = e.getActionCommand();
            if (!AggregationMethod.valid(methodName)) {
                throw new IllegalArgumentException("No valid aggregation method");
            }
            final AggregationMethod aggrMethod = AggregationMethod.getMethod4Command(methodName);
            if (vizModel.setAggregationMethod(aggrMethod)) {
                updatePaintModel();
            }
        }
    });
    m_props.addShowMissingValSectionListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            if (vizModel.setShowMissingValSection(e.getStateChange() == ItemEvent.SELECTED)) {
                // reset the details view if the missing section was selected
                final P properties = getPropertiesPanel();
                if (properties != null) {
                    properties.updateHTMLDetailsPanel(vizModel.getHTMLDetailData());
                }
                updatePaintModel();
            }
        }
    });
    m_props.addExplodeSelectedSectionListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            if (vizModel.setExplodeSelectedSections(e.getStateChange() == ItemEvent.SELECTED)) {
                updatePaintModel();
            }
        }
    });
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) ItemEvent(java.awt.event.ItemEvent) PieVizModel(org.knime.base.node.viz.pie.datamodel.PieVizModel) ActionEvent(java.awt.event.ActionEvent) AbstractDrawingPane(org.knime.base.node.viz.plotter.AbstractDrawingPane) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) JSlider(javax.swing.JSlider) ItemListener(java.awt.event.ItemListener) ChangeListener(javax.swing.event.ChangeListener)

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