Search in sources :

Example 1 with ListCellRendererWrapper

use of com.intellij.ui.ListCellRendererWrapper in project idea-handlebars by dmarcotte.

the class HbConfigurationPage method resetCommentLanguageCombo.

private void resetCommentLanguageCombo(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, new Comparator<Language>() {

        @Override
        public int compare(final Language o1, final Language o2) {
            return 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)

Example 2 with ListCellRendererWrapper

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

the class ExecutionHelper method selectContentDescriptor.

public static void selectContentDescriptor(@NotNull final DataContext dataContext, @NotNull final Project project, @NotNull Collection<RunContentDescriptor> consoles, String selectDialogTitle, final Consumer<RunContentDescriptor> descriptorConsumer) {
    if (consoles.size() == 1) {
        RunContentDescriptor descriptor = consoles.iterator().next();
        descriptorConsumer.consume(descriptor);
        descriptorToFront(project, descriptor);
    } else if (consoles.size() > 1) {
        final JList list = new JBList(consoles);
        final Icon icon = DefaultRunExecutor.getRunExecutorInstance().getIcon();
        list.setCellRenderer(new ListCellRendererWrapper<RunContentDescriptor>() {

            @Override
            public void customize(final JList list, final RunContentDescriptor value, final int index, final boolean selected, final boolean hasFocus) {
                setText(value.getDisplayName());
                setIcon(icon);
            }
        });
        final PopupChooserBuilder builder = new PopupChooserBuilder(list);
        builder.setTitle(selectDialogTitle);
        builder.setItemChoosenCallback(() -> {
            final Object selectedValue = list.getSelectedValue();
            if (selectedValue instanceof RunContentDescriptor) {
                RunContentDescriptor descriptor = (RunContentDescriptor) selectedValue;
                descriptorConsumer.consume(descriptor);
                descriptorToFront(project, descriptor);
            }
        }).createPopup().showInBestPositionFor(dataContext);
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 3 with ListCellRendererWrapper

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

the class FullyQualifiedNamesInJavadocOptionProvider method composePanel.

private void composePanel() {
    myPanel = new JPanel(new GridBagLayout());
    myComboBox = new ComboBox();
    for (QualifyJavadocOptions options : QualifyJavadocOptions.values()) {
        myComboBox.addItem(options);
    }
    myComboBox.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) {
            if (value instanceof QualifyJavadocOptions) {
                setText(((QualifyJavadocOptions) value).getPresentableText());
            }
        }
    });
    JLabel title = new JLabel(ApplicationBundle.message("radio.use.fully.qualified.class.names.in.javadoc"));
    myPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    GridBagConstraints left = new GridBagConstraints();
    left.anchor = GridBagConstraints.WEST;
    GridBagConstraints right = new GridBagConstraints();
    right.anchor = GridBagConstraints.WEST;
    right.weightx = 1.0;
    right.insets = JBUI.insetsLeft(5);
    myPanel.add(title, left);
    myPanel.add(myComboBox, right);
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper)

Example 4 with ListCellRendererWrapper

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

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

the class SourceSetComboProvider method createComponent.

@NotNull
@Override
public JComboBox createComponent() {
    DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
    for (AndroidSourceSet sourceSet : mySourceSets) {
        comboBoxModel.addElement(sourceSet);
    }
    JComboBox sourceSetCombo = new JComboBox(comboBoxModel);
    sourceSetCombo.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            setText(((AndroidSourceSet) value).getName());
        }
    });
    sourceSetCombo.setToolTipText("<html>The source set within which to generate new project files.<br>" + "If you specify a source set that does not yet exist on disk, a folder will be created for it.</html>");
    return sourceSetCombo;
}
Also used : ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) AndroidSourceSet(com.android.tools.idea.npw.project.AndroidSourceSet) NotNull(org.jetbrains.annotations.NotNull)

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