Search in sources :

Example 36 with DocumentEvent

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

the class BuildElementsEditor method createOutputPathPanel.

private CommitableFieldPanel createOutputPathPanel(final String title, final CommitPathRunnable commitPathRunnable) {
    final JTextField textField = new JTextField();
    final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    outputPathsChooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, getModel().getModule());
    outputPathsChooserDescriptor.setHideIgnored(false);
    InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
    FileChooserFactory.getInstance().installFileCompletion(textField, outputPathsChooserDescriptor, true, null);
    final Runnable commitRunnable = () -> {
        if (!getModel().isWritable()) {
            return;
        }
        final String path = textField.getText().trim();
        if (path.length() == 0) {
            commitPathRunnable.saveUrl(null);
        } else {
            // should set only absolute paths
            String canonicalPath;
            try {
                canonicalPath = FileUtil.resolveShortWindowsName(path);
            } catch (IOException e) {
                canonicalPath = path;
            }
            commitPathRunnable.saveUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(canonicalPath)));
        }
    };
    final ActionListener listener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            commitRunnable.run();
        }
    };
    myPerModuleCompilerOutput.addActionListener(listener);
    textField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            commitRunnable.run();
        }
    });
    return new CommitableFieldPanel(textField, null, null, new BrowseFilesListener(textField, title, "", outputPathsChooserDescriptor) {

        @Override
        public void actionPerformed(ActionEvent e) {
            super.actionPerformed(e);
            commitRunnable.run();
        }
    }, null, commitRunnable);
}
Also used : ActionListener(java.awt.event.ActionListener) BrowseFilesListener(com.intellij.ide.util.BrowseFilesListener) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent)

Example 37 with DocumentEvent

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

the class IdeaJdkConfigurable method createComponent.

public JComponent createComponent() {
    mySandboxHome.setHistorySize(5);
    JPanel wholePanel = new JPanel(new GridBagLayout());
    wholePanel.add(mySandboxHomeLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    wholePanel.add(GuiUtils.constructFieldWithBrowseButton(mySandboxHome, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
            descriptor.setTitle(DevKitBundle.message("sandbox.home"));
            descriptor.setDescription(DevKitBundle.message("sandbox.purpose"));
            VirtualFile file = FileChooser.chooseFile(descriptor, mySandboxHome, null, null);
            if (file != null) {
                mySandboxHome.setText(FileUtil.toSystemDependentName(file.getPath()));
            }
            myModified = true;
        }
    }), new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
    wholePanel.add(myInternalJreLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    wholePanel.add(myInternalJres, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
    myInternalJres.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof Sdk) {
                setText(((Sdk) value).getName());
            }
        }
    });
    myInternalJres.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            if (myFreeze)
                return;
            final Sdk javaJdk = (Sdk) e.getItem();
            for (OrderRootType type : OrderRootType.getAllTypes()) {
                if (!((SdkType) javaJdk.getSdkType()).isRootTypeApplicable(type)) {
                    continue;
                }
                final VirtualFile[] internalRoots = javaJdk.getSdkModificator().getRoots(type);
                final VirtualFile[] configuredRoots = mySdkModificator.getRoots(type);
                for (VirtualFile file : internalRoots) {
                    if (e.getStateChange() == ItemEvent.DESELECTED) {
                        mySdkModificator.removeRoot(file, type);
                    } else {
                        if (ArrayUtil.find(configuredRoots, file) == -1) {
                            mySdkModificator.addRoot(file, type);
                        }
                    }
                }
            }
        }
    });
    mySandboxHome.addDocumentListener(new DocumentAdapter() {

        protected void textChanged(DocumentEvent e) {
            myModified = true;
        }
    });
    mySandboxHome.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            myModified = true;
        }
    });
    mySandboxHome.setText("");
    myModified = true;
    return wholePanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener) OrderRootType(com.intellij.openapi.roots.OrderRootType) ItemListener(java.awt.event.ItemListener)

Example 38 with DocumentEvent

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

the class IdeaGradleProjectSettingsControlBuilder method addGradleHomeComponents.

@Override
public IdeaGradleProjectSettingsControlBuilder addGradleHomeComponents(PaintAwarePanel content, int indentLevel) {
    if (dropGradleHomePathComponents)
        return this;
    myGradleHomeLabel = new JBLabel(GradleBundle.message("gradle.settings.text.home.path"));
    myGradleHomePathField = new TextFieldWithBrowseButton();
    myGradleHomePathField.addBrowseFolderListener("", GradleBundle.message("gradle.settings.text.home.path"), null, GradleUtil.getGradleHomeFileChooserDescriptor(), TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
    myGradleHomePathField.getTextField().getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            myGradleHomePathField.getTextField().setForeground(LocationSettingType.EXPLICIT_CORRECT.getColor());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            myGradleHomePathField.getTextField().setForeground(LocationSettingType.EXPLICIT_CORRECT.getColor());
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    content.add(myGradleHomeLabel, ExternalSystemUiUtil.getLabelConstraints(indentLevel));
    content.add(myGradleHomePathField, ExternalSystemUiUtil.getFillLineConstraints(0));
    return this;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) JBLabel(com.intellij.ui.components.JBLabel) DocumentEvent(javax.swing.event.DocumentEvent)

Example 39 with DocumentEvent

use of javax.swing.event.DocumentEvent in project ChatGameFontificator by GlitchCog.

the class ControlPanelChat method build.

@Override
protected void build() {
    resizableBox = new JCheckBox("Resize Chat by Dragging");
    scrollableBox = new JCheckBox("Mouse Wheel Scrolls Chat");
    reverseScrollBox = new JCheckBox("Reverse Chat Order");
    chatFromBottomBox = new JCheckBox("Chat Starts from Bottom");
    widthInput = new LabeledInput("Width", 3);
    heightInput = new LabeledInput("Height", 3);
    DocumentListener chatSizeDocListener = new DocumentListener() {

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

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            somethingChanged(e);
        }

        /**
             * Something changed, so try to get the new width and height and set the updateSizeButton to enabled or
             * disabled accordingly
             * 
             * @param e
             */
        private void somethingChanged(DocumentEvent e) {
            try {
                int w = Integer.parseInt(widthInput.getText());
                int h = Integer.parseInt(heightInput.getText());
                updateSizeButton.setEnabled(w != config.getWidth() || h != config.getHeight());
            } catch (Exception ex) {
                updateSizeButton.setEnabled(false);
            }
        }
    };
    DocumentListener chromaDocListener = new DocumentListener() {

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

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            toggleChromaButtonEnabled();
        }
    };
    widthInput.addDocumentListener(chatSizeDocListener);
    heightInput.addDocumentListener(chatSizeDocListener);
    updateSizeButton = new JButton("Update Chat Size");
    chromaEnabledBox = new JCheckBox("Enable Chroma Key Border");
    chromaInvertBox = new JCheckBox("Invert Chroma Key Border");
    chromaCornerSlider = new LabeledSlider("Corner Radius", "pixels", ConfigChat.MIN_CHROMA_CORNER_RADIUS, ConfigChat.MAX_CHROMA_CORNER_RADIUS);
    final String[] chromaLabels = new String[] { "Left", "Top", "Right", "Bottom" };
    chromaBorderInput = new LabeledInput[chromaLabels.length];
    for (int i = 0; i < chromaBorderInput.length; i++) {
        chromaBorderInput[i] = new LabeledInput(chromaLabels[i], 4);
        chromaBorderInput[i].addDocumentListener(chromaDocListener);
    }
    updateChromaSizeButton = new JButton("Update Chroma Border");
    ActionListener boxListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox source = (JCheckBox) e.getSource();
            if (resizableBox.equals(source)) {
                chatWindow.setResizable(resizableBox.isSelected());
                config.setResizable(resizableBox.isSelected());
            } else if (scrollableBox.equals(source)) {
                config.setScrollable(scrollableBox.isSelected());
                if (!scrollableBox.isSelected()) {
                    // No scrolling, so reset any existing scroll offset
                    chat.resetScrollOffset();
                }
            } else if (reverseScrollBox.equals(source)) {
                config.setReverseScrolling(reverseScrollBox.isSelected());
            } else if (chatFromBottomBox.equals(source)) {
                // Reset scrolling to avoid having to translate it between chat-start top/bottom styles
                chat.resetScrollOffset();
                config.setChatFromBottom(chatFromBottomBox.isSelected());
            } else if (chromaEnabledBox.equals(source)) {
                config.setChromaEnabled(chromaEnabledBox.isSelected());
                toggleChromaInputFields();
            } else if (chromaInvertBox.equals(source)) {
                config.setChromaInvert(chromaInvertBox.isSelected());
            }
            chat.repaint();
        }
    };
    resizableBox.addActionListener(boxListener);
    scrollableBox.addActionListener(boxListener);
    reverseScrollBox.addActionListener(boxListener);
    chatFromBottomBox.addActionListener(boxListener);
    chromaEnabledBox.addActionListener(boxListener);
    chromaInvertBox.addActionListener(boxListener);
    ActionListener dimListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                LoadConfigReport report = new LoadConfigReport();
                config.validateDimStrings(report, widthInput.getText(), heightInput.getText());
                if (report.isErrorFree()) {
                    final int width = Integer.parseInt(widthInput.getText());
                    final int height = Integer.parseInt(heightInput.getText());
                    config.setWidth(width);
                    config.setHeight(height);
                    chatWindow.setSize(config.getWidth(), config.getHeight());
                } else {
                    ChatWindow.popup.handleProblem(report);
                }
            } catch (Exception ex) {
                ChatWindow.popup.handleProblem("Chat Width and Chat Height values could not be parsed", ex);
            }
        }
    };
    updateSizeButton.addActionListener(dimListener);
    ActionListener chromaDimListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                LoadConfigReport report = new LoadConfigReport();
                config.validateChromaDimStrings(report, chromaBorderInput[0].getText(), chromaBorderInput[1].getText(), chromaBorderInput[2].getText(), chromaBorderInput[3].getText());
                if (report.isErrorFree()) {
                    inputToConfigChromaBorders();
                    chat.repaint();
                } else {
                    ChatWindow.popup.handleProblem(report);
                }
            } catch (Exception ex) {
                ChatWindow.popup.handleProblem("Chat Chroma border values could not be parsed", ex);
            }
        }
    };
    updateChromaSizeButton.addActionListener(chromaDimListener);
    chromaCornerSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            config.setChromaCornerRadius(chromaCornerSlider.getValue());
            chat.repaint();
        }
    });
    JPanel chatDimPanel = new JPanel(new GridBagLayout());
    JPanel chatOptionsPanel = new JPanel(new GridBagLayout());
    JPanel chromaDimPanel = new JPanel(new GridBagLayout());
    chatDimPanel.setBorder(new TitledBorder(baseBorder, "Chat Window Size", TitledBorder.CENTER, TitledBorder.TOP));
    chatOptionsPanel.setBorder(new TitledBorder(baseBorder, "Chat Window Options", TitledBorder.CENTER, TitledBorder.TOP));
    chromaDimPanel.setBorder(baseBorder);
    GridBagConstraints dGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, DEFAULT_INSETS, 0, 0);
    dGbc.gridx = 0;
    dGbc.gridy = 0;
    dGbc.gridwidth = 1;
    chatDimPanel.add(widthInput, dGbc);
    dGbc.gridx++;
    chatDimPanel.add(heightInput, dGbc);
    dGbc.gridx = 0;
    dGbc.gridy++;
    dGbc.gridwidth = 2;
    chatDimPanel.add(updateSizeButton, dGbc);
    dGbc.gridy++;
    chatDimPanel.add(resizableBox, dGbc);
    dGbc.gridy++;
    GridBagConstraints coGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, DEFAULT_INSETS, 0, 0);
    coGbc.anchor = GridBagConstraints.WEST;
    chatOptionsPanel.add(scrollableBox, coGbc);
    coGbc.gridy++;
    chatOptionsPanel.add(reverseScrollBox, coGbc);
    coGbc.gridy++;
    chatOptionsPanel.add(chatFromBottomBox, coGbc);
    coGbc.gridy++;
    GridBagConstraints chromaGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, NO_INSETS, 0, 0);
    chromaGbc.gridwidth = 3;
    chromaDimPanel.add(chromaEnabledBox, chromaGbc);
    chromaGbc.gridy++;
    chromaDimPanel.add(chromaBorderInput[1], chromaGbc);
    chromaGbc.gridy++;
    chromaGbc.gridwidth = 1;
    chromaGbc.anchor = GridBagConstraints.EAST;
    chromaDimPanel.add(chromaBorderInput[0], chromaGbc);
    chromaGbc.gridx++;
    chromaGbc.anchor = GridBagConstraints.CENTER;
    chromaDimPanel.add(updateChromaSizeButton, chromaGbc);
    chromaGbc.gridx++;
    chromaGbc.anchor = GridBagConstraints.WEST;
    chromaDimPanel.add(chromaBorderInput[2], chromaGbc);
    chromaGbc.gridx = 0;
    chromaGbc.anchor = GridBagConstraints.CENTER;
    chromaGbc.gridy++;
    chromaGbc.gridwidth = 3;
    chromaDimPanel.add(chromaBorderInput[3], chromaGbc);
    chromaGbc.gridy++;
    chromaDimPanel.add(chromaInvertBox, chromaGbc);
    chromaGbc.gridy++;
    chromaDimPanel.add(chromaCornerSlider, chromaGbc);
    JPanel everything = new JPanel(new GridBagLayout());
    GridBagConstraints eGbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, NO_INSETS, 0, 0);
    eGbc.weighty = 0.5;
    eGbc.weightx = 0.5;
    eGbc.fill = GridBagConstraints.HORIZONTAL;
    eGbc.insets = new Insets(0, 3, 0, 3);
    everything.add(chatDimPanel, eGbc);
    eGbc.weightx = 0.5;
    eGbc.gridx++;
    everything.add(chatOptionsPanel, eGbc);
    eGbc.weightx = 1.0;
    eGbc.weighty = 0.0;
    eGbc.gridx = 0;
    eGbc.gridy++;
    eGbc.gridwidth = 2;
    eGbc.fill = GridBagConstraints.BOTH;
    eGbc.anchor = GridBagConstraints.CENTER;
    everything.add(chromaDimPanel, eGbc);
    eGbc.gridy++;
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    add(everything, gbc);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) LabeledInput(com.glitchcog.fontificator.gui.component.LabeledInput) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) DocumentEvent(javax.swing.event.DocumentEvent) TitledBorder(javax.swing.border.TitledBorder) LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport) JCheckBox(javax.swing.JCheckBox) LabeledSlider(com.glitchcog.fontificator.gui.component.LabeledSlider) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 40 with DocumentEvent

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

the class EditLogPatternDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myFilePattern.addBrowseFolderListener(UIBundle.message("file.chooser.default.title"), null, null, FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(), TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
    myFilePattern.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            setOKActionEnabled(myFilePattern.getText() != null && myFilePattern.getText().length() > 0);
        }
    });
    return myWholePanel;
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) 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