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); }
protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Icon icon = b.getIcon(); Icon tmpIcon = null; if (icon == null) { return; } Icon selectedIcon = null; /* the fallback icon should be based on the selected state */ if (model.isSelected()) { selectedIcon = (Icon) b.getSelectedIcon(); if (selectedIcon != null) { icon = selectedIcon; } } if (!model.isEnabled()) { if (model.isSelected()) { tmpIcon = (Icon) b.getDisabledSelectedIcon(); if (tmpIcon == null) { tmpIcon = selectedIcon; } } if (tmpIcon == null) { tmpIcon = (Icon) b.getDisabledIcon(); } } else if (model.isPressed() && model.isArmed()) { tmpIcon = (Icon) b.getPressedIcon(); if (tmpIcon != null) { // revert back to 0 offset clearTextShiftOffset(); } } else if (b.isRolloverEnabled() && model.isRollover()) { if (model.isSelected()) { tmpIcon = (Icon) b.getRolloverSelectedIcon(); if (tmpIcon == null) { tmpIcon = selectedIcon; } } if (tmpIcon == null) { tmpIcon = (Icon) b.getRolloverIcon(); } } if (tmpIcon != null) { icon = tmpIcon; } if (model.isPressed() && model.isArmed()) { icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset()); } else { icon.paintIcon(c, g, iconRect.x, iconRect.y); } }
/** * 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); } } }
@Override protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Icon icon = b.getIcon(); Icon tmpIcon = null; Icon shadowIcon = null; boolean borderHasPressedCue = borderHasPressedCue(b); if (icon == null) { return; } if (!model.isEnabled()) { if (model.isSelected()) { tmpIcon = (Icon) b.getDisabledSelectedIcon(); } else { tmpIcon = (Icon) b.getDisabledIcon(); } } else if (model.isPressed() && model.isArmed()) { tmpIcon = (Icon) b.getPressedIcon(); if (tmpIcon != null) { // revert back to 0 offset clearTextShiftOffset(); } else if (icon != null && icon instanceof ImageIcon && !borderHasPressedCue) { // Create an icon on the fly. // Note: This is only needed for borderless buttons, which // have no other way to provide feedback about the pressed // state. tmpIcon = new ImageIcon(HalfbrightFilter.createHalfbrightImage(((ImageIcon) icon).getImage())); shadowIcon = new ImageIcon(ShadowFilter.createShadowImage(((ImageIcon) icon).getImage())); } } else if (b.isRolloverEnabled() && model.isRollover()) { if (model.isSelected()) { tmpIcon = b.getRolloverSelectedIcon(); if (tmpIcon == null) { tmpIcon = b.getSelectedIcon(); } } else { tmpIcon = (Icon) b.getRolloverIcon(); } } else if (model.isSelected()) { tmpIcon = b.getSelectedIcon(); } if (tmpIcon != null) { icon = tmpIcon; } if (model.isPressed() && model.isArmed()) { if (shadowIcon != null) { shadowIcon.paintIcon( c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset() + 1); } icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset()); } else { icon.paintIcon(c, g, iconRect.x, iconRect.y); } }
@Override public final void paintIcon(InstancePainter painter) { Graphics g = painter.getGraphics(); g.setColor(Color.black); if (painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) { Icon iconRect = getIconRectangular(); if (iconRect != null) { iconRect.paintIcon(painter.getDestination(), g, 2, 2); } else { paintIconRectangular(painter); } } else if (painter.getGateShape() == AppPreferences.SHAPE_DIN40700) { Icon iconDin = getIconDin40700(); if (iconDin != null) { iconDin.paintIcon(painter.getDestination(), g, 2, 2); } else { paintIconRectangular(painter); } } else { Icon iconShaped = getIconShaped(); if (iconShaped != null) { iconShaped.paintIcon(painter.getDestination(), g, 2, 2); } else { paintIconShaped(painter); } } }
/** * Paints the thumb icon for the slider. * * @param g the graphics device. */ public void paintThumb(Graphics g) { Color save = g.getColor(); g.setColor(thumbColor); if (slider.getOrientation() == JSlider.HORIZONTAL) horizThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y); else vertThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y); g.setColor(save); }
/** * Paints the View. * * @param g the rendering surface to use * @param a the allocated region to render into * @see View#paint */ @Override public void paint(Graphics g, Shape a) { sync(); Rectangle rect = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds(); Image image = getImage(); Rectangle clip = g.getClipBounds(); fBounds.setBounds(rect); paintHighlights(g, a); paintBorder(g, rect); if (clip != null) { g.clipRect( rect.x + leftInset, rect.y + topInset, rect.width - leftInset - rightInset, rect.height - topInset - bottomInset); } if (image != null) { if (!hasPixels(image)) { // No pixels yet, use the default Icon icon = (image == null) ? getNoImageIcon() : getLoadingImageIcon(); if (icon != null) { icon.paintIcon(getContainer(), g, rect.x + leftInset, rect.y + topInset); } } else { // Draw the image g.drawImage(image, rect.x + leftInset, rect.y + topInset, width, height, imageObserver); } } else { Icon icon = getNoImageIcon(); if (icon != null) { icon.paintIcon(getContainer(), g, rect.x + leftInset, rect.y + topInset); } View view = getAltView(); // Paint the view representing the alt text, if its non-null if (view != null && ((state & WIDTH_FLAG) == 0 || width > DEFAULT_WIDTH)) { // Assume layout along the y direction Rectangle altRect = new Rectangle( rect.x + leftInset + DEFAULT_WIDTH, rect.y + topInset, rect.width - leftInset - rightInset - DEFAULT_WIDTH, rect.height - topInset - bottomInset); view.paint(g, altRect); } } if (clip != null) { // Reset clip. g.setClip(clip.x, clip.y, clip.width, clip.height); } }
public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { Icon icon = getIcon(context); if (icon != null) { if (context == null) { icon.paintIcon(null, g, x, y); } else { icon.paintIcon(context.getComponent(), g, x, y); } } }
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); } }
@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); } */ }
/** * Paints the wrapped icon with this <CODE>AlphaIcon</CODE>'s transparency. * * @param c The component to 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(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.setComposite(AlphaComposite.SrcAtop.derive(alpha)); icon.paintIcon(c, g2, x, y); g2.dispose(); }
@Override @SuppressWarnings("unchecked") public void paintIcon(final Component c, final Graphics g, final int x, final int y) { JCheckBox cb = (JCheckBox) c; javax.swing.ButtonModel model = cb.getModel(); if (ThemeManager.isLookAndFeelNimbus()) { icon.paintIcon(c, g, x, y); if (c.hasFocus()) { nimbusFocusBorder.paintBorder(g, x, y, iconWidth, iconHeight); } drawIndeterminateNimbusLine(g, x, y); } else { if (model.isEnabled()) { if (model.isPressed() && model.isArmed()) { g.setColor(MetalLookAndFeel.getControlShadow()); g.fillRect(x, y, iconWidth - 1, iconHeight - 1); drawPressed3DBorder(g, x, y, iconWidth, iconHeight); } else { drawFlush3DBorder(g, x, y, iconWidth, iconHeight); } g.setColor(MetalLookAndFeel.getControlInfo()); } else { g.setColor(MetalLookAndFeel.getControlShadow()); g.drawRect(x, y, iconWidth - 1, iconHeight - 1); } drawIndeterminateLine(g, x, y); } }
@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); }
@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(); } }
public static BufferedImage convertIconToBufferedImage(final Icon icon) { if (icon == null) { return null; } if (icon instanceof ImageIcon) { final Image ret = ((ImageIcon) icon).getImage(); if (ret instanceof BufferedImage) { return (BufferedImage) ret; } } final int w = icon.getIconWidth(); final int h = icon.getIconHeight(); final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice gd = ge.getDefaultScreenDevice(); final GraphicsConfiguration gc = gd.getDefaultConfiguration(); final BufferedImage image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT); final Graphics2D g = image.createGraphics(); g.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // g.setColor(Color.RED); // g.fillRect(0, 0, w, h); icon.paintIcon(null, g, 0, 0); g.dispose(); return image; }
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); }
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; }
/** {@inheritedDoc} */ public void paint(Graphics g) { g.setColor(Color.WHITE); g.fillRect(0, 0, width + 2 * INSET, height + 2 * INSET); g.setColor(Color.LIGHT_GRAY); g.drawRect(0, 0, width + 2 * INSET - 1, height + 2 * INSET - 1); icon.paintIcon(this, g, INSET, INSET); }
@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); } }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { final Icon icon = getOrComputeIcon(); if (icon != null) { icon.paintIcon(c, 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 Image jswingIconToImage(javax.swing.Icon jswingIcon) { BufferedImage bufferedImage = new BufferedImage( jswingIcon.getIconWidth(), jswingIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); jswingIcon.paintIcon(null, bufferedImage.getGraphics(), 0, 0); return SwingFXUtils.toFXImage(bufferedImage, null); }
public void paintIcon(Component c, Graphics g, int x, int y) { if (MetalUtils.isLeftToRight(c)) { super.paintIcon(c, g, x, y); } else { rtl.paintIcon(c, g, x, y); } }
public void paintThumb(Graphics g) { Icon icon = null; if (slider.getOrientation() == JSlider.HORIZONTAL) { if (isRollover && slider.isEnabled()) { icon = getThumbHorIconRollover(); } else { icon = getThumbHorIcon(); } } else { if (isRollover && slider.isEnabled()) { icon = getThumbVerIconRollover(); } else { icon = getThumbVerIcon(); } } Graphics2D g2D = (Graphics2D) g; Composite savedComposite = g2D.getComposite(); if (!slider.isEnabled()) { g.setColor(AbstractLookAndFeel.getBackgroundColor()); g.fillRect(thumbRect.x + 1, thumbRect.y + 1, thumbRect.width - 2, thumbRect.height - 2); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); } icon.paintIcon(null, g, thumbRect.x, thumbRect.y); g2D.setComposite(savedComposite); }
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); }
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); }
public void dragGestureRecognized(DragGestureEvent evt) { if (files == null) return; if (files.length <= 0) { return; } Icon icn = files[0].getIcon(false); Toolkit tk = Toolkit.getDefaultToolkit(); if (icn == null) icn = new EmptyIcon(); Dimension dim = tk.getBestCursorSize(icn.getIconWidth(), icn.getIconHeight()); // set up drag image if (DragSource.isDragImageSupported()) { BufferedImage buff = new BufferedImage(dim.width + 100, dim.height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = buff.getGraphics(); Color color = graphics.getColor(); icn.paintIcon(null, graphics, 0, 0); graphics.setColor(color); graphics.setColor(Color.RED); graphics.drawString(files.length + " Elements", icn.getIconWidth(), dim.height / 2); try { evt.startDrag( DragSource.DefaultCopyDrop, buff, new Point(0, 0), new FileTransferable(files, table.getTableModel()), this); } catch (IOException ex) { Logger.getLogger(FileDragGestureListener.class.getName()).log(Level.SEVERE, null, ex); } } else { BufferedImage buff = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = buff.getGraphics(); icn.paintIcon(null, graphics, 0, 0); try { cursor = tk.createCustomCursor(buff, new Point(0, 0), "tempcursor"); evt.startDrag( cursor, null, new Point(0, 0), new FileTransferable(files, table.getTableModel()), this); } catch (IOException ex) { Logger.getLogger(FileDragGestureListener.class.getName()).log(Level.SEVERE, null, ex); } } }
public void paintIcon(Component c, Graphics g, int x, int y) { ButtonModel model = ((AbstractButton) c).getModel(); if (model.isPressed() && model.isArmed()) { pressed.paintIcon(c, g, x, y); } else { super.paintIcon(c, g, x, y); } }