classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] FYI: MetalIconFactory.getRadioButtonMenuItemIcon()


From: David Gilbert
Subject: Re: [cp-patches] FYI: MetalIconFactory.getRadioButtonMenuItemIcon()
Date: Wed, 31 Aug 2005 20:32:06 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

Tom Tromey wrote:

On Tue, 2005-08-30 at 21:35 +0000, David Gilbert wrote:
I committed this patch to add an icon for JRadioButtonMenuItems under the Metal look and feel:

+ public int getIconWidth() + {
+      return 10;
+    }

I notice there are an awful lot of constant integers in the plaf code.
My reflex is to say that these ought to be given a name somewhere,
so that we can more easily change them later if need be -- particularly
if we know that, say, many of the "2"s are actually "METAL_BORDER_WIDTH"
or the like, if you catch my meaning.  What do you think?

Tom

I'll keep a look out for anything that might need a named constant. The particular example you mentioned shouldn't cause a problem, because this is the value that matches Sun's JDK and it is covered with a Mauve test (not sure if I checked in all my icon dimension tests yet, but I will). The value will never change (it is a 10x10 icon, forever).

But as I start to dig deeper into the look and feel code, I'm sure there will be some magic values for which your comment is spot on. Very likely in the layout code which I haven't dug into very far yet.

The icon drawing code is another area where there are lots of constants, for example:

     g.drawLine(x + 2, y, x + 6, y);
     g.drawLine(x + 7, y + 1, x + 7, y + 1);
     g.drawLine(x + 8, y + 2, x + 8, y + 6);
     g.drawLine(x + 7, y + 7, x + 7, y + 7);
     g.drawLine(x + 2, y + 8, x + 6, y + 8);
     g.drawLine(x + 1, y + 7, x + 1, y + 7);
     g.drawLine(x, y + 2, x, y + 6);
     g.drawLine(x + 1, y + 1, x + 1, y + 1);

Icons get *drawn* this way in the MetalLookAndFeel, rather than displaying a PNG image for example, so that the icon can change appearance when (a) the component state changes and (b) the Metal theme (primarily colors) is changed (less common). There are no state changes in the fragment above, but take a look through MetalIconFactory.java if you are interested. The constants are just offsets from the top-left corner of the icon, and won't change as long as we are replicating the icons from the Metal look and feel.

Regards,

Dave




reply via email to

[Prev in Thread] Current Thread [Next in Thread]