> Does the action control the 
> customization or does the LNF?

Neither, the code for setting up a component is just hardcoded into the
component. This limits the options available to a L&F creator; what if
you wanted to display text and the image on a Jbutton? As it stands
there is no way to do this from within the L&F.

The ability to use arbitrary keys with Action suggests that wanted us to
be able to customise any way we like, but as far as the implementation
goes, the list of keys may as well be considered final. IMO an Action
should be able to define any number of keys, and also be responsible for
specifying how those keys are used.

This code is lifted straight from AbstractButton:

    void configurePropertiesFromAction(Action a, String[] types) {
        if (types == null) {
            String[] alltypes = { Action.MNEMONIC_KEY, Action.NAME,
                                  Action.SHORT_DESCRIPTION,
Action.SMALL_ICON,
                                  Action.ACTION_COMMAND_KEY, "enabled"
};
            types = alltypes;
        }
        for (int i=0; i<types.length; i++) {
            String type = types[i];
            if (type == null) continue;

            if (type.equals(Action.MNEMONIC_KEY)) {
                Integer n = (a==null) ? null :
(Integer)a.getValue(type);
                setMnemonic(n==null ? '\0' : n.intValue());
            } else if (type.equals(Action.NAME)) {
                setText(a!=null ? (String)a.getValue(type) : null);
            } else if (type.equals(Action.SHORT_DESCRIPTION)) {
                setToolTipText(a!=null ? (String)a.getValue(type) :
null);
            } else if (type.equals(Action.SMALL_ICON)) {
                setIcon(a!=null ? (Icon)a.getValue(type) : null);
            } else if (type.equals(Action.ACTION_COMMAND_KEY)) {
                setActionCommand(a!=null? (String)a.getValue(type) :
null);
            } else if (type.equals("enabled")) {
                setEnabled(a!=null ? a.isEnabled() : true);
            }
        }
    }

Pretty static!


> but you must be in charge of constructing the components 
> correctly for it to work.  (Factory methods come to mind here).

Have you seen my other reply? I post some code that does this, it holds
responsibility of adding Actions to Components. Ugly compromise, but
does the job.
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to