com.intellij.openapi.util.Iconable Java Examples

The following examples show how to use com.intellij.openapi.util.Iconable. 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: Switcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(@Nonnull JList<? extends FileInfo> list, FileInfo value, int index, boolean selected, boolean hasFocus) {
  Project project = mySwitcherPanel.project;
  VirtualFile virtualFile = value.getFirst();
  String renderedName = value.getNameForRendering();
  setIcon(VfsIconUtil.getIcon(virtualFile, Iconable.ICON_FLAG_READ_STATUS, project));

  FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(virtualFile);
  open = FileEditorManager.getInstance(project).isFileOpen(virtualFile);

  boolean hasProblem = WolfTheProblemSolver.getInstance(project).isProblemFile(virtualFile);
  TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null, hasProblem ? JBColor.red : null, EffectType.WAVE_UNDERSCORE, Font.PLAIN);
  append(renderedName, SimpleTextAttributes.fromTextAttributes(attributes));

  // calc color the same way editor tabs do this, i.e. including EPs
  Color color = EditorTabPresentationUtil.getFileBackgroundColor(project, virtualFile);

  if (!selected && color != null) {
    setBackground(color);
  }
  SpeedSearchUtil.applySpeedSearchHighlighting(mySwitcherPanel, this, false, selected);

  IdeDocumentHistoryImpl.appendTimestamp(project, this, virtualFile);
}
 
Example #2
Source File: SoyPsiElementPresentationFactory.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
static ItemPresentation getItemPresentation(PsiNamedElement element) {
  return new ItemPresentation() {

    @Nullable
    @Override
    public String getPresentableText() {
      return element.getName();
    }

    @Nullable
    @Override
    public String getLocationString() {
      return null;
    }

    @Nullable
    @Override
    public Icon getIcon(boolean unused) {
      return element.getIcon(Iconable.ICON_FLAG_READ_STATUS);
    }
  };
}
 
Example #3
Source File: FileChooserDialogImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showRecentFilesPopup() {
  final JBList files = new JBList(getRecentFiles()) {
    @Override
    public Dimension getPreferredSize() {
      return new Dimension(myPathTextField.getField().getWidth(), super.getPreferredSize().height);
    }
  };
  files.setCellRenderer(new ColoredListCellRenderer() {
    @Override
    protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      final String path = value.toString();
      append(path);
      final VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
      if (file != null) {
        setIcon(VfsIconUtil.getIcon(file, Iconable.ICON_FLAG_READ_STATUS, null));
      }
    }
  });
  JBPopupFactory.getInstance().createListPopupBuilder(files).setItemChoosenCallback(new Runnable() {
    @Override
    public void run() {
      myPathTextField.getField().setText(files.getSelectedValue().toString());
    }
  }).createPopup().showUnderneathOf(myPathTextField.getField());
}
 
Example #4
Source File: ThriftSubDeclarationPresentationProvider.java    From intellij-thrift with Apache License 2.0 6 votes vote down vote up
@Override
public ItemPresentation getPresentation(final ThriftSubDeclaration item) {
  return new ItemPresentation() {
    @Nullable
    @Override
    public String getPresentableText() {
      return item.getName();
    }

    @Nullable
    @Override
    public String getLocationString() {
      ThriftTopLevelDeclaration topLevelDeclaration = PsiTreeUtil.getParentOfType(item, ThriftTopLevelDeclaration.class, true);
      return topLevelDeclaration != null ? topLevelDeclaration.getName() : item.getContainingFile().getName();
    }

    @Nullable
    @Override
    public Icon getIcon(boolean unused) {
      return item.getIcon(Iconable.ICON_FLAG_VISIBILITY);
    }
  };
}
 
Example #5
Source File: ThriftTopLevelDeclarationPresentationProvider.java    From intellij-thrift with Apache License 2.0 6 votes vote down vote up
@Override
public ItemPresentation getPresentation(final ThriftDeclaration item) {
  return new ItemPresentation() {
    @Nullable
    @Override
    public String getPresentableText() {
      return item.getName();
    }

    @Nullable
    @Override
    public String getLocationString() {
      PsiFile containingFile = item.getContainingFile();
      return containingFile == null ? null : containingFile.getName();
    }

    @Nullable
    @Override
    public Icon getIcon(boolean unused) {
      return item.getIcon(Iconable.ICON_FLAG_VISIBILITY);
    }
  };
}
 
Example #6
Source File: CSharpLookupElementBuilder.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
private static <E extends DotNetGenericParameterListOwner & DotNetQualifiedElement> LookupElementBuilder buildTypeLikeElement(@Nonnull E element, @Nonnull DotNetGenericExtractor extractor)
{
	String genericText = CSharpElementPresentationUtil.formatGenericParameters(element, extractor);

	String name = CSharpNamedElement.getEscapedName(element);

	LookupElementBuilder builder = LookupElementBuilder.create(element, name + (extractor == DotNetGenericExtractor.EMPTY ? "" : genericText));

	builder = builder.withPresentableText(name); // always show only name

	builder = builder.withIcon(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY));

	builder = builder.withTypeText(element.getPresentableParentQName());

	builder = builder.withTailText(genericText, true);

	if(extractor == DotNetGenericExtractor.EMPTY)
	{
		builder = withGenericInsertHandler(element, builder);
	}
	return builder;
}
 
Example #7
Source File: JSGraphQLEndpointIconProvider.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public Icon getIcon(@NotNull PsiElement element, @Iconable.IconFlags int flags) {
    if (element.getLanguage() != JSGraphQLEndpointLanguage.INSTANCE) {
        return null;
    }
    if (element instanceof JSGraphQLEndpointNamedTypeDef) {
        if (element.getParent() instanceof JSGraphQLEndpointNamedTypeDefinition) {
            return getTypeDefinitionIcon((JSGraphQLEndpointNamedTypeDefinition) element.getParent());
        }
    }
    if (element instanceof JSGraphQLEndpointNamedTypeDefinition) {
        return getTypeDefinitionIcon((JSGraphQLEndpointNamedTypeDefinition) element);
    }
    if (element instanceof JSGraphQLEndpointProperty) {
        return JSGraphQLIcons.Schema.Field;
    }
    if (element instanceof JSGraphQLEndpointInputValueDefinition) {
        return JSGraphQLIcons.Schema.Attribute;
    }
    if(element instanceof JSGraphQLEndpointImportDeclaration) {
        return JSGraphQLIcons.Files.GraphQLSchema;
    }
    return null;
}
 
Example #8
Source File: PsiFileNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateImpl(PresentationData data) {
  PsiFile value = getValue();
  data.setPresentableText(value.getName());
  data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS));

  VirtualFile file = getVirtualFile();
  if (file != null && file.is(VFileProperty.SYMLINK)) {
    String target = file.getCanonicalPath();
    if (target == null) {
      data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
      data.setTooltip(CommonBundle.message("vfs.broken.link"));
    }
    else {
      data.setTooltip(FileUtil.toSystemDependentName(target));
    }
  }
}
 
Example #9
Source File: AnnotationIconProvider.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public Icon getIcon(@NotNull PsiElement element, @Iconable.IconFlags int flags) {
    if (element instanceof PhpFile && PhpPsiUtil.findClasses((PhpFile)element, AnnotationUtil::isAnnotationClass).size() == 1) {
        return PlatformIcons.ANNOTATION_TYPE_ICON;
    }

    return null;
}
 
Example #10
Source File: HaxeIconProvider.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon(@NotNull PsiElement element, @Iconable.IconFlags int flags) {
  if (element instanceof HaxeFile) {
    return getHaxeFileIcon((HaxeFile)element, flags);
  }
  return null;
}
 
Example #11
Source File: ThriftIconProvider.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Icon getIcon(@NotNull PsiElement element, @Iconable.IconFlags int flags) {
  if (element instanceof ThriftConst) {
    return ThriftIcons.CONST;
  }
  if (element instanceof ThriftEnum) {
    return ThriftIcons.ENUM;
  }
  if (element instanceof ThriftException) {
    return ThriftIcons.EXCEPTION;
  }
  if (element instanceof ThriftService) {
    return ThriftIcons.SERVICE;
  }
  if (element instanceof ThriftStruct) {
    return ThriftIcons.STRUCT;
  }
  if (element instanceof ThriftTypedef) {
    return ThriftIcons.TYPEDEF;
  }
  if (element instanceof ThriftUnion) {
    return ThriftIcons.UNION;
  }
  if (element instanceof ThriftField) {
    return AllIcons.Nodes.Field;
  }
  if (element instanceof ThriftFunction) {
    return AllIcons.Nodes.Method;
  }
  return null;
}
 
Example #12
Source File: PsiTreeElementBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Image getIcon() {
  final PsiElement element = getElement();
  if (element != null) {
    int flags = Iconable.ICON_FLAG_READ_STATUS;
    if (!(element instanceof PsiFile) || !element.isWritable()) flags |= Iconable.ICON_FLAG_VISIBILITY;
    return IconDescriptorUpdaters.getIcon(element, flags);
  }
  else {
    return null;
  }
}
 
Example #13
Source File: VfsIconUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Image getIcon(@Nonnull final VirtualFile file, @Iconable.IconFlags final int flags, @Nullable final Project project) {
  Image icon = Iconable.LastComputedIcon.get(file, flags);
  if (icon == null) {
    icon = VirtualFilePresentation.getIcon(file);
  }

  return IconDeferrer.getInstance().defer(icon, new AnyIconKey<>(file, project, flags), ourVirtualFileIconFunc);
}
 
Example #14
Source File: TreeComboBox.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Icon getValueIcon(final Object value, final int index) {
  if (value instanceof CustomPresentation) {
    return ((CustomPresentation)value).getIcon(index, 0);
  }
  if (value instanceof Iconable) {
    return TargetAWT.to(((Iconable)value).getIcon(0));
  }

  return null;
}
 
Example #15
Source File: CachedIntentions.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Image getIcon(@Nonnull IntentionActionWithTextCaching value) {
  if (value.getIcon() != null) {
    return value.getIcon();
  }

  IntentionAction action = value.getAction();

  while (action instanceof IntentionActionDelegate) {
    action = ((IntentionActionDelegate)action).getDelegate();
  }
  Object iconable = action;
  //custom icon
  if (action instanceof QuickFixWrapper) {
    iconable = ((QuickFixWrapper)action).getFix();
  }

  if (iconable instanceof Iconable) {
    final Image icon = ((Iconable)iconable).getIcon(0);
    if (icon != null) {
      return icon;
    }
  }

  if (IntentionManagerSettings.getInstance().isShowLightBulb(action)) {
    return myErrorFixes.contains(value) ? AllIcons.Actions.QuickfixBulb : myInspectionFixes.contains(value) ? AllIcons.Actions.IntentionBulb : AllIcons.Actions.RealIntentionBulb;
  }
  else {
    if (myErrorFixes.contains(value)) return AllIcons.Actions.QuickfixOffBulb;
    return ImageEffects.grayed(AllIcons.Actions.RealIntentionBulb);
  }
}
 
Example #16
Source File: RefElementImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Icon getIcon(final boolean expanded) {
  final PsiElement element = getPsiElement();
  if (element != null && element.isValid()) {
    return TargetAWT.to(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS));
  }
  return null;
}
 
Example #17
Source File: IconDescriptorUpdaters.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public static Image getIcon(@Nonnull final PsiElement element, @Iconable.IconFlags final int flags) {
  if (!element.isValid()) return AllIcons.Nodes.NodePlaceholder;

  Image baseIcon = Iconable.LastComputedIcon.get(element, flags);
  if (baseIcon == null) {
    baseIcon = computeBaseIcon(element, flags);
  }
  return IconDeferrer.getInstance().defer(baseIcon, new ElementIconRequest(element, flags), ourIconCompute);
}
 
Example #18
Source File: IconDescriptorUpdaters.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Image computeBaseIcon(@Nonnull PsiElement element, int flags) {
  Image icon = computeBaseIcon(element);
  if ((flags & Iconable.ICON_FLAG_VISIBILITY) > 0) {
    return ImageEffects.appendRight(icon, ourVisibilityIconPlaceholder.getValue());
  }
  return icon;
}
 
Example #19
Source File: LockedIconDescriptorUpdater.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public void updateIcon(@Nonnull IconDescriptor iconDescriptor, @Nonnull PsiElement element, int flags) {
  if (BitUtil.isSet(flags, Iconable.ICON_FLAG_READ_STATUS)) {
    VirtualFile file = PsiUtilCore.getVirtualFile(element);
    final boolean isLocked = !element.isWritable() || !WritingAccessProvider.isPotentiallyWritable(file, element.getProject());

    if (isLocked) {
      iconDescriptor.addLayerIcon(AllIcons.Nodes.Locked);
    }
  }
}
 
Example #20
Source File: DefaultLookupItemRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Icon _getRawIcon(LookupElement item, boolean real) {
  if (item instanceof LookupItem) {
    Icon icon = (Icon)((LookupItem)item).getAttribute(LookupItem.ICON_ATTR);
    if (icon != null) return icon;
  }

  Object o = item.getObject();

  if (!real) {
    if (item.getObject() instanceof String) {
      return EmptyIcon.ICON_0;
    }

    return new EmptyIcon(IconUtil.getDefaultNodeIconSize() * 2, IconUtil.getDefaultNodeIconSize());
  }

  if (o instanceof Iconable && !(o instanceof PsiElement)) {
    return TargetAWT.to(((Iconable)o).getIcon(Iconable.ICON_FLAG_VISIBILITY));
  }

  final PsiElement element = item.getPsiElement();
  if (element != null && element.isValid()) {
    return TargetAWT.to(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY));
  }
  return null;
}
 
Example #21
Source File: SpecTreeElementFactory.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon(boolean open) {
  if (value instanceof Iconable) {
    return ((Iconable) value).getIcon(Iconable.ICON_FLAG_READ_STATUS);
  }
  return null;
}
 
Example #22
Source File: CSharpBaseGroupingRule.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Image getIcon()
{
	T element = myPointer.getElement();
	if(element == null)
	{
		return null;
	}
	return IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
}
 
Example #23
Source File: AbstractPsiBasedNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Iconable.IconFlags
protected int getIconableFlags() {
  int flags = 0;
  if (isMarkReadOnly()) {
    flags |= Iconable.ICON_FLAG_READ_STATUS;
  }
  return flags;
}
 
Example #24
Source File: CSharpMemberChooseObject.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public void renderTreeNode(SimpleColoredComponent component, JTree tree)
{
	component.setIcon(IconDescriptorUpdaters.getIcon(myDeclaration, Iconable.ICON_FLAG_VISIBILITY));
	component.append(getPresentationText());
}
 
Example #25
Source File: MethodNodeBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void customizeRenderer(ColoredTreeCellRenderer renderer) {
  if (myMethod == null) return;
  int flags = Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS;
  renderer.setIcon(IconDescriptorUpdaters.getIcon(myMethod, flags));

  customizeRendererText(renderer);
}
 
Example #26
Source File: ReferenceNode.java    From intellij-reference-diagram with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon() {
    if (getIdentifyingElement() instanceof PsiMethod && ((PsiMethod) getIdentifyingElement()).isConstructor()) {
        return UmlIcons.Constructor;
    }
    return getElement().getIcon(Iconable.ICON_FLAG_VISIBILITY);
}
 
Example #27
Source File: HaxeIconProvider.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Icon getHaxeFileIcon(HaxeFile file, @Iconable.IconFlags int flags) {
  final String fileName = FileUtil.getNameWithoutExtension(file.getName());
  for (HaxeComponent component : HaxeResolveUtil.findComponentDeclarations(file)) {
    if (fileName.equals(component.getName())) {
      return component.getIcon(flags);
    }
  }
  return null;
}
 
Example #28
Source File: BasePsiNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon() {
  final PsiElement element = getPsiElement();
  if (myIcon == null) {
    myIcon = element != null && element.isValid() ? TargetAWT.to(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS)) : null;
  }
  return myIcon;
}
 
Example #29
Source File: SmartElementDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public boolean update() {
  PsiElement element = mySmartPointer.getElement();
  if (element == null) return true;
  int flags = Iconable.ICON_FLAG_VISIBILITY;
  if (isMarkReadOnly()){
    flags |= Iconable.ICON_FLAG_READ_STATUS;
  }
  consulo.ui.image.Image icon = null;
  try {
    icon = IconDescriptorUpdaters.getIcon(element, flags);
  }
  catch (IndexNotReadyException ignored) {
  }
  Color color = null;

  if (isMarkModified() ){
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
    if (virtualFile != null) {
      color = FileStatusManager.getInstance(myProject).getStatus(virtualFile).getColor();
    }
  }
  if (CopyPasteManager.getInstance().isCutElement(element)) {
    color = CopyPasteManager.CUT_COLOR;
  }

  boolean changes = !Comparing.equal(icon, getIcon()) || !Comparing.equal(color, myColor);
  setIcon(icon);
  myColor = color;
  return changes;
}
 
Example #30
Source File: IconUtilEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Image getIcon(Object object, @Iconable.IconFlags int flags, Project project) {
  if (object instanceof PsiElement) {
    return IconDescriptorUpdaters.getIcon(((PsiElement)object), flags);
  }
  if (object instanceof Module) {
    return AllIcons.Nodes.Module;
  }
  if (object instanceof VirtualFile) {
    VirtualFile file = (VirtualFile)object;
    return VfsIconUtil.getIcon(file, flags, project);
  }
  return null;
}