org.jdesktop.jdnc.form
Class FormFactory

java.lang.Object
  extended by org.jdesktop.jdnc.form.FormFactory
Direct Known Subclasses:
DefaultFormFactory

public abstract class FormFactory
extends java.lang.Object

Form factory class which provides support for constructing the user-interface components and associated bindings for a JForm component.

Generally, applications need not interact directly with this class because the default operation of the JForm component will invoke this factory as necessary to construct the form based on how the application binds the form to the application's data models.

This factory provides methods for 3 key form-building operations:

  1. createComponent: given a MetaData object which describes a data field (name, type, edit constraints, etc), return the user-interface component which can best display and/or edit values for that field.
  2. createBinding: given a user-interface component and a named field on a data model, return the Binding instance required to bind that component to that field.
  3. addComponent: adds the provided component to the specified form container, including laying it out according to the layout paradigm of the form factory

This factory can handle non-visual data fields - createComponent will return null in that case. Note that a form factory is stateless and these methods operate independent of each other, thus an application may invoke only those methods it requires to construct the form. For example, an application that wishes to use the form factory's components and bindings, but intends to handle the layout itself, may choose to invoke only the first two methods.

Version:
1.0
Author:
Amy Fowler

Constructor Summary
FormFactory()
           
 
Method Summary
abstract  Binding addComponent(javax.swing.JComponent parent, javax.swing.JComponent component, DataModel dataModel, java.lang.String fieldName)
          Adds the component to the specified parent container and configures its layout within that container according to the form factory's layout paradigm.
abstract  void addComponent(javax.swing.JComponent parent, javax.swing.JComponent component, MetaData metaData)
          Adds the component to the specified parent container and configures its layout within that container according to the form factory's layout paradigm.
abstract  Binding createBinding(DataModel model, java.lang.String fieldName, javax.swing.JComponent component)
          Factory method for returning the binding object which connects the user-interface component to the specified field in a data model.
abstract  javax.swing.JComponent createComponent(MetaData metaData)
          Factory method for returning the user-interface component best suited to edit/display values for the data model field represented by the metaData object.
static FormFactory getDefaultFormFactory()
           
 boolean isNonVisual(MetaData metaData)
           
static void setDefaultFormFactory(FormFactory formFactory)
          Sets the default FormFactory instance which is shared across the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormFactory

public FormFactory()
Method Detail

getDefaultFormFactory

public static FormFactory getDefaultFormFactory()
Returns:
FormFactory instance which is shared across the application

setDefaultFormFactory

public static void setDefaultFormFactory(FormFactory formFactory)
Sets the default FormFactory instance which is shared across the application.

Parameters:
formFactory - factory to be used as the default form factory

createComponent

public abstract javax.swing.JComponent createComponent(MetaData metaData)
Factory method for returning the user-interface component best suited to edit/display values for the data model field represented by the metaData object. The returned component is not only based on the metadata's type, but also on it's edit constraints.

Parameters:
metaData - object which describes the named field
Returns:
JComponent which can display/edit values defined by the metaData object or null if the field is non-visual.

createBinding

public abstract Binding createBinding(DataModel model,
                                      java.lang.String fieldName,
                                      javax.swing.JComponent component)
Factory method for returning the binding object which connects the user-interface component to the specified field in a data model.

Parameters:
model - data model object to which the component is being bound
fieldName - String containing the name of the field within the data model
component - JComponent which can display/edit values defined by the metaData object
Returns:
Binding instance which binds the component to the field in the data model

addComponent

public abstract void addComponent(javax.swing.JComponent parent,
                                  javax.swing.JComponent component,
                                  MetaData metaData)
Adds the component to the specified parent container and configures its layout within that container according to the form factory's layout paradigm. If the metaData argument is not null, then a label will be automatically created and aligned with the component. Note that the component being added need not be the component which has the binding. For example, an edit component may be contained within another container (scrollpane, panel, etc); the edit component will have the binding, but the container is what must be added to the form.

Parameters:
parent - Container where the component is being added
component - JComponent being added to the container
metaData - object which describes the named field

addComponent

public abstract Binding addComponent(javax.swing.JComponent parent,
                                     javax.swing.JComponent component,
                                     DataModel dataModel,
                                     java.lang.String fieldName)
Adds the component to the specified parent container and configures its layout within that container according to the form factory's layout paradigm. If the DataModel and metaData argument are not null, then a label will be automatically created and aligned with the component. The label will be bound to the field's metaData. Note that the component being added need not be the component which has the binding. For example, an edit component may be contained within another container (scrollpane, panel, etc); the edit component will have the binding, but the container is what must be added to the form.

Parameters:
parent - Container where the component is being added
component - JComponent being added to the container
dataModel - the data to take the field from.
fieldName - name of the field
Returns:
the meta binding to the label, might be null

isNonVisual

public boolean isNonVisual(MetaData metaData)
Parameters:
metaData -
Returns:


Copyright © 2005 Sun Microsystems All Rights Reserved.