However, the area of concern is refactoring of course. if someone changes the variable name on the Java side it becomes out of sync with the name defined in the YAML file and runtime exceptions will occur.
So, as an optional feature to proof the JavaBuilder concept against refactoring, I have introduced an @Name annotation that basically maps the Java instance variable to the name of the control as it was created in the build file.
You can see it in the YAML file (e.g. the "fNameLabel"):
http://code.google.com/p/javabuilders/source/browse/trunk/org.javabuilders.swing/test/org/javabuilders/swing/test/TestFrame.yaml
and in the corresponding Java file:
http://code.google.com/p/javabuilders/source/browse/trunk/org.javabuilders.swing/test/org/javabuilders/swing/test/TestFrame.java
And here it is:
@Name("fNameField") private JTextField firstNameTextField;
Also, you may have noticed some new things in the YAML file such as:onFocusThis is work in progress to add simple Javascript-style event handlers that will automatically call a corresponding method on the Java side. This reduces the verbosity of code required to create KeyListeners, FocusListeners, MouseListeners, etc.
onFocusLost
onKeyPressed
onKeyReleased
onKeyTyped
onAction
It's still work in progress, but it will basically find any method on the Java side with the same name as defined in YAML and either zero arguments (e.g. save()) or with one argument that is compatible with the type that generated the event, e.g.
YAML:
- JButton: {name: editButton, text: button.edit, onAction: edit}Java:private void edit(JButton sender) {
JOptionPane.showMessageDialog(this, "Edit invoked from sender with name: " + sender.getName());
}
I plan to enhance it further to automatically recognize event-specific arguments, e.g.:private void onLastNameKeyPressed(KeyEvent event) {
this.setTitle("Last name key pressed: " + event.getKeyChar());
}
but that's not there yet...coming soon this week, I hope, time permitting. I think the initial concepts of the JavaBuilder are slowly nicely coming together.P.S. I mentioned this before, but the JavaBuilder concept is NOT Swing-specific. Swing is just the first domain that I am using as a proof of concept. There are some *very* early proofs of a working builder for SWT, but it's just working code to prove this will work across multiple domains. I will only start seriously working on the SWT builder once the Swing one is done.
See some early SWT code samples here:
http://code.google.com/p/javabuilders/source/browse/trunk/org.javabuilders.swt/src/org/javabuilders/swt/
http://code.google.com/p/javabuilders/source/browse/trunk/org.javabuilders.swt/test/org/javabuilders/swt/test/TestShell.yaml
P.S.S. Also, I have settled on the Apache Wicket approach of forcing the Java and YAML files to have the same name and to be in the same package. It's a good idea and will follow the convention over configuration principle.
P.S.S.S. I also plan to add the @Name support for the Java event methods as well, to also proof them in case of refactoring. List of things to do grows by the day...
[EDIT 2008-04-29]
Latest code drop available:
http://javabuilders.googlecode.com/files/javabuilder.swing.0.0.2008-04-29.zip

8 comments:
Hmm, @Name may also lead into resource injection, in that case I suggest you take a look at Fuse, it is also non-Swing specific if needed be :-)
https://fuse.dev.java.net/
The naming convention also makes a lot of sense, down with the over-configuration syndrome!
On the event handlers that take 1 argument, does it have to be the exact class or may it be a super class/interface ?
Superclass / interace is fine. It uses Class.isAssignableFrom() to find a compatible one.
@Name is not really for resource injection (since that happens automatically), it's more to hard-code a link between a variable in the YAML file and in the Java world, to guard against the case where refactoring the Java code would break the link with YAML.
It is optional, just an extra safeguard. Better safe/paranoid than sorry...
Some minor updates from tonight's coding session:
@Name is supported on both variables and method
Methods that are executed are ranked in the following order of preference
- (caller class, event specific class) (e.g. (JButton, MouseEvent)
- (caller class)
- (event class)
- () [no arguments]
Work in progress on adding mouse events, with easy support for the ones that are a bit convoluted in Swing, such as onMouseDoubleClicked and onMouseRightClicked
Finished Ant build file, so now I can easily create downloadable ZIPs with all the jars, including dependencies and the manual in PDF format (as minimalistic as it is still now)
Phew! More late night coding tomorrow...
Oh, yeah, forgot to mention: did some very early proof of concept testing with adding support for binding via Beans Binding.
Definitely doable. Let me finish up the mouse stuff tomorrow and then I will look at the binding next.
That will take more time as it will require a design change in the main engine and related APIs, they were not designed to support either straight values or binding. Should not be too bad though...
How could I forget possibly the most important part: changed all the code to be JDK 5.0 compliant. before I was running on JDK 6. Should help to spurn the adoption of the project once we reach a 0.1 release.
Fantastic work! A long overdue fix for Swing. And let me add another vote for convention over configuration.
When I begin to play this Seal Online game, I first go to buy seal online cegel to buy some my favorite and beautiful clothes to dress up my character. I have spent cheap seal cegel to buy my favorite cloth. I mean we have anime and some necessary seal online cegel based games that do not look really kid dish. Though I will admit with my own seal cegel I went crazy on leveling with DECO. Some of the skills that we can use our sealonline cegel to improve to look amazing, and are fun to just watch honestly.
Post a Comment