Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline
Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Subscription to Java Pro


Serialize Java Data Objects to XML (Continued)

You can go to a commercial implementation of a Java Swing fast food menu system (see Resources). Imagine that another menu designer GUI lets the store manager design and save various JPanels full of buttons when food items or drinks change from day to day (see Figure 1). If the designer application can save them in XML in a database for use after a specified date, and the menu GUI can read them in from a database given the current date, it would be a good solution. For this test, just edit the XML file and change the button labels. Here is a sample output:

button pressed , cmd = Hamburger
thing #1 orderSomething = Chicken

// edit XML button labels
// to Ham and Chick
// and reload the panel

thing #3 orderSomething = Chick
button pressed , cmd = Fish
button pressed , cmd = Ham
button pressed , cmd = Fish
ADVERTISEMENT

Note that the Fish button on the restored panel is now active because we set the action listener on it after loading the panel. It was not set in the original source code. The saved panel uses FlowLayout with a left alignment. Listing 9 shows the resulting XML. The FlowLayout component itself is not saved in the XML because it happens to be the default layout manager for a JPanel. No special persistence delegates were needed, and there were no save and restore problems for this GUI example. However, GUIs in general are complex, and there will be some that don't work. In particular GUI components that use inner classes properties that are transient in nature such as the visible property—and issues related to flashing windows as the persistence mechanism clones objects to determine default properties—have led to complex built-in persistence delegates for the GUI components.

This technology is still new; some of the built-in persistence delegates may have bugs. Practical advice for saving GUIs would be to keep it simple, look at the XML for clues, and beware of default component values that will not appear in the XML archive.

About the Author
Charlie Havener is an independent software developer specializing in Java applications ranging from database-driven Web sites to GUIs to custom compilers. Recently Charlie was involved in a project to develop a Verilog compiler for a digital circuit simulator accelerator using the JavaCC parsing tool. Reach Charlie at .



Back to top

Printer-Friendly Version












Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home