use of javax.swing.event.DocumentEvent in project JMRI by JMRI.
the class AbstractMonPane method configureDataPane.
/**
* Do default configuration of a data pane
* @param textPane a JTextArea into which the data pane will be placed
*/
protected void configureDataPane(JTextArea textPane) {
textPane.setVisible(true);
// NOI18N
textPane.setToolTipText(Bundle.getMessage("TooltipMonTextPane"));
textPane.setEditable(false);
// Add document listener to scroll to end when modified if required
textPane.getDocument().addDocumentListener(new DocumentListener() {
// References to the JTextArea and JCheckBox
// of this instantiation
JTextArea ta = textPane;
JCheckBox chk = autoScrollCheckBox;
@Override
public void insertUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void removeUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void changedUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
});
}
use of javax.swing.event.DocumentEvent in project android by JetBrains.
the class IconPickerDialog method createUIComponents.
private void createUIComponents() {
mySearchField = new SearchField(false);
mySearchField.addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
updateFilter();
}
});
}
use of javax.swing.event.DocumentEvent in project processdash by dtuma.
the class SvnLOCDiffPanel method textField.
private JTextField textField(final JCheckBox associatedCheckBox, final CheckBoxCoordinator coord) {
final JTextField result = new JTextField();
result.getDocument().addDocumentListener(new DocumentListener() {
public void removeUpdate(DocumentEvent e) {
update();
}
public void insertUpdate(DocumentEvent e) {
update();
}
public void changedUpdate(DocumentEvent e) {
update();
}
private void update() {
boolean hasValue = result.getText().trim().length() > 0;
associatedCheckBox.setSelected(hasValue);
coord.actionPerformed(null);
}
});
return result;
}
use of javax.swing.event.DocumentEvent in project cayenne by apache.
the class EjbqlQueryScriptsTab method initView.
private void initView() {
scriptArea = new JUndoableCayenneTextPane(new EJBQLSyntaxConstant());
scriptArea.getDocument().addDocumentListener(this);
scriptArea.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
try {
String text = scriptArea.getDocument().getText(e.getOffset(), 1);
if (text.equals(" ") || text.equals("\n") || text.equals("\t")) {
getQuery().setEjbql(scriptArea.getDocumentTextDirect());
validateEJBQL();
}
} catch (BadLocationException ex) {
logger.warn("Error reading document", ex);
}
}
public void removeUpdate(DocumentEvent e) {
getQuery().setEjbql(scriptArea.getDocumentTextDirect());
validateEJBQL();
}
});
scriptArea.getPane().addFocusListener(new FocusListener() {
EJBQLValidationThread thread;
public void focusGained(FocusEvent e) {
thread = new EJBQLValidationThread();
thread.start();
}
public void focusLost(FocusEvent e) {
thread.terminate();
}
});
scriptArea.getPane().addKeyListener(new KeyListener() {
boolean pasteOrCut;
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_END || e.getKeyCode() == KeyEvent.VK_HOME || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_UNDO) {
getQuery().setEjbql(scriptArea.getText());
validateEJBQL();
}
if ((e.getKeyCode() == KeyEvent.VK_V || e.getKeyCode() == KeyEvent.VK_X) && e.isControlDown()) {
pasteOrCut = true;
}
}
public void keyReleased(KeyEvent e) {
if ((pasteOrCut && e.getKeyCode() == KeyEvent.VK_CONTROL) || e.getKeyCode() == KeyEvent.VK_DELETE) {
scriptArea.removeHighlightText();
getQuery().setEjbql(scriptArea.getText());
validateEJBQL();
pasteOrCut = false;
}
}
public void keyTyped(KeyEvent e) {
}
});
setLayout(new BorderLayout());
add(scriptArea, BorderLayout.WEST);
add(scriptArea.getScrollPane(), BorderLayout.CENTER);
setVisible(true);
}
use of javax.swing.event.DocumentEvent in project knime-core by knime.
the class DialogComponent method showError.
/**
* Colors the component red, and registers a listener to the edit field that
* sets the colors back to the default as soon as the user edits something
* in the field.
*
* @param field the component to set the color in
*/
protected void showError(final JTextField field) {
if (!getModel().isEnabled()) {
// don't show no error, if the model is not enabled.
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);
}
});
}
Aggregations