Search in sources :

Example 1 with JBImageIcon

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();
    }
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) JBImageIcon(com.intellij.util.ui.JBImageIcon) IOException(java.io.IOException) JBImageIcon(com.intellij.util.ui.JBImageIcon) AnAction(com.intellij.openapi.actionSystem.AnAction) File(java.io.File)

Example 2 with JBImageIcon

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;
}
Also used : RetrievableIcon(com.intellij.ui.RetrievableIcon) JBImageIcon(com.intellij.util.ui.JBImageIcon) BufferedImage(java.awt.image.BufferedImage) JBImageIcon(com.intellij.util.ui.JBImageIcon) BufferedImage(java.awt.image.BufferedImage) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with JBImageIcon

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);
}
Also used : JBImageIcon(com.intellij.util.ui.JBImageIcon)

Example 4 with JBImageIcon

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);
}
Also used : ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer) NotNull(org.jetbrains.annotations.NotNull) BufferedImage(java.awt.image.BufferedImage) DnDTransferItem(com.android.tools.idea.uibuilder.model.DnDTransferItem) JBImageIcon(com.intellij.util.ui.JBImageIcon) JBImageIcon(com.intellij.util.ui.JBImageIcon)

Example 5 with JBImageIcon

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);
}
Also used : JBImageIcon(com.intellij.util.ui.JBImageIcon) BufferedImage(java.awt.image.BufferedImage) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JBImageIcon (com.intellij.util.ui.JBImageIcon)6 BufferedImage (java.awt.image.BufferedImage)4 NotNull (org.jetbrains.annotations.NotNull)2 DnDTransferItem (com.android.tools.idea.uibuilder.model.DnDTransferItem)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)1 ColoredTreeCellRenderer (com.intellij.ui.ColoredTreeCellRenderer)1 RetrievableIcon (com.intellij.ui.RetrievableIcon)1 File (java.io.File)1 IOException (java.io.IOException)1 Nullable (org.jetbrains.annotations.Nullable)1