use of javax.swing.event.DocumentEvent in project knime-core by knime.
the class DialogComponentMultiLineString method showError.
private void showError(final JTextArea field) {
if (!getModel().isEnabled()) {
// don't flag an error in disabled components.
return;
}
if (field.getText().length() == 0) {
field.setBackground(Color.RED);
} else {
field.setForeground(Color.RED);
}
field.requestFocusInWindow();
// change the color back as soon as he changes something
field.getDocument().addDocumentListener(new DocumentListener() {
public void removeUpdate(final DocumentEvent e) {
field.setForeground(DEFAULT_FG);
field.setBackground(DEFAULT_BG);
field.getDocument().removeDocumentListener(this);
}
public void insertUpdate(final DocumentEvent e) {
field.setForeground(DEFAULT_FG);
field.setBackground(DEFAULT_BG);
field.getDocument().removeDocumentListener(this);
}
public void changedUpdate(final DocumentEvent e) {
field.setForeground(DEFAULT_FG);
field.setBackground(DEFAULT_BG);
field.getDocument().removeDocumentListener(this);
}
});
}
use of javax.swing.event.DocumentEvent 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 javax.swing.event.DocumentEvent in project knime-core by knime.
the class LimitRowsPanel method getLimitPanel.
private Container getLimitPanel() {
m_limitRows = new JCheckBox("Read only the first");
m_maxNumber = new JTextField();
m_maxNumber.setColumns(6);
m_maxNumber.setPreferredSize(new Dimension(125, 25));
m_maxNumber.setMaximumSize(new Dimension(125, 25));
m_limitRows.setSelected(false);
m_maxNumber.setEnabled(false);
// make sure we always have a valid value. Reject invalid characters.
m_maxNumber.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(final DocumentEvent e) {
checkAndFixTextfield();
}
@Override
public void insertUpdate(final DocumentEvent e) {
checkAndFixTextfield();
}
@Override
public void changedUpdate(final DocumentEvent e) {
checkAndFixTextfield();
}
});
m_maxNumber.addFocusListener(new FocusListener() {
@Override
public void focusLost(final FocusEvent e) {
if (m_maxNumber.getText().trim().length() == 0) {
// can't handle no empty strings.
m_lastValidValue = "0";
m_maxNumber.setText(m_lastValidValue);
}
}
@Override
public void focusGained(final FocusEvent e) {
}
});
m_limitRows.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
// en/disable the textfield
m_maxNumber.setEnabled(m_limitRows.isSelected());
// also - if the textfield is enabled and empty set a value
if (m_maxNumber.isEnabled()) {
if ((m_maxNumber.getText() == null) || (m_maxNumber.getText().trim().length() == 0)) {
// set a valid value, so we can safely assume that if there is a value in there it's always valid.
m_maxNumber.setText("1000");
m_lastValidValue = "1000";
}
}
}
});
Box result = Box.createHorizontalBox();
result.add(m_limitRows);
result.add(Box.createHorizontalStrut(3));
result.add(m_maxNumber);
result.add(Box.createHorizontalStrut(3));
result.add(new JLabel("table rows from the file."));
result.add(Box.createHorizontalGlue());
return result;
}
use of javax.swing.event.DocumentEvent in project knime-core by knime.
the class CharsetNamePanel method getSelectionPanel.
private Container getSelectionPanel() {
m_group = new ButtonGroup();
/*
* use action commands that are valid charset names (we use them later
* directly as parameter). Except for "default" and "user defined".
*/
m_default = new JRadioButton(DEFAULT_LABEL);
m_default.setToolTipText("uses the default decoding set by the operating system");
m_default.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
buttonsChanged();
}
});
m_group.add(m_default);
m_iso8859 = new JRadioButton("ISO-8859-1");
m_iso8859.setToolTipText("ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1");
m_iso8859.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
buttonsChanged();
}
});
m_group.add(m_iso8859);
m_utf8 = new JRadioButton("UTF-8");
m_utf8.setToolTipText("Eight-bit UCS Transformation Format");
m_utf8.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
buttonsChanged();
}
});
m_group.add(m_utf8);
m_utf16le = new JRadioButton("UTF-16LE");
m_utf16le.setToolTipText("Sixteen-bit UCS Transformation Format, little-endian byte order");
m_utf16le.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
buttonsChanged();
}
});
m_group.add(m_utf16le);
m_utf16be = new JRadioButton("UTF-16BE");
m_utf16be.setToolTipText("Sixteen-bit UCS Transformation Format, big-endian byte order");
m_utf16be.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
buttonsChanged();
}
});
m_group.add(m_utf16be);
m_utf16 = new JRadioButton("UTF-16");
m_utf16.setToolTipText("Sixteen-bit UCS Transformation Format, byte order identified by an optional " + "byte-order mark in the file");
m_utf16.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
buttonsChanged();
}
});
m_group.add(m_utf16);
m_custom = new JRadioButton(CUSTOM_LABEL);
m_custom.setToolTipText("Enter a valid charset name supported by the Java Virtual Machine");
m_custom.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
buttonsChanged();
}
});
m_group.add(m_custom);
m_customName = new JTextField(20);
m_customName.setPreferredSize(new Dimension(250, 25));
m_customName.setMaximumSize(new Dimension(250, 25));
m_customName.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(final DocumentEvent e) {
checkCustomCharsetName();
}
@Override
public void insertUpdate(final DocumentEvent e) {
checkCustomCharsetName();
}
@Override
public void changedUpdate(final DocumentEvent e) {
checkCustomCharsetName();
}
});
JPanel result = new JPanel(new GridBagLayout());
result.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Select a character set for decoding:"));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(5, 5, 5, 5);
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
result.add(m_default, gbc);
gbc.gridy++;
result.add(m_iso8859, gbc);
gbc.gridy++;
result.add(m_utf8, gbc);
gbc.gridy++;
result.add(m_utf16le, gbc);
gbc.gridy++;
result.add(m_utf16be, gbc);
gbc.gridy++;
result.add(m_utf16, gbc);
gbc.gridy++;
result.add(m_custom, gbc);
gbc.gridx++;
result.add(m_customName, gbc);
gbc.gridx++;
gbc.gridy++;
gbc.weightx = 1;
gbc.weighty = 1;
result.add(new JPanel(), gbc);
return result;
}
use of javax.swing.event.DocumentEvent 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