com.intellij.ui.ListCellRendererWrapper Java Examples

The following examples show how to use com.intellij.ui.ListCellRendererWrapper. 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: FluidConfigurationPage.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
private void resetCommentLanguageCombo(@NotNull Language commentLanguage) {
    final DefaultComboBoxModel model = (DefaultComboBoxModel) myCommenterLanguage.getModel();
    final List<Language> languages = TemplateDataLanguageMappings.getTemplateableLanguages();

    languages.add(FluidLanguage.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);
}
 
Example #2
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 #3
Source File: TestForm.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
TestForm(@NotNull Project project) {
  scope.setModel(new DefaultComboBoxModel<>(new Scope[]{DIRECTORY, FILE, NAME}));
  scope.addActionListener((ActionEvent e) -> {
    final Scope next = getScope();
    updateFields(next);
    render(next);
  });
  scope.setRenderer(new ListCellRendererWrapper<Scope>() {
    @Override
    public void customize(final JList list,
                          final Scope value,
                          final int index,
                          final boolean selected,
                          final boolean hasFocus) {
      setText(value.getDisplayName());
    }
  });

  initDartFileTextWithBrowse(project, testFile);
  testDir.addBrowseFolderListener("Test Directory", null, project,
                                  FileChooserDescriptorFactory.createSingleFolderDescriptor());
}
 
Example #4
Source File: TestForm.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
TestForm(@NotNull Project project) {
  scope.setModel(new DefaultComboBoxModel<>(new Scope[]{DIRECTORY, FILE, NAME}));
  scope.addActionListener((ActionEvent e) -> {
    final Scope next = getScope();
    updateFields(next);
    render(next);
  });
  scope.setRenderer(new ListCellRendererWrapper<Scope>() {
    @Override
    public void customize(final JList list,
                          final Scope value,
                          final int index,
                          final boolean selected,
                          final boolean hasFocus) {
      setText(value.getDisplayName());
    }
  });

  initDartFileTextWithBrowse(project, testFile);
  testDir.addBrowseFolderListener("Test Directory", null, project,
                                  FileChooserDescriptorFactory.createSingleFolderDescriptor());
}
 
Example #5
Source File: BlazeIntellijPluginConfiguration.java    From intellij with Apache License 2.0 6 votes vote down vote up
public BlazeIntellijPluginConfigurationSettingsEditor(
    Iterable<Label> javaLabels,
    RunConfigurationStateEditor blazeFlagsEditor,
    RunConfigurationStateEditor exeFlagsEditor) {
  targetCombo =
      new ComboBox<>(
          new DefaultComboBoxModel<>(
              Ordering.usingToString().sortedCopy(javaLabels).toArray(new Label[0])));
  targetCombo.setRenderer(
      new ListCellRendererWrapper<Label>() {
        @Override
        public void customize(
            JList list, @Nullable Label value, int index, boolean selected, boolean hasFocus) {
          setText(value == null ? null : value.toString());
        }
      });
  this.blazeFlagsEditor = blazeFlagsEditor;
  this.exeFlagsEditor = exeFlagsEditor;
  ProjectSdksModel sdksModel = new ProjectSdksModel();
  sdksModel.reset(null);
  sdkCombo = new JdkComboBox(sdksModel, IdeaJdkHelper::isIdeaJdkType);

  keepInSyncCheckBox = new JBCheckBox("Keep in sync with source XML");
  keepInSyncCheckBox.addItemListener(e -> updateEnabledStatus());
}
 
Example #6
Source File: CSharpChangeSignatureDialog.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
protected VisibilityPanelBase<CSharpAccessModifier> createVisibilityControl()
{
	return new ComboBoxVisibilityPanel<CSharpAccessModifier>(CSharpAccessModifier.VALUES)
	{
		@Override
		protected ListCellRendererWrapper<CSharpAccessModifier> getRenderer()
		{
			return new ListCellRendererWrapper<CSharpAccessModifier>()
			{
				@Override
				public void customize(JList list, CSharpAccessModifier value, int index, boolean selected, boolean hasFocus)
				{
					setText(value.getPresentableText());
				}
			};
		}
	};
}
 
Example #7
Source File: DataSourceSelector.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
public DataSourceSelector(JComboBox dataSourceList) {
    this.dataSourceList = dataSourceList;
    new ComboboxSpeedSearch(this.dataSourceList) {
        protected String getElementText(Object element) {
            if (element instanceof XQueryDataSourceConfiguration) {
                return ((XQueryDataSourceConfiguration) element).NAME;
            } else if (element == null) {
                return NO_DATA_SOURCE;
            }
            return super.getElementText(element);
        }
    };
    this.dataSourceList.setModel(dataSourcesModel);
    this.dataSourceList.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 XQueryDataSourceConfiguration) {
                final XQueryDataSourceConfiguration dataSourceConfiguration = (XQueryDataSourceConfiguration) value;
                setText(dataSourceConfiguration.NAME);
            } else if (value == null) {
                setText(NO_DATA_SOURCE);
            }
        }
    });
}
 
Example #8
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 #9
Source File: ProfilesConfigurableComboBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ProfilesConfigurableComboBox(final ListCellRendererWrapper<Profile> comboBoxItemsRenderer) {
  myCardLayout = new CardLayout();
  setLayout(myCardLayout);

  myProfilesComboBox = new JComboBox();
  add(myProfilesComboBox, COMBO_CARD);

  mySaveListener = new SaveInputComponentValidator.Wrapper();
  mySubmitNameComponent = new ValidatedTextField(mySaveListener);
  add(mySubmitNameComponent, EDIT_CARD);

  myProfilesComboBox.setRenderer(comboBoxItemsRenderer);
  myProfilesComboBox.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      final InspectionProfileImpl profile = getSelectedProfile();
      if (profile != null) {
        onProfileChosen(profile);
      }
    }
  });

  showComboBoxCard();
}
 
Example #10
Source File: CommonConfigView.java    From easy_javadoc with Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
    typeMapList = new JBList<>(new CollectionListModel<>(Lists.newArrayList()));
    typeMapList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    typeMapList.setCellRenderer(new ListCellRendererWrapper<Entry<String, String>>() {
        @Override
        public void customize(JList list, Entry<String, String> value, int index, boolean selected, boolean hasFocus) {
            setText(value.getKey() + " -> " + value.getValue());
        }
    });

    typeMapList.setEmptyText("请添加单词映射");
    typeMapList.setSelectedIndex(0);
    ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(typeMapList);
    toolbarDecorator.setAddAction(button -> {
        WordMapAddView wordMapAddView = new WordMapAddView();
        if (wordMapAddView.showAndGet()) {
            if (config != null) {
                Entry<String, String> entry = wordMapAddView.getMapping();
                config.getWordMap().put(entry.getKey(), entry.getValue());
                refreshWordMap();
            }
        }
    });
    toolbarDecorator.setRemoveAction(anActionButton -> {
        if (config != null) {
            Map<String, String> typeMap = config.getWordMap();
            typeMap.remove(typeMapList.getSelectedValue().getKey());
            refreshWordMap();
        }
    });
    wordMapPanel = toolbarDecorator.createPanel();
}
 
Example #11
Source File: ImplementationViewComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateRenderer(final Project project) {
  myFileChooser.setRenderer(new ListCellRendererWrapper<FileDescriptor>() {
    @Override
    public void customize(JList list, FileDescriptor value, int index, boolean selected, boolean hasFocus) {
      final PsiFile file = value.myFile;
      setIcon(getIconForFile(file));
      final VirtualFile vFile = file.getVirtualFile();
      setForeground(FileStatusManager.getInstance(project).getStatus(vFile).getColor());
      //noinspection ConstantConditions
      setText(value.getPresentableName(vFile));
    }
  });
}
 
Example #12
Source File: ArrangementComboBoxUiComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public ArrangementComboBoxUiComponent(@Nonnull List<ArrangementSettingsToken> tokens) {
  super(tokens);
  ArrangementSettingsToken[] tokensArray = tokens.toArray(new ArrangementSettingsToken[tokens.size()]);
  Arrays.sort(tokensArray, new Comparator<ArrangementSettingsToken>() {
    @Override
    public int compare(ArrangementSettingsToken t1, ArrangementSettingsToken t2) {
      return t1.getRepresentationValue().compareTo(t2.getRepresentationValue());
    }
  });
  myComboBox = new JComboBox(tokensArray);
  myComboBox.setRenderer(new ListCellRendererWrapper() {
    @Override
    public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      setText(((ArrangementSettingsToken)value).getRepresentationValue());
    }
  });
  myComboBox.addItemListener(new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent e) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
        fireStateChanged();
      }
    }
  });
  int minWidth = 0;
  ListCellRenderer renderer = myComboBox.getRenderer();
  JBList dummyList = new JBList();
  for (int i = 0, max = myComboBox.getItemCount(); i < max; i++) {
    Component rendererComponent = renderer.getListCellRendererComponent(dummyList, myComboBox.getItemAt(i), i, false, true);
    minWidth = Math.max(minWidth, rendererComponent.getPreferredSize().width);
  }
  myComboBox.setPreferredSize(new Dimension(minWidth * 5 / 3, myComboBox.getPreferredSize().height));
}
 
Example #13
Source File: FileTypePatternDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FileTypePatternDialog(@Nullable String initialPatterns, FileType fileType, Language templateDataLanguage) {
  myPatternField.setText(initialPatterns);

  if (fileType instanceof TemplateLanguageFileType) {
    final DefaultComboBoxModel model = (DefaultComboBoxModel) myLanguageCombo.getModel();
    model.addElement(null);
    final List<Language> languages = TemplateDataLanguageMappings.getTemplateableLanguages();
    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);
    }
    myLanguageCombo.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(TargetAWT.to(type.getIcon()));
          }
        }
      }
    });
    myLanguageCombo.setSelectedItem(templateDataLanguage);
  } else {
    myLanguageCombo.setVisible(false);
    myTemplateDataLanguageButton.setVisible(false);
  }
}
 
Example #14
Source File: ComboBoxVisibilityPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected ListCellRendererWrapper getRenderer() {
  return new ListCellRendererWrapper() {
    @Override
    public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      setText(myNamesMap.get((V)value));
    }
  };
}
 
Example #15
Source File: ComboWrapper.java    From intellij with Apache License 2.0 4 votes vote down vote up
public void setRenderer(ListCellRendererWrapper<T> renderer) {
  combo.setRenderer(renderer);
}