Monday, May 12, 2008

Java SwingBuilder: binding done, SwingWorker done, fat trimmed

Latest code drop on javabuilders.org has the latest and greatest.

The binding support comes in two basic flavors:

a) straight bean-style property, e.g:

bind:
- this.lastName : firstNameTextField.text

This is a straighforward command to bind the text field's Text property (the source) to the "lastName" property of the backing Java class.

b) EL-style property that allows binding to multiple properties, e.g.:

bind:
- this.fullName: "${this.firstName} ${this.lastName}"

Since "{" and "}" are reserved characters in YAML you have to break out into quoted string to put it in. Note that when dealing with multiple properties like this it is NOT POSSIBLE to bind to properties from a different object (e.g. get the text from one text field and then one from another and combine them). This is just a limitation of how Beans Binding works.

As I mentioned before, the support for running background methods via @DoInBackground is done and it automatically pops up a nice progress dialog with an optional cancel button, if required. See the code in the sample's save() method to see how you can interact with it from the Java code:
http://code.google.com/p/javabuilders/source/browse/trunk/org.javabuilders.swing/samples/org/javabuilders/swing/samples/binding/BindingFrame1.java

In another node, I removed all the Log4J logging code and switched to regular Java logging API (even though it is sucky compared to Log4J). Thanks to this I cut nearly 500KB in the download size (for the actual JB jar and its dependencies). We are now at a total of 1.1 MB...an overhead of 50% seemed a lot for something like logging, hence Log4J had to go.

I like to keep it lean. This ain't .Net with a 30MB download forced upon you in the background via Windows Update :-)

Next up: validations. Stay tuned.

10 comments:

binkley said...

If you are interested in logging, you might cast a glance at the SL4J framework. The logback implementation is nice, but has a j.u.l. one as well.

Jacek Furmankiewicz said...

Well, I just need basic logging, nothing more. My primary concern is reducing the size of jars that JB depends on...if someone is using it let's say in an applet 2.0 environment shaving off 0.5 MB from the download is a good thing.

Jacek Furmankiewicz said...

Hm...I had a quick look at it...the base JDK version is only 9KB...thanks for the tip, I may look into it, especially if the API is nicer than the awkward one that comes in the base JDK...

codecraig said...

how about making the logging framework pluggable. by default you could use the Java Logging API but allow users to specify another library if they wish. Probably overkill as you mentioned..but could be fun :)

Jacek Furmankiewicz said...

I have so much more other stuff I want to add first... :-)

...like getting around to finally doing some docs and the 9,000 JUnit tests I should write to test all the different functionality that is in there already...

jgulisano said...

Is it (or will it be possible) to use only the binding from SwingBuilder? I use JFormDesigner, and although I am not ready to give it up just yet, I am looking for a quick way to bind my backing beans to components.

Jacek Furmankiewicz said...

I believe it should. In this case you would probably just have a simple entry for the root node (e.g. your panel) with no properties.

JPanel: {}
bind:
this.firstName : this.textFieldName.text

However, since your controls are not defined in the YAML file it would not know about them, so you would have to make them as public properties on the calling objects (e.g. public JTextField getTextFieldName())

That *should* work. If it doesn't just mail me directly and I *will* make it work. I want JB to be as flexible as possible and have people as as much or as little of its functionality as is possible.

Jacek Furmankiewicz said...

I confirmed, it works with the latest build, quite simple. All you need in YAML is the bind:

TestFrame.yaml:
bind:
- this.name : this.nameField.text

Just remember that your Java class must be a FULL JavaBean, i.e. get/set, each set must implement PropertyChangeSupport.firePropertyChange and you need to have addPropertyChangeListener and removePropertyChangeListener implemented as well (pointing to the same methods on your local instance of PropertyChangeSupport)

Anonymous said...

You will get a beautiful cloth which in the game if we want to need the beautiful cloth, we can use our own Scions Of Fate gold to buy. The one I owned on my character is one of my friends sent to me the necessary SOF gold. Sometimes we can share the trophy as the necessary Scions Of Fate money together, and we do quest together. I do not have enough confidence and cheap SOF gold about my weak memory. First I have to buy sof gold to improve my pet which I have a lovely leopard in this game.

wholesale jewelry said...

wholesale jewelry , supply vast kinds of styles handmade jewelry,mainly engage in handmade jewelry wholesale handmade jewelry,such as wholesale pearl wholesale crystalwholesale

gemstone,wholesale costume jewelry,also wholesale fashion jewelry like wholesale swarovski

crystal,wholesale beads,wholesaleturquoise,wholesale coral,wholesale costume jewelry ,shell

jewelrycostume jewelry and discount jewelry, jewelry wholesale, just on AYpearl jewelry store.