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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations