Search in sources :

Example 56 with DocumentEvent

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

Example 57 with DocumentEvent

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();
        }
    });
}
Also used : SearchField(com.android.tools.idea.ui.SearchField) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 58 with DocumentEvent

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

Example 59 with DocumentEvent

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);
}
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 60 with DocumentEvent

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

Aggregations

DocumentEvent (javax.swing.event.DocumentEvent)139 DocumentListener (javax.swing.event.DocumentListener)70 DocumentAdapter (com.intellij.ui.DocumentAdapter)64 ActionEvent (java.awt.event.ActionEvent)36 ActionListener (java.awt.event.ActionListener)34 JTextField (javax.swing.JTextField)22 JLabel (javax.swing.JLabel)18 JPanel (javax.swing.JPanel)18 Dimension (java.awt.Dimension)16 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)13 ItemEvent (java.awt.event.ItemEvent)13 ItemListener (java.awt.event.ItemListener)13 ChangeEvent (javax.swing.event.ChangeEvent)13 JButton (javax.swing.JButton)12 JCheckBox (javax.swing.JCheckBox)12 ChangeListener (javax.swing.event.ChangeListener)11 Document (javax.swing.text.Document)10 GridBagLayout (java.awt.GridBagLayout)9 NotNull (org.jetbrains.annotations.NotNull)9 GridBagConstraints (java.awt.GridBagConstraints)8