Search in sources :

Example 11 with ComboBox

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

the class CreateFieldFromParameterDialog method createNorthPanel.

@Override
protected JComponent createNorthPanel() {
    if (myNames.length > 1) {
        final ComboBox combobox = new ComboBox(myNames, 200);
        myNameField = combobox;
        combobox.setEditable(true);
        combobox.setSelectedIndex(0);
        combobox.setMaximumRowCount(8);
        combobox.registerKeyboardAction(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (combobox.isPopupVisible()) {
                    combobox.setPopupVisible(false);
                } else {
                    doCancelAction();
                }
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        combobox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                updateOkStatus();
            }
        });
        combobox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                updateOkStatus();
            }

            @Override
            public void keyReleased(KeyEvent e) {
                updateOkStatus();
            }

            @Override
            public void keyTyped(KeyEvent e) {
                updateOkStatus();
            }
        });
    } else {
        JTextField field = new JTextField() {

            @Override
            public Dimension getPreferredSize() {
                Dimension size = super.getPreferredSize();
                return new Dimension(200, size.height);
            }
        };
        myNameField = field;
        field.setText(myNames[0]);
        field.getDocument().addDocumentListener(new DocumentAdapter() {

            @Override
            protected void textChanged(DocumentEvent e) {
                updateOkStatus();
            }
        });
    }
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.insets = JBUI.insets(4);
    gbConstraints.anchor = GridBagConstraints.EAST;
    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.gridwidth = 1;
    gbConstraints.weightx = 1;
    gbConstraints.weighty = 1;
    gbConstraints.gridx = 0;
    gbConstraints.gridy = 0;
    final JLabel typeLabel = new JLabel(CodeInsightBundle.message("dialog.create.field.from.parameter.field.type.label"));
    panel.add(typeLabel, gbConstraints);
    gbConstraints.gridx = 1;
    if (myTypes.length > 1) {
        myTypeSelector = new TypeSelector(myProject);
        myTypeSelector.setTypes(myTypes);
    } else {
        myTypeSelector = new TypeSelector(myTypes[0], myProject);
    }
    panel.add(myTypeSelector.getComponent(), gbConstraints);
    gbConstraints.gridwidth = 1;
    gbConstraints.weightx = 0;
    gbConstraints.weighty = 1;
    gbConstraints.gridx = 0;
    gbConstraints.gridy = 1;
    JLabel namePrompt = new JLabel(CodeInsightBundle.message("dialog.create.field.from.parameter.field.name.label"));
    panel.add(namePrompt, gbConstraints);
    gbConstraints.gridwidth = 1;
    gbConstraints.weightx = 1;
    gbConstraints.gridx = 1;
    gbConstraints.gridy = 1;
    panel.add(myNameField, gbConstraints);
    return panel;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) TypeSelector(com.intellij.refactoring.ui.TypeSelector)

Example 12 with ComboBox

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

the class ArtifactConfigurable method createTopRightComponent.

@Override
protected JComponent createTopRightComponent() {
    final ComboBox artifactTypeBox = new ComboBox();
    for (ArtifactType type : ArtifactType.getAllTypes()) {
        artifactTypeBox.addItem(type);
    }
    artifactTypeBox.setRenderer(new ArtifactTypeCellRenderer(artifactTypeBox.getRenderer()));
    artifactTypeBox.setSelectedItem(getArtifact().getArtifactType());
    artifactTypeBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final ArtifactType selected = (ArtifactType) artifactTypeBox.getSelectedItem();
            if (selected != null && !Comparing.equal(selected, getArtifact().getArtifactType())) {
                getEditor().setArtifactType(selected);
            }
        }
    });
    final JPanel panel = new JPanel(new FlowLayout());
    panel.add(new JLabel("Type: "));
    panel.add(artifactTypeBox);
    return panel;
}
Also used : ActionListener(java.awt.event.ActionListener) ComboBox(com.intellij.openapi.ui.ComboBox) ArtifactType(com.intellij.packaging.artifacts.ArtifactType) ActionEvent(java.awt.event.ActionEvent)

Example 13 with ComboBox

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

the class MakeParameterizedStaticDialog method createComboBoxForName.

private JComboBox createComboBoxForName() {
    final ComboBox combobox = new ComboBox(myNameSuggestions);
    combobox.setEditable(true);
    combobox.setSelectedIndex(0);
    combobox.setMaximumRowCount(8);
    combobox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            updateControls();
        }
    });
    combobox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            updateControls();
        }

        public void keyReleased(KeyEvent e) {
            updateControls();
        }

        public void keyTyped(KeyEvent e) {
            updateControls();
        }
    });
    return combobox;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox)

Example 14 with ComboBox

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

the class ExternalDependenciesConfigurable method editPluginDependency.

@Nullable
private DependencyOnPlugin editPluginDependency(@NotNull JComponent parent, @NotNull final DependencyOnPlugin original) {
    List<String> pluginIds = new ArrayList<>(getPluginNameByIdMap().keySet());
    if (!original.getPluginId().isEmpty() && !pluginIds.contains(original.getPluginId())) {
        pluginIds.add(original.getPluginId());
    }
    Collections.sort(pluginIds, (o1, o2) -> getPluginNameById(o1).compareToIgnoreCase(getPluginNameById(o2)));
    final ComboBox pluginChooser = new ComboBox(ArrayUtilRt.toStringArray(pluginIds), 250);
    pluginChooser.setRenderer(new ListCellRendererWrapper<String>() {

        @Override
        public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
            setText(getPluginNameById(value));
        }
    });
    new ComboboxSpeedSearch(pluginChooser) {

        @Override
        protected String getElementText(Object element) {
            return getPluginNameById((String) element);
        }
    };
    pluginChooser.setSelectedItem(original.getPluginId());
    final JBTextField minVersionField = new JBTextField(StringUtil.notNullize(original.getMinVersion()));
    final JBTextField maxVersionField = new JBTextField(StringUtil.notNullize(original.getMaxVersion()));
    final JBTextField channelField = new JBTextField(StringUtil.notNullize(original.getChannel()));
    minVersionField.getEmptyText().setText("<any>");
    minVersionField.setColumns(10);
    maxVersionField.getEmptyText().setText("<any>");
    maxVersionField.setColumns(10);
    channelField.setColumns(10);
    JPanel panel = FormBuilder.createFormBuilder().addLabeledComponent("Plugin:", pluginChooser).addLabeledComponent("Minimum version:", minVersionField).addLabeledComponent("Maximum version:", maxVersionField).addLabeledComponent("Channel:", channelField).getPanel();
    final DialogBuilder dialogBuilder = new DialogBuilder(parent).title("Required Plugin").centerPanel(panel);
    dialogBuilder.setPreferredFocusComponent(pluginChooser);
    pluginChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialogBuilder.setOkActionEnabled(!StringUtil.isEmpty((String) pluginChooser.getSelectedItem()));
        }
    });
    if (dialogBuilder.show() == DialogWrapper.OK_EXIT_CODE) {
        return new DependencyOnPlugin(((String) pluginChooser.getSelectedItem()), StringUtil.nullize(minVersionField.getText().trim()), StringUtil.nullize(maxVersionField.getText().trim()), StringUtil.nullize(channelField.getText().trim()));
    }
    return null;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent) JBTextField(com.intellij.ui.components.JBTextField) DependencyOnPlugin(com.intellij.externalDependencies.DependencyOnPlugin) ActionListener(java.awt.event.ActionListener) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with ComboBox

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

the class ChangeListCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull final CompletionResultSet result) {
    final PsiFile file = parameters.getOriginalFile();
    final Document document = PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file);
    if (document == null)
        return;
    ComboBox comboBox = document.getUserData(COMBO_BOX_KEY);
    if (comboBox == null)
        return;
    final CompletionResultSet resultSet = result.withPrefixMatcher(new PlainPrefixMatcher(document.getText()));
    for (int i = 0; i < comboBox.getItemCount(); i++) {
        resultSet.addElement(LookupElementBuilder.create(comboBox.getItemAt(i)));
    }
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document)

Aggregations

ComboBox (com.intellij.openapi.ui.ComboBox)46 Nullable (org.jetbrains.annotations.Nullable)12 ActionListener (java.awt.event.ActionListener)11 ActionEvent (java.awt.event.ActionEvent)10 JBLabel (com.intellij.ui.components.JBLabel)7 NotNull (org.jetbrains.annotations.NotNull)7 JBTextField (com.intellij.ui.components.JBTextField)6 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)5 AndroidTargetHash.getAddonHashString (com.android.sdklib.AndroidTargetHash.getAddonHashString)4 BuildFileKey (com.android.tools.idea.gradle.parser.BuildFileKey)4 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)4 Project (com.intellij.openapi.project.Project)4 javax.swing (javax.swing)4 Module (com.intellij.openapi.module.Module)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 JBCheckBox (com.intellij.ui.components.JBCheckBox)3 java.awt (java.awt)3 ItemEvent (java.awt.event.ItemEvent)3 ItemListener (java.awt.event.ItemListener)3 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2