CookSwing

CookSwing is an open source Java library that converts an XML document into Java Swing GUI at runtime. It is a tag library for CookXml, a general purpose XML parser. It was developed to be fast, extensible, and simple to use.

Reasons to Describe GUI using XML
In General
* Simple internationalization. CookSwing offers a mechanism to load strings from resource bundles.
* Simple localization. Some languages require different GUI layouts due to font and orientation. In these cases, with CookSwing one could use different XML layouts for a component depending on the target platform. It is a significantly more challenging task for other approaches that do not involve the use of UI scripts.
* CookSwing provides a centralized place to configure the look-n-feel of components. For instance, one could change the meaning of from a regular JToolBar to a custom toolbar which supports 3D look and possibly docking. In contrast, it is harder to do so for Java based approaches since such need must be envisioned beforehand and use factory based approaches in creating components to avoid the massive changes across GUI components, although the use of AspectJ can alleviate such problem.
* Being in XML allows tools such XSLT to transform from one look-n-feel to another. For example, one initially uses for certain windows. Later, switching to a docking framework would requires the use a . With XSLT, one could translate to for select windows, all without changing the Java code.

Comparing to Java code
* Clear separation of presentation from business logic. Although good programmers can do good jobs with Java code alone, using CookSwing strengthens such separation.
* GUI layout is inherently hierarchical, which is a perfect fit for XML. On the other hand, it is much harder to visualize layout from hundreds of lines of Java code and one could easily get lost with numerous temporary variables.
* There is little performance penalty in generating GUI layout using XML.

Comparing to visual GUI design tools
* Pixel-precise and cross-platform layouts. What you see on your screen is not what you get on a different platform. One has to use layout managers to deal with issues considering alignment, font, resolution, resizing, etc, which are the focus of CookSwing.
* Faster to do the layout for experts. Instead of point-n-clicking a field and then modify a property, switching from mouse to keyboard and back, experts who know components by heart can just type the property and its appropriate values. Cut-n-paste and/or use of templates further speed up the layout.
* Not tied to a particular IDE. If one uses NetBeans' Form Designer, using Eclipse IDE becomes problematic.
* Some components of the GUI are either generated from elsewhere or hard coded and thus can be problematic with GUI designers. There has been plenty of debates of using GUI designers vs hand coding . In contrast, CookSwing caters this need by allowing the mixing of components that are either custom defined or XML defined, and supporting scripts.

Main Features
CookSwing is intended to be a complete solution for creating Swing GUI with XML.

* All Swing components can be configured. Complex input field constraints can all be specified in XML.
* All layouts, including GridBagLayout, SpringLayout, and JGoodies Forms layout, can be used.
* All listeners can be attached to any components that support them. It is also easy to add custom listener types.
* All Swing Border classes, including complex *CompoundBorder* can be created.
* Include other XML documents.
* Support Locale and ResourceBundle. So it is easy to internationalize the software.
* Go beyond Swing. Various containers (Vector, LinkedList, Map, Set and such), String, Integer, Icon, etc can all be configured within CookSwing.
* Scripting support can be added with other CookXml tag library extensions.

One of the reason why CookSwing goes beyond just Swing is because many settings in Swing inevitably require objects that are not part of Swing. Going too much back-n-forth between Java and XML defeats the purpose of using an XML->Swing toolkit.

In addition, it is the heavy emphasis of CookSwing to be extensible because Java developers create new GUI classes all the time.

Links
* CookXml
 
< Prev   Next >