use of java.awt.event.ItemListener 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);
}
use of java.awt.event.ItemListener 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;
}
use of java.awt.event.ItemListener 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());
}
});
}
use of java.awt.event.ItemListener 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;
}
use of java.awt.event.ItemListener in project knime-core by knime.
the class FileReaderNodeDialog method createSettingsPanel.
private JPanel createSettingsPanel() {
JButton advanced = new JButton("Advanced...");
int buttonHeight = advanced.getPreferredSize().height;
m_hasRowHeaders = new JCheckBox("read row IDs");
m_hasRowHeaders.setToolTipText("Check if the file contains row IDs" + " in the first column");
m_hasColHeaders = new JCheckBox("read column headers");
m_hasColHeaders.setToolTipText("Check if the file contains column" + " headers in the first line");
JLabel deliLabel = new JLabel("Column delimiter:");
m_delimField = new JComboBox();
m_delimField.setMaximumSize(new Dimension(70, buttonHeight));
m_delimField.setMinimumSize(new Dimension(70, buttonHeight));
m_delimField.setPreferredSize(new Dimension(70, buttonHeight));
m_delimField.setEditable(true);
Delimiter[] selDelims = DEFAULT_DELIMS;
m_delimField.setModel(new DefaultComboBoxModel(selDelims));
deliLabel.setToolTipText("Specify the data delimiter character(s)");
m_delimField.setToolTipText("Specify the data delimiter character(s)");
m_cStyleComment = new JCheckBox("Java-style comments");
m_cStyleComment.setToolTipText("Check to add support for '//' and " + "\"'/*' and '*/'\" comment");
m_singleLineComment = new JTextField(2);
m_singleLineComment.setMaximumSize(new Dimension(55, buttonHeight));
m_singleLineComment.setMinimumSize(new Dimension(55, buttonHeight));
m_singleLineComment.setPreferredSize(new Dimension(55, buttonHeight));
JLabel commentLabel = new JLabel("Single line comment:");
m_ignoreWS = new JCheckBox("ignore spaces and tabs");
m_ignoreWS.setToolTipText("If checked, whitespaces (spaces and tabs)" + " will be discarded (if not quoted)");
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3, 3));
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Basic Settings"));
// top row
Box rowBox = Box.createHorizontalBox();
rowBox.add(m_hasRowHeaders);
rowBox.add(Box.createGlue());
Box delimBox = Box.createHorizontalBox();
delimBox.add(Box.createHorizontalStrut(4));
delimBox.add(deliLabel);
delimBox.add(Box.createHorizontalStrut(3));
delimBox.add(m_delimField);
delimBox.add(Box.createGlue());
Box advBox = Box.createHorizontalBox();
advBox.add(Box.createGlue());
advBox.add(advanced);
advBox.add(Box.createGlue());
// middle row
Box colBox = Box.createHorizontalBox();
colBox.add(m_hasColHeaders);
colBox.add(Box.createGlue());
Box wsBox = Box.createHorizontalBox();
wsBox.add(m_ignoreWS);
wsBox.add(Box.createGlue());
// bottom row
Box pValBox = Box.createHorizontalBox();
// placeholder
pValBox.add(new JLabel(""));
pValBox.add(Box.createGlue());
Box cCmtBox = Box.createHorizontalBox();
cCmtBox.add(m_cStyleComment);
cCmtBox.add(Box.createGlue());
Box slcBox = Box.createHorizontalBox();
slcBox.add(commentLabel);
slcBox.add(Box.createHorizontalStrut(3));
slcBox.add(m_singleLineComment);
slcBox.add(Box.createGlue());
// now fill the grid: first row
panel.add(rowBox);
panel.add(delimBox);
panel.add(advBox);
// second row
panel.add(colBox);
panel.add(wsBox);
panel.add(new JLabel(""));
// third row
panel.add(pValBox);
panel.add(cCmtBox);
panel.add(slcBox);
int componentsHeight = (2 * COMP_HEIGHT) + 30 + buttonHeight;
panel.setMaximumSize(new Dimension(PANEL_WIDTH, componentsHeight));
advanced.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
advancedSettings();
}
});
m_hasRowHeaders.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
rowHeadersSettingsChanged();
}
});
m_hasColHeaders.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
colHeadersSettingsChanged();
}
});
m_cStyleComment.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
commentSettingsChanged();
}
});
m_delimField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
delimSettingsChanged();
}
});
m_ignoreWS.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
ignoreWSChanged();
}
});
m_singleLineComment.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(final DocumentEvent e) {
commentSettingsChanged();
}
@Override
public void insertUpdate(final DocumentEvent e) {
commentSettingsChanged();
}
@Override
public void removeUpdate(final DocumentEvent e) {
commentSettingsChanged();
}
});
// add a panel for the errors:
m_errorLabel = new JLabel("");
m_errorLabel.setForeground(Color.red);
m_errorDetail = new JLabel("");
m_errorDetail.setForeground(Color.red);
JPanel errorBox = new JPanel();
errorBox.setLayout(new BoxLayout(errorBox, BoxLayout.X_AXIS));
errorBox.add(Box.createHorizontalGlue());
errorBox.add(m_errorLabel);
// reserve a certain height for the (in the beginning invisible) label
errorBox.add(Box.createVerticalStrut(17));
errorBox.add(Box.createHorizontalGlue());
JPanel detailBox = new JPanel();
detailBox.setLayout(new BoxLayout(detailBox, BoxLayout.X_AXIS));
detailBox.add(Box.createHorizontalGlue());
detailBox.add(m_errorDetail);
// reserve a certain height for the (in the beginning invisible) label
detailBox.add(Box.createVerticalStrut(17));
detailBox.add(Box.createHorizontalGlue());
JPanel result = new JPanel();
result.setLayout(new BoxLayout(result, BoxLayout.Y_AXIS));
result.add(panel);
result.add(errorBox);
result.add(detailBox);
return result;
}
Aggregations