Search in sources :

Example 46 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class DuplicateStringLiteralInspection method createOptionsPanel.

@Override
public JComponent createOptionsPanel() {
    final OptionsPanel optionsPanel = new OptionsPanel();
    optionsPanel.myIgnorePropertyKeyExpressions.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            IGNORE_PROPERTY_KEYS = optionsPanel.myIgnorePropertyKeyExpressions.isSelected();
        }
    });
    optionsPanel.myMinStringLengthField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(final DocumentEvent e) {
            try {
                MIN_STRING_LENGTH = Integer.parseInt(optionsPanel.myMinStringLengthField.getText());
            } catch (NumberFormatException ignored) {
            }
        }
    });
    optionsPanel.myIgnorePropertyKeyExpressions.setSelected(IGNORE_PROPERTY_KEYS);
    optionsPanel.myMinStringLengthField.setText(Integer.toString(MIN_STRING_LENGTH));
    return optionsPanel.myPanel;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 47 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class GitRebaseDialog method setupBranches.

/**
   * Setup branch drop down.
   */
private void setupBranches() {
    GitUIUtil.getTextField(myOntoComboBox).getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            validateFields();
        }
    });
    final ActionListener rootListener = new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            loadRefs();
            updateBranches();
        }
    };
    final ActionListener showListener = new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            updateOntoFrom();
        }
    };
    myShowRemoteBranchesCheckBox.addActionListener(showListener);
    myShowTagsCheckBox.addActionListener(showListener);
    rootListener.actionPerformed(null);
    myGitRootComboBox.addActionListener(rootListener);
    myBranchComboBox.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            updateTrackedBranch();
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 48 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class ScopePanel method initComponent.

public void initComponent(@Nullable Module currentModule, final SearchScope scope) {
    final ItemListener stateListener = new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            myModuleSelection.setEnabled(myModuleScope.isSelected());
            myDirectory.setEnabled(myDirectoryScope.isSelected());
            myRecursive.setEnabled(myDirectoryScope.isSelected());
            myCustomScopeSelection.setEnabled(myCustomScope.isSelected());
            if (e.getStateChange() == ItemEvent.SELECTED) {
                firePropertyChange("scope", null, getSelectedScope());
            }
        }
    };
    final ItemListener scopeListener = new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                firePropertyChange("scope", null, getSelectedScope());
            }
        }
    };
    myWholeProjectScope.addItemListener(stateListener);
    myWholeProjectScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.PROJECT);
    myModuleScope.addItemListener(stateListener);
    myModuleScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.MODULE);
    myDirectoryScope.addItemListener(stateListener);
    myDirectoryScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.DIRECTORY);
    myCustomScope.addItemListener(stateListener);
    myCustomScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.CUSTOM);
    myModuleSelection.fillModules(myProject);
    Module m;
    if (scope.getModuleName() != null) {
        if ((m = ModuleManager.getInstance(myProject).findModuleByName(scope.getModuleName())) == null) {
            m = currentModule;
        }
    } else {
        m = currentModule;
    }
    if (m != null) {
        myModuleSelection.setSelectedModule(m);
    }
    myModuleSelection.addItemListener(scopeListener);
    ((ScopeChooserCombo) myCustomScopeSelection).init(myProject, true, true, scope.getScopeName());
    myCustomScopeSelection.getComboBox().addItemListener(scopeListener);
    myDirectory.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(DocumentEvent e) {
            firePropertyChange("scope", null, getSelectedScope());
        }
    });
    myDirectory.setText(scope.getPath());
    myDirectory.addBrowseFolderListener("Select Path", "Select Path", myProject, FileChooserDescriptorFactory.createSingleFolderDescriptor());
    myRecursive.setSelected(scope.isRecursive());
}
Also used : ItemEvent(java.awt.event.ItemEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) ItemListener(java.awt.event.ItemListener) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) Module(com.intellij.openapi.module.Module) DocumentEvent(javax.swing.event.DocumentEvent)

Example 49 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class I18nInspection method createOptionsPanel.

@Override
public JComponent createOptionsPanel() {
    final GridBagLayout layout = new GridBagLayout();
    final JPanel panel = new JPanel(layout);
    final JCheckBox assertStatementsCheckbox = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.assert"), ignoreForAssertStatements);
    assertStatementsCheckbox.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreForAssertStatements = assertStatementsCheckbox.isSelected();
        }
    });
    final JCheckBox exceptionConstructorCheck = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.for.exception.constructor.arguments"), ignoreForExceptionConstructors);
    exceptionConstructorCheck.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreForExceptionConstructors = exceptionConstructorCheck.isSelected();
        }
    });
    final JTextField specifiedExceptions = new JTextField(ignoreForSpecifiedExceptionConstructors);
    specifiedExceptions.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            ignoreForSpecifiedExceptionConstructors = specifiedExceptions.getText();
        }
    });
    final JCheckBox junitAssertCheckbox = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.for.junit.assert.arguments"), ignoreForJUnitAsserts);
    junitAssertCheckbox.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreForJUnitAsserts = junitAssertCheckbox.isSelected();
        }
    });
    final JCheckBox classRef = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.qualified.class.names"), ignoreForClassReferences);
    classRef.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreForClassReferences = classRef.isSelected();
        }
    });
    final JCheckBox propertyRef = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.property.keys"), ignoreForPropertyKeyReferences);
    propertyRef.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreForPropertyKeyReferences = propertyRef.isSelected();
        }
    });
    final JCheckBox nonAlpha = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.nonalphanumerics"), ignoreForNonAlpha);
    nonAlpha.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreForNonAlpha = nonAlpha.isSelected();
        }
    });
    final JCheckBox assignedToConstants = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.assigned.to.constants"), ignoreAssignedToConstants);
    assignedToConstants.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreAssignedToConstants = assignedToConstants.isSelected();
        }
    });
    final JCheckBox chkToString = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.tostring"), ignoreToString);
    chkToString.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreToString = chkToString.isSelected();
        }
    });
    final JCheckBox ignoreEnumConstants = new JCheckBox("Ignore enum constants", ignoreForEnumConstants);
    ignoreEnumConstants.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(@NotNull ChangeEvent e) {
            ignoreForEnumConstants = ignoreEnumConstants.isSelected();
        }
    });
    final GridBagConstraints gc = new GridBagConstraints();
    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.insets.bottom = 2;
    gc.gridx = GridBagConstraints.REMAINDER;
    gc.gridy = 0;
    gc.weightx = 1;
    gc.weighty = 0;
    panel.add(assertStatementsCheckbox, gc);
    gc.gridy++;
    panel.add(junitAssertCheckbox, gc);
    gc.gridy++;
    panel.add(exceptionConstructorCheck, gc);
    gc.gridy++;
    final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    panel.add(new FieldPanel(specifiedExceptions, null, CodeInsightBundle.message("inspection.i18n.option.ignore.for.specified.exception.constructor.arguments"), openProjects.length == 0 ? null : new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            createIgnoreExceptionsConfigurationDialog(openProjects[0], specifiedExceptions).show();
        }
    }, null), gc);
    gc.gridy++;
    panel.add(classRef, gc);
    gc.gridy++;
    panel.add(propertyRef, gc);
    gc.gridy++;
    panel.add(assignedToConstants, gc);
    gc.gridy++;
    panel.add(chkToString, gc);
    gc.gridy++;
    panel.add(nonAlpha, gc);
    gc.gridy++;
    panel.add(ignoreEnumConstants, gc);
    gc.gridy++;
    gc.anchor = GridBagConstraints.NORTHWEST;
    gc.weighty = 1;
    final JTextField text = new JTextField(nonNlsCommentPattern);
    final FieldPanel nonNlsCommentPatternComponent = new FieldPanel(text, CodeInsightBundle.message("inspection.i18n.option.ignore.comment.pattern"), CodeInsightBundle.message("inspection.i18n.option.ignore.comment.title"), null, () -> {
        nonNlsCommentPattern = text.getText();
        cacheNonNlsCommentPattern();
    });
    panel.add(nonNlsCommentPatternComponent, gc);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(panel);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setBorder(null);
    scrollPane.setPreferredSize(new Dimension(panel.getPreferredSize().width + scrollPane.getVerticalScrollBar().getPreferredSize().width, panel.getPreferredSize().height + scrollPane.getHorizontalScrollBar().getPreferredSize().height));
    return scrollPane;
}
Also used : ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) Project(com.intellij.openapi.project.Project) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ChangeListener(javax.swing.event.ChangeListener) FieldPanel(com.intellij.ui.FieldPanel)

Example 50 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class GotoLineNumberDialog method createNorthPanel.

protected JComponent createNorthPanel() {
    class MyTextField extends JTextField {

        public MyTextField() {
            super("");
        }

        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            return new Dimension(200, d.height);
        }
    }
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.insets = JBUI.insets(4, 0, 8, 8);
    gbConstraints.fill = GridBagConstraints.VERTICAL;
    gbConstraints.weightx = 0;
    gbConstraints.weighty = 1;
    gbConstraints.anchor = GridBagConstraints.EAST;
    JLabel label = new JLabel("[Line] [:column]:");
    panel.add(label, gbConstraints);
    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.weightx = 1;
    myField = new MyTextField();
    panel.add(myField, gbConstraints);
    myField.setText(String.format("%d:%d", getLine() + 1, getColumn() + 1));
    if (isInternal()) {
        gbConstraints.gridy = 1;
        gbConstraints.weightx = 0;
        gbConstraints.weighty = 1;
        gbConstraints.anchor = GridBagConstraints.EAST;
        final JLabel offsetLabel = new JLabel("Offset:");
        panel.add(offsetLabel, gbConstraints);
        gbConstraints.fill = GridBagConstraints.BOTH;
        gbConstraints.weightx = 1;
        myOffsetField = new MyTextField();
        panel.add(myOffsetField, gbConstraints);
        myOffsetField.setText(String.valueOf(getOffset()));
        DocumentAdapter valueSync = new DocumentAdapter() {

            boolean inSync;

            @Override
            protected void textChanged(DocumentEvent e) {
                if (inSync)
                    return;
                inSync = true;
                String s = "<invalid>";
                JTextField f = null;
                try {
                    if (e.getDocument() == myField.getDocument()) {
                        f = myOffsetField;
                        Coordinates p = getCoordinates();
                        s = p == null ? s : String.valueOf(coordinatesToOffset(p));
                    } else {
                        f = myField;
                        int offset = StringUtil.parseInt(myOffsetField.getText(), -1);
                        Coordinates p = offset >= 0 ? offsetToCoordinates(Math.min(getMaxOffset() - 1, offset)) : null;
                        s = p == null ? s : String.format("%d:%d", p.row + 1, p.column + 1);
                    }
                    f.setText(s);
                } catch (IndexOutOfBoundsException ignored) {
                    if (f != null)
                        f.setText(s);
                } finally {
                    inSync = false;
                }
            }
        };
        myField.getDocument().addDocumentListener(valueSync);
        myOffsetField.getDocument().addDocumentListener(valueSync);
    }
    return panel;
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Aggregations

DocumentAdapter (com.intellij.ui.DocumentAdapter)64 DocumentEvent (javax.swing.event.DocumentEvent)64 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)15 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)10 ItemEvent (java.awt.event.ItemEvent)7 ItemListener (java.awt.event.ItemListener)7 Document (javax.swing.text.Document)7 JTextComponent (javax.swing.text.JTextComponent)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FieldPanel (com.intellij.ui.FieldPanel)4 JBTextField (com.intellij.ui.components.JBTextField)4 ChangeEvent (javax.swing.event.ChangeEvent)4 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 VariantsCompletionAction (com.intellij.find.editorHeaderActions.VariantsCompletionAction)2 MemberChooser (com.intellij.ide.util.MemberChooser)2 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2