Example usage for com.intellij.openapi.ui ComboBox ComboBox

List of usage examples for com.intellij.openapi.ui ComboBox ComboBox

Introduction

In this page you can find the example usage for com.intellij.openapi.ui ComboBox ComboBox.

Prototype

public ComboBox(E @NotNull [] items) 

Source Link

Usage

From source file:com.intellij.designer.propertyTable.editors.ComboEditor.java

License:Apache License

public ComboEditor() {
    myCombo = new ComboBox(-1);
    myComboBorder = myCombo.getBorder();
    installListeners(myCombo, createComboListeners());
}

From source file:com.intellij.find.impl.FindDialog.java

License:Apache License

@Override
public JComponent createNorthPanel() {
    JPanel panel = new JPanel(new GridBagLayout());

    JLabel prompt = new JLabel(FindBundle.message("find.text.to.find.label"));
    panel.add(prompt, new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE,
            new Insets(0, 0, UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP), 0, 0));

    myInputComboBox = new ComboBox(300);
    revealWhitespaces(myInputComboBox);//w  ww  .  ja  va  2 s .co  m
    initCombobox(myInputComboBox);

    myReplaceComboBox = new ComboBox(300);
    revealWhitespaces(myReplaceComboBox);

    initCombobox(myReplaceComboBox);
    final Component editorComponent = myReplaceComboBox.getEditor().getEditorComponent();
    editorComponent.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            myReplaceComboBox.getEditor().selectAll();
            editorComponent.removeFocusListener(this);
        }
    });

    panel.add(myInputComboBox, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, UIUtil.DEFAULT_VGAP, 0), 0, 0));
    prompt.setLabelFor(myInputComboBox.getEditor().getEditorComponent());

    myReplacePrompt = new JLabel(FindBundle.message("find.replace.with.label"));
    panel.add(myReplacePrompt, new GridBagConstraints(0, 1, 1, 1, 0, 1, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(0, 0, UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP), 0, 0));

    panel.add(myReplaceComboBox, new GridBagConstraints(1, 1, 1, 1, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, UIUtil.DEFAULT_VGAP, 0), 0, 0));
    myReplacePrompt.setLabelFor(myReplaceComboBox.getEditor().getEditorComponent());
    return panel;
}

From source file:com.intellij.find.impl.FindDialog.java

License:Apache License

@NotNull
private JComponent createFilterPanel() {
    JPanel filterPanel = new JPanel();
    filterPanel.setLayout(new BorderLayout());
    filterPanel.setBorder(/* w  w  w .j  a v a 2  s .  co  m*/
            IdeBorderFactory.createTitledBorder(FindBundle.message("find.filter.file.name.group"), true));

    myFileFilter = new ComboBox(100);
    initCombobox(myFileFilter);
    filterPanel.add(myUseFileFilter = createCheckbox(FindBundle.message("find.filter.file.mask.checkbox")),
            BorderLayout.WEST);
    filterPanel.add(myFileFilter, BorderLayout.CENTER);
    initFileFilter(myFileFilter, myUseFileFilter);
    myUseFileFilter.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            findSettingsChanged();
            validateFindButton();
        }
    });
    return filterPanel;
}

From source file:com.intellij.find.impl.FindDialog.java

License:Apache License

@NotNull
private JPanel createFindOptionsPanel() {
    JPanel findOptionsPanel = new JPanel();
    findOptionsPanel/* w w  w .jav  a2  s .c om*/
            .setBorder(IdeBorderFactory.createTitledBorder(FindBundle.message("find.options.group"), true));
    findOptionsPanel.setLayout(new BoxLayout(findOptionsPanel, BoxLayout.Y_AXIS));

    myCbCaseSensitive = createCheckbox(FindBundle.message("find.options.case.sensitive"));
    findOptionsPanel.add(myCbCaseSensitive);
    ChangeListener l = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            findSettingsChanged();
        }
    };
    myCbCaseSensitive.addChangeListener(l);

    myCbPreserveCase = createCheckbox(FindBundle.message("find.options.replace.preserve.case"));
    myCbPreserveCase.addChangeListener(l);
    findOptionsPanel.add(myCbPreserveCase);
    myCbPreserveCase.setVisible(myModel.isReplaceState());
    myCbWholeWordsOnly = createCheckbox(FindBundle.message("find.options.whole.words.only"));
    myCbWholeWordsOnly.addChangeListener(l);

    findOptionsPanel.add(myCbWholeWordsOnly);

    myCbRegularExpressions = createCheckbox(FindBundle.message("find.options.regular.expressions"));
    myCbRegularExpressions.addChangeListener(l);

    final JPanel regExPanel = new JPanel();
    regExPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    regExPanel.setLayout(new BoxLayout(regExPanel, BoxLayout.X_AXIS));
    regExPanel.add(myCbRegularExpressions);

    regExPanel.add(RegExHelpPopup.createRegExLink("[Help]", regExPanel, LOG));

    findOptionsPanel.add(regExPanel);

    mySearchContext = new ComboBox(new Object[] { FindBundle.message("find.context.anywhere.scope.label"),
            FindBundle.message("find.context.in.comments.scope.label"),
            FindBundle.message("find.context.in.literals.scope.label"),
            FindBundle.message("find.context.except.comments.scope.label"),
            FindBundle.message("find.context.except.literals.scope.label"),
            FindBundle.message("find.context.except.comments.and.literals.scope.label") });
    mySearchContext.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            findSettingsChanged();
        }
    });
    final JPanel searchContextPanel = new JPanel(new BorderLayout());
    searchContextPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    JLabel searchContextLabel = new JLabel(FindBundle.message("find.context.combo.label"));
    searchContextLabel.setLabelFor(mySearchContext);
    JPanel panel = new JPanel();
    panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(searchContextLabel);
    searchContextPanel.add(panel, BorderLayout.WEST);

    panel = new JPanel(new BorderLayout());
    panel.add(mySearchContext, BorderLayout.NORTH);
    searchContextPanel.add(panel, BorderLayout.CENTER);

    findOptionsPanel.add(searchContextPanel);

    ActionListener actionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateControls();
        }
    };
    myCbRegularExpressions.addActionListener(actionListener);
    myCbRegularExpressions.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(final ItemEvent e) {
            setupRegExpSetting();
        }
    });

    myCbCaseSensitive.addActionListener(actionListener);
    myCbPreserveCase.addActionListener(actionListener);

    return findOptionsPanel;
}

From source file:com.intellij.find.impl.FindDialog.java

License:Apache License

@NotNull
private JComponent createGlobalScopePanel() {
    JPanel scopePanel = new JPanel();
    scopePanel.setLayout(new GridBagLayout());
    scopePanel.setBorder(IdeBorderFactory.createTitledBorder(FindBundle.message("find.scope.group"), true));
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.anchor = GridBagConstraints.WEST;

    gbConstraints.gridx = 0;/*from  ww  w  .  j a v a 2s. c  o  m*/
    gbConstraints.gridy = 0;
    gbConstraints.gridwidth = 3;
    gbConstraints.weightx = 1;
    myRbProject = new JRadioButton(FindBundle.message("find.scope.whole.project.radio"), true);
    scopePanel.add(myRbProject, gbConstraints);
    ChangeListener l = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            findSettingsChanged();
        }
    };
    myRbProject.addChangeListener(l);

    gbConstraints.gridx = 0;
    gbConstraints.gridy++;
    gbConstraints.weightx = 0;
    gbConstraints.gridwidth = 1;
    myRbModule = new JRadioButton(FindBundle.message("find.scope.module.radio"), false);
    scopePanel.add(myRbModule, gbConstraints);
    myRbModule.addChangeListener(l);

    gbConstraints.gridx = 1;
    gbConstraints.gridwidth = 2;
    gbConstraints.weightx = 1;
    Module[] modules = ModuleManager.getInstance(myProject).getModules();
    String[] names = new String[modules.length];
    for (int i = 0; i < modules.length; i++) {
        names[i] = modules[i].getName();
    }

    Arrays.sort(names, String.CASE_INSENSITIVE_ORDER);
    myModuleComboBox = new ComboBox(names);
    myModuleComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            findSettingsChanged();
        }
    });
    scopePanel.add(myModuleComboBox, gbConstraints);

    if (modules.length == 1) {
        myModuleComboBox.setVisible(false);
        myRbModule.setVisible(false);
    }

    gbConstraints.gridx = 0;
    gbConstraints.gridy++;
    gbConstraints.weightx = 0;
    gbConstraints.gridwidth = 1;
    myRbDirectory = new JRadioButton(FindBundle.message("find.scope.directory.radio"), false);
    scopePanel.add(myRbDirectory, gbConstraints);
    myRbDirectory.addChangeListener(l);

    gbConstraints.gridx = 1;
    gbConstraints.weightx = 1;
    myDirectoryComboBox = new ComboBox(200);
    Component editorComponent = myDirectoryComboBox.getEditor().getEditorComponent();
    if (editorComponent instanceof JTextField) {
        JTextField field = (JTextField) editorComponent;
        field.setColumns(40);
    }
    initCombobox(myDirectoryComboBox);
    myDirectoryComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            findSettingsChanged();
        }
    });
    scopePanel.add(myDirectoryComboBox, gbConstraints);

    gbConstraints.weightx = 0;
    gbConstraints.gridx = 2;
    mySelectDirectoryButton = new FixedSizeButton(myDirectoryComboBox);
    TextFieldWithBrowseButton.MyDoClickAction.addTo(mySelectDirectoryButton, myDirectoryComboBox);
    mySelectDirectoryButton.setMargin(new Insets(0, 0, 0, 0));
    scopePanel.add(mySelectDirectoryButton, gbConstraints);

    gbConstraints.gridx = 0;
    gbConstraints.gridy++;
    gbConstraints.weightx = 1;
    gbConstraints.gridwidth = 3;
    gbConstraints.insets = new Insets(0, 16, 0, 0);
    myCbWithSubdirectories = createCheckbox(true,
            FindBundle.message("find.scope.directory.recursive.checkbox"));
    myCbWithSubdirectories.setSelected(true);
    scopePanel.add(myCbWithSubdirectories, gbConstraints);

    gbConstraints.gridx = 0;
    gbConstraints.gridy++;
    gbConstraints.weightx = 0;
    gbConstraints.gridwidth = 1;
    gbConstraints.insets = new Insets(0, 0, 0, 0);
    myRbCustomScope = new JRadioButton(FindBundle.message("find.scope.custom.radio"), false);
    scopePanel.add(myRbCustomScope, gbConstraints);

    gbConstraints.gridx++;
    gbConstraints.weightx = 1;
    gbConstraints.gridwidth = 2;
    myScopeCombo = new ScopeChooserCombo(myProject, true, true,
            FindSettings.getInstance().getDefaultScopeName());
    myRbCustomScope.addChangeListener(l);

    Disposer.register(myDisposable, myScopeCombo);
    scopePanel.add(myScopeCombo, gbConstraints);

    ButtonGroup bgScope = new ButtonGroup();
    bgScope.add(myRbDirectory);
    bgScope.add(myRbProject);
    bgScope.add(myRbModule);
    bgScope.add(myRbCustomScope);

    ActionListener validateAll = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            validateScopeControls();
            validateFindButton();
        }
    };
    myRbProject.addActionListener(validateAll);
    myRbCustomScope.addActionListener(validateAll);

    myRbDirectory.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            validateScopeControls();
            validateFindButton();
            myDirectoryComboBox.getEditor().getEditorComponent().requestFocusInWindow();
        }
    });

    myRbModule.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            validateScopeControls();
            validateFindButton();
            myModuleComboBox.requestFocusInWindow();
        }
    });

    mySelectDirectoryButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
            FileChooser.chooseFiles(descriptor, myProject, null, new Consumer<List<VirtualFile>>() {
                @Override
                public void consume(final List<VirtualFile> files) {
                    myDirectoryComboBox.setSelectedItem(files.get(0).getPresentableUrl());
                }
            });
        }
    });

    return scopePanel;
}

From source file:com.intellij.lang.jsgraphql.ide.project.JSGraphQLLanguageUIProjectService.java

License:Open Source License

private JComponent createHeaderComponent(FileEditor fileEditor, Editor editor) {

    final JSGraphQLEditorHeaderComponent headerComponent = new JSGraphQLEditorHeaderComponent();

    // variables & settings actions
    final DefaultActionGroup settingsActions = new DefaultActionGroup();
    settingsActions.add(new JSGraphQLEditEndpointsAction());
    settingsActions.add(new JSGraphQLToggleVariablesAction());

    final JComponent settingsToolbar = createToolbar(settingsActions);
    headerComponent.add(settingsToolbar, BorderLayout.WEST);

    // query execute
    final DefaultActionGroup queryActions = new DefaultActionGroup();
    final AnAction executeGraphQLAction = ActionManager.getInstance()
            .getAction(JSGraphQLExecuteEditorAction.class.getName());
    queryActions.add(executeGraphQLAction);
    final JComponent queryToolbar = createToolbar(queryActions);

    // configured endpoints combo box
    final List<JSGraphQLEndpoint> endpoints = JSGraphQLConfigurationProvider.getService(myProject)
            .getEndpoints();/*from   ww w  .java2 s . com*/
    final JSGraphQLEndpointsModel endpointsModel = new JSGraphQLEndpointsModel(endpoints,
            PropertiesComponent.getInstance(myProject));
    final ComboBox endpointComboBox = new ComboBox(endpointsModel);
    endpointComboBox.setToolTipText("GraphQL endpoint");
    editor.putUserData(JS_GRAPH_QL_ENDPOINTS_MODEL, endpointsModel);
    final JPanel endpointComboBoxPanel = new JPanel(new BorderLayout());
    endpointComboBoxPanel.setBorder(BorderFactory.createEmptyBorder(1, 2, 2, 2));
    endpointComboBoxPanel.add(endpointComboBox);

    // splitter to resize endpoints
    final OnePixelSplitter splitter = new OnePixelSplitter(false, .25F);
    splitter.setBorder(BorderFactory.createEmptyBorder());
    splitter.setFirstComponent(endpointComboBoxPanel);
    splitter.setSecondComponent(queryToolbar);
    splitter.setHonorComponentsMinimumSize(true);
    splitter.setAndLoadSplitterProportionKey("JSGraphQLEndpointSplitterProportion");
    splitter.setOpaque(false);
    splitter.getDivider().setOpaque(false);

    headerComponent.add(splitter, BorderLayout.CENTER);

    // variables editor
    final LightVirtualFile virtualFile = new LightVirtualFile(GRAPH_QL_VARIABLES_JSON, JsonFileType.INSTANCE,
            "");
    final FileEditor variablesFileEditor = PsiAwareTextEditorProvider.getInstance().createEditor(myProject,
            virtualFile);
    final EditorEx variablesEditor = (EditorEx) ((TextEditor) variablesFileEditor).getEditor();
    virtualFile.putUserData(IS_GRAPH_QL_VARIABLES_VIRTUAL_FILE, Boolean.TRUE);
    variablesEditor.setPlaceholder("{ variables }");
    variablesEditor.setShowPlaceholderWhenFocused(true);
    variablesEditor.getSettings().setRightMarginShown(false);
    variablesEditor.getSettings().setAdditionalLinesCount(0);
    variablesEditor.getSettings().setShowIntentionBulb(false);
    variablesEditor.getSettings().setFoldingOutlineShown(false);
    variablesEditor.getSettings().setLineNumbersShown(false);
    variablesEditor.getSettings().setLineMarkerAreaShown(false);
    variablesEditor.getSettings().setCaretRowShown(false);
    variablesEditor.putUserData(JS_GRAPH_QL_ENDPOINTS_MODEL, endpointsModel);

    // hide variables by default
    variablesEditor.getComponent().setVisible(false);

    // link the query and variables editor together
    variablesEditor.putUserData(GRAPH_QL_QUERY_EDITOR, editor);
    editor.putUserData(GRAPH_QL_VARIABLES_EDITOR, variablesEditor);

    final NonOpaquePanel variablesPanel = new NonOpaquePanel(variablesFileEditor.getComponent());
    variablesPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));

    Disposer.register(fileEditor, variablesFileEditor);

    headerComponent.add(variablesPanel, BorderLayout.SOUTH);

    return headerComponent;
}

From source file:com.intellij.refactoring.ui.NameSuggestionsField.java

License:Apache License

public NameSuggestionsField(String[] nameSuggestions, Project project, FileType fileType) {
    super(new BorderLayout());
    myProject = project;/*from   w  w w  .  j  a va  2 s . c om*/
    if (nameSuggestions == null || nameSuggestions.length <= 1) {
        myComponent = createTextFieldForName(nameSuggestions, fileType);
    } else {
        final ComboBox combobox = new ComboBox(nameSuggestions);
        combobox.setSelectedIndex(0);
        setupComboBox(combobox, fileType);
        myComponent = combobox;
    }
    add(myComponent, BorderLayout.CENTER);
    myComboBoxModel = null;
}

From source file:com.intellij.remoteServer.impl.configuration.deployment.DeployToServerSettingsEditor.java

License:Apache License

public DeployToServerSettingsEditor(final ServerType<S> type, DeploymentConfigurator<D> deploymentConfigurator,
        Project project) {//  w  w w  . j  a va 2 s .co m
    myServerType = type;
    myDeploymentConfigurator = deploymentConfigurator;
    myProject = project;

    myServerListModel = new SortedComboBoxModel<String>(String.CASE_INSENSITIVE_ORDER);
    myServerComboBox = new ComboboxWithBrowseButton(new ComboBox(myServerListModel));
    fillApplicationServersList(null);
    myServerComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            RemoteServerListConfigurable configurable = RemoteServerListConfigurable.createConfigurable(type);
            if (ShowSettingsUtil.getInstance().editConfigurable(myServerComboBox, configurable)) {
                fillApplicationServersList(configurable.getLastSelectedServer());
            }
        }
    });
    myServerComboBox.getComboBox().setRenderer(new ColoredListCellRendererWrapper<String>() {
        @Override
        protected void doCustomize(JList list, String value, int index, boolean selected, boolean hasFocus) {
            if (value == null)
                return;
            RemoteServer<S> server = RemoteServersManager.getInstance().findByName(value, type);
            SimpleTextAttributes attributes = server == null ? SimpleTextAttributes.ERROR_ATTRIBUTES
                    : SimpleTextAttributes.REGULAR_ATTRIBUTES;
            setIcon(server != null ? server.getType().getIcon() : null);
            append(value, attributes);
        }
    });

    mySourceListModel = new SortedComboBoxModel<DeploymentSource>(new Comparator<DeploymentSource>() {
        @Override
        public int compare(DeploymentSource o1, DeploymentSource o2) {
            return o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName());
        }
    });
    mySourceListModel.addAll(deploymentConfigurator.getAvailableDeploymentSources());
    mySourceComboBox = new ComboBox(mySourceListModel);
    mySourceComboBox.setRenderer(new ListCellRendererWrapper<DeploymentSource>() {
        @Override
        public void customize(JList list, DeploymentSource value, int index, boolean selected,
                boolean hasFocus) {
            if (value == null)
                return;
            setIcon(value.getIcon());
            setText(value.getPresentableName());
        }
    });

    myDeploymentSettingsComponent = new JPanel(new BorderLayout());
    mySourceComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onDeploymentSourceChanged(null);
        }
    });
}

From source file:com.intellij.remoteServer.impl.configuration.localServer.LocalToServerSettingsEditor.java

License:Apache License

public LocalToServerSettingsEditor(final ServerType<S> type, DeploymentConfigurator<D> deploymentConfigurator,
        Project project) {/*from  w  w w  . ja  va 2 s  .co  m*/
    myServerType = type;
    myDeploymentConfigurator = deploymentConfigurator;
    myProject = project;

    mySourceListModel = new SortedComboBoxModel<DeploymentSource>(new Comparator<DeploymentSource>() {
        @Override
        public int compare(DeploymentSource o1, DeploymentSource o2) {
            return o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName());
        }
    });
    mySourceListModel.addAll(deploymentConfigurator.getAvailableDeploymentSources());
    mySourceComboBox = new ComboBox(mySourceListModel);
    mySourceComboBox.setRenderer(new ListCellRendererWrapper<DeploymentSource>() {
        @Override
        public void customize(JList list, DeploymentSource value, int index, boolean selected,
                boolean hasFocus) {
            if (value == null)
                return;
            setIcon(value.getIcon());
            setText(value.getPresentableName());
        }
    });

    myDeploymentSettingsComponent = new JPanel(new BorderLayout());
    mySourceComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onDeploymentSourceChanged(null);
        }
    });
}

From source file:com.intellij.tasks.trello.TrelloRepositoryEditor.java

License:Apache License

@Nullable
@Override/*from  w  w w . j a  va 2s  .co m*/
protected JComponent createCustomPanel() {
    myBoardComboBox = new ComboBox(300);
    myBoardLabel = new JBLabel("Board:", SwingConstants.RIGHT);
    myBoardLabel.setLabelFor(myBoardComboBox);

    myListComboBox = new ComboBox(300);
    myListLabel = new JBLabel("List:", SwingConstants.RIGHT);
    myListLabel.setLabelFor(myListComboBox);
    return FormBuilder.createFormBuilder().addLabeledComponent(myBoardLabel, myBoardComboBox)
            .addLabeledComponent(myListLabel, myListComboBox).getPanel();
}