Java 类com.intellij.ui.ColoredListCellRendererWrapper 实例源码

项目:intellij-ce-playground    文件:LanguageLevelCombo.java   
public LanguageLevelCombo(String defaultItem) {
  myDefaultItem = defaultItem;
  for (LanguageLevel level : LanguageLevel.values()) {
    addItem(level);
  }
  setRenderer(new ColoredListCellRendererWrapper() {
    @Override
    protected void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      if (value instanceof LanguageLevel) {
        append(((LanguageLevel)value).getPresentableText());
      }
      else if (value instanceof String) {    // default for SDK or project
        append((String)value);
        LanguageLevel defaultLevel = getDefaultLevel();
        if (defaultLevel != null) {
          append(" (" + defaultLevel.getPresentableText() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
        }
      }
    }
  });
}
项目:consulo-dotnet    文件:DotNetCoverageConfigurationEditor.java   
public DotNetCoverageConfigurationEditor()
{
    myPanel.add(myEnabledCheckBox);
    myPanel.add(LabeledComponent.left(myRunnersBox, "Runner"));
    myRunnersBox.setRenderer(new ColoredListCellRendererWrapper<Object>()
    {
        @Override
        protected void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus)
        {
            if(value == null)
            {
                append("<none>");
            }
            else if(value instanceof String)
            {
                append((String) value, SimpleTextAttributes.ERROR_ATTRIBUTES);
            }
            else if(value instanceof CoverageRunner)
            {
                append(((CoverageRunner) value).getPresentableName());
            }
        }
    });
}
项目:consulo-dotnet    文件:DotNetLibraryModuleDependencyTabContext.java   
public DotNetLibraryModuleDependencyTabContext(ClasspathPanel classpathPanel, StructureConfigurableContext context)
{
    super(classpathPanel, context);

    myLibraryList = new JBList();
    myLibraryList.setCellRenderer(new ColoredListCellRendererWrapper<Map.Entry<String, String>>()
    {
        @Override
        protected void doCustomize(JList jList, Map.Entry<String, String> entry, int i, boolean b, boolean b2)
        {
            append(entry.getKey());
            append(" ");
            append("(" + entry.getValue() + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
        }
    });
}
项目:consulo    文件:ProjectLibraryTabContext.java   
public ProjectLibraryTabContext(final ClasspathPanel classpathPanel, StructureConfigurableContext context) {
  super(classpathPanel, context);

  StructureLibraryTableModifiableModelProvider projectLibrariesProvider = context.getProjectLibrariesProvider();
  Library[] libraries = projectLibrariesProvider.getModifiableModel().getLibraries();
  final Condition<Library> condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel());

  myItems = ContainerUtil.filter(libraries, condition);
  ContainerUtil.sort(myItems, new Comparator<Library>() {
    @Override
    public int compare(Library o1, Library o2) {
      return StringUtil.compare(o1.getName(), o2.getName(), false);
    }
  });

  myLibraryList = new JBList(myItems);
  myLibraryList.setCellRenderer(new ColoredListCellRendererWrapper<Library>() {
    @Override
    protected void doCustomize(JList list, Library value, int index, boolean selected, boolean hasFocus) {
      final CellAppearanceEx appearance = OrderEntryAppearanceService.getInstance().forLibrary(classpathPanel.getProject(), value, false);

      appearance.customize(this);
    }
  });
  new ListSpeedSearch(myLibraryList);
}
项目:intellij-ce-playground    文件:ExternalSystemJdkComboBox.java   
public ExternalSystemJdkComboBox(@Nullable Project project) {
  myProject = project;
  setRenderer(new ColoredListCellRendererWrapper() {

    @Override
    protected void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      JdkComboBoxItem item = (JdkComboBoxItem)value;
      CompositeAppearance appearance = new CompositeAppearance();
      SdkType sdkType = JavaSdk.getInstance();
      appearance.setIcon(sdkType.getIcon());
      SimpleTextAttributes attributes = getTextAttributes(item.valid, selected);
      CompositeAppearance.DequeEnd ending = appearance.getEnding();

      ending.addText(item.label, attributes);
      if (item.comment != null && !item.comment.equals(item.jdkName)) {
        final SimpleTextAttributes textAttributes;
        if (!item.valid) {
          textAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
        }
        else {
          textAttributes = SystemInfo.isMac && selected
                           ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.WHITE)
                           : SimpleTextAttributes.GRAY_ATTRIBUTES;
        }

        ending.addComment(item.comment, textAttributes);
      }

      final CompositeAppearance compositeAppearance = ending.getAppearance();
      compositeAppearance.customize(this);
    }
  });
}
项目:intellij-ce-playground    文件:MultipleChangeListBrowser.java   
public ChangeListChooser(List<? extends ChangeList> lists) {
  super(new BorderLayout(4, 2));
  myChooser = new JComboBox();
  myChooser.setRenderer(new ColoredListCellRendererWrapper<LocalChangeList>() {
    @Override
    protected void doCustomize(JList list, LocalChangeList value, int index, boolean selected, boolean hasFocus) {
      if (value != null) {
        String name = value.getName().trim();
        if (name.length() > MAX_LEN) {
          name = name.substring(0, MAX_LEN - 3) + "...";
        }
        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()));
      }
    }
  });

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

  JLabel label = new JLabel(VcsBundle.message("commit.dialog.changelist.label"));
  label.setLabelFor(myChooser);
  add(label, BorderLayout.WEST);
}
项目:tools-idea    文件:MultipleChangeListBrowser.java   
public ChangeListChooser(List<? extends ChangeList> lists) {
  super(new BorderLayout(4, 2));
  myChooser = new JComboBox();
  myChooser.setRenderer(new ColoredListCellRendererWrapper<LocalChangeList>() {
    @Override
    protected void doCustomize(JList list, LocalChangeList value, int index, boolean selected, boolean hasFocus) {
      if (value != null) {
        String name = value.getName().trim();
        if (name.length() > MAX_LEN) {
          name = name.substring(0, MAX_LEN - 3) + "...";
        }
        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()));
      }
    }
  });

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

  JLabel label = new JLabel(VcsBundle.message("commit.dialog.changelist.label"));
  label.setLabelFor(myChooser);
  add(label, BorderLayout.WEST);
}
项目:consulo    文件:MultipleChangeListBrowser.java   
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);
}
项目:intellij-ce-playground    文件:LanguagePanel.java   
public LanguagePanel(Project project, BaseInjection injection) {
  super(injection, project);
  $$$setupUI$$$();

  final String[] languageIDs = InjectedLanguage.getAvailableLanguageIDs();
  Arrays.sort(languageIDs);

  myLanguage.setModel(new DefaultComboBoxModel(languageIDs));
  myLanguage.setRenderer(new ColoredListCellRendererWrapper<String>() {
    final Set<String> IDs = new HashSet<String>(Arrays.asList(languageIDs));

    @Override
    protected void doCustomize(JList list, String s, int index, boolean selected, boolean hasFocus) {
      final SimpleTextAttributes attributes =
          IDs.contains(s) ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.ERROR_ATTRIBUTES;
      append(s, attributes);

      final Language language = InjectedLanguage.findLanguageById(s);
      if (language != null) {
        final FileType fileType = language.getAssociatedFileType();
        if (fileType != null) {
          setIcon(fileType.getIcon());
          append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
          append("(" + fileType.getDescription() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
        }
      }
    }
  });
  myLanguage.addItemListener(new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent e) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
        updateHighlighters();
      }
    }
  });

  myRoot.addAncestorListener(new AncestorListenerAdapter() {
    @Override
    public void ancestorAdded(AncestorEvent event) {
      updateHighlighters();
    }
  });
}
项目:tools-idea    文件:LanguagePanel.java   
public LanguagePanel(Project project, BaseInjection injection) {
  super(injection, project);
  $$$setupUI$$$();

  final String[] languageIDs = InjectedLanguage.getAvailableLanguageIDs();
  Arrays.sort(languageIDs);

  myLanguage.setModel(new DefaultComboBoxModel(languageIDs));
  myLanguage.setRenderer(new ColoredListCellRendererWrapper<String>() {
    final Set<String> IDs = new HashSet<String>(Arrays.asList(languageIDs));

    @Override
    protected void doCustomize(JList list, String s, int index, boolean selected, boolean hasFocus) {
      final SimpleTextAttributes attributes =
          IDs.contains(s) ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.ERROR_ATTRIBUTES;
      append(s, attributes);

      final Language language = InjectedLanguage.findLanguageById(s);
      if (language != null) {
        final FileType fileType = language.getAssociatedFileType();
        if (fileType != null) {
          setIcon(fileType.getIcon());
          append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
          append("(" + fileType.getDescription() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
        }
      }
    }
  });
  myLanguage.addItemListener(new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent e) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
        updateHighlighters();
      }
    }
  });

  myRoot.addAncestorListener(new AncestorListenerAdapter() {
    @Override
    public void ancestorAdded(AncestorEvent event) {
      updateHighlighters();
    }
  });
}