Search in sources :

Example 26 with ItemListener

use of java.awt.event.ItemListener 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 27 with ItemListener

use of java.awt.event.ItemListener in project intellij-community by JetBrains.

the class ParameterNameHintsConfigurable method initLanguageCombo.

private void initLanguageCombo(Language selected, List<Language> languages) {
    ListComboBoxModel<Language> model = new ListComboBoxModel<>(languages);
    myCurrentLanguageCombo = new ComboBox<>(model);
    myCurrentLanguageCombo.setSelectedItem(selected);
    myCurrentLanguageCombo.setRenderer(new ListCellRendererWrapper<Language>() {

        @Override
        public void customize(JList list, Language value, int index, boolean selected, boolean hasFocus) {
            setText(value.getDisplayName());
        }
    });
    myCurrentLanguageCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            Language language = (Language) e.getItem();
            if (e.getStateChange() == ItemEvent.SELECTED) {
                showLanguagePanel(language);
            }
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) Language(com.intellij.lang.Language) ListComboBoxModel(org.jdesktop.swingx.combobox.ListComboBoxModel) ItemListener(java.awt.event.ItemListener)

Example 28 with ItemListener

use of java.awt.event.ItemListener in project intellij-community by JetBrains.

the class PullUpDialogBase method createNorthPanel.

protected JComponent createNorthPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.insets = new Insets(4, 0, 4, 8);
    gbConstraints.weighty = 1;
    gbConstraints.weightx = 1;
    gbConstraints.gridy = 0;
    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.anchor = GridBagConstraints.WEST;
    final JLabel classComboLabel = new JLabel();
    panel.add(classComboLabel, gbConstraints);
    myClassCombo = new JComboBox(mySuperClasses.toArray());
    initClassCombo(myClassCombo);
    classComboLabel.setText(RefactoringBundle.message("pull.up.members.to", UsageViewUtil.getLongName(myClass)));
    classComboLabel.setLabelFor(myClassCombo);
    final Class preselection = getPreselection();
    int indexToSelect = 0;
    if (preselection != null) {
        indexToSelect = mySuperClasses.indexOf(preselection);
    }
    myClassCombo.setSelectedIndex(indexToSelect);
    myClassCombo.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                updateMemberInfo();
            }
        }
    });
    gbConstraints.gridy++;
    panel.add(myClassCombo, gbConstraints);
    return panel;
}
Also used : ItemEvent(java.awt.event.ItemEvent) ItemListener(java.awt.event.ItemListener)

Example 29 with ItemListener

use of java.awt.event.ItemListener in project intellij-community by JetBrains.

the class ExtractSuperBaseDialog method createActionComponent.

protected JComponent createActionComponent() {
    Box box = Box.createHorizontalBox();
    final String s = StringUtil.decapitalize(getEntityName());
    myRbExtractSuperclass = new JRadioButton();
    myRbExtractSuperclass.setText(RefactoringBundle.message("extractSuper.extract", s));
    myRbExtractSubclass = new JRadioButton();
    myRbExtractSubclass.setText(RefactoringBundle.message("extractSuper.rename.original.class", s));
    myRbExtractSubclass.setEnabled(isPossibleToRenameOriginal());
    box.add(myRbExtractSuperclass);
    box.add(myRbExtractSubclass);
    box.add(Box.createHorizontalGlue());
    final ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(myRbExtractSuperclass);
    buttonGroup.add(myRbExtractSubclass);
    customizeRadiobuttons(box, buttonGroup);
    myRbExtractSuperclass.setSelected(true);
    ItemListener listener = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            updateDialog();
        }
    };
    myRbExtractSuperclass.addItemListener(listener);
    myRbExtractSubclass.addItemListener(listener);
    return box;
}
Also used : ItemEvent(java.awt.event.ItemEvent) ItemListener(java.awt.event.ItemListener)

Example 30 with ItemListener

use of java.awt.event.ItemListener in project intellij-community by JetBrains.

the class SourcePathsStep method createComponentForEmptyRootCase.

private JComponent createComponentForEmptyRootCase() {
    final JPanel panel = new JPanel(new GridBagLayout());
    final String text = IdeBundle.message("prompt.please.specify.java.sources.directory");
    final JLabel label = new JLabel(text);
    label.setUI(new MultiLineLabelUI());
    panel.add(label, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(8, 10, 0, 10), 0, 0));
    myRbCreateSource = new JRadioButton(IdeBundle.message("radio.create.source.directory"), true);
    panel.add(myRbCreateSource, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(8, 10, 0, 10), 0, 0));
    myTfSourceDirectoryName = new JTextField(suggestSourceDirectoryName());
    final JLabel srcPathLabel = new JLabel(IdeBundle.message("prompt.enter.relative.path.to.module.content.root", File.separator));
    panel.add(srcPathLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insets(8, 30, 0, 0), 0, 0));
    final FileChooserDescriptor chooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    chooserDescriptor.withTreeRootVisible(true);
    final FieldPanel fieldPanel = createFieldPanel(myTfSourceDirectoryName, null, new BrowsePathListener(myTfSourceDirectoryName, chooserDescriptor));
    panel.add(fieldPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insets(8, 30, 0, 10), 0, 0));
    myRbNoSource = new JRadioButton(IdeBundle.message("radio.do.not.create.source.directory"), true);
    panel.add(myRbNoSource, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(8, 10, 0, 10), 0, 0));
    final JLabel fullPathLabel = new JLabel(IdeBundle.message("label.source.directory"));
    panel.add(fullPathLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, JBUI.insets(8, 10, 0, 10), 0, 0));
    myTfFullPath = new JTextField();
    myTfFullPath.setEditable(false);
    myTfFullPath.setOpaque(false);
    final Insets borderInsets = myTfFullPath.getBorder().getBorderInsets(myTfFullPath);
    myTfFullPath.setBorder(BorderFactory.createEmptyBorder(borderInsets.top, borderInsets.left, borderInsets.bottom, borderInsets.right));
    panel.add(myTfFullPath, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insets(8, 10), 0, 0));
    ButtonGroup group = new ButtonGroup();
    group.add(myRbCreateSource);
    group.add(myRbNoSource);
    myTfSourceDirectoryName.getDocument().addDocumentListener(new DocumentAdapter() {

        public void textChanged(DocumentEvent event) {
            updateFullPathField();
        }
    });
    myRbCreateSource.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            final boolean enabled = e.getStateChange() == ItemEvent.SELECTED;
            srcPathLabel.setEnabled(enabled);
            fieldPanel.setEnabled(enabled);
            fullPathLabel.setVisible(enabled);
            myTfFullPath.setVisible(enabled);
            if (enabled) {
                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                    IdeFocusManager.getGlobalInstance().requestFocus(myTfSourceDirectoryName, true);
                });
            }
        }
    });
    return panel;
}
Also used : ItemEvent(java.awt.event.ItemEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) MultiLineLabelUI(com.intellij.openapi.ui.MultiLineLabelUI) ItemListener(java.awt.event.ItemListener) FieldPanel(com.intellij.ui.FieldPanel)

Aggregations

ItemListener (java.awt.event.ItemListener)331 ItemEvent (java.awt.event.ItemEvent)314 ActionEvent (java.awt.event.ActionEvent)111 ActionListener (java.awt.event.ActionListener)108 JPanel (javax.swing.JPanel)93 JLabel (javax.swing.JLabel)81 JCheckBox (javax.swing.JCheckBox)65 JComboBox (javax.swing.JComboBox)64 JButton (javax.swing.JButton)51 Dimension (java.awt.Dimension)50 BorderLayout (java.awt.BorderLayout)47 JTextField (javax.swing.JTextField)46 ButtonGroup (javax.swing.ButtonGroup)34 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)33 GridBagConstraints (java.awt.GridBagConstraints)29 JMenu (javax.swing.JMenu)29 ChangeEvent (javax.swing.event.ChangeEvent)29 GridBagLayout (java.awt.GridBagLayout)28 JMenuItem (javax.swing.JMenuItem)28 ChangeListener (javax.swing.event.ChangeListener)28