As the author of CookSwing, a tool that does what you need, I gave this topic a long look before doing the actual implementation. I made my living as a Java Swing GUI application.
IMO, if you intend to use any imperative programming languages ββto describe the Java Swing component, you can simply use Java. Groovy etc. only adds complexity without much simplification.
Declarative languages ββare much better, because even non-programmers can understand this, especially when you need to delegate the task of fine-tuning specific layouts to artists. XML is ideal for declarative languages ββ(compared to other options) because of its simplicity, readability, and the many editors and translation tools available for editing.
These are the problems that are encountered in a declarative graphical interface, and not in any particular order. These issues were addressed at CookSwing.
- Readability and simplicity. (JavaFX is no simpler than XML). Closing XML tags helps to read a little, and does not add extra typing, as XML editors usually do this for you)
- extensibility. Very important, because custom Swing components are suitable for any non-trivial projects.
- GUI layouts. Also very important. Ability to manage BorderLayout, GridBagLayout, JGoodies FormsLayout, etc. Almost required.
- Easy to copy / paste. In the design process, you need to try different ones. Therefore, you need to be able to copy / paste and move things. XML is better because the hierarchy of components and layouts is easy to see. JavaFX is somewhat problematic due to multi-line attributes and indentation issues. Having a good editor is a must, and there are many good XML editors.
- Templates (i.e. the ability to add another layout file) are very useful for sequential viewing. For example, you may need a constant view of dialog boxes, button panels, etc.
- Interaction with Java code. It is important. Some GUI components can only be created using Java code (for some reason). Therefore, you must be able to load these objects. It is also a must to directly connect listeners and other Java objects / components in XML code. Using ids to connect them later, WILL will not work, as it is very tiring.
- Internationalization (i18n). Ability to load text / line from a set of resources, rather than hard-coded text. This feature may be critical for some applications.
- Localization (l10n). The advantage of declarative programming (in particular XML) is that you can simply switch to another form of GUI for a specific locale and its. If you code Java or any other imperative languages, this is not so simple.
- Error checking / tolerances. Initial designs often contain errors here and there. Sometimes an error can be caused by the fact that the corresponding Java code has not yet been developed. Or missing icon resource. Dealing with imperative coding errors is extremely tedious. Thus, it is desirable to be able to find errors, but at the same time be error tolerant, so you can preview the GUI layout as early as possible.
- GUI component replacement. That is, replace the text box that used the JTextField with some more convenient version of the components. Replace the dialog value with some fancy user interface dialogs (like JIDE) instead of JDialog. This feature can save significant effort. XML itself is also useful thanks to XSLT and other conversion tools.
- Outside of the swing. Since sooner or later you will find many component configurations, use object types such as arrays, icons, images, vectors, etc.
coconut May 28 '09 at 12:41 2009-05-28 12:41
source share