Search in sources :

Example 11 with DocumentListener

use of javax.swing.event.DocumentListener in project yyl_example by Relucent.

the class Command method registerListener.

private void registerListener() {
    txtDebug.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == 8 && execOffset >= doc.getLength()) {
                e.setKeyCode(27);
            }
            if (e.getKeyCode() == 10 && execOffset < doc.getLength()) {
                try {
                    String str = doc.getText(execOffset, doc.getLength() - execOffset);
                    exec(str + "\n");
                } catch (BadLocationException ex) {
                    ex.printStackTrace();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }

        public void keyTyped(KeyEvent e) {
        // System.out.println(e.getKeyChar());
        }
    });
    doc.addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
        }

        public void removeUpdate(DocumentEvent e) {
        }
    });
    txtDebug.addCaretListener(new CaretListener() {

        public void caretUpdate(CaretEvent e) {
            if (execOffset > caret.getMark() || execOffset > caret.getDot()) {
                caret.setDot(execOffset);
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) CaretEvent(javax.swing.event.CaretEvent) DocumentListener(javax.swing.event.DocumentListener) CaretListener(javax.swing.event.CaretListener) KeyAdapter(java.awt.event.KeyAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent) BadLocationException(javax.swing.text.BadLocationException)

Example 12 with DocumentListener

use of javax.swing.event.DocumentListener in project ACS by ACS-Community.

the class ScriptFilter method getFilterComponentTextField.

/**
	 * This method initializes filterComponentTextField
	 * @return javax.swing.JTextField
	 */
private JTextField getFilterComponentTextField() {
    if (filterComponentTextField == null) {
        Dimension d = new Dimension(100, 19);
        filterComponentTextField = new JTextField();
        filterComponentTextField.setPreferredSize(d);
        filterComponentTextField.setToolTipText("Write a word to find a particular component.");
        //filterComponentTextField.setSize(d);
        filterComponentTextField.setMinimumSize(d);
        filterComponentTextField.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        filterComponentTextField.setHorizontalAlignment(JTextField.LEFT);
        filterComponentTextField.getDocument().addDocumentListener(new DocumentListener() {

            public void applyFilter() {
                int total = compList.length;
                String text = filterComponentTextField.getText();
                if (!filterComponentTextField.getText().isEmpty()) {
                    ComponentComboBox.removeAllItems();
                    for (int i = 0; i < total; i++) {
                        if (compList[i].contains(text)) {
                            ComponentComboBox.addItem(compList[i]);
                        }
                    }
                    ComponentComboBox.hidePopup();
                    ComponentComboBox.showPopup();
                } else {
                    ComponentComboBox.hidePopup();
                    ComponentComboBox.removeAllItems();
                    for (int j = 0; j < total; j++) {
                        ComponentComboBox.addItem(compList[j]);
                    }
                }
                if (ComponentComboBox.getItemCount() == 0) {
                    PropertyComboBox.removeAllItems();
                }
            }

            public void changedUpdate(DocumentEvent e) {
            }

            public void insertUpdate(DocumentEvent e) {
                applyFilter();
            }

            public void removeUpdate(DocumentEvent e) {
                applyFilter();
            }
        });
    }
    return filterComponentTextField;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent)

Example 13 with DocumentListener

use of javax.swing.event.DocumentListener in project ACS by ACS-Community.

the class ScriptFilter method getFilterPropertyTextField.

/**
	 * This method initializes filterPropertyTextField
	 * @return javax.swing.JTextField
	 */
private JTextField getFilterPropertyTextField() {
    if (filterPropertyTextField == null) {
        Dimension d = new Dimension(100, 19);
        filterPropertyTextField = new JTextField();
        filterPropertyTextField.setPreferredSize(d);
        filterPropertyTextField.setToolTipText("Write a word to find a particular property.");
        //filterPropertyTextField.setSize(d);
        filterPropertyTextField.setMinimumSize(d);
        filterPropertyTextField.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        filterPropertyTextField.setHorizontalAlignment(JTextField.LEFT);
        filterPropertyTextField.getDocument().addDocumentListener(new DocumentListener() {

            public void applyFilter() {
                String item = (String) ComponentComboBox.getSelectedItem();
                int i = -1;
                for (int j = 0; j < compList.length; j++) {
                    if (compList[j].compareTo(item) == 0) {
                        i = j;
                        break;
                    }
                }
                if (i == -1) {
                    PropertyComboBox.removeAll();
                    return;
                }
                int total = propList.get(i).size();
                String text = filterPropertyTextField.getText();
                PropertyComboBox.removeAllItems();
                for (int j = 0; j < total; j++) {
                    PropertyComboBox.addItem(propList.get(i).get(j).toString());
                }
                PropertyComboBox.showPopup();
                if (!filterPropertyTextField.getText().isEmpty()) {
                    PropertyComboBox.removeAllItems();
                    for (int j = 0; j < total; j++) {
                        if (propList.get(i).get(j).toString().contains(text)) {
                            PropertyComboBox.addItem(propList.get(i).get(j).toString());
                        }
                    }
                } else {
                    PropertyComboBox.hidePopup();
                }
            }

            public void changedUpdate(DocumentEvent e) {
            }

            public void insertUpdate(DocumentEvent e) {
                applyFilter();
            }

            public void removeUpdate(DocumentEvent e) {
                applyFilter();
            }
        });
    }
    return filterPropertyTextField;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent)

Example 14 with DocumentListener

use of javax.swing.event.DocumentListener in project intellij-community by JetBrains.

the class ArrayRendererConfigurable method createComponent.

public JComponent createComponent() {
    myPanel = new JPanel(new GridBagLayout());
    myStartIndex = new JTextField(5);
    myEndIndex = new JTextField(5);
    myEntriesLimit = new JTextField(5);
    final FontMetrics fontMetrics = myStartIndex.getFontMetrics(myStartIndex.getFont());
    final Dimension minSize = new Dimension(myStartIndex.getPreferredSize());
    //noinspection HardCodedStringLiteral
    minSize.width = fontMetrics.stringWidth("AAAAA");
    myStartIndex.setMinimumSize(minSize);
    myEndIndex.setMinimumSize(minSize);
    myEntriesLimit.setMinimumSize(minSize);
    JLabel startIndexLabel = new JLabel(DebuggerBundle.message("label.array.renderer.configurable.start.index"));
    startIndexLabel.setLabelFor(myStartIndex);
    JLabel endIndexLabel = new JLabel(DebuggerBundle.message("label.array.renderer.configurable.end.index"));
    endIndexLabel.setLabelFor(myEndIndex);
    JLabel entriesLimitLabel = new JLabel(DebuggerBundle.message("label.array.renderer.configurable.max.count1"));
    entriesLimitLabel.setLabelFor(myEntriesLimit);
    myPanel.add(startIndexLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insetsRight(8), 0, 0));
    myPanel.add(myStartIndex, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insetsRight(8), 0, 0));
    myPanel.add(endIndexLabel, new GridBagConstraints(2, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insetsRight(8), 0, 0));
    myPanel.add(myEndIndex, new GridBagConstraints(3, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    myPanel.add(entriesLimitLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(4, 0, 0, 8), 0, 0));
    myPanel.add(myEntriesLimit, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(4, 0, 0, 8), 0, 0));
    myPanel.add(new JLabel(DebuggerBundle.message("label.array.renderer.configurable.max.count2")), new GridBagConstraints(2, GridBagConstraints.RELATIVE, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insetsTop(4), 0, 0));
    // push other components up
    myPanel.add(new JLabel(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    final DocumentListener listener = new DocumentListener() {

        private void updateEntriesLimit() {
            final boolean state = myIndexUpdateEnabled;
            myIndexUpdateEnabled = false;
            try {
                if (myEntriesLimitUpdateEnabled) {
                    myEntriesLimit.setText(String.valueOf(getInt(myEndIndex) - getInt(myStartIndex) + 1));
                }
            } finally {
                myIndexUpdateEnabled = state;
            }
        }

        public void changedUpdate(DocumentEvent e) {
            updateEntriesLimit();
        }

        public void insertUpdate(DocumentEvent e) {
            updateEntriesLimit();
        }

        public void removeUpdate(DocumentEvent e) {
            updateEntriesLimit();
        }
    };
    myStartIndex.getDocument().addDocumentListener(listener);
    myEndIndex.getDocument().addDocumentListener(listener);
    myEntriesLimit.getDocument().addDocumentListener(new DocumentListener() {

        private void updateEndIndex() {
            final boolean state = myEntriesLimitUpdateEnabled;
            myEntriesLimitUpdateEnabled = false;
            try {
                if (myIndexUpdateEnabled) {
                    myEndIndex.setText(String.valueOf(getInt(myEntriesLimit) + getInt(myStartIndex) - 1));
                }
            } finally {
                myEntriesLimitUpdateEnabled = state;
            }
        }

        public void insertUpdate(DocumentEvent e) {
            updateEndIndex();
        }

        public void removeUpdate(DocumentEvent e) {
            updateEndIndex();
        }

        public void changedUpdate(DocumentEvent e) {
            updateEndIndex();
        }
    });
    return myPanel;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) DocumentEvent(javax.swing.event.DocumentEvent)

Example 15 with DocumentListener

use of javax.swing.event.DocumentListener in project zaproxy by zaproxy.

the class DialogAddUser method getNameTextField.

protected ZapTextField getNameTextField() {
    if (nameTextField == null) {
        nameTextField = new ZapTextField(25);
        nameTextField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void removeUpdate(DocumentEvent e) {
                checkValidAndEnableConfirmButton();
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                checkValidAndEnableConfirmButton();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                checkValidAndEnableConfirmButton();
            }
        });
    }
    return nameTextField;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) ZapTextField(org.zaproxy.zap.utils.ZapTextField) 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