Search in sources :

Example 41 with ComboBox

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

the class ParameterTablePanel method init.

public void init(VariableData[] variableData, Project project, PsiElement... scopeElements) {
    super.init(variableData);
    myParameterTypeSelectors = new TypeSelector[getVariableData().length];
    for (int i = 0; i < myParameterTypeSelectors.length; i++) {
        final VariableData data = variableData[i];
        final TypeSelector selector = createSelector(project, data, scopeElements);
        myParameterTypeSelectors[i] = selector;
        //reverse order
        getVariableData()[i].type = myParameterTypeSelectors[i].getSelectedType();
    }
    myTypeRendererCombo = new ComboBox<>(getVariableData());
    myTypeRendererCombo.setOpaque(true);
    myTypeRendererCombo.setBorder(null);
    myTypeRendererCombo.setRenderer(new ListCellRendererWrapper<VariableData>() {

        @Override
        public void customize(JList list, VariableData value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setText(value.type.getPresentableText());
            }
        }
    });
    final TableColumn typeColumn = myTable.getColumnModel().getColumn(1);
    typeColumn.setCellEditor(new AbstractTableCellEditor() {

        TypeSelector myCurrentSelector;

        final JBComboBoxTableCellEditorComponent myEditorComponent = new JBComboBoxTableCellEditorComponent();

        final JLabel myTypeLabel = new JLabel();

        @Nullable
        public Object getCellEditorValue() {
            if (myCurrentSelector.getComponent() instanceof JLabel) {
                return myCurrentSelector.getSelectedType();
            }
            return myEditorComponent.getEditorValue();
        }

        public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
            myCurrentSelector = myParameterTypeSelectors[row];
            if (myParameterTypeSelectors[row].getComponent() instanceof JLabel) {
                PsiType selectedType = myCurrentSelector.getSelectedType();
                if (selectedType != null) {
                    myTypeLabel.setText(selectedType.getPresentableText());
                }
                return myTypeLabel;
            }
            myEditorComponent.setCell(table, row, column);
            myEditorComponent.setOptions(myCurrentSelector.getTypes());
            myEditorComponent.setDefaultValue(getVariableData()[row].type);
            myEditorComponent.setToString(o -> ((PsiType) o).getPresentableText());
            return myEditorComponent;
        }
    });
    myTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {

        private final JBComboBoxLabel myLabel = new JBComboBoxLabel();

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (value != null) {
                myLabel.setText(((PsiType) value).getPresentableText());
                myLabel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
                myLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
                if (isSelected) {
                    myLabel.setSelectionIcon();
                } else {
                    myLabel.setRegularIcon();
                }
            }
            return myLabel;
        }
    });
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TypeSelectorManagerImpl(com.intellij.refactoring.ui.TypeSelectorManagerImpl) TableColumn(javax.swing.table.TableColumn) Predicate(java.util.function.Predicate) TypeSelector(com.intellij.refactoring.ui.TypeSelector) ColumnInfo(com.intellij.util.ui.ColumnInfo) TypeSelectorManager(com.intellij.refactoring.ui.TypeSelectorManager) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) LanguageNamesValidation(com.intellij.lang.LanguageNamesValidation) ArrayList(java.util.ArrayList) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) JBComboBoxLabel(com.intellij.ui.components.JBComboBoxLabel) Project(com.intellij.openapi.project.Project) com.intellij.psi(com.intellij.psi) JavaLanguage(com.intellij.lang.java.JavaLanguage) javax.swing(javax.swing) JBComboBoxLabel(com.intellij.ui.components.JBComboBoxLabel) TableColumn(javax.swing.table.TableColumn) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) TypeSelector(com.intellij.refactoring.ui.TypeSelector) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with ComboBox

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

the class FindPopupScopeUIImpl method initComponents.

public void initComponents() {
    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);
    ActionListener restartSearchListener = e -> scheduleResultsUpdate();
    myModuleComboBox.addActionListener(restartSearchListener);
    myDirectoryChooser = new FindPopupDirectoryChooser(myFindPopupPanel);
    myScopeCombo = new ScopeChooserCombo();
    myScopeCombo.init(myProject, true, true, FindSettings.getInstance().getDefaultScopeName(), new Condition<ScopeDescriptor>() {

        final String projectFilesScopeName = PsiBundle.message("psi.search.scope.project");

        final String moduleFilesScopeName;

        {
            String moduleScopeName = PsiBundle.message("search.scope.module", "");
            final int ind = moduleScopeName.indexOf(' ');
            moduleFilesScopeName = moduleScopeName.substring(0, ind + 1);
        }

        @Override
        public boolean value(ScopeDescriptor descriptor) {
            final String display = descriptor.getDisplay();
            return !projectFilesScopeName.equals(display) && !display.startsWith(moduleFilesScopeName);
        }
    });
    myScopeCombo.setBrowseListener(new ScopeChooserCombo.BrowseListener() {

        private FindModel myModelSnapshot;

        @Override
        public void onBeforeBrowseStarted() {
            myModelSnapshot = myHelper.getModel();
            myFindPopupPanel.getCanClose().set(false);
        }

        @Override
        public void onAfterBrowseFinished() {
            if (myModelSnapshot != null) {
                SearchScope scope = myScopeCombo.getSelectedScope();
                if (scope != null) {
                    myModelSnapshot.setCustomScope(scope);
                }
                myFindPopupPanel.getCanClose().set(true);
            }
        }
    });
    myScopeCombo.getComboBox().addActionListener(restartSearchListener);
    Disposer.register(myFindPopupPanel.getDisposable(), myScopeCombo);
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) ActionListener(java.awt.event.ActionListener) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) ModuleManager(com.intellij.openapi.module.ModuleManager) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.find(com.intellij.find) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) SearchScope(com.intellij.psi.search.SearchScope) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) Disposer(com.intellij.openapi.util.Disposer) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Condition(com.intellij.openapi.util.Condition) PsiBundle(com.intellij.psi.PsiBundle) javax.swing(javax.swing) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) ActionListener(java.awt.event.ActionListener) SearchScope(com.intellij.psi.search.SearchScope) Module(com.intellij.openapi.module.Module)

Example 43 with ComboBox

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

the class GenerateGetterSetterHandlerBase method getHeaderPanel.

protected static JComponent getHeaderPanel(final Project project, final TemplatesManager templatesManager, final String templatesTitle) {
    final JPanel panel = new JPanel(new BorderLayout());
    final JLabel templateChooserLabel = new JLabel(templatesTitle);
    panel.add(templateChooserLabel, BorderLayout.WEST);
    final ComboBox comboBox = new ComboBox();
    templateChooserLabel.setLabelFor(comboBox);
    comboBox.setRenderer(new ListCellRendererWrapper<TemplateResource>() {

        @Override
        public void customize(JList list, TemplateResource value, int index, boolean selected, boolean hasFocus) {
            setText(value.getName());
        }
    });
    final ComponentWithBrowseButton<ComboBox> comboBoxWithBrowseButton = new ComponentWithBrowseButton<>(comboBox, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final TemplatesPanel ui = new TemplatesPanel(project, templatesManager) {

                @Override
                protected boolean onMultipleFields() {
                    return false;
                }

                @Nls
                @Override
                public String getDisplayName() {
                    return StringUtil.capitalizeWords(UIUtil.removeMnemonic(StringUtil.trimEnd(templatesTitle, ":")), true);
                }
            };
            ui.setHint("Visibility is applied according to File | Settings | Editor | Code Style | Java | Code Generation");
            ui.selectNodeInTree(templatesManager.getDefaultTemplate());
            if (ShowSettingsUtil.getInstance().editConfigurable(panel, ui)) {
                setComboboxModel(templatesManager, comboBox);
            }
        }
    });
    setComboboxModel(templatesManager, comboBox);
    comboBox.addActionListener(new ActionListener() {

        public void actionPerformed(@NotNull final ActionEvent M) {
            templatesManager.setDefaultTemplate((TemplateResource) comboBox.getSelectedItem());
        }
    });
    panel.add(comboBoxWithBrowseButton, BorderLayout.CENTER);
    return panel;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent) TemplatesPanel(org.jetbrains.java.generate.view.TemplatesPanel) ActionListener(java.awt.event.ActionListener) Nls(org.jetbrains.annotations.Nls) ComponentWithBrowseButton(com.intellij.openapi.ui.ComponentWithBrowseButton) TemplateResource(org.jetbrains.java.generate.template.TemplateResource)

Example 44 with ComboBox

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

the class StudyNewProjectPanel method layoutPanel.

private void layoutPanel() {
    myCoursesComboBox = new ComboBox<>();
    final LabeledComponent<ComboBox> coursesCombo = LabeledComponent.create(myCoursesComboBox, "Courses:", BorderLayout.WEST);
    myRefreshButton = new FixedSizeButton(coursesCombo);
    if (SystemInfo.isMac && !UIUtil.isUnderDarcula())
        myRefreshButton.putClientProperty("JButton.buttonType", null);
    myRefreshButton.setIcon(AllIcons.Actions.Refresh);
    myBrowseButton = new FixedSizeButton(coursesCombo);
    final JPanel comboPanel = new JPanel(new BorderLayout());
    comboPanel.add(coursesCombo, BorderLayout.CENTER);
    comboPanel.add(myRefreshButton, BorderLayout.EAST);
    final JPanel coursesPanel = new JPanel(new BorderLayout());
    coursesPanel.add(comboPanel, BorderLayout.CENTER);
    coursesPanel.add(myBrowseButton, BorderLayout.EAST);
    add(coursesPanel);
    myAnchor = coursesCombo;
    final JPanel panel = new JPanel(new BorderLayout());
    final JLabel invisibleLabel = new JLabel();
    invisibleLabel.setPreferredSize(new JLabel("Location: ").getPreferredSize());
    panel.add(invisibleLabel, BorderLayout.WEST);
    myInfoPanel = new JPanel(new VerticalFlowLayout());
    myAuthorLabel = new JLabel();
    myDescriptionPane = new JTextPane();
    myDescriptionPane.setEditable(true);
    myDescriptionPane.setEnabled(true);
    myAuthorLabel.setEnabled(true);
    myDescriptionPane.setPreferredSize(new Dimension(150, 200));
    myDescriptionPane.setFont(coursesCombo.getFont());
    myInfoPanel.add(myAuthorLabel);
    myInfoPanel.add(new JBScrollPane(myDescriptionPane));
    panel.add(myInfoPanel, BorderLayout.CENTER);
    add(panel);
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton) JBScrollPane(com.intellij.ui.components.JBScrollPane) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout)

Example 45 with ComboBox

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

the class PyMethodParametersInspection method createOptionsPanel.

@Nullable
@Override
public JComponent createOptionsPanel() {
    ComboBox comboBox = new ComboBox(new String[] { "mcs", "metacls" });
    comboBox.setSelectedItem(MCS);
    comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ComboBox cb = (ComboBox) e.getSource();
            MCS = (String) cb.getSelectedItem();
        }
    });
    JPanel option = new JPanel(new BorderLayout());
    option.add(new JLabel("Metaclass method first argument name"), BorderLayout.WEST);
    option.add(comboBox, BorderLayout.EAST);
    final JPanel root = new JPanel(new BorderLayout());
    root.add(option, BorderLayout.PAGE_START);
    return root;
}
Also used : ActionListener(java.awt.event.ActionListener) ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent) Nullable(org.jetbrains.annotations.Nullable)

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