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; }
@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); } }
/** * 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; }
private static BufferedImage makeBufferedImage(Icon icon, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconWidth()) / 2); g.dispose(); return image; }
/** * Returns the image that matches the position of the mouse event. * * @param evt Mouse event * @return Image at mouse position, or {@code null} if there is no image at the mouse position * @since 6392 */ public ImageEntry getPhotoUnderMouse(MouseEvent evt) { if (data != null) { for (int idx = data.size() - 1; idx >= 0; --idx) { ImageEntry img = data.get(idx); if (img.getPos() == null) { continue; } Point p = Main.map.mapView.getPoint(img.getPos()); Rectangle r; if (useThumbs && img.hasThumbnail()) { Dimension d = scaledDimension(img.getThumbnail()); r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); } else { r = new Rectangle( p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2, icon.getIconWidth(), icon.getIconHeight()); } if (r.contains(evt.getPoint())) { return img; } } } return null; }
@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); }
@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); }
/** * Paint the icons of this compound icon at the specified location * * @param c The component on which the icon is painted * @param g the graphics context * @param x the X coordinate of the icon's top-left corner * @param y the Y coordinate of the icon's top-left corner */ @Override public void paintIcon(final Component c, final Graphics g, int x, int y) { if (axis == Axis.X_AXIS) { final int height = getIconHeight(); for (final Icon icon : icons) { final int iconY = getOffset(height, icon.getIconHeight(), alignmentY); icon.paintIcon(c, g, x, y + iconY); x += icon.getIconWidth() + gap; } } else if (axis == Axis.Y_AXIS) { final int width = getIconWidth(); for (final Icon icon : icons) { final int iconX = getOffset(width, icon.getIconWidth(), alignmentX); icon.paintIcon(c, g, x + iconX, y); y += icon.getIconHeight() + gap; } } else // must be Z_AXIS { final int width = getIconWidth(); final int height = getIconHeight(); for (final Icon icon : icons) { final int iconX = getOffset(width, icon.getIconWidth(), alignmentX); final int iconY = getOffset(height, icon.getIconHeight(), alignmentY); icon.paintIcon(c, g, x + iconX, y + iconY); } } }
public void paintIcon(Component c, Graphics g, int x, int y) { boolean enabled = c.isEnabled(); // paint the icon Icon paintedIcon = enabled ? icon : disabledIcon; if (paintedIcon != null) paintedIcon.paintIcon(c, g, x, y); // backup current color Color oldColor = g.getColor(); int insetx = 4; if (c instanceof JComponent) { Insets borderinset = ((JComponent) c).getBorder().getBorderInsets(c); insetx = borderinset.left; } if (paintedIcon != null) { g.translate(paintedIcon.getIconWidth() + X_GAP + insetx, 0); } arrow.paintIcon(c, g, x, y); if (paintedIcon != null) { g.translate(-paintedIcon.getIconWidth() - X_GAP - insetx, 0); } // restore previous color g.setColor(oldColor); }
/** Creates a disabled checkbox icon. */ private static Icon createDisabledIcon(JCheckBox checkBox, Icon icon) { Image image = new BufferedImage(icon.getIconWidth(), icon.getIconWidth(), BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); checkBox.setSelected(true); icon.paintIcon(checkBox, g, 0, 0); g.dispose(); return UIManager.getLookAndFeel().getDisabledIcon(checkBox, new ImageIcon(image)); }
/** * @param icon * @param w * @param h * @param hint */ public ScaledIcon( final Icon icon, final int width, final int height, final Interpolation interpolation) { this.source = icon; this.faktor = 1d / Math.max( (double) icon.getIconWidth() / width, (double) icon.getIconHeight() / height); this.width = Math.max((int) (icon.getIconWidth() * this.faktor), 1); this.height = Math.max((int) (icon.getIconHeight() * this.faktor), 1); this.interpolation = interpolation; }
static void printIcon(PrintWriter html, Icon icon) { html.println("<td>Icon " + icon.getIconWidth() + " x " + icon.getIconHeight() + "</pre></td>"); BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.Clear); g2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight()); g2.setComposite(old); JButton foo = new JButton(); icon.paintIcon(foo, g2, 0, 0); g2.dispose(); html.println("<td>" + saveImage(img) + "</td>"); }
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 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 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; }
/** * The user clicked on the clarifier. * * @param x the x of the point clicked * @param y the y of the point clicked * @return the todo item clicked */ public ToDoItem hitClarifier(int x, int y) { int iconPos = 25, xOff = -4, yOff = -4; Point p = new Point(); ToDoList list = Designer.theDesigner().getToDoList(); Vector items = list.elementsForOffender(getOwner()); int size = items.size(); for (int i = 0; i < size; i++) { ToDoItem item = (ToDoItem) items.elementAt(i); Icon icon = item.getClarifier(); stuffPointAlongPerimeter(iconPos, p); int width = icon.getIconWidth(); int height = icon.getIconHeight(); if (y >= p.y + yOff && y <= p.y + height + yOff && x >= p.x + xOff && x <= p.x + width + xOff) return item; iconPos += width; } for (int i = 0; i < size; i++) { ToDoItem item = (ToDoItem) items.elementAt(i); Icon icon = item.getClarifier(); if (icon instanceof Clarifier) { ((Clarifier) icon).setFig(this); ((Clarifier) icon).setToDoItem(item); if (((Clarifier) icon).hit(x, y)) return item; } } items = list.elementsForOffender(this); size = items.size(); for (int i = 0; i < size; i++) { ToDoItem item = (ToDoItem) items.elementAt(i); Icon icon = item.getClarifier(); stuffPointAlongPerimeter(iconPos, p); int width = icon.getIconWidth(); int height = icon.getIconHeight(); if (y >= p.y + yOff && y <= p.y + height + yOff && x >= p.x + xOff && x <= p.x + width + xOff) return item; iconPos += width; } for (int i = 0; i < size; i++) { ToDoItem item = (ToDoItem) items.elementAt(i); Icon icon = item.getClarifier(); if (icon instanceof Clarifier) { ((Clarifier) icon).setFig(this); ((Clarifier) icon).setToDoItem(item); if (((Clarifier) icon).hit(x, y)) return item; } } return null; }
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); }
/** * /** paint is subclassed to draw the background correctly. JLabel currently does not allow * backgrounds other than white, and it will also fill behind the icon. Something that isn't * desirable. */ public void paint(Graphics g) { Color bColor; Icon currentI = getIcon(); if (selected) { bColor = SelectedBackgroundColor; } else if (getParent() != null) { /* Pick background color up from parent (which will come from the JTree we're contained in). */ bColor = getParent().getBackground(); } else { bColor = getBackground(); } g.setColor(bColor); if (currentI != null && getText() != null) { int offset = (currentI.getIconWidth() + getIconTextGap()); if (getComponentOrientation().isLeftToRight()) { g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); } else { g.fillRect(0, 0, getWidth() - 1 - offset, getHeight() - 1); } } else { g.fillRect(0, 0, getWidth() - 1, getHeight() - 1); } super.paint(g); }
public void paint(Graphics g, JComponent c) { if (Boolean.FALSE.equals(c.getClientProperty("roundedCorners"))) paintSquare(g, c); else paintRounded(g, c); KCollapsiblePane pane = (KCollapsiblePane) c.getClientProperty(KCollapsiblePane.HEADER_UI_PROPERTY_OWNER_PANE); if (pane != null) { Rectangle bounds = c.getBounds(); Icon arrowIcon = pane.isExpanded() ? arrowExpandedIcon : arrowCollapsedIcon; arrowIcon.paintIcon( c, g, bounds.width - arrowIcon.getIconWidth(), (bounds.height - arrowIcon.getIconWidth()) / 2); } }
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); }
@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); } */ }
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 static Icon createPartiallyIncludedIcon() { Icon icon = UIManager.getIcon("CheckBox.icon"); if (icon == null || icon.getIconWidth() == 0 || icon.getIconHeight() == 0) { icon = MetalIconFactory.getCheckBoxIcon(); } return createDisabledIcon(configureCheckBox(new JCheckBox()), icon); }
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 protected void doWidgetLayout(LayoutHelper helper) { int availableWidth = helper.getParentWidth() - (buttons.size() - 1) * 2; // account for gaps int buttonWidth = availableWidth / buttons.size(); Graphics g = buttons.get(0).getGraphics(); if (buttonWidth <= 0 || g == null) { return; } int maxTextWidth = buttonWidth - 8; // account for padding for (FLabel btn : buttons) { if (btn.getText() != null && !btn.getText().isEmpty()) { int max = maxTextWidth; Icon icon = btn.getIcon(); if (icon != null) { max -= icon.getIconWidth() + 4; } for (int fs = 11; fs > 5; fs--) { SkinFont skinFont = FSkin.getFont(fs); if (skinFont.measureTextWidth(g, btn.getText()) <= max) { btn.setFont(skinFont); break; } } } helper.include(btn, buttonWidth, 25); helper.offset(-1, 0); // keep buttons tighter together } }
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); }
/** Updates the button. */ private void updateButton() { if (!initialized) return; Icon icon = IconManager.instance().getIconForButton(iconName); if (icon == null) { super.setText(message); setVerticalTextPosition(SwingConstants.CENTER); setHorizontalTextPosition(SwingConstants.CENTER); setContentAreaFilled(true); setBorderPainted(true); setOpaque(true); } else { setIcon(icon); Icon rollover = IconManager.instance().getIconForButton(rollOverIconName); if (rollover == null) { rollover = IconManager.instance().getRolloverIconForButton(iconName); } setRolloverIcon(rollover); if (!horizontalText) { setVerticalTextPosition(SwingConstants.BOTTOM); setHorizontalTextPosition(SwingConstants.CENTER); } else { setVerticalTextPosition(SwingConstants.CENTER); setHorizontalTextPosition(SwingConstants.TRAILING); } if (useTransparentBackground) { setBorderPainted(false); setOpaque(false); setContentAreaFilled(false); } else { setBorderPainted(true); setOpaque(false); setContentAreaFilled(true); } if (!iconOnly && UISettings.TEXT_WITH_ICONS.getValue() && message != null && message.length() > 0) { super.setText(message); setPreferredSize(null); } else { super.setText(null); int height = icon.getIconHeight(); int width = icon.getIconWidth(); if (message == null || message.length() > 0) { height += 15; width += 15; } setPreferredSize(new Dimension(height, width)); } } }
public Icon getIcon(File f) { if (isDirLink(f)) { /* all of this nonsense is to get to the default file view */ System.out.println("get icon for: " + f); JFileChooser chooser = new JFileChooser(); ComponentUI ui = UIManager.getUI(chooser); System.out.println("got : " + ui); FileChooserUI fcui = (FileChooserUI) ui; fcui.installUI(chooser); FileView def = fcui.getFileView(chooser); // get the standard icon for a folder File tmp = new File("C:\\windows"); Icon folder = def.getIcon(tmp); int w = folder.getIconWidth(); int h = folder.getIconHeight(); // create a buffered image the same size as the icon Image img = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); Graphics g = img.getGraphics(); // draw the normal icon folder.paintIcon(chooser, g, 0, 0); Image shortcut = new ImageIcon("shortcut.png").getImage(); g.drawImage(shortcut, 0, 0, null); g.dispose(); return new ImageIcon(img); } return super.getIcon(f); }
@Override protected void paintOverlay(Graphics g) { if (drop != null) { final Graphics2D g2 = (Graphics2D) g.create(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); g2.setColor(Color.GREEN); for (int r = 0; r < 8; r++) { for (int c = 0; c < 8; c++) { if (drop.targets[r][c]) { g2.fillRect(x(c), y(r), w(c), h(r)); } } } int r = drop.row; int c = drop.column; if (!drop.valid) { g2.setColor(Color.RED); g2.fillRect(x(c), y(r), w(c), h(r)); } Icon icon = drop.figure.getFigure().getBigIcon(); icon.paintIcon( this, g2, x(c) + (w(c) - icon.getIconWidth()) / 2, y(r) + (h(r) - icon.getIconHeight()) / 2); g2.dispose(); } }