Search in sources :

Example 11 with DocumentEvent

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

the class EncodeDecodeDialog method getInputField.

private ZapTextArea getInputField() {
    if (inputField == null) {
        inputField = newField(true);
        inputField.setName(ENCODE_DECODE_FIELD);
        inputField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent documentEvent) {
                updateEncodeDecodeFields();
            }

            @Override
            public void removeUpdate(DocumentEvent documentEvent) {
                updateEncodeDecodeFields();
            }

            @Override
            public void changedUpdate(DocumentEvent documentEvent) {
            }
        });
        inputField.addMouseListener(new java.awt.event.MouseAdapter() {

            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });
    }
    return inputField;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) DocumentEvent(javax.swing.event.DocumentEvent)

Example 12 with DocumentEvent

use of javax.swing.event.DocumentEvent in project azure-tools-for-java by Microsoft.

the class SparkSubmissionContentPanel method addSelectedArtifactLineItem.

private void addSelectedArtifactLineItem() {
    final String tipInfo = "The Artifact you want to use.";
    JLabel artifactSelectLabel = new JLabel("Select an Artifact to submit");
    artifactSelectLabel.setToolTipText(tipInfo);
    selectedArtifactComboBox = new ComboBox();
    selectedArtifactComboBox.setToolTipText(tipInfo);
    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()] = new JLabel("Artifact should not be null!");
    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()].setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()].setVisible(false);
    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()] = new JLabel("Could not find the local jar package for Artifact");
    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()].setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()].setVisible(false);
    selectedArtifactTextField = new TextFieldWithBrowseButton();
    selectedArtifactTextField.setToolTipText("Artifact from local jar package.");
    selectedArtifactTextField.setEditable(true);
    selectedArtifactTextField.setEnabled(false);
    selectedArtifactTextField.getTextField().getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }
    });
    selectedArtifactTextField.getButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true, false);
            chooserDescriptor.setTitle("Select Local Artifact File");
            VirtualFile chooseFile = FileChooser.chooseFile(chooserDescriptor, null, null);
            if (chooseFile != null) {
                String path = chooseFile.getPath();
                if (path.endsWith("!/")) {
                    path = path.substring(0, path.length() - 2);
                }
                selectedArtifactTextField.setText(path);
            }
        }
    });
    intelliJArtifactRadioButton = new JRadioButton("Artifact from IntelliJ project:", true);
    localArtifactRadioButton = new JRadioButton("Artifact from local disk:", false);
    intelliJArtifactRadioButton.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectedArtifactComboBox.setEnabled(true);
                selectedArtifactTextField.setEnabled(false);
                mainClassTextField.setButtonEnabled(true);
                setVisibleForFixedErrorMessageLabel(2, false);
                if (selectedArtifactComboBox.getItemCount() == 0) {
                    setVisibleForFixedErrorMessageLabel(2, true);
                }
            }
        }
    });
    localArtifactRadioButton.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectedArtifactComboBox.setEnabled(false);
                selectedArtifactTextField.setEnabled(true);
                mainClassTextField.setButtonEnabled(false);
                setVisibleForFixedErrorMessageLabel(1, false);
                if (StringHelper.isNullOrWhiteSpace(selectedArtifactTextField.getText())) {
                    setVisibleForFixedErrorMessageLabel(2, true);
                }
            }
        }
    });
    ButtonGroup group = new ButtonGroup();
    group.add(intelliJArtifactRadioButton);
    group.add(localArtifactRadioButton);
    intelliJArtifactRadioButton.setSelected(true);
    add(artifactSelectLabel, new GridBagConstraints(0, ++displayLayoutCurrentRow, 0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin, margin, 0, margin), 0, 0));
    add(intelliJArtifactRadioButton, new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0));
    add(selectedArtifactComboBox, new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0));
    add(errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()], new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));
    add(localArtifactRadioButton, new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0));
    add(selectedArtifactTextField, new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0));
    add(errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()], new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentListener(javax.swing.event.DocumentListener) ItemEvent(java.awt.event.ItemEvent) ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DocumentEvent(javax.swing.event.DocumentEvent) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener)

Example 13 with DocumentEvent

use of javax.swing.event.DocumentEvent 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 14 with DocumentEvent

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

the class HgBookmarkDialog method createCenterPanel.

@Override
@NotNull
protected JComponent createCenterPanel() {
    JPanel contentPanel = new JPanel(new GridBagLayout());
    GridBag g = new GridBag().setDefaultInsets(new Insets(0, 0, DEFAULT_VGAP, DEFAULT_HGAP)).setDefaultAnchor(GridBagConstraints.LINE_START).setDefaultFill(GridBagConstraints.HORIZONTAL);
    JLabel icon = new JLabel(UIUtil.getQuestionIcon(), SwingConstants.LEFT);
    myBookmarkName = new JBTextField(13);
    myBookmarkName.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void textChanged(DocumentEvent e) {
            validateFields();
        }
    });
    JBLabel bookmarkLabel = new JBLabel("Bookmark name:");
    bookmarkLabel.setLabelFor(myBookmarkName);
    myActiveCheckbox = new JBCheckBox("Inactive", false);
    contentPanel.add(icon, g.nextLine().next().coverColumn(3).pady(DEFAULT_HGAP));
    contentPanel.add(bookmarkLabel, g.next().fillCellNone().insets(new Insets(0, 6, DEFAULT_VGAP, DEFAULT_HGAP)));
    contentPanel.add(myBookmarkName, g.next().coverLine().setDefaultWeightX(1));
    contentPanel.add(myActiveCheckbox, g.nextLine().next().next().coverLine(2));
    return contentPanel;
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) DocumentAdapter(com.intellij.ui.DocumentAdapter) JBTextField(com.intellij.ui.components.JBTextField) GridBag(com.intellij.util.ui.GridBag) DocumentEvent(javax.swing.event.DocumentEvent) JBCheckBox(com.intellij.ui.components.JBCheckBox) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with DocumentEvent

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

the class MavenArtifactSearchPanel method initComponents.

private void initComponents(String initialText) {
    myResultList = new Tree();
    myResultList.setExpandableItemsEnabled(false);
    myResultList.getEmptyText().setText("Loading...");
    myResultList.setRootVisible(false);
    myResultList.setShowsRootHandles(true);
    myResultList.setModel(null);
    MyArtifactCellRenderer renderer = myClassMode ? new MyClassCellRenderer(myResultList) : new MyArtifactCellRenderer(myResultList);
    myResultList.setCellRenderer(renderer);
    myResultList.setRowHeight(renderer.getPreferredSize().height);
    mySearchField = new JTextField(initialText);
    mySearchField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            int d;
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                d = 1;
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
                d = -1;
            } else {
                return;
            }
            int row = myResultList.getSelectionModel().getLeadSelectionRow();
            row += d;
            if (row >= 0 && row < myResultList.getRowCount()) {
                myResultList.setSelectionRow(row);
            }
        }
    });
    setLayout(new BorderLayout());
    add(mySearchField, BorderLayout.NORTH);
    JScrollPane pane = ScrollPaneFactory.createScrollPane(myResultList);
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // Don't remove this line.
    pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    // Without VERTICAL_SCROLLBAR_ALWAYS policy our custom layout
    // works incorrectly, see https://youtrack.jetbrains.com/issue/IDEA-72986
    add(pane, BorderLayout.CENTER);
    mySearchField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            scheduleSearch();
        }
    });
    myResultList.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (!myAlarm.isEmpty())
                return;
            boolean hasSelection = !myResultList.isSelectionEmpty();
            myListener.canSelectStateChanged(MavenArtifactSearchPanel.this, hasSelection);
        }
    });
    myResultList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && myResultList.getLastSelectedPathComponent() != null) {
                myListener.itemSelected();
                e.consume();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            final TreePath path = myResultList.getPathForLocation(e.getX(), e.getY());
            if (path != null && myResultList.isPathSelected(path)) {
                Object sel = path.getLastPathComponent();
                if (sel != null && myResultList.getModel().isLeaf(sel)) {
                    myListener.itemSelected();
                    return true;
                }
            }
            return false;
        }
    }.installOn(myResultList);
}
Also used : MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DocumentEvent(javax.swing.event.DocumentEvent) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

DocumentEvent (javax.swing.event.DocumentEvent)122 DocumentAdapter (com.intellij.ui.DocumentAdapter)64 DocumentListener (javax.swing.event.DocumentListener)53 ActionEvent (java.awt.event.ActionEvent)34 ActionListener (java.awt.event.ActionListener)32 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)13 JPanel (javax.swing.JPanel)12 JTextField (javax.swing.JTextField)12 ItemEvent (java.awt.event.ItemEvent)10 ItemListener (java.awt.event.ItemListener)10 JButton (javax.swing.JButton)10 Document (javax.swing.text.Document)10 NotNull (org.jetbrains.annotations.NotNull)9 JLabel (javax.swing.JLabel)8 ChangeEvent (javax.swing.event.ChangeEvent)8 JCheckBox (javax.swing.JCheckBox)7 JTextComponent (javax.swing.text.JTextComponent)7 ZapTextField (org.zaproxy.zap.utils.ZapTextField)7 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6