@NotNull public static Icon cropIcon(@NotNull Icon icon, int maxWidth, int maxHeight) { if (icon.getIconHeight() <= maxHeight && icon.getIconWidth() <= maxWidth) { return icon; } final int w = Math.min(icon.getIconWidth(), maxWidth); final int h = Math.min(icon.getIconHeight(), maxHeight); final BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration() .createCompatibleImage( icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT); final Graphics2D g = image.createGraphics(); icon.paintIcon(new JPanel(), g, 0, 0); g.dispose(); final BufferedImage img = UIUtil.createImage(w, h, Transparency.TRANSLUCENT); final int offX = icon.getIconWidth() > maxWidth ? (icon.getIconWidth() - maxWidth) / 2 : 0; final int offY = icon.getIconHeight() > maxHeight ? (icon.getIconHeight() - maxHeight) / 2 : 0; for (int col = 0; col < w; col++) { for (int row = 0; row < h; row++) { img.setRGB(col, row, image.getRGB(col + offX, row + offY)); } } return new ImageIcon(img); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); AnAction action = getAction(); if (action instanceof ActivateCard) { Rectangle bounds = getBounds(); Icon icon = AllIcons.Actions.Forward; // AllIcons.Icons.Ide.NextStepGrayed; int y = (bounds.height - icon.getIconHeight()) / 2; int x = bounds.width - icon.getIconWidth() - 15; if (getPopState() == POPPED) { final GraphicsConfig config = GraphicsUtil.setupAAPainting(g); g.setColor(WelcomeScreenColors.CAPTION_BACKGROUND); g.fillOval(x - 3, y - 3, icon.getIconWidth() + 6, icon.getIconHeight() + 6); g.setColor(WelcomeScreenColors.GROUP_ICON_BORDER_COLOR); g.drawOval(x - 3, y - 3, icon.getIconWidth() + 6, icon.getIconHeight() + 6); config.restore(); } else { icon = IconLoader.getDisabledIcon(icon); } icon.paintIcon(this, g, x, y); } }
protected JLabel createActionLabel( final AnAction anAction, final String anActionName, final Color fg, final Color bg, final Icon icon) { final LayeredIcon layeredIcon = new LayeredIcon(2); layeredIcon.setIcon(EMPTY_ICON, 0); if (icon != null && icon.getIconWidth() <= EMPTY_ICON.getIconWidth() && icon.getIconHeight() <= EMPTY_ICON.getIconHeight()) { layeredIcon.setIcon( icon, 1, (-icon.getIconWidth() + EMPTY_ICON.getIconWidth()) / 2, (EMPTY_ICON.getIconHeight() - icon.getIconHeight()) / 2); } final Shortcut[] shortcutSet = KeymapManager.getInstance().getActiveKeymap().getShortcuts(getActionId(anAction)); final String actionName = anActionName + (shortcutSet != null && shortcutSet.length > 0 ? " (" + KeymapUtil.getShortcutText(shortcutSet[0]) + ")" : ""); final JLabel actionLabel = new JLabel(actionName, layeredIcon, SwingConstants.LEFT); actionLabel.setBackground(bg); actionLabel.setForeground(fg); return actionLabel; }
public void paintIcon(Graphics g) { final BufferedImage image = new BufferedImage( myIcon.getIconWidth(), myIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D gg = image.createGraphics(); myIcon.paintIcon(this, gg, 0, 0); final Rectangle bounds = g.getClipBounds(); int y = myIcon.getIconHeight() - 1; while (y < bounds.y + bounds.height) { g.drawImage( image, bounds.x, y, bounds.x + bounds.width, y + 1, 0, myIcon.getIconHeight() - 1, bounds.width, myIcon.getIconHeight(), this); y++; } g.drawImage(image, 0, 0, this); }
@NotNull public static Icon colorize(@NotNull final Icon source, @NotNull Color color, boolean keepGray) { float[] base = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); final BufferedImage image = UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT); final Graphics2D g = image.createGraphics(); source.paintIcon(null, g, 0, 0); g.dispose(); final BufferedImage img = UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT); int[] rgba = new int[4]; float[] hsb = new float[3]; for (int y = 0; y < image.getRaster().getHeight(); y++) { for (int x = 0; x < image.getRaster().getWidth(); x++) { image.getRaster().getPixel(x, y, rgba); if (rgba[3] != 0) { Color.RGBtoHSB(rgba[0], rgba[1], rgba[2], hsb); int rgb = Color.HSBtoRGB(base[0], base[1] * (keepGray ? hsb[1] : 1f), base[2] * hsb[2]); img.getRaster() .setPixel(x, y, new int[] {rgb >> 16 & 0xff, rgb >> 8 & 0xff, rgb & 0xff, rgba[3]}); } } } return createImageIcon(img); }
/** * 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)) { LOG.error(icon); // # 22481 return EMPTY_ICON; } final int scale = UIUtil.isRetina() ? 2 : 1; @SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage( scale * icon.getIconWidth(), 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.isRetina()) img = RetinaImage.createFrom(img, 2, ImageLoader.ourComponent); disabledIcon = new JBImageIcon(img); ourIcon2DisabledIcon.put(icon, disabledIcon); } return disabledIcon; }
public static void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g = g.create(x, y, width, height); // corners TL.paintIcon(c, g, x, y); BL.paintIcon(c, g, x, y + height - BL.getIconHeight()); TR.paintIcon(c, g, x + width - TR.getIconWidth(), y); BR.paintIcon(c, g, x + width - BR.getIconWidth(), y + height - BR.getIconHeight()); // top and bottom lines int xOffset = x + TL.getIconWidth(); int stop = x + width - TR.getIconWidth(); int top = y; int bottom = y + height - B.getIconHeight(); g.setClip(xOffset, y, width - L.getIconWidth() - R.getIconWidth(), height); while (xOffset < stop) { T.paintIcon(c, g, xOffset, top); B.paintIcon(c, g, xOffset, bottom); xOffset += T.getIconWidth(); } // left and right lines int left = x; int right = x + width - R.getIconWidth(); int yOffset = y + T.getIconHeight(); stop = y + height - B.getIconHeight(); g.setClip(x, yOffset, width, height - T.getIconHeight() - B.getIconHeight()); while (yOffset < stop) { L.paintIcon(c, g, left, yOffset); R.paintIcon(c, g, right, yOffset); yOffset += L.getIconHeight(); } g.dispose(); }
public void paintShadow(Component c, Graphics2D g, int x, int y, int width, int height) { final int leftSize = myLeft.getIconWidth(); final int rightSize = myRight.getIconWidth(); final int bottomSize = myBottom.getIconHeight(); final int topSize = myTop.getIconHeight(); myTopLeft.paintIcon(c, g, x, y); myTopRight.paintIcon(c, g, x + width - myTopRight.getIconWidth(), y); myBottomRight.paintIcon( c, g, x + width - myBottomRight.getIconWidth(), y + height - myBottomRight.getIconHeight()); myBottomLeft.paintIcon(c, g, x, y + height - myBottomLeft.getIconHeight()); for (int _x = myTopLeft.getIconWidth(); _x < width - myTopRight.getIconWidth(); _x++) { myTop.paintIcon(c, g, _x + x, y); } for (int _x = myBottomLeft.getIconWidth(); _x < width - myBottomLeft.getIconWidth(); _x++) { myBottom.paintIcon(c, g, _x + x, y + height - bottomSize); } for (int _y = myTopLeft.getIconHeight(); _y < height - myBottomLeft.getIconHeight(); _y++) { myLeft.paintIcon(c, g, x, _y + y); } for (int _y = myTopRight.getIconHeight(); _y < height - myBottomRight.getIconHeight(); _y++) { myRight.paintIcon(c, g, x + width - rightSize, _y + y); } if (myBorderColor != null) { g.setColor(myBorderColor); g.drawRect( x + leftSize - 1, y + topSize - 1, width - leftSize - rightSize + 1, height - topSize - bottomSize + 1); } }
public static Icon getEvenIcon(Icon icon) { LayeredIcon layeredIcon = new LayeredIcon(2); layeredIcon.setIcon(EMPTY_ICON, 0); if (icon != null && icon.getIconHeight() <= EMPTY_ICON.getIconHeight() && icon.getIconWidth() <= EMPTY_ICON.getIconWidth()) { layeredIcon.setIcon( icon, 1, (-icon.getIconWidth() + EMPTY_ICON.getIconWidth()) / 2, (EMPTY_ICON.getIconHeight() - icon.getIconHeight()) / 2); } return layeredIcon; }
public int getIconHeight() { Icon lafIcon = getLaFIcon(); if (lafIcon != null) { return lafIcon.getIconHeight(); } Icon icon = getIcon(); int height = 0; if (icon != null) { height = icon.getIconHeight() + 2 * OFFSET; } else { Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPCHECK); height = skin.getHeight() + 2 * OFFSET; } return height; }
public static Icon augmentIcon(@Nullable Icon icon, @NotNull Icon standard) { if (icon == null) { return standard; } if (icon.getIconHeight() < standard.getIconHeight() || icon.getIconWidth() < standard.getIconWidth()) { final LayeredIcon layeredIcon = new LayeredIcon(2); layeredIcon.setIcon(icon, 0, 0, (standard.getIconHeight() - icon.getIconHeight()) / 2); layeredIcon.setIcon(standard, 1); return layeredIcon; } return icon; }
int updateMaximumWidth(final LookupElementPresentation p, LookupElement item) { final Icon icon = p.getIcon(); if (icon != null && (icon.getIconWidth() > myEmptyIcon.getIconWidth() || icon.getIconHeight() > myEmptyIcon.getIconHeight())) { myEmptyIcon = new EmptyIcon( Math.max(icon.getIconWidth(), myEmptyIcon.getIconWidth()), Math.max(icon.getIconHeight(), myEmptyIcon.getIconHeight())); } return RealLookupElementPresentation.calculateWidth( p, getRealFontMetrics(item, false), getRealFontMetrics(item, true)) + AFTER_TAIL + AFTER_TYPE; }
private void calcMaxIconSize(final ActionGroup actionGroup) { AnAction[] actions = actionGroup.getChildren(createActionEvent(actionGroup)); for (AnAction action : actions) { if (action == null) continue; if (action instanceof ActionGroup) { final ActionGroup group = (ActionGroup) action; if (!group.isPopup()) { calcMaxIconSize(group); continue; } } Icon icon = action.getTemplatePresentation().getIcon(); if (icon == null && action instanceof Toggleable) icon = PlatformIcons.CHECK_ICON; if (icon != null) { final int width = icon.getIconWidth(); final int height = icon.getIconHeight(); if (myMaxIconWidth < width) { myMaxIconWidth = width; } if (myMaxIconHeight < height) { myMaxIconHeight = height; } } } }
@Override public void paint(Component c, Graphics g, Rectangle r) { DaemonCodeAnalyzerStatus status = getDaemonCodeAnalyzerStatus(false, mySeverityRegistrar); Icon icon = getIcon(status); int height = icon.getIconHeight(); int width = icon.getIconWidth(); int x = r.x + (r.width - width) / 2; int y = r.y + (r.height - height) / 2; icon.paintIcon(c, g, x, y); /* if (status != null && status.enabled && !status.errorAnalyzingFinished) { Color oldColor = g.getColor(); g.setColor(Color.gray); //UIUtil.drawDottedRectangle(g, x, y, x + width, y + height); Graphics2D g2 = (Graphics2D)g; final Stroke saved = g2.getStroke(); g2.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[]{3,1,1,1}, System.currentTimeMillis() % 400 / 100)); g2.drawRect(x-1, y-1, width, height); //g2.drawRect(r.x, r.y, r.width, r.height); g2.setStroke(saved); g.setColor(oldColor); } */ }
private Icon getIcon(DaemonCodeAnalyzerStatus status) { if (status == null) { return NO_ICON; } if (status.noHighlightingRoots != null && status.noHighlightingRoots.length == status.rootsNumber) { return NO_ANALYSIS_ICON; } Icon icon = HighlightDisplayLevel.DO_NOT_SHOW.getIcon(); for (int i = status.errorCount.length - 1; i >= 0; i--) { if (status.errorCount[i] != 0) { icon = mySeverityRegistrar.getRendererIconByIndex(i); break; } } if (status.errorAnalyzingFinished) { if (myProject != null && DumbService.isDumb(myProject)) { return new LayeredIcon(NO_ANALYSIS_ICON, icon, STARING_EYE_ICON); } return icon; } if (!status.enabled) return NO_ANALYSIS_ICON; double progress = getOverallProgress(status); TruncatingIcon trunc = new TruncatingIcon(icon, icon.getIconWidth(), (int) (icon.getIconHeight() * progress)); return new LayeredIcon(NO_ANALYSIS_ICON, trunc, STARING_EYE_ICON); }
public void paint(Graphics g) { Dimension size = getSize(); Color colors[]; if (isEnabled()) { if (getModel().isArmed() && getModel().isPressed()) { colors = BaseLookAndFeel.getTheme().getPressedColors(); } else if (getModel().isRollover()) { colors = BaseLookAndFeel.getTheme().getRolloverColors(); } else { colors = BaseLookAndFeel.getTheme().getButtonColors(); } } else { colors = BaseLookAndFeel.getTheme().getDisabledColors(); } Utilities.fillHorGradient(g, colors, 0, 0, size.width, size.height); boolean inverse = ColorHelper.getGrayValue(colors) < 128; Icon icon = inverse ? BaseIcons.getComboBoxInverseIcon() : BaseIcons.getComboBoxIcon(); int x = (size.width - icon.getIconWidth()) / 2; int y = (size.height - icon.getIconHeight()) / 2; Graphics2D g2D = (Graphics2D) g; Composite savedComposite = g2D.getComposite(); g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); if (getModel().isPressed() && getModel().isArmed()) { icon.paintIcon(this, g, x + 2, y + 1); } else { icon.paintIcon(this, g, x + 1, y); } g2D.setComposite(savedComposite); paintBorder(g2D); }
public int getIconHeight(SynthContext context) { Icon icon = getIcon(context); if (icon != null) { return icon.getIconHeight(); } return 0; }
@NotNull private static Icon createEmptyIconLike(@NotNull String baseIconPath) { Icon baseIcon = IconLoader.findIcon(baseIconPath); if (baseIcon == null) { return EmptyIcon.ICON_16; } return new EmptyIcon(baseIcon.getIconWidth(), baseIcon.getIconHeight()); }
protected void paintComponent(Graphics g) { final Border border = getBorder(); int shiftX = 0; int shiftY = 0; if (border != null) { shiftX = border.getBorderInsets(this).left; shiftY = border.getBorderInsets(this).top; } setForeground(getTextColor()); super.paintComponent(g); if (getText() != null) { g.setColor(getTextColor()); int x = myIconWidth; int y = getTextBaseLine(); if (myUnderline) { int k = 1; if (getFont().getSize() > 11) { k += (getFont().getSize() - 11); } y += k; int lineY = y + shiftY; if (lineY >= getSize().height) { lineY = getSize().height - 1; } if (getHorizontalAlignment() == LEFT) { UIUtil.drawLine( g, x + shiftX, lineY, x + getFontMetrics(getFont()).stringWidth(getText()) + shiftX, lineY); } else { UIUtil.drawLine( g, getWidth() - 1 - getFontMetrics(getFont()).stringWidth(getText()) + shiftX, lineY, getWidth() - 1 + shiftX, lineY); } } else { } if (myPaintDefaultIcon) { int endX = myIconWidth + getFontMetrics(getFont()).stringWidth(getText()); int endY = getHeight() / 2 - LINK.getIconHeight() / 2 + 1; LINK.paintIcon(this, g, endX + shiftX + DEFAULT_ICON_GAP, endY); } } }
static Icon reescala(Icon ic, int maxW, int maxH) { if (ic == null) { return null; } if (ic.getIconHeight() == maxH && ic.getIconWidth() == maxW) { return ic; } BufferedImage bi = new BufferedImage(ic.getIconHeight(), ic.getIconWidth(), BufferedImage.TYPE_INT_ARGB); Graphics g = bi.createGraphics(); ic.paintIcon(null, g, 0, 0); g.dispose(); Image bf = bi.getScaledInstance(maxW, maxH, Image.SCALE_SMOOTH); return new ImageIcon(bf); }
@NotNull private static Icon getEmptyPinIcon() { if (ourEmptyPinIcon == null) { Icon icon = AllIcons.Nodes.PinToolWindow; int width = icon.getIconWidth(); ourEmptyPinIcon = IconUtil.cropIcon( icon, new Rectangle(width / 2, 0, width - width / 2, icon.getIconHeight())); } return ourEmptyPinIcon; }
private void recalculateSize() { int width = 0; int height = 0; for (Icon icon : myIcons) { if (icon == null) continue; width += icon.getIconWidth(); // height += icon.getIconHeight(); height = Math.max(height, icon.getIconHeight()); } myWidth = width; myHeight = height; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { int _x = x; int _y = y; for (Icon icon : myIcons) { if (icon == null) continue; switch (myAlignment) { case TOP: _y = y; break; case CENTER: _y = y + (myHeight - icon.getIconHeight()) / 2; break; case BOTTOM: _y = y + (myHeight - icon.getIconHeight()); break; } icon.paintIcon(c, g, _x, _y); _x += icon.getIconWidth(); // _y += icon.getIconHeight(); } }
@Override public void paint(Graphics2D g) { Icon icon = swingImage.getIcon(); if (icon != null) { ImageView node = getNode(); swingImage.setBounds( node.getX().intValue(), node.getY().intValue(), icon.getIconWidth(), icon.getIconHeight()); swingImage.paint(g); } }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Dimension dim = getSize(); Insets ins = getInsets(); // if there is popup menu, paint triangle in lower right corner if (pop != null) { int x = dim.width - ins.right - i.getIconWidth(); int y = dim.width - ins.right - i.getIconHeight(); i.paintIcon(this, g, x, y); } }
protected boolean doSetIcon( DefaultMutableTreeNode node, @Nullable String path, Component component) { if (StringUtil.isNotEmpty(path) && !new File(path).isFile()) { Messages.showErrorDialog( component, IdeBundle.message("error.file.not.found.message", path), IdeBundle.message("title.choose.action.icon")); return false; } String actionId = getActionId(node); if (actionId == null) return false; final AnAction action = ActionManager.getInstance().getAction(actionId); if (action != null && action.getTemplatePresentation() != null) { if (StringUtil.isNotEmpty(path)) { Image image = null; try { image = ImageLoader.loadFromStream( VfsUtil.convertToURL(VfsUtil.pathToUrl(path.replace(File.separatorChar, '/'))) .openStream()); } catch (IOException e) { LOG.debug(e); } Icon icon = new File(path).exists() ? IconLoader.getIcon(image) : null; if (icon != null) { if (icon.getIconWidth() > EmptyIcon.ICON_18.getIconWidth() || icon.getIconHeight() > EmptyIcon.ICON_18.getIconHeight()) { Messages.showErrorDialog( component, IdeBundle.message("custom.icon.validation.message"), IdeBundle.message("title.choose.action.icon")); return false; } node.setUserObject(Pair.create(actionId, icon)); mySelectedSchema.addIconCustomization(actionId, path); } } else { node.setUserObject(Pair.create(actionId, null)); mySelectedSchema.removeIconCustomization(actionId); final DefaultMutableTreeNode nodeOnToolbar = findNodeOnToolbar(actionId); if (nodeOnToolbar != null) { editToolbarIcon(actionId, nodeOnToolbar); node.setUserObject(nodeOnToolbar.getUserObject()); } } return true; } return false; }
private Dimension calcTypeListPreferredSize(final ModuleType[] allModuleTypes) { int width = 0; int height = 0; final FontMetrics fontMetrics = myTypesList.getFontMetrics(myTypesList.getFont()); final int fontHeight = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); for (final ModuleType type : allModuleTypes) { final Icon icon = type.getBigIcon(); final int iconHeight = icon != null ? icon.getIconHeight() : 0; final int iconWidth = icon != null ? icon.getIconWidth() : 0; height += Math.max(iconHeight, fontHeight) + 6; width = Math.max(width, iconWidth + fontMetrics.stringWidth(type.getName()) + 10); } return new Dimension(width, height); }
protected void paintChildren(final Graphics g) { super.paintChildren(g); if (myOverlayedIcon == null || myLabel.getParent() == null) return; final Rectangle textBounds = SwingUtilities.convertRectangle(myLabel.getParent(), myLabel.getBounds(), this); if (getLayeredIcon().isLayerEnabled(1)) { final int top = (getSize().height - myOverlayedIcon.getIconHeight()) / 2; myOverlayedIcon.paintIcon(this, g, textBounds.x - myOverlayedIcon.getIconWidth() / 2, top); } }
/** Result icons look like original but have equal (maximum) size */ @NotNull public static Icon[] getEqualSizedIcons(@NotNull Icon... icons) { Icon[] result = new Icon[icons.length]; int width = 0; int height = 0; for (Icon icon : icons) { width = Math.max(width, icon.getIconWidth()); height = Math.max(height, icon.getIconHeight()); } for (int i = 0; i < icons.length; i++) { result[i] = new IconSizeWrapper(icons[i], width, height); } return result; }
/** * Metodo che prende una icona e la bufferizza * * @param icon - L'icona da bufferizzare * @return L'icona bufferizzata */ public static BufferedImage iconToBufferedImage(Icon icon) { if (icon == null) { // Se non e stata fornita nessuna icona return null; } BufferedImage image = new BufferedImage( icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); // Bufferizzo l'icona fornita icon.paintIcon(null, image.getGraphics(), 0, 0); // Stampo l'icona fornita return image; // Ritorno l'icona buferizzata } // Fine iconToBufferedImage