net.xoetrope.xui
Class XComponentFactory

java.lang.Object
  extended by net.xoetrope.xui.XComponentFactory
Direct Known Subclasses:
XStyleFactory

public class XComponentFactory
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 XPanel 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 XComponentConstructors. 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 XPage so as to make referencing the constants easier in the client code (subclasses of XPage). 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) Xoetrope Ltd., 2002-2003

License: see license.txt

$Revision: 2.21 $


Field Summary
protected  WidgetAdapter adapter
          The adapter used for the current package's widgets
protected  java.lang.String basePackageName
          The package to which the widgets belong
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  XProject currentProject
          The project that owns this factory
protected static LayoutHelper layoutHelper
          A helper to construct various layout managers
protected  int parentH
           
protected  java.lang.Object parentPanel
          The parent panel to which components are added
protected  int parentW
           
protected static boolean requiresParent
          A flag indicating is the components require the parent object to be passed as an argumnet to the constructor.
protected  XTranslator 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 XANNOTATEDIMAGE
          A constant used internally to identify an annotated image component.
static int XBUTTON
          A constant used internally to identify a push buttob.
static int XCHECK
          A constant used internally to identify a Checkbox.
static int XCOMBO
          A constant used internally to identify a Combo Box.
static int XEDIT
          A constant used internally to identify a Edit field.
static int XGROUP
          A constant used internally to identify a RadioButton group.
static int XHOTSPOTIMAGE
          A constant used internally to identify a hotspot image.
static int XIMAGE
          A constant used internally to identify an image component.
static int XIMAGEMAP
          A constant used internally to identify an image map.
static int XLABEL
          A static text
static int XLIST
          A constant used internally to identify a List.
static int XMENU
          A constant used internally to identify a Menu.
static int XMENUBAR
          A constant used internally to identify a MenuBar.
static int XMENUITEM
          A constant used internally to identify a Menu item.
static int XMETACONTENT
          A constant used internally to identify a container for tagged content.
static int XPANEL
          A panel / container
static int XPASSWORD
          A constant used internally to identify a password field.
static int XRADIO
          A constant used internally to identify a RadioButton.
static int XSCROLLABLEMETACONTENT
          A constant used internally to identify a scrollable meta content.
static int XSCROLLPANE
          A constant used internally to identify a scroll panel.
static int XSPLITPANE
          A constant used internally to identify a splitter.
static int XTABLE
          A constant used internally to identify a table component.
static int XTABPANEL
          A constant used internally to identify a tab panel.
static int XTEXTAREA
          A constant used internally to identify a multiline text edit component.
static int XUNKNOWN
          A component of a type that is unknown to XUI (i.e. not one of the built in types)
static int XWMF
          A constant used internally to identify a vector image component.
 
Constructor Summary
XComponentFactory(XProject proj, java.lang.String packageName)
          Constructs a component factory
 
Method Summary
 void addComponent(java.lang.Object c)
          Add a component to the panel.
 void addComponent(java.lang.Object c, java.lang.Object constraint)
          Add a component to the panel.
 java.lang.Object addComponent(java.lang.String type, int x, int y, int w, int h, java.lang.String content)
          A generic factory for adding XComponents.
 java.lang.Object addComponent(java.lang.String type, java.lang.Object pos, java.lang.String content)
          A generic factory for adding XComponents.
 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 XComponentConstructor interface or component factories.
 java.lang.Object constructComponent(java.lang.String type, java.lang.String content)
          A generic factory for constructing XComponents.
 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, XComponentConstructor 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

XUNKNOWN

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

See Also:
Constant Field Values

XPANEL

public static final int XPANEL
A panel / container

See Also:
Constant Field Values

XLABEL

public static final int XLABEL
A static text

See Also:
Constant Field Values

XRADIO

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

See Also:
Constant Field Values

XCHECK

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

See Also:
Constant Field Values

XCOMBO

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

See Also:
Constant Field Values

XLIST

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

See Also:
Constant Field Values

XIMAGE

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

See Also:
Constant Field Values

XEDIT

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

See Also:
Constant Field Values

XBUTTON

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

See Also:
Constant Field Values

XMETACONTENT

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

See Also:
Constant Field Values

XGROUP

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

See Also:
Constant Field Values

XSCROLLPANE

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

See Also:
Constant Field Values

XSCROLLABLEMETACONTENT

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

See Also:
Constant Field Values

XHOTSPOTIMAGE

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

See Also:
Constant Field Values

XTABLE

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

See Also:
Constant Field Values

XWMF

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

See Also:
Constant Field Values

XANNOTATEDIMAGE

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

See Also:
Constant Field Values

XMENUBAR

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

See Also:
Constant Field Values

XMENU

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

See Also:
Constant Field Values

XMENUITEM

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

See Also:
Constant Field Values

XTEXTAREA

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

See Also:
Constant Field Values

XPASSWORD

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

See Also:
Constant Field Values

XIMAGEMAP

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

See Also:
Constant Field Values

XTABPANEL

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

See Also:
Constant Field Values

XSPLITPANE

public static final int XSPLITPANE
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 XTranslator translator
The translator used for translation


currentProject

protected XProject 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

XComponentFactory

public XComponentFactory(XProject 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 XComponents.

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,
                                     int x,
                                     int y,
                                     int w,
                                     int h,
                                     java.lang.String content)
A generic factory for adding XComponents. 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.Object pos,
                                     java.lang.String content)
A generic factory for adding XComponents. 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 XComponentConstructor 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,
                                            XComponentConstructor 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 XuiBuilder 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 void addComponent(java.lang.Object c)
Add a component to the panel.

Parameters:
c - the component to add

addComponent

public void 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 XLayoutHelper 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