Tutorial for XMLPanelEdit: Java Swing GUI by XML > Overview
Overview
Java Swing GUI can be represented in XML!
OOP XMLPanelEdit depends on the simple fact. That is:
- All Java Swing GUI can be represented in XML.
Java Swing GUI has the nested structure, i.e. the 'container' component has other 'atomic' level components as its child components.
Such a 'container' component knows how to place its child components in it.
And each component has a set of the attributes, such as the size, the alignment, the font, the background color and so on.
As you know, XML is the good solution to represent the parent-child relationship along with the attributes of each component.
Please look at the
DTD for this purpose will look like this:
<!ENTITY % panel.mdl
"layout?,size?,border?,toolbar?,panel.child*">
<!ELEMENT panel (%panel.mdl;)>
<!ATTLIST panel
%opaque.att;
%panel.name.att;
%alignmentX.att;
%alignmentY.att;
%label.text.att;
%label.image.att;
%layout.border.constraint.att;
%access.name.att;
%access.descript.att;
%color.fg.att;
%color.bg.att;>
|
Based on this DTD, Java Swing GUI can be written in XML like this:
<panel opaque="false">
<layout>
<layout.border/>
</layout>
<size>
<preferred>
<dimension dimensionX="500" dimensionY="300"/>
</preferred>
<max>
<dimension dimensionX="500" dimensionY="300"/>
</max>
<min>
<dimension dimensionX="500" dimensionY="300"/>
</min>
</size>
<border border="RAISED">
<insets insets.bottom="10"
insets.left="10"
insets.right="10"
insets.top="10"/>
</border>
<toolbar opaque="false"
toolbar.direction="horizontal"
toolbar.float="false"
toolbar.layout.border.constraint="NORTH">
<insets insets.bottom="5"
insets.left="5"
insets.right="5"
insets.top="5"/>
<toolbar.child>
<component
class.name="javax.swing.JLabel"
editable="false"
label.text="Select!"
opaque="false"
value.name="label"
wordwrap="false"/>
</toolbar.child>
.....
|
The full DTD is available at the link below:
Once the appearance of Java Swing GUI can be written in XML, our source code will be free from:
- How to place the child Java components on their parent component
- How to specify the attribute of each Java component
As a result, our source code can concentrate on the function of each Java component.
Moreover, we can modify our GUI without touching any lines of the source code.
This ensures the integrity of our source code.
To make it possible, OOP-Reserch developed OOP XMLPanelEdit (XMLPanelEdit for short).
XMLPanelEdit consists of:
-
The XML editor for Java Swing GUI.
-
The parser which generates the GUI objects from XML.
-
And well-designed abstract classes, which enable us to get the Swing GUI without using the above parser directly.
About XMLPanelEdit
With XMLPanelEdit, all we have to do is:
-
To write Java Swing GUI in XML
-
To define the class which generates Java Swing GUI from the above XML
The first step can be done by:
- com.oopreserch.xml.edit.XMLPanelEdit
This class is the XML editor, by which we can pre-view our Swing GUI.
View Full image
The second step can be done by one of the following classes:
- com.oopreserch.xml.util.GUIParser_1_0
- com.oopreserch.xml.util.XMLPanel_1_0
- com.oopreserch.xml.util.XMLFrame_1_0
- com.oopreserch.xml.util.XMLDialog_1_0
In the subsequent sections, I'll describe:
Java and all Java-based trademarks and logos are trademarks or registered of Sun Microsystems, Inc. in the United States and other countries.
ALL CONTENTS COPYRIGHT 2002, Jun Inamori. All rights reserved.
Any questions and comments are welcome to
Jun Inamori
.