Java Code Examples for com.intellij.openapi.ui.ComboBox#setRenderer()

The following examples show how to use com.intellij.openapi.ui.ComboBox#setRenderer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectFileTemplateDialog.java    From PackageTemplates with Apache License 2.0 6 votes vote down vote up
@NotNull
private ComboBox getSelector() {
    ArrayList<TemplateForSearch> listTemplateForSearch = FileTemplateHelper.getTemplates(
            project,
            cbAddInternal.isSelected(),
            cbAddJ2EE.isSelected(),
            ptWrapper.getPackageTemplate().getFileTemplateSource()
    );

    ComboBox comboBox = new ComboBox(listTemplateForSearch.toArray());
    comboBox.setRenderer(new ListCellRendererWrapper<TemplateForSearch>() {
        @Override
        public void customize(JList list, TemplateForSearch template, int index, boolean selected, boolean hasFocus) {
            if (template != null) {
                setIcon(FileTemplateUtil.getIcon(template.getTemplate()));
                setText(template.getTemplate().getName());
            }
        }
    });

    new ComboboxSpeedSearch(comboBox);
    return comboBox;
}
 
Example 2
Source File: WriteRulesDialog.java    From PackageTemplates with Apache License 2.0 6 votes vote down vote up
@Override
public void preShow() {
    panel.setLayout(new MigLayout(new LC().gridGap("0", "8pt")));

    //Type
    ArrayList<WriteRules> actionTypes = new ArrayList<>();
    if(hasParent){
        actionTypes.add(WriteRules.FROM_PARENT);
    }
    actionTypes.add(WriteRules.USE_EXISTING);
    actionTypes.add(WriteRules.ASK_ME);
    actionTypes.add(WriteRules.OVERWRITE);

    comboBoxRules = new ComboBox(actionTypes.toArray());
    comboBoxRules.setRenderer(new WriteRulesCellRenderer());
    comboBoxRules.setSelectedItem(writeRules);

    panel.add(comboBoxRules, new CC().pushX().growX().spanX().gapY("10","10"));
}
 
Example 3
Source File: KeymapPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private JPanel createKeymapListPanel() {
  JPanel panel = new JPanel();
  panel.setLayout(new GridBagLayout());

  myKeymapList = new ComboBox(myKeymapListModel);
  myKeymapList.setEditor(new MyEditor());
  myKeymapList.setRenderer(new MyKeymapRenderer(myKeymapList.getRenderer()));
  JLabel keymapLabel = new JLabel(KeyMapBundle.message("keymaps.border.factory.title"));
  keymapLabel.setLabelFor(myKeymapList);
  panel.add(keymapLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  panel.add(myKeymapList, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 4, 0, 0), 0, 0));

  panel.add(createKeymapButtonsPanel(),
            new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  myKeymapList.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      if (myKeymapListModel.getSelectedItem() != mySelectedKeymap) processCurrentKeymapChanged(getCurrentQuickListIds());
    }
  });
  panel.add(createKeymapNamePanel(),
            new GridBagConstraints(3, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0));
  return panel;
}
 
Example 4
Source File: CreateNewLibraryDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CreateNewLibraryDialog(@Nonnull JComponent parent, @Nonnull StructureConfigurableContext context, @Nonnull NewLibraryEditor libraryEditor,
                              @Nonnull List<LibraryTable> libraryTables, int selectedTable) {
  super(parent, new LibraryRootsComponent(context.getProject(), libraryEditor));
  myContext = context;
  myLibraryEditor = libraryEditor;
  final DefaultComboBoxModel model = new DefaultComboBoxModel();
  for (LibraryTable table : libraryTables) {
    model.addElement(table);
  }
  myLibraryLevelCombobox = new ComboBox(model);
  myLibraryLevelCombobox.setSelectedIndex(selectedTable);
  myLibraryLevelCombobox.setRenderer(new ListCellRendererWrapper() {
    @Override
    public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      if (value instanceof LibraryTable) {
        setText(((LibraryTable)value).getPresentation().getDisplayName(false));
      }
    }
  });
  init();
}
 
Example 5
Source File: ArtifactConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createTopRightComponent(final JTextField nameField) {
  final ComboBox artifactTypeBox = new ComboBox();
  for (ArtifactType type : ArtifactType.EP_NAME.getExtensions()) {
    artifactTypeBox.addItem(type);
  }

  artifactTypeBox.setRenderer(new ArtifactTypeCellRenderer());

  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);
      }
    }
  });

  return LabeledComponent.left(artifactTypeBox, "Type");
}
 
Example 6
Source File: ScopeChooserCombo.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void init(final Project project, final boolean suggestSearchInLibs, final boolean prevSearchWholeFiles, final Object selection, @Nullable Condition<? super ScopeDescriptor> scopeFilter) {
  if (myProject != null) {
    throw new IllegalStateException("scope chooser combo already initialized");
  }
  myOptions = BitUtil.set(myOptions, OPT_LIBRARIES, suggestSearchInLibs);
  myOptions = BitUtil.set(myOptions, OPT_SEARCH_RESULTS, prevSearchWholeFiles);
  myProject = project;

  NamedScopesHolder.ScopeListener scopeListener = () -> {
    SearchScope selectedScope = getSelectedScope();
    rebuildModelAndSelectScopeOnSuccess(selectedScope);
  };
  myScopeFilter = scopeFilter;
  NamedScopeManager.getInstance(project).addScopeListener(scopeListener, this);
  DependencyValidationManager.getInstance(project).addScopeListener(scopeListener, this);
  addActionListener(this::handleScopeChooserAction);

  ComboBox<ScopeDescriptor> combo = getComboBox();
  combo.setMinimumAndPreferredWidth(JBUIScale.scale(300));
  combo.setRenderer(createDefaultRenderer());
  combo.setSwingPopup(false);

  rebuildModelAndSelectScopeOnSuccess(selection);
}
 
Example 7
Source File: NameSuggestionsField.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setupComboBox(final ComboBox combobox, FileType fileType) {
  final EditorComboBoxEditor comboEditor = new StringComboboxEditor(myProject, fileType, combobox) {
    @Override
    public void setItem(Object anObject) {
      myNonHumanChange = true;
      super.setItem(anObject);
    }
  };

  combobox.setEditor(comboEditor);
  combobox.setRenderer(new EditorComboBoxRenderer(comboEditor));

  combobox.setEditable(true);
  combobox.setMaximumRowCount(8);

  comboEditor.selectAll();
}
 
Example 8
Source File: AbstractAddDialog.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
void initCombo(final ComboBox combobox, final JPanel parentPanel) {
    combobox.setModel(new DefaultComboBoxModel(JsonDataType.values()));
    combobox.setRenderer(new ColoredListCellRenderer() {

        @Override
        protected void customizeCellRenderer(JList jList, Object o, int i, boolean b, boolean b2) {
            append(((JsonDataType) o).type);
        }
    });

    combobox.setSelectedItem(null);
    combobox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent itemEvent) {
            JsonDataType selectedType = (JsonDataType) combobox.getSelectedItem();
            currentEditor = UI_COMPONENT_BY_JSON_DATATYPE.get(selectedType);
            currentEditor.reset();

            parentPanel.invalidate();
            parentPanel.removeAll();
            parentPanel.add(currentEditor.getComponent(), BorderLayout.CENTER);
            parentPanel.validate();
        }
    });

    combobox.setSelectedItem(JsonDataType.STRING);
}
 
Example 9
Source File: LocalToServerSettingsEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LocalToServerSettingsEditor(final ServerType<S> type, DeploymentConfigurator<D> deploymentConfigurator, Project project) {
  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 ColoredListCellRenderer<DeploymentSource>() {
    @Override
    protected void customizeCellRenderer(@Nonnull JList list, DeploymentSource value, int index, boolean selected, boolean hasFocus) {
      if (value == null) return;
      setIcon(value.getIcon());
      append(value.getPresentableName());
    }
  });

  myDeploymentSettingsComponent = new JPanel(new BorderLayout());
  mySourceComboBox.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      onDeploymentSourceChanged(null);
    }
  });
}
 
Example 10
Source File: MultipleChangeListBrowser.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ChangeListChooser() {
  super(new BorderLayout(4, 2));
  myChooser = new ComboBox();
  //noinspection unchecked
  myChooser.setRenderer(new ColoredListCellRendererWrapper<LocalChangeList>() {
    @Override
    protected void doCustomize(JList list, LocalChangeList value, int index, boolean selected, boolean hasFocus) {
      if (value != null) {
        String name = StringUtil.shortenTextWithEllipsis(value.getName().trim(), MAX_LEN, 0);

        append(name, value.isDefault() ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES);
      }
    }
  });

  myChooser.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
        final LocalChangeList changeList = (LocalChangeList)myChooser.getSelectedItem();
        setSelectedList(changeList);
        myChooser.setToolTipText(changeList == null ? "" : (changeList.getName()));
      }
    }
  });

  myChooser.setEditable(false);
  add(myChooser, BorderLayout.CENTER);

  JLabel label = new JLabel(VcsBundle.message("commit.dialog.changelist.label"));
  label.setLabelFor(myChooser);
  add(label, BorderLayout.WEST);
}
 
Example 11
Source File: PackageTemplateWrapper.java    From PackageTemplates with Apache License 2.0 4 votes vote down vote up
private void buildProperties() {
    // Header
    JLabel jlName = new JLabel(Localizer.get("Name"));
    JLabel jlDescription = new JLabel(Localizer.get("Description"));

    jtfName = new JBTextField(packageTemplate.getName());
    jtaDescription = new JTextArea(packageTemplate.getDescription());

    panelProperties.add(jlName, new CC().wrap().spanX().pad(0, 0, 0, 8).gapY("0", "4pt"));
    panelProperties.add(jtfName, new CC().spanX().growX().pushX().wrap());
    panelProperties.add(jlDescription, new CC().wrap().spanX().pad(0, 0, 0, 8).gapY("4pt", "4pt"));
    panelProperties.add(jtaDescription, new CC().spanX().growX().pushX().wrap().gapY("0", "4pt"));

    //FileTemplate Source
    ArrayList<FileTemplateSource> actionTypes = new ArrayList<>();
    actionTypes.add(FileTemplateSource.DEFAULT_ONLY);
    actionTypes.add(FileTemplateSource.PROJECT_ONLY);
    actionTypes.add(FileTemplateSource.PROJECT_PRIORITY);
    actionTypes.add(FileTemplateSource.DEFAULT_PRIORITY);

    cboxFileTemplateSource = new ComboBox(actionTypes.toArray());
    cboxFileTemplateSource.setRenderer(new FileTemplateSourceCellRenderer());
    cboxFileTemplateSource.setSelectedItem(packageTemplate.getFileTemplateSource());
    cboxFileTemplateSource.addActionListener(e -> {
        packageTemplate.setFileTemplateSource((FileTemplateSource) cboxFileTemplateSource.getSelectedItem());
    });

    if (mode == ViewMode.USAGE) {
        jtfName.setEditable(false);
        jtaDescription.setEditable(false);
        cboxFileTemplateSource.setEnabled(false);
    } else {
        // Properties
        cbShouldRegisterAction = new JBCheckBox(Localizer.get("property.ShouldRegisterAction"), packageTemplate.isShouldRegisterAction());
        cbSkipDefiningNames = new JBCheckBox(Localizer.get("property.SkipPresettings"), packageTemplate.isSkipDefiningNames());
        panelProperties.add(cbShouldRegisterAction, new CC().wrap().spanX());
        panelProperties.add(cbSkipDefiningNames, new CC().wrap().spanX());
    }

    // Properties
    cbSkipRootDirectory = new JBCheckBox(Localizer.get("property.SkipRootDirectory"), packageTemplate.isSkipRootDirectory());
    cbSkipRootDirectory.addItemListener(e -> {
        collectDataFromFields();
        reBuildElements();
    });
    cbShowReportDialog = new JBCheckBox(Localizer.get("property.ShowReportDialog"), packageTemplate.shouldShowReport());

    panelProperties.add(cbSkipRootDirectory, new CC().spanX().wrap());
    panelProperties.add(cbShowReportDialog, new CC().spanX().wrap());
    panelProperties.add(new JLabel(Localizer.get("FileTemplateSource")), new CC().spanX().split(2));
    panelProperties.add(cboxFileTemplateSource, new CC().pushX().growX().wrap());

}
 
Example 12
Source File: SettingsDialog.java    From PackageTemplates with Apache License 2.0 4 votes vote down vote up
private void buildAutoImportBlock() {
    panel.add(new SeparatorComponent(10), new CC().pushX().growX().wrap().spanX());
    panel.add(new JLabel(Localizer.get("settings.AutoImport"), JLabel.CENTER), new CC().wrap().growX().pushX().spanX());

    //WriteRules
    ArrayList<WriteRules> actionTypes = new ArrayList<>();
    actionTypes.add(WriteRules.USE_EXISTING);
    actionTypes.add(WriteRules.ASK_ME);
    actionTypes.add(WriteRules.OVERWRITE);

    cbAutoImportWriteRules = new ComboBox(actionTypes.toArray());
    cbAutoImportWriteRules.setRenderer(new WriteRulesCellRenderer());

    panel.add(cbAutoImportWriteRules, new CC().pushX().growX().spanX().gapY("10", "10"));

    //Paths
    paths = new ArrayList<>();
    lvAutoImport = new ListView<String>(paths) {
        @Nullable
        @Override
        public CollectDataFromUI onBuildView(String item, int pos) {
            TextFieldWithBrowseButton btnPath = new TextFieldWithBrowseButton();
            btnPath.setText(item);
            btnPath.addBrowseFolderListener(Localizer.get("SelectDirectoryToImport"), "", project, FileReaderUtil.getDirectoryDescriptor());

            JButton btnDelete = new JButton(IconUtil.getRemoveIcon());
            btnDelete.addMouseListener(new ClickListener() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    lvAutoImport.collectDataFromUI();
                    presenter.removeImportPath(paths, pos);
                }
            });

            add(btnDelete, new CC().split(2).spanX());
            add(btnPath, new CC().pushX().growX());
            return () -> list.set(pos, btnPath.getText());
        }
    };
    panel.add(lvAutoImport, new CC().spanX().pushX().growX().wrap());

    JButton btnAdd = new JButton(Localizer.get("action.AddPath"), IconUtil.getAddIcon());
    btnAdd.addMouseListener(new ClickListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            lvAutoImport.collectDataFromUI();
            presenter.addImportPath(paths);
        }
    });
    panel.add(btnAdd, new CC().wrap());
}