org.formaria.aria
Class ApplicationContext

java.lang.Object
  extended by org.formaria.aria.ApplicationContext
All Implemented Interfaces:
java.awt.event.WindowListener, java.util.EventListener, PageDisplay

public class ApplicationContext
extends java.lang.Object
implements PageDisplay, java.awt.event.WindowListener


Field Summary
protected  WidgetAdapter adapter
           
protected  boolean bUseWindow
          true if a popup window is in use
protected  int clientHeight
          The height of the client area
protected  int clientWidth
          The width of the client area
protected  Project currentProject
           
protected  java.lang.Class defaultSourceClass
          The default model data source class
protected  java.lang.String defaultTargetClass
           
protected  DataSource modelDataSource
          The model data source
protected  PageManager pageMgr
          The page manager
protected  StartupObject startupObject
          The Applet/Application/Startup instance
protected  java.lang.String widgetSet
           
 
Constructor Summary
ApplicationContext(StartupObject startObject, java.lang.String[] args)
          A default constructor.
ApplicationContext(StartupObject startObject, java.lang.String defTargetClass, java.lang.String[] args)
          A default constructor.
 
Method Summary
 void addLifeCycleListener()
          Add the lifecycle listener to the current project based upon the LifeCycleListener startup parameter/property
protected  void addSecondaryClassLoaders(java.lang.String packageName)
          Construct a new builder and set the default package.
protected  void addShutdownHook()
           
 ContentHolder addTarget(java.lang.String name, java.lang.Object constraint, int preferredWidth, int preferredHeight, java.util.Hashtable params)
          Add a new frame or target area to a frameset
 boolean canClose()
          Can the application close? If a life cycle listener has been added then its canClose method is invoked
 java.lang.Object displayDecoration(PageSupport page, java.lang.String constraint)
          Display a window decoration, for example a toolbar
 java.lang.Object displayPage(PageSupport page)
          Called when a page has been added or shown via the PageManager.
 java.lang.Object displayPage(PageSupport pageObj, java.lang.String target)
          Called when a page has been added or shown via the PageManager.
 java.lang.Object displayPage(PageSupport pageObj, java.lang.String target, java.lang.Object attributes)
          Called when a page has been added or shown via the PageManager.
 void doLayout()
          Update the page display layout
 java.lang.Object findTarget(java.lang.String target)
          Finds the target area for a page display request, this only applies to a frameset.
 int getClientHeight()
          Get the height of the main window.
 int getClientWidth()
          Get the width of the main window.
 int getNumTargets()
          Get the number of targets in the container
 java.lang.Object getTarget(int idx)
          Get the target for a page display request.
 void hidePage(PageSupport page)
          Remove the page from container.
 void init()
          Invoked when used as an applet.
protected  void initialise()
          Generic function which is called from the constructor if it's an application or from start if its an applet.
protected  int loadSecondaryProject(XmlElement projectElememt)
          Load a secondary project.
protected  void register()
          Load the componentFactories by reading the factory names from the startup file.
 void removeAllTargets()
          Remove all frames/targets from the current frameset
 void restoreState()
          Restore the application state
 void saveState()
          Save the application state
protected  void setContent(boolean initialized)
          Load the content into the model.
 void setDefaultDataSource(java.lang.String className)
          Sets the default datasource class.
 void setDefaultTargetClass(java.lang.String clsName)
          Set the name of the default target class
 void setHome()
          Set the home page using the startup properties.
protected  void setResourceFile(java.lang.String startFile)
          Setup the default resource file for the application and load some of the information in it.
protected  void setup(java.lang.String[] args, boolean isMainProject)
          Setup the applet by setting paths and then initializing the applet.
 void setupFrameset(java.util.Hashtable params)
          Setup frameset.
 void shutdown()
          Shutdown and exit the application
 void windowActivated(java.awt.event.WindowEvent e)
          Template method, unused at present
 void windowClosed(java.awt.event.WindowEvent e)
          Template method, unused at present
 void windowClosing(java.awt.event.WindowEvent e)
          Exit the application
 void windowDeactivated(java.awt.event.WindowEvent e)
          Template method, unused at present
 void windowDeiconified(java.awt.event.WindowEvent e)
          Template method, unused at present
 void windowIconified(java.awt.event.WindowEvent e)
          Template method, unused at present
 void windowOpened(java.awt.event.WindowEvent e)
          Template method, unused at present
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pageMgr

protected PageManager pageMgr
The page manager


bUseWindow

protected boolean bUseWindow
true if a popup window is in use


modelDataSource

protected DataSource modelDataSource
The model data source


defaultSourceClass

protected java.lang.Class defaultSourceClass
The default model data source class


startupObject

protected StartupObject startupObject
The Applet/Application/Startup instance


clientWidth

protected int clientWidth
The width of the client area


clientHeight

protected int clientHeight
The height of the client area


currentProject

protected Project currentProject

defaultTargetClass

protected java.lang.String defaultTargetClass

adapter

protected WidgetAdapter adapter

widgetSet

protected java.lang.String widgetSet
Constructor Detail

ApplicationContext

public ApplicationContext(StartupObject startObject,
                          java.lang.String[] args)
A default constructor. Most of the setup work is actually done by the initialize method and is called by the main method or the init method depending on whether or not an application of applet is being launched.

Parameters:
startObject - the invoking startup object
args - the optional command line arguments
  1. the relative path to the startup file, defaults to startup.properties if no arguments are provided
  2. the package name for the widgets e.g. "org.formaria.swing"

ApplicationContext

public ApplicationContext(StartupObject startObject,
                          java.lang.String defTargetClass,
                          java.lang.String[] args)
A default constructor. Most of the setup work is actually done by the initialize method and is called by the main method or the init method depending on whether or not an application of applet is being launched.

Parameters:
startObject - the invoking startup object
defTargetClass - the class name for the default target areas/containers
args - the optional command line arguments
  1. the relative path to the startup file, defaults to startup.properties if no arguments are provided
  2. the package name for the widgets e.g. "org.formaria.swing"
Method Detail

loadSecondaryProject

protected int loadSecondaryProject(XmlElement projectElememt)

Load a secondary project. A secondary project is loaded at the behest of the main project, and it is the main project's settings that control the application's appearance with the secondary project(s) contribution content and resources.

Secondary projects are specified as part of the projects resources, in a 'projects.xml' file that contains an entry for each project to load

Parameters:
projectElememt - the xml element for the new project
Returns:
0 on successful loading, non zero otherwise.

setup

protected void setup(java.lang.String[] args,
                     boolean isMainProject)
Setup the applet by setting paths and then initializing the applet. This method is a stand-in for the main method, processing the commandline parameters, so that its work is reusable and does not needed to be redone by derived classes. This method should not be called directly by user code.

Parameters:
args - the optional command line arguments
  1. the relative path to the startup file, defaults to startup.properties if no arguments are provided
  2. the package name for the widgets e.g. "org.formaria.swing"
isMainProject - true if this is the main project

shutdown

public void shutdown()
Shutdown and exit the application


addSecondaryClassLoaders

protected void addSecondaryClassLoaders(java.lang.String packageName)

Construct a new builder and set the default package. Aria sometimes uses additional class loaders to find the resources needed in a project. By default Aria uses the AriaBuilder class loader to convert XML files to Java classes.

A custom class loader can be referenced in the startup properties file using the 'BuilderClass' property. Once this property has been determined this method will instantiate an instance of that class if necessary.

Parameters:
packageName - the name of the default widget package e.g. org.formaria.awt, this is normally defined as a result of choosing the appropriate version of the Applet class

saveState

public void saveState()
Save the application state


restoreState

public void restoreState()
Restore the application state


setDefaultDataSource

public void setDefaultDataSource(java.lang.String className)
Sets the default datasource class. The default data source will be used to provide any initial data for the DataModel. Normally this data is static data that will be used to populate things like lists and provide default values.

Parameters:
className - the name of the datasource class e.g. org.formaria.data.DataSource.class, this class reads data from an XML file

setResourceFile

protected void setResourceFile(java.lang.String startFile)
Setup the default resource file for the application and load some of the information in it. The resource file is the startup properties file

Parameters:
startFile - The name of the file to be loaded, by default startup.properties

init

public void init()
Invoked when used as an applet. Sets up the startup file and initialises the application. Reads the applet parameters and calls initialize.


initialise

protected void initialise()

Generic function which is called from the constructor if it's an application or from start if its an applet.

The initialization process proceeds in the following order
  1. Register the component factories
  2. Setup the project class
  3. Setup the page manager
  4. Setup the resource manager
  5. Setup the style manager
  6. Size the main window
  7. Set the layout
  8. Add a shutdown hook
  9. Display the main window
the style manager


addShutdownHook

protected void addShutdownHook()

addLifeCycleListener

public void addLifeCycleListener()
Add the lifecycle listener to the current project based upon the LifeCycleListener startup parameter/property


canClose

public boolean canClose()
Can the application close? If a life cycle listener has been added then its canClose method is invoked


register

protected void register()
Load the componentFactories by reading the factory names from the startup file. The value of the 'NumComponentFactories' is first read and then the value of ComponentFactory (i.e. ComponentFactory0, ComponentFactory1) where is the number, starting at zero, of the factory. Each factory is then instantiated and will be called upon to construct components in the order in which the factories were registered.


setContent

protected void setContent(boolean initialized)
Load the content into the model. In the process an instance of the default model data source class is instantiated and reads data from a file pointed to by the 'ModelData' startup parameter.


setHome

public void setHome()
Set the home page using the startup properties. The home page is established by combining the two startup properties 'StartPackage' and 'StartClass'. By default 'StartClass' is set to a value of 'home. Both startup parameters are optional. Load the first page for the application.


displayPage

public java.lang.Object displayPage(PageSupport page)
Called when a page has been added or shown via the PageManager. The page manager then requests that the applet/application then displays the page in the appropriate location.

Specified by:
displayPage in interface PageDisplay
Parameters:
page - The Page which has been loaded.
Returns:
the page being displayed

displayPage

public java.lang.Object displayPage(PageSupport pageObj,
                                    java.lang.String target)

Called when a page has been added or shown via the PageManager. The page manager then requests that the applet/application then displays the page in the appropriate location.

The sequence with which the page transition occurs is as follows:

  • Find the appropriate target area
  • Ask the page to make its components non visible (to avoid flicker during the page update)
  • Set the page size
  • Save the current page's data by calling 'saveBoundComponentValues
  • Mark the current page as deactivated, and call the page's deactivated() method
  • Remove the old page from the container
  • Add the new page
  • Update the new page's bindings by calling updateBindings()
  • Update the new page's data by calling updateBoundComponentValues()
  • Layout the container and request it to repaint
  • Show the new page
  • Mark the new page as activated, and call its pageActivated method

    Specified by:
    displayPage in interface PageDisplay
    Parameters:
    pageObj - the page to display
    target - the area to update
    Returns:
    the page being displayed

    displayPage

    public java.lang.Object displayPage(PageSupport pageObj,
                                        java.lang.String target,
                                        java.lang.Object attributes)

    Called when a page has been added or shown via the PageManager. The page manager then requests that the applet/application then displays the page in the appropriate location.

    The sequence with which the page transition occurs is as follows:

  • Find the appropriate target area
  • Ask the page to make its components non visible (to avoid flicker during the page update)
  • Set the page size
  • Save the current page's data by calling 'saveBoundComponentValues
  • Mark the current page as deactivated, and call the page's deactivated() method
  • Remove the old page from the container
  • Add the new page
  • Update the new page's bindings by calling updateBindings()
  • Update the new page's data by calling updateBoundComponentValues()
  • Layout the container and request it to repaint
  • Show the new page
  • Mark the new page as activated, and call its pageActivated method

    Specified by:
    displayPage in interface PageDisplay
    Parameters:
    pageObj - the page to dosplay
    target - the name of the target area to update
    attributes - attributes for use by the new page / taregt
    Returns:
    the page being displayed

    displayDecoration

    public java.lang.Object displayDecoration(PageSupport page,
                                              java.lang.String constraint)
    Display a window decoration, for example a toolbar

    Specified by:
    displayDecoration in interface PageDisplay
    Parameters:
    page - the new page
    constraint - a value controlling how and where the decoration is displayed, this value is application type specific
    Returns:
    the page being displayed

    doLayout

    public void doLayout()
    Update the page display layout

    Specified by:
    doLayout in interface PageDisplay

    hidePage

    public void hidePage(PageSupport page)
    Remove the page from container. The page is simply removed and the container validated.

    Parameters:
    page - the page to hide

    findTarget

    public java.lang.Object findTarget(java.lang.String target)
    Finds the target area for a page display request, this only applies to a frameset. If there is no frameset the main area or default area is named 'content' and this area is used if null is used as the target name.

    Specified by:
    findTarget in interface PageDisplay
    Parameters:
    target - the target area name
    Returns:
    the container to be updated

    getTarget

    public java.lang.Object getTarget(int idx)
    Get the target for a page display request. The target areas are stored in the order in which they were declared or added.

    Specified by:
    getTarget in interface PageDisplay
    Parameters:
    idx - the target area
    Returns:
    the container to be updated

    getNumTargets

    public int getNumTargets()
    Get the number of targets in the container

    Specified by:
    getNumTargets in interface PageDisplay
    Returns:
    the number of targets

    setupFrameset

    public void setupFrameset(java.util.Hashtable params)
    Setup frameset. This method is called prior to the addition of any target areas in the framset and prior to the display of any pages

    Specified by:
    setupFrameset in interface PageDisplay
    Parameters:
    params - the framset parameters if any

    addTarget

    public ContentHolder addTarget(java.lang.String name,
                                   java.lang.Object constraint,
                                   int preferredWidth,
                                   int preferredHeight,
                                   java.util.Hashtable params)
    Add a new frame or target area to a frameset

    Specified by:
    addTarget in interface PageDisplay
    Parameters:
    name - the frame name
    constraint - the BorderlayoutConstraint
    preferredWidth - the preferred width
    preferredHeight - the preferred height
    params - extra parameters for the target
    Returns:
    the selected target

    removeAllTargets

    public void removeAllTargets()
    Remove all frames/targets from the current frameset

    Specified by:
    removeAllTargets in interface PageDisplay

    setDefaultTargetClass

    public void setDefaultTargetClass(java.lang.String clsName)
    Set the name of the default target class

    Parameters:
    clsName - the class name

    windowClosing

    public void windowClosing(java.awt.event.WindowEvent e)
    Exit the application

    Specified by:
    windowClosing in interface java.awt.event.WindowListener
    Parameters:
    e - the window event

    getClientWidth

    public int getClientWidth()
    Get the width of the main window. Retrieved from the startup file or defaulted

    Returns:
    the client width

    getClientHeight

    public int getClientHeight()
    Get the height of the main window. Retrieved from the startup file or defaulted

    Returns:
    the client height

    windowActivated

    public void windowActivated(java.awt.event.WindowEvent e)
    Template method, unused at present

    Specified by:
    windowActivated in interface java.awt.event.WindowListener
    Parameters:
    e - the window event

    windowClosed

    public void windowClosed(java.awt.event.WindowEvent e)
    Template method, unused at present

    Specified by:
    windowClosed in interface java.awt.event.WindowListener
    Parameters:
    e - the window event

    windowDeiconified

    public void windowDeiconified(java.awt.event.WindowEvent e)
    Template method, unused at present

    Specified by:
    windowDeiconified in interface java.awt.event.WindowListener
    Parameters:
    e - the window event

    windowDeactivated

    public void windowDeactivated(java.awt.event.WindowEvent e)
    Template method, unused at present

    Specified by:
    windowDeactivated in interface java.awt.event.WindowListener
    Parameters:
    e - the window event

    windowIconified

    public void windowIconified(java.awt.event.WindowEvent e)
    Template method, unused at present

    Specified by:
    windowIconified in interface java.awt.event.WindowListener
    Parameters:
    e - the window event

    windowOpened

    public void windowOpened(java.awt.event.WindowEvent e)
    Template method, unused at present

    Specified by:
    windowOpened in interface java.awt.event.WindowListener
    Parameters:
    e - the window event