org.formaria.aria
Class ComponentFactory

java.lang.Object
  extended by org.formaria.aria.ComponentFactory
Direct Known Subclasses:
StyleFactory

public class ComponentFactory
extends java.lang.Object

A component factory. The factory is designed to create components for a null layout. The factory will use an incrementing id to name each component. When an Panel is added it will automatically become the parent for subsequent components added using the factory. If another parent component is needed then the parent can be explicitly set.

When components are added their size is checked against that of the parent and reduced if they extend beyond the bounds of the parent.

The component factory can be extended by registering new ComponentConstructors. These constructors are invoked if the build in constructors cannot build the specified type.

Components can be specified by a type name, an type constant or by a class name. The type constants for the built-in components are specified in Page so as to make referencing the constants easier in the client code (subclasses of Page). The package name is set as an attribute of the factory so that various versions of the widgets can be create for say Swing and AWT without needing to create distinct factories and without need to include such implementation details in the client code.

Copyright (c) Formaria Ltd., 2008

License: see license.txt

$Revision: 2.21 $


Field Summary
protected  WidgetAdapter adapter
          The adapter used for the current package's widgets
static int ANNOTATEDIMAGE
          A constant used internally to identify an annotated image component.
protected  java.lang.String basePackageName
          The package to which the widgets belong
static int BUTTON
          A constant used internally to identify a push buttob.
static int CHECK
          A constant used internally to identify a Checkbox.
static int COMBO
          A constant used internally to identify a Combo Box.
protected static java.util.Hashtable componentFactories
          A collection of component factories
protected  java.lang.Object currentMenu
          The current menu.
protected  java.lang.Object currentMenuBar
          The application's menu bar
protected  Project currentProject
          The project that owns this factory
static int EDIT
          A constant used internally to identify a Edit field.
static int GROUP
          A constant used internally to identify a RadioButton group.
static int HOTSPOTIMAGE
          A constant used internally to identify a hotspot image.
static int IMAGE
          A constant used internally to identify an image component.
static int IMAGEMAP
          A constant used internally to identify an image map.
static int LABEL
          A static text
protected static LayoutHelper layoutHelper
          A helper to construct various layout managers
static int LIST
          A constant used internally to identify a List.
static int MENU
          A constant used internally to identify a Menu.
static int MENUBAR
          A constant used internally to identify a MenuBar.
static int MENUITEM
          A constant used internally to identify a Menu item.
static int METACONTENT
          A constant used internally to identify a container for tagged content.
static int PANEL
          A panel / container
protected  int parentH
           
protected  java.lang.Object parentPanel
          The parent panel to which components are added
protected  int parentW
           
static int PASSWORD
          A constant used internally to identify a password field.
static int RADIO
          A constant used internally to identify a RadioButton.
protected static boolean requiresParent
          A flag indicating is the components require the parent object to be passed as an argumnet to the constructor.
static int SCROLLABLEMETACONTENT
          A constant used internally to identify a scrollable meta content.
static int SCROLLPANE
          A constant used internally to identify a scroll panel.
static int SPLITPANE
          A constant used internally to identify a splitter.
static int TABLE
          A constant used internally to identify a table component.
static int TABPANEL
          A constant used internally to identify a tab panel.
static int TEXTAREA
          A constant used internally to identify a multiline text edit component.
protected  Translator translator
          The translator used for translation
protected static java.util.Hashtable typeNames
          A collection of component type names and ids used to aid construction of components
static int UNKNOWN
          A component of a type that is unknown to Aria (i.e.
static int WMF
          A constant used internally to identify a vector image component.
 
Constructor Summary
ComponentFactory(Project proj, java.lang.String packageName)
          Constructs a component factory
 
Method Summary
 java.lang.Object addComponent(java.lang.Object c)
          Add a component to the panel.
 java.lang.Object addComponent(java.lang.Object c, java.lang.Object constraint)
          Add a component to the panel.
 java.lang.Object addComponent(java.lang.String type, java.lang.String nameStr, int x, int y, int w, int h, java.lang.String content)
          A generic factory for adding Components.
 java.lang.Object addComponent(java.lang.String type, java.lang.String nameStr, java.lang.Object pos, java.lang.String content)
          A generic factory for adding Components.
 java.lang.Object addElement(java.lang.String type, java.lang.String name, java.lang.String content, java.util.Hashtable attribs)
          Add a non-component object to the panel or an element of the panel.
 java.lang.Object addLayout(java.lang.Object cont, int type)
          Sets a LayoutManager for the panel
protected  java.lang.Object buildRegisteredComponent(java.lang.String type, java.lang.String content)
          A generic factory for adding registered components via the ComponentConstructor interface or component factories.
 java.lang.Object constructComponent(java.lang.String type, java.lang.String content)
          A generic factory for constructing Components.
 ComponentAdapter getComponentAdapter(java.lang.String type)
          Lookup the component adapter for the named type
static java.util.Hashtable getFactories()
          Get the component factories
static LayoutHelper getLayoutHelper()
          Get the layout helper
 java.lang.Object getParentComponent()
          Get the current parent component
protected static int getTypeCode(java.lang.String typeName)
          Get the type constant associated with a type name
protected  java.lang.Object instantiate(java.lang.String className)
          Instantiate a component using reflection to locate the constructor.
static void registerComponentFactory(java.lang.String name, ComponentConstructor factory)
          Add a componentFactory to the static register of component constructors
static void setLayoutHelper(LayoutHelper newHelper)
          Set the layout helper
 void setParentComponent(java.lang.Object c)
          Change the parent for new components.
static void setRequiresParent(boolean b)
          Flags whether or not the component constructors require the parent as an argument.
 void setResourceBundle(java.lang.String resourceBundleName)
          Set the resource bundle for this component factory.
protected static void setupTypeNames()
          Setup a hashtable of type names.
 java.lang.String translate(java.lang.String key)
          Look up the translation of a key using the current language resource
static void updateComponentFactories()
          Notify the component factories that some of their settings may have changed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN

public static final int UNKNOWN
A component of a type that is unknown to Aria (i.e. not one of the built in types)

See Also:
Constant Field Values

PANEL

public static final int PANEL
A panel / container

See Also:
Constant Field Values

LABEL

public static final int LABEL
A static text

See Also:
Constant Field Values

RADIO

public static final int RADIO
A constant used internally to identify a RadioButton.

See Also:
Constant Field Values

CHECK

public static final int CHECK
A constant used internally to identify a Checkbox.

See Also:
Constant Field Values

COMBO

public static final int COMBO
A constant used internally to identify a Combo Box.

See Also:
Constant Field Values

LIST

public static final int LIST
A constant used internally to identify a List.

See Also:
Constant Field Values

IMAGE

public static final int IMAGE
A constant used internally to identify an image component.

See Also:
Constant Field Values

EDIT

public static final int EDIT
A constant used internally to identify a Edit field.

See Also:
Constant Field Values

BUTTON

public static final int BUTTON
A constant used internally to identify a push buttob.

See Also:
Constant Field Values

METACONTENT

public static final int METACONTENT
A constant used internally to identify a container for tagged content.

See Also:
Constant Field Values

GROUP

public static final int GROUP
A constant used internally to identify a RadioButton group.

See Also:
Constant Field Values

SCROLLPANE

public static final int SCROLLPANE
A constant used internally to identify a scroll panel.

See Also:
Constant Field Values

SCROLLABLEMETACONTENT

public static final int SCROLLABLEMETACONTENT
A constant used internally to identify a scrollable meta content.

See Also:
Constant Field Values

HOTSPOTIMAGE

public static final int HOTSPOTIMAGE
A constant used internally to identify a hotspot image.

See Also:
Constant Field Values

TABLE

public static final int TABLE
A constant used internally to identify a table component.

See Also:
Constant Field Values

WMF

public static final int WMF
A constant used internally to identify a vector image component.

See Also:
Constant Field Values

ANNOTATEDIMAGE

public static final int ANNOTATEDIMAGE
A constant used internally to identify an annotated image component.

See Also:
Constant Field Values

MENUBAR

public static final int MENUBAR
A constant used internally to identify a MenuBar.

See Also:
Constant Field Values

MENU

public static final int MENU
A constant used internally to identify a Menu.

See Also:
Constant Field Values

MENUITEM

public static final int MENUITEM
A constant used internally to identify a Menu item.

See Also:
Constant Field Values

TEXTAREA

public static final int TEXTAREA
A constant used internally to identify a multiline text edit component.

See Also:
Constant Field Values

PASSWORD

public static final int PASSWORD
A constant used internally to identify a password field.

See Also:
Constant Field Values

IMAGEMAP

public static final int IMAGEMAP
A constant used internally to identify an image map.

See Also:
Constant Field Values

TABPANEL

public static final int TABPANEL
A constant used internally to identify a tab panel.

See Also:
Constant Field Values

SPLITPANE

public static final int SPLITPANE
A constant used internally to identify a splitter.

See Also:
Constant Field Values

componentFactories

protected static java.util.Hashtable componentFactories
A collection of component factories


typeNames

protected static java.util.Hashtable typeNames
A collection of component type names and ids used to aid construction of components


layoutHelper

protected static LayoutHelper layoutHelper
A helper to construct various layout managers


requiresParent

protected static boolean requiresParent
A flag indicating is the components require the parent object to be passed as an argumnet to the constructor.


basePackageName

protected java.lang.String basePackageName
The package to which the widgets belong


translator

protected Translator translator
The translator used for translation


currentProject

protected Project currentProject
The project that owns this factory


adapter

protected WidgetAdapter adapter
The adapter used for the current package's widgets


currentMenuBar

protected java.lang.Object currentMenuBar
The application's menu bar


currentMenu

protected java.lang.Object currentMenu
The current menu. Menu construction is slightly abnormal for the factory and requires additional parameters


parentPanel

protected java.lang.Object parentPanel
The parent panel to which components are added


parentW

protected int parentW

parentH

protected int parentH
Constructor Detail

ComponentFactory

public ComponentFactory(Project proj,
                        java.lang.String packageName)
Constructs a component factory

Parameters:
proj - The project to which the fctory belongs
packageName - the package name for the components
Method Detail

setResourceBundle

public void setResourceBundle(java.lang.String resourceBundleName)
Set the resource bundle for this component factory. The resource bundle is used for translation of text and other content.

Parameters:
resourceBundleName - the resource bundle name

constructComponent

public java.lang.Object constructComponent(java.lang.String type,
                                           java.lang.String content)
A generic factory for constructing Components.

Parameters:
type - a name identifying the type of component to be created
content - the component text/content
Returns:
the new component

instantiate

protected java.lang.Object instantiate(java.lang.String className)
Instantiate a component using reflection to locate the constructor. This method of creating a component is used where the parent object or some other constructor argument is required to create the component.

Parameters:
className - the class to instantiate
Returns:
the new component

translate

public java.lang.String translate(java.lang.String key)
Look up the translation of a key using the current language resource

Parameters:
key - the key string
Returns:
the translation

addComponent

public java.lang.Object addComponent(java.lang.String type,
                                     java.lang.String nameStr,
                                     int x,
                                     int y,
                                     int w,
                                     int h,
                                     java.lang.String content)
A generic factory for adding Components. The component is constructed, positioned and added to the parent panel if one exists. This method delegates to the registered component factories if any. All built in components are constructed with an ID. When a ScrollPane is addd it becomes the parent.

Parameters:
type - a name identifying the type of component to be created
x - the left coordinate
y - the top coordinate
w - the width
h - the height
content - the component text/content
Returns:
the new component

addComponent

public java.lang.Object addComponent(java.lang.String type,
                                     java.lang.String nameStr,
                                     java.lang.Object pos,
                                     java.lang.String content)
A generic factory for adding Components. The component is constructed, positioned and added to the parent panel if one exists. This method delegates to the registered component factories if any. All built in components are constructed with an ID. When a ScrollPane is addd it becomes the parent.

Parameters:
type - a name identifying the type of component to be created
pos - the constraint
content - the component text/content
Returns:
the new component

buildRegisteredComponent

protected java.lang.Object buildRegisteredComponent(java.lang.String type,
                                                    java.lang.String content)
A generic factory for adding registered components via the ComponentConstructor interface or component factories.

Parameters:
type - a name identifying the type of component to be created
content - the component text/content
Returns:
the new component

getComponentAdapter

public ComponentAdapter getComponentAdapter(java.lang.String type)
Lookup the component adapter for the named type

Parameters:
type - a name identifying the type of component to be created
Returns:
the new component adapter for the type

registerComponentFactory

public static void registerComponentFactory(java.lang.String name,
                                            ComponentConstructor factory)
Add a componentFactory to the static register of component constructors

Parameters:
name - the name by which this factory will be known.
factory - the new componentFactory

updateComponentFactories

public static void updateComponentFactories()
Notify the component factories that some of their settings may have changed


getFactories

public static java.util.Hashtable getFactories()
Get the component factories

Returns:
a the factor store.

addElement

public java.lang.Object addElement(java.lang.String type,
                                   java.lang.String name,
                                   java.lang.String content,
                                   java.util.Hashtable attribs)
Add a non-component object to the panel or an element of the panel. This method is invoked is the AriaBuilder fails to construct a component for an XML element

Parameters:
type - the object type
name - a name identifying the element to be created
content - the component text/content
attribs - the element attributes if any
Returns:
the new component

addComponent

public java.lang.Object addComponent(java.lang.Object c)
Add a component to the panel.

Parameters:
c - the component to add

addComponent

public java.lang.Object addComponent(java.lang.Object c,
                                     java.lang.Object constraint)
Add a component to the panel.

Parameters:
c - the component to add
constraint - the layout manager constraint

addLayout

public java.lang.Object addLayout(java.lang.Object cont,
                                  int type)
Sets a LayoutManager for the panel

Parameters:
cont - the container whose layout manager is being set or null to set the parent panel's layout manager
type - the layout manager as defined in the LayoutHelper class
Returns:
the new layout manager instance

setParentComponent

public void setParentComponent(java.lang.Object c)
Change the parent for new components. This method will affect the next component added.

Parameters:
c - the new parent, this should be an instance of java.awt.Container

getParentComponent

public java.lang.Object getParentComponent()
Get the current parent component

Returns:
the parent component.

getLayoutHelper

public static LayoutHelper getLayoutHelper()
Get the layout helper

Returns:
the layout helper

setLayoutHelper

public static void setLayoutHelper(LayoutHelper newHelper)
Set the layout helper

Parameters:
newHelper - the new layout helper

getTypeCode

protected static int getTypeCode(java.lang.String typeName)
Get the type constant associated with a type name

Parameters:
typeName - the type name
Returns:
the type constant

setupTypeNames

protected static void setupTypeNames()
Setup a hashtable of type names. This will be moved to a helper class at some stage


setRequiresParent

public static void setRequiresParent(boolean b)
Flags whether or not the component constructors require the parent as an argument. Set to false by default.

Parameters:
b - true to pass the parent to the constructor