Raising "action" from the Attribute to the Tag level ?
Some thoughts about that:
The most important part of an object that implements the Action interface is
obviously its actionPerformed() method. Since this methods needs to be
implemented through code, a java programmer has to write an (anonymous
inner) class and implement the aforementioned method.
Unfortunately, AbstractAction, a default implementation of the Action
interface, doesn't provide setter methods for icon, text, etc, but provides
a set of constructors to set initial values. TO remain compatible your
probably don't want to extends AbstractAction and build your own either.
Since an Action tag's attributes would have to be used to construct the
object, the programmer would have to write a class (with the
actionPerformed() method) like this:
class MyEngine extends SwingEngine {
public class MyAction extends AbstractAction {
// 3 ctors:
MyAction Action() { .. }
MyAction(String name) { .. }
MyAction(String name, Icon icon) { .. }
public actionPerformed (..) { .. }
}
..
}
The parser would then instantiate a MyAction using the constructor based on
the provided attributes, resulting in a myAction instance:
<action
id="action-open"
text="Open"
icon="/icons/open.gif"
mnemonic="VK_O" ToolTipText="Open"
enabled="true"
class="MyAction"
/>
The myAction instance needs to have access to all the members of the
MyEngine class and therefore should be an member itself. This leads to the
next requirement, the programmer has to provide a field in the MyEngine
class:
MyAction myActionInstance = null;
The parser could now update this field with the instantiated MyAction
object.
What seems a little bothering here is the strong dependence between the XML
and the java code.
Having an Action tag would make the XML descriptor probably a little
shorter, however, it would also make the parser much more complicated since
the AbstractAction object is so much different from all the other objects
the parser instantiates (most of them have a Component or Container as an
ancestor).
Form the get go, Swixml was all about the description for the GUI without
the GUI's behavior. For now I don't see a real need for an Action tag.
However, this is open for discussion .. let us know you think.
--
Wolf Paulus
MSCS, SCJP, Sr. Software Engineer