Search in sources :

Example 6 with ListCellRendererWrapper

use of com.intellij.ui.ListCellRendererWrapper in project android by JetBrains.

the class EmulatorTargetConfigurable method createUIComponents.

private void createUIComponents() {
    myAvdCombo = new AvdComboBox(myProject, true, false) {

        @Override
        public Module getModule() {
            return myContext.getModule();
        }
    };
    myAvdCombo.startUpdatingAvds(ModalityState.current());
    JComboBox avdComboBox = myAvdCombo.getComboBox();
    avdComboBox.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof IdDisplay) {
                setText(((IdDisplay) value).getDisplay());
            } else {
                setText(String.format("<html><font color='red'>Unknown AVD %1$s</font></html>", value == null ? "" : value.toString()));
            }
        }
    });
    avdComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            resetAvdCompatibilityWarningLabel();
        }
    });
    myAvdComboWithButton = new ComboboxWithBrowseButton(avdComboBox);
    Disposer.register(myParentDisposable, myAvdCombo);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) AvdComboBox(com.android.tools.idea.run.AvdComboBox) IdDisplay(com.android.sdklib.repository.IdDisplay) ActionListener(java.awt.event.ActionListener) ComboboxWithBrowseButton(com.intellij.ui.ComboboxWithBrowseButton) Module(com.intellij.openapi.module.Module)

Example 7 with ListCellRendererWrapper

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

the class ParametersPerConstructorInspection method createOptionsPanel.

@Override
public JComponent createOptionsPanel() {
    final JFormattedTextField valueField = prepareNumberEditor("m_limit");
    final JComboBox comboBox = new ComboBox(new Object[] { Scope.NONE, Scope.PRIVATE, Scope.PACKAGE_LOCAL, Scope.PROTECTED });
    comboBox.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof Scope)
                setText(((Scope) value).getText());
        }
    });
    comboBox.setSelectedItem(ignoreScope);
    comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ignoreScope = (Scope) comboBox.getSelectedItem();
        }
    });
    comboBox.setPrototypeDisplayValue(Scope.PROTECTED);
    final FormBuilder formBuilder = FormBuilder.createFormBuilder();
    formBuilder.addLabeledComponent(getConfigurationLabel(), valueField);
    formBuilder.addLabeledComponent(InspectionGadgetsBundle.message("constructor.visibility.option"), comboBox);
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(formBuilder.getPanel(), BorderLayout.NORTH);
    return panel;
}
Also used : FormBuilder(com.intellij.util.ui.FormBuilder) ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) ActionListener(java.awt.event.ActionListener)

Example 8 with ListCellRendererWrapper

use of com.intellij.ui.ListCellRendererWrapper 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 9 with ListCellRendererWrapper

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

the class WrapReturnValueDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    sourceMethodTextField.setEditable(false);
    final DocumentListener docListener = new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            validateButtons();
        }
    };
    classNameField.getDocument().addDocumentListener(docListener);
    myFieldsCombo.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            validateButtons();
        }
    });
    myInnerClassNameTextField.getDocument().addDocumentListener(docListener);
    final PsiFile file = sourceMethod.getContainingFile();
    if (file instanceof PsiJavaFile) {
        final String packageName = ((PsiJavaFile) file).getPackageName();
        packageTextField.setText(packageName);
    }
    final PsiClass containingClass = sourceMethod.getContainingClass();
    assert containingClass != null : sourceMethod;
    final String containingClassName = containingClass instanceof PsiAnonymousClass ? "Anonymous " + ((PsiAnonymousClass) containingClass).getBaseClassType().getClassName() : containingClass.getName();
    final String sourceMethodName = sourceMethod.getName();
    sourceMethodTextField.setText(containingClassName + '.' + sourceMethodName);
    final ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(useExistingClassButton);
    buttonGroup.add(createNewClassButton);
    buttonGroup.add(myCreateInnerClassButton);
    createNewClassButton.setSelected(true);
    final ActionListener enableListener = new ActionListener() {

        public void actionPerformed(ActionEvent actionEvent) {
            toggleRadioEnablement();
        }
    };
    useExistingClassButton.addActionListener(enableListener);
    createNewClassButton.addActionListener(enableListener);
    myCreateInnerClassButton.addActionListener(enableListener);
    toggleRadioEnablement();
    final DefaultComboBoxModel model = new DefaultComboBoxModel();
    myFieldsCombo.setModel(model);
    myFieldsCombo.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof PsiField) {
                final PsiField field = (PsiField) value;
                setText(field.getName());
                setIcon(field.getIcon(Iconable.ICON_FLAG_VISIBILITY));
            }
        }
    });
    existingClassField.getChildComponent().getDocument().addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {

        @Override
        public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
            final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject);
            final PsiClass currentClass = facade.findClass(existingClassField.getText(), GlobalSearchScope.allScope(myProject));
            if (currentClass != null) {
                model.removeAllElements();
                final PsiType returnType = sourceMethod.getReturnType();
                assert returnType != null;
                for (PsiField field : currentClass.getFields()) {
                    final PsiType fieldType = field.getType();
                    if (TypeConversionUtil.isAssignable(fieldType, returnType)) {
                        model.addElement(field);
                    } else {
                        if (WrapReturnValueProcessor.getInferredType(fieldType, returnType, currentClass, sourceMethod) != null) {
                            model.addElement(field);
                        }
                    }
                }
            }
        }
    });
    return myWholePanel;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) ActionEvent(java.awt.event.ActionEvent) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener)

Example 10 with ListCellRendererWrapper

use of com.intellij.ui.ListCellRendererWrapper in project intellij-plugins by JetBrains.

the class HbConfigurationPage method resetCommentLanguageCombo.

private void resetCommentLanguageCombo(@NotNull Language commentLanguage) {
    final DefaultComboBoxModel model = (DefaultComboBoxModel) myCommenterLanguage.getModel();
    final List<Language> languages = TemplateDataLanguageMappings.getTemplateableLanguages();
    // add using the native Handlebars commenter as an option
    languages.add(HbLanguage.INSTANCE);
    Collections.sort(languages, (o1, o2) -> o1.getID().compareTo(o2.getID()));
    for (Language language : languages) {
        model.addElement(language);
    }
    myCommenterLanguage.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            setText(value == null ? "" : ((Language) value).getDisplayName());
            if (value != null) {
                final FileType type = ((Language) value).getAssociatedFileType();
                if (type != null) {
                    setIcon(type.getIcon());
                }
            }
        }
    });
    myCommenterLanguage.setSelectedItem(commentLanguage);
}
Also used : Language(com.intellij.lang.Language) HbLanguage(com.dmarcotte.handlebars.HbLanguage) FileType(com.intellij.openapi.fileTypes.FileType) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper)

Aggregations

ListCellRendererWrapper (com.intellij.ui.ListCellRendererWrapper)10 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 ComboBox (com.intellij.openapi.ui.ComboBox)3 HbLanguage (com.dmarcotte.handlebars.HbLanguage)2 Language (com.intellij.lang.Language)2 FileType (com.intellij.openapi.fileTypes.FileType)2 DocumentAdapter (com.intellij.ui.DocumentAdapter)2 DocumentEvent (javax.swing.event.DocumentEvent)2 IdDisplay (com.android.sdklib.repository.IdDisplay)1 AndroidSourceSet (com.android.tools.idea.npw.project.AndroidSourceSet)1 AvdComboBox (com.android.tools.idea.run.AvdComboBox)1 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)1 LanguageNamesValidation (com.intellij.lang.LanguageNamesValidation)1 JavaLanguage (com.intellij.lang.java.JavaLanguage)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)1