| Newsgroups |
gmane.comp.embedded.carlsbad-cubes |
| Message-ID |
<[email protected]> |
Lutz,
This is been very informative! I didn't realize this could be done.
Thanks, Fred
Lutz Neumann writes:
> Yes as Kate said, background="WHITE" works for sure,
> background="Color.WHITE" does not (by the way - background="xxx, xxx,
> xxx" works also.)
> Because SwixML includes the Color class as a constant provider, all
> predefined colors will work this way.
> Have a look at PrimitiveConverter.java to see all included providers.
>
> If you have special needs you can always register a new provider like:
>
> PrimitiveConverter.addConstantProvider(Font.class);
>
> .. and use PLAIN, BOLD, ITALIC, ...
>
> If you want to use system colors (as I do), try the following:
>
> import javax.swing.*;
>
> import org.jdom.Attribute;
> import org.swixml.Localizer;
> import org.swixml.converters.ColorConverter;
>
> /**
> * Extends SwixMLs ColorConverter to use system colors.
> *
> * @author Lutz Neumann
> */
> public class ExtColorConverter extends ColorConverter
> {
> public Object convert(Class type, Attribute attr, Localizer localizer)
> {
> if (attr.getValue().startsWith("UIColor."))
> {
> return UIManager.getColor(attr.getValue().substring(8));
> }
> if (attr.getValue().startsWith("Color."))
> attr.setValue(attr.getValue().substring(6));
> return super.convert(type, attr, localizer);
> }
> }
>
> Register it with:
>
> ConverterLibrary.getInstance().register(Color.class, new ExtColorConverter());
>
> Now you can use foreground="UIColor.activeCaptionText",
> background="UIColor.Button.background", etc. - even "Color.WHITE"
> works ;-).
>
> Hope this helps,
>
> -Lutz
>
>
>
>> I agree about extending attributes needing to be more obvious. I think
>> this is mostly a documentation issue although I haven't actually tried it.
>
>> The biggest problem with things like new Color(xxx, xxx, xxx) as an
>> attribute value is that there are just too many possibilities that
>> people would want and too little time to code them all. I think the
>> best approach is to do the main ones (see below) and just really
>> document how to extend it. Plus get this all the things like this into a
>> plug-in archictecture (old discussion see archives) so that we can all
>> contribute our little bits to the whole.
>
>> While Color.WHITE may not work I *think* that WHITE does. I think all
>> the Color.xxx have been implemented. But, it's been a while since I
>> tried that I just remember it working and not having to specify hex vals.
>
>> -Kate
>
>
> _______________________________________________
> Forum mailing list
> [email protected]
> http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com