Search in sources :

Example 26 with DocumentListener

use of javax.swing.event.DocumentListener 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());
        }
    });
}
Also used : JCheckBox(javax.swing.JCheckBox) DocumentListener(javax.swing.event.DocumentListener) JTextArea(javax.swing.JTextArea) DocumentEvent(javax.swing.event.DocumentEvent)

Example 27 with DocumentListener

use of javax.swing.event.DocumentListener 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;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent)

Example 28 with DocumentListener

use of javax.swing.event.DocumentListener 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);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) DocumentEvent(javax.swing.event.DocumentEvent) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) JUndoableCayenneTextPane(org.apache.cayenne.modeler.util.JUndoableCayenneTextPane) KeyListener(java.awt.event.KeyListener) EJBQLSyntaxConstant(org.apache.cayenne.swing.components.textpane.syntax.EJBQLSyntaxConstant) FocusListener(java.awt.event.FocusListener) BadLocationException(javax.swing.text.BadLocationException)

Example 29 with DocumentListener

use of javax.swing.event.DocumentListener 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);
        }
    });
}
Also used : DocumentListener(javax.swing.event.DocumentListener) DocumentEvent(javax.swing.event.DocumentEvent)

Example 30 with DocumentListener

use of javax.swing.event.DocumentListener 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);
        }
    });
}
Also used : DocumentListener(javax.swing.event.DocumentListener) DocumentEvent(javax.swing.event.DocumentEvent)

Aggregations

DocumentListener (javax.swing.event.DocumentListener)73 DocumentEvent (javax.swing.event.DocumentEvent)70 JTextField (javax.swing.JTextField)24 ActionEvent (java.awt.event.ActionEvent)21 ActionListener (java.awt.event.ActionListener)19 JLabel (javax.swing.JLabel)19 JPanel (javax.swing.JPanel)18 Dimension (java.awt.Dimension)16 JButton (javax.swing.JButton)13 JCheckBox (javax.swing.JCheckBox)13 GridBagLayout (java.awt.GridBagLayout)9 ChangeEvent (javax.swing.event.ChangeEvent)9 GridBagConstraints (java.awt.GridBagConstraints)8 Box (javax.swing.Box)8 ChangeListener (javax.swing.event.ChangeListener)8 BoxLayout (javax.swing.BoxLayout)7 ZapTextField (org.zaproxy.zap.utils.ZapTextField)7 BorderLayout (java.awt.BorderLayout)6 Insets (java.awt.Insets)6 FocusEvent (java.awt.event.FocusEvent)6