October 1, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

An XML based Framework for Developing Swing Applications

  • May 13, 2004
  • By R Venkatavaradan and Suresh P R
  • Send Email »
  • More Articles »

Introduction

In today's world time to market is shrinking. Frameworks help in saving time during the design and development phase. IDEs help in easier development of the user interface. Standard GUI applications show an underlying pattern where the GUI flow can be defined by the flow of various panels. Based on this pattern, a framework is thought of for increasing the speed of implementation, achieving higher degree of parallelism and facilitating loosely-coupled development. Such a framework is described here by taking the applications that are based on Java swing.

Sample Application - Library Management System

Let's discuss a simple library management system to understand the xml based GUI framework.

The above flowchart describes how the library's user interface is designed. Home, Member Login, User Registration and Search book are the panels that exist in this application. From the flowchart, the set of possible paths that describe the flow of panels in this application are

Home ->User Registration -> Search book
Home -> Member Login -> Search book

Principle

The panel in display at any time depends on the outputs from the previous panels. Hence, a generic controller that forms the basis of the framework is designed such that it supplies the necessary inputs to the panels and processes the expected outputs from the panels. These panels are expected to implement the XSFPanel interface that has an execute() method which takes inputs in the form of a HashMap and return the outputs as another HashMap. The controller of the framework processes the outputs that are returned using the HashMap and determines which panel should be on display at any time.

public interface XSFPanel extends JPanel
{
   public HashMap execute(HashMap inputs);
   . . .
}

Controller and XML Flow Definition

The controller of the flow works on a simple XML that defines the flow of the user interface. This XML has to be defined based on the inputs that each panel takes and the output expected from each panel. The sample application that we have discussed, 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 used just to describe the framework and may not completely describe the sample application discussed in the example.

In the above XML, all the panels that implement the XFSPanel interface are mentioned. The flow from one panel to another is also defined. The RegistrationPreview panel has been defined in the XML just for clarifying that a panel may take inputs from the controller.

From the above XML it can be identified that based on the userOption output from the Home panel, the following panel is displayed and the flow continues based on the xml flow definition.





Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel