SwiXml ReviewApr 24, 2008 · 2 minute read · Comments
Externalizing the screen layout is a natural step for many applications. It can be because a customer might want a slightly different presentation, or just for the sake of clearly separating layout code, or for using a kind of screen generator. Back in 2003, I wrote a small utility to help with GridBagLayout, nothing fantastic, but there was the feature of saving a generated layout in XML (or Beanshell) and using it in an application.
SwiXml saves a bit more than a layout as it instantiates the components as well, allowing to represent a hierarchy of components in XML. But it does not more than that. The “no generation” approach is interesting, I bet the author thinks the XML should be kept concise enough to be used easily without using a kind of generator. the XML is almost a mirror of Java code, but fortunately makes layouts more compact and easier to read. I tried version 1.51, and while it is quite well done, its documentation is a bit lacking and to me an important functionality is missing:
There is no “component” tag by default. One needs to explicitely name the class of component we want to add. I think there could be a component tag that instantiate an 0 parameter constructor by default, using reflection for example. The class of component to instantiate would be found through the field name.
Fortunately SwiXml is quite well done and this is not that big of an issue since you can just interpret new tags with 1 line of code:
for a Jide DateComboBox.
I said documentation was lacking, because in my first non Hello World trial, I wanted to use the standard constant names for GridBagConstraints (RELATIVE,REMAINDER, FIRST_LINE, LAST_LINE, …). Putting <gridbagconstraint anchor=“FIRST_LINE”>did not work. By reading the code, I found out you could achieve it but you have to do <gridbagconstraint anchor=“GridBagConstraint.FIRST_LINE”>.
In the end SwiXml left me with a good impression. It is non intrusive, and handle well enough what it is done for. One major drawback, you can only use either BorderLayout or GridBagLayout or FormLayout (from JGoodies).