use of com.intellij.util.ui.JBImageIcon in project intellij-community by JetBrains.
the class CustomActionsSchema method initActionIcons.
private void initActionIcons() {
ActionManager actionManager = ActionManager.getInstance();
for (String actionId : myIconCustomizations.keySet()) {
final AnAction anAction = actionManager.getAction(actionId);
if (anAction != null) {
Icon icon;
final String iconPath = myIconCustomizations.get(actionId);
if (iconPath != null && new File(FileUtil.toSystemDependentName(iconPath)).exists()) {
Image image = null;
try {
image = ImageLoader.loadFromStream(VfsUtilCore.convertToURL(VfsUtil.pathToUrl(iconPath)).openStream());
} catch (IOException e) {
LOG.debug(e);
}
icon = image == null ? null : new JBImageIcon(image);
} else {
icon = AllIcons.Toolbar.Unknown;
}
anAction.getTemplatePresentation().setIcon(icon);
anAction.getTemplatePresentation().setDisabledIcon(IconLoader.getDisabledIcon(icon));
anAction.setDefaultIcon(false);
}
}
final IdeFrameImpl frame = WindowManagerEx.getInstanceEx().getFrame(null);
if (frame != null) {
frame.updateView();
}
}
use of com.intellij.util.ui.JBImageIcon in project intellij-community by JetBrains.
the class IconLoader method getDisabledIcon.
/**
* Gets (creates if necessary) disabled icon based on the passed one.
*
* @return <code>ImageIcon</code> constructed from disabled image of passed icon.
*/
@Nullable
public static Icon getDisabledIcon(Icon icon) {
if (icon instanceof LazyIcon)
icon = ((LazyIcon) icon).getOrComputeIcon();
if (icon == null)
return null;
Icon disabledIcon = ourIcon2DisabledIcon.get(icon);
if (disabledIcon == null) {
if (!isGoodSize(icon)) {
// # 22481
LOG.error(icon);
return EMPTY_ICON;
}
if (icon instanceof CachedImageIcon) {
disabledIcon = ((CachedImageIcon) icon).asDisabledIcon();
} else {
// [tav] todo: no screen available
final float scale = UIUtil.isJreHiDPI() ? JBUI.sysScale() : 1f;
@SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage((int) (scale * icon.getIconWidth()), (int) (scale * icon.getIconHeight()), BufferedImage.TYPE_INT_ARGB);
final Graphics2D graphics = image.createGraphics();
graphics.setColor(UIUtil.TRANSPARENT_COLOR);
graphics.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
graphics.scale(scale, scale);
icon.paintIcon(LabelHolder.ourFakeComponent, graphics, 0, 0);
graphics.dispose();
Image img = ImageUtil.filter(image, UIUtil.getGrayFilter());
if (UIUtil.isJreHiDPI())
img = RetinaImage.createFrom(img, scale, null);
disabledIcon = new JBImageIcon(img);
}
ourIcon2DisabledIcon.put(icon, disabledIcon);
}
return disabledIcon;
}
use of com.intellij.util.ui.JBImageIcon in project android by JetBrains.
the class PreviewIconsPanel method updateImage.
private static void updateImage(@NotNull ImageComponent imageComponent, @NotNull BufferedImage sourceImage) {
JBImageIcon icon = IconUtil.createImageIcon(sourceImage);
Dimension d = new Dimension(icon.getIconWidth(), icon.getIconHeight());
imageComponent.setPreferredSize(d);
imageComponent.setMinimumSize(d);
imageComponent.setIcon(icon);
}
use of com.intellij.util.ui.JBImageIcon in project android by JetBrains.
the class NlOldPalettePanel method createCellRenderer.
private void createCellRenderer(@NotNull JTree tree) {
ColoredTreeCellRenderer renderer = new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object content = node.getUserObject();
if (content instanceof Palette.Item) {
Palette.Item item = (Palette.Item) content;
BufferedImage image = null;
if (!needsLibraryLoad(item) && myMode == Mode.PREVIEW && myConfiguration != null) {
image = myIconFactory.getImage(item, myConfiguration, getScale(item));
}
if (image != null) {
setIcon(new JBImageIcon(image));
setToolTipText(item.getTitle());
} else if (needsLibraryLoad(item)) {
Icon icon = item.getIcon();
Icon download = AllIcons.Actions.Download;
int factor = SystemInfo.isAppleJvm ? 2 : 1;
image = UIUtil.createImage(factor * (download.getIconWidth() + icon.getIconWidth() + ICON_SPACER), factor * icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.scale(factor, factor);
icon.paintIcon(myTree, g2, 0, 0);
download.paintIcon(myTree, g2, icon.getIconWidth() + ICON_SPACER, 0);
g2.dispose();
append(item.getTitle());
setIcon(new JBImageIcon(ImageUtils.convertToRetinaIgnoringFailures(image)));
} else {
append(item.getTitle());
setIcon(item.getIcon());
}
} else if (content instanceof Palette.Group) {
Palette.Group group = (Palette.Group) content;
append(group.getName());
setIcon(AllIcons.Nodes.Folder);
}
}
};
renderer.setBorder(BorderFactory.createEmptyBorder(1, 1, 0, 0));
tree.setCellRenderer(renderer);
}
use of com.intellij.util.ui.JBImageIcon in project android by JetBrains.
the class DependencyManager method createItemIcon.
@NotNull
private Icon createItemIcon(@NotNull Palette.Item item, @NotNull Icon icon, @NotNull Icon download, @NotNull Component componentContext) {
if (!needsLibraryLoad(item)) {
return icon;
}
BufferedImage image = UIUtil.createImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) image.getGraphics();
icon.paintIcon(componentContext, g2, 0, 0);
int x = icon.getIconWidth() - download.getIconWidth();
int y = icon.getIconHeight() - download.getIconHeight();
download.paintIcon(componentContext, g2, x, y);
g2.dispose();
return new JBImageIcon(UIUtil.isRetina() ? ImageUtils.convertToRetinaIgnoringFailures(image) : image);
}
Aggregations