ContentWelcomeProducts Abeona Gaia News Documentation Introduction Swing support Components Building from XML Step by step XML elements Data binding Internationalization Client / server Server application Validation XML Logging Utilities Launcher License Download Hephaistos JavaGantt Services Promote your software Contact Us Links |
XML builderOne of the most attractive features of our Swing part of the Gaia library is the XML support for building Swing forms or applications. Yes, there are many such tools, but as far as we know, no one of them supports also data binding and internationalization. So Gaia offers the possibility to build Swing form (or whole application) from XML file in runtime with minimum programmer effort. For example, this data class: import java.util.Date; public class Person { private String firstName; private String lastName; private Date dateOfBirth; private Person father; private Person mother; public Person(String firstName, String lastName, Date dateOfBirth) { this.firstName = firstName; this.lastName = lastName; this.dateOfBirth = dateOfBirth; } public String getFirstName () {return firstName;} public void setFirstName (String firstName) {this.firstName = firstName;} public String getLastName () {return lastName;} public void setLastName (String lastName) {this.lastName = lastName;} public Date getDateOfBirth () {return dateOfBirth;} public void setDateOfBirth (Date dateOfBirth) {this.dateOfBirth = dateOfBirth;} public Person getFather () {return father;} public void setFather (Person father) {this.father = father;} public Person getMother () {return mother;} public void setMother (Person mother) {this.mother = mother;} } can be displayed in this form: with this code: import java.awt.Frame; import java.io.InputStream; import java.util.Date; import javax.swing.JDialog; import javax.swing.JPanel; import eu.beesoft.gaia.swing.builder.SwingBuilder; import eu.beesoft.gaia.swing.builder.SwingBuilderFactory; import eu.beesoft.gaia.util.Streams; public class ShowPerson { public static void main (String[] arg) { // prepare data objects Person person = new Person ("John", "Cassidy", new Date (1980 - 1900, 5, 20)); Person father = new Person ("Frank", "Censky", null); person.setFather (father); Person mother = new Person ("Annie", "Abell", null); person.setMother (mother); // build form InputStream is = Streams.getInputStream ("PersonForm.xml"); SwingBuilderFactory factory = new SwingBuilderFactory (); SwingBuilder<?> builder = (SwingBuilder<?>) factory.build (is); JPanel panel = (JPanel) builder.getObject (); // bind data builder.setBoundData (person, null); // show form JDialog dialog = new JDialog ((Frame) null, "Person", true); dialog.getContentPane ().add (panel); dialog.pack (); dialog.setVisible (true); } } from this XML FORM description file: <?xml version="1.0" encoding="UTF-8"?> <form editableComponentBackground="white"> <!-- Person section --> <label id="personTitle" text="Person" foreground="blue" font="arial-bold-18"> <cell id="personTitleCell" x="0" y="0" width="2" height="1" weightx="1.0" weighty="0.0" anchor="west" border="bottom"/> </label> <label text="First name: "> <cell id="firstColumn" x="0" y="1" width="1" height="1" weightx="0.0" weighty="0.0" anchor="east" border="bottom" /> </label> <textfield id="firstName" binding="firstName" > <cell id="secondColumn" as="firstColumn" x="1" weightx="1.0" anchor="west" fill="horizontal" border="bottom" /> </textfield> <label text="Last name: "> <cell as="firstColumn" under="firstName" /> </label> <textfield id="lastName" binding="lastName"> <cell as="secondColumn" under="firstName" /> </textfield> <label text="Date of birth: "> <cell as="firstColumn" under="lastName" /> </label> <datefield id="dateOfBirth" binding="dateOfBirth"> <cell as="secondColumn" under="lastName" /> </datefield> <!-- Father section --> <label id="spaceBeforeFather" text=" "> <cell as="firstColumn" under="dateOfBirth" border="none" /> </label> <label id="fatherTitle" as="personTitle" text="Father"> <cell as="personTitleCell" under="spaceBeforeFather" /> </label> <label text="First name: "> <cell as="firstColumn" under="fatherTitle" /> </label> <textfield id="fatherFirstName" binding="father.firstName"> <cell as="secondColumn" under="fatherTitle"/> </textfield> <label text="Last name: "> <cell as="firstColumn" under="fatherFirstName" /> </label> <textfield id="fatherLastName" binding="father.lastName"> <cell as="secondColumn" under="fatherFirstName" /> </textfield> <!-- Mother section --> <label id="spaceBeforeMother" text=" "> <cell as="firstColumn" under="fatherLastName" border="none" /> </label> <label id="motherTitle" as="personTitle" text="Mother"> <cell as="personTitleCell" under="spaceBeforeMother" /> </label> <label text="First name: "> <cell as="firstColumn" under="motherTitle" /> </label> <textfield id="motherFirstName" binding="mother.firstName"> <cell as="secondColumn" under="motherTitle" /> </textfield> <label text="Last name: "> <cell as="firstColumn" under="motherFirstName" /> </label> <textfield id="motherLastName" binding="mother.lastName"> <cell as="secondColumn" under="motherFirstName" /> </textfield> </form>
|