Example -- developing an XML framework for Swing programs
Introduction
Now, the market is tight. The framework can save time in the design and development stages. IDE makes it easier for us to develop user interfaces. Standard GUI applications use different panel la s to define the GUI, which has become a fundamental pattern. Based on this model, we consider using a framework to increase the execution speed, achieve a higher degree of parallel processing, and coordinate more relaxed development methods. Here we will use Java swing applications to describe such a framework.
Simple Application-Library Management System
Next we will discuss a simple library management system to understand the XML-based GUI framework.
The flowchart above defines the design of library user interfaces. Main directory, member logon, user registration, and book retrieval are all applications
Panel in the program ). The flowchart shows that there are several possible processing paths in the application:
Home Directory-> User Registration-> Book Search
Home Directory-> member logon-> Book Search
Principles
The Panel displayed at any time depends on the output content of the previous panel. Therefore, you need to design a common controller as the form of the entire framework. It provides the panel for necessary input and processing the output content that is expected to be returned in the panel. These panels all implement the xsfpanel interface, which has an execute () method used to store the input content in the form into a hashmap and return the output content from another hashmap. The Controller of the Framework processes the output content returned using hashmap and determines which panel should be displayed at any time.
Public interface xsfpanel extends jpanel
{
Public hashmap execute (hashmap inputs );
...
}
Controller and XML Stream Definition
The stream controller is associated with a simple XML that defines user interfaces. This XML must be defined based on the input content and expected output content of each panel. The simple program we discuss here works based on the following XML.
<Xfsframework>
<Xfspanels>
<Xfspanel name = "home" class = "library. Home">
<Inputs/>
<Outputs>
<Output variable = "useroption"/>
</Outputs>
</Xfspanel>
<Xfspanel name = "memberlogin" class = "library. memberlogin">
<Inputs/>
<Outputs>
<Output variable = "username"/>
<Output variable = "password"/>
</Outputs>
</Xfspanel>
<Xfspanel name = "Registration" class = "library. userregistration">
<Inputs/>
<Outputs>
<Output variable = "username"/>
<Output variable = "password"/>
<Output variable = "emailid"/>
<Output variable = "Address"/>
</Outputs>
</Xfspanel>
<Xfspanel name = "registrationpreview" class = "library. userpreview">
<Inputs>
<Input variable = "username"/>
<Input variable = "emailid"/>
<Input variable = "Address"/>
</Inputs>
<Outputs/>
</Xfspanel>
<Xfspanel name = "searchbook" class = "library. searchbook">
<Inputs/>
<Outputs>
<Output variable = "criterion"/>
<Output variable = "searchvalue"/>
</Outputs>
</Xfspanel>
</Xfspanels>
<Xfspanelflow>
<Step id = "S1" from = "home" to = "memberlogin">
<Conditions>
<Condition variable = "useroption" value = "login"/>
</Conditions>
</Step>
<Step id = "S2" from = "home" to = "Registration">
<Conditions>
<Condition variable = "useroption" value = "newregistration"/>
</Conditions>
</Step>
<Step id = "S3" from = "Registration" to = "registrationpreview">
<Conditions/>
</Step>
<Step id = "S4" from = "memberlogin" to = "searchbook">
<Conditions>
<Condition variable = "controller_loginresult" value = "success"/>
</Conditions>
</Step>
<Step id = "S5" from = "registrationpreview" to = "memberlogin">
<Conditions>
<Condition variable = "controller_accountcreationresult" value = "success"/>
</Conditions>
</Step>
</Xfspanelflow>
</Xfsframework>
Note: This XML is only used to describe the framework.
In the preceding XML, we mentioned all the panels that implement the xfspanel interface. Streams from one panel to another.
Translated by caiyi0903 (willpower), 2004.5.23