<Swing Dev> [9] Review request for 8081411 Add an API for painting an icon with a SynthContext
Sergey Bylokhov
Sergey.Bylokhov at oracle.com
Wed Aug 12 12:53:44 UTC 2015
The fix looks fine to me.
On 06.08.15 11:29, Alexander Scherbatiy wrote:
>
> Hello,
>
> Could you review the fix:
> bug: https://bugs.openjdk.java.net/browse/JDK-8081411
> webrev: http://cr.openjdk.java.net/~alexsch/8081411/webrev.00
>
> The following use case were considered:
>
> 1. An icon is taken from UIManager.getIcon(iconKey) and should be
> painted.
> Icon icon = UIManager.getIcon(iconKey);
>
> icon.paint(graphics, x, y) may not work for icons that are used by
> Synth L&F because the paint method with null synth context may just do
> nothing.
>
> 2. One icons is created based on existed icon.
>
> Foe example, creating a centered icon:
> ----------------------------
> Icon centeredIcon = new SynthIcon() {
> private final SynthIcon synthIcon = (SynthIcon)icon;
> public void paintIcon(SynthContext sc, Graphics grphcs, int x,
> int y, int w, int h) {
> try {
> int dw = SynthIcon.getIconWidth(synthIcon, sc);
> int dh = SynthIcon.getIconHeight(synthIcon, sc);
> int dx = width - dw;
> int dy = height - dh;
> SynthIcon.paintIcon(synthIcon, sc, grphcs, x + dx/2, y
> + dy/2, dw + 2, dh + 2);
> } catch (Throwable t) {
> try { synthIcon.paintIcon(sc, grphcs, x, y, w, h); }
> catch (Throwable th) {}
> }
> }
> public int getIconWidth(SynthContext sc) { return width; }
> public int getIconHeight(SynthContext sc) { return height; }
> };
> ----------------------------
>
> Overriding just paintIcon(Component c, Graphics g, int x, int y)
> leads to the same issue. The icon may not be drawn in this case.
>
> 3. Replace an icon in UIManager to a custom icon which can use a synth
> context for painting:
> UIManager.putIcon(iconKey, new CustomIcon())
>
> The case 1 requires that only the following static methods were public:
> SynthIcon.paintIcon(context, graphics, x, y, w, h)
> SynthIcon.getIconwidth(context)
> SynthIcon.getIconHeight(context)
>
> The cases 2 and 3 need to work with SyntIcon class.
>
> The proposed fix moves the paintIcon/getIconwidth/getIconHeight
> methods to the public SynthGraphicsUtils class
> and make the SynthIcon class public by moving it to the
> javax.swing.plaf.synth package.
>
> Thanks,
> Alexandr.
>
--
Best regards, Sergey.
More information about the swing-dev
mailing list