ewe.ui
Class UIBuilder

java.lang.Object
  extended byewe.ui.UIBuilder

public class UIBuilder
extends Object

The UIBuilder class provides a very easy way of building a user interface using an Editor and an editable object. See the Programmer's Guide for instructions on how to use it in detail.


Field Summary
 Object editedObject
          This is an instance of the object being edited (this is allowed to be null).
 Editor editor
          This is the Editor that the UIBuilder is building.
static int inputStackLength
           
 Reflect objectClass
          This is a ewe.reflect.Reflect object representing the object being edited.
protected  Vector openPanels
           
protected  Object properties
           
 
Constructor Summary
UIBuilder()
           
UIBuilder(Editor ed)
          Create a UIBuilder for an Editor.
UIBuilder(Editor ed, Object classOrObject)
          Create a UIBuilder for an Editor which will edit a specific type of object.
UIBuilder(Editor ed, Object classOrObject, CellPanel cp)
          Create a UIBuilder for an Editor which will edit a specific type of object, given a CellPanel that has already been added to the Editor as the starting point.
 
Method Summary
 Control add(Control c)
           
 Control add(String field)
           
 Control add(String field, Control c)
           
 Control add(String prompt, String field)
           
 Control add(String prompt, String field, Control c)
           
 Control[] addAll(String promptsAndFields)
          Add all the specified fields.
 Control addChoice(String prompt, String field, String[] choices)
           
 Control addCombo(String prompt, String field, String[] choices)
           
 CellPanel addTo(CellPanel cp)
          Set the specified CellPanel as being the current open panel.
static String askClassName(String pathToClass, StringBuffer programDir, Frame parent)
           
 CellPanel close()
          Close the current cell panel.
 CellPanel close(boolean endRow)
          Close the current cell panel.
 void endRow()
          This ends the row in the current open CellPanel.
 Control getControlFor(String prompt, FieldTransfer ft, boolean forInputStack, Object properties, FieldData fd)
          This returns the appropriate Control for a given field.
protected  Control getControlFor(String prompt, String field, boolean forInputStack)
           
 Control getControlFor(String prompt, String field, boolean forInputStack, Object properties)
          This returns the appropriate Control for a given field.
 CellPanel getOpenPanel()
          Return the current open CellPanel.
static UIBuilder newInputStack(CellPanel cp, Editor ed, Object objectOrClass)
          A quick way of creating a new UIBuilder and opening an InputStack.
static UIBuilder newPanel(CellPanel cp, Editor ed, Object objectOrClass)
          A quick way of creating a new UIBuilder and opening a panel.
static UIBuilder newStack(CellPanel cp, Editor ed, Object objectOrClass)
          A quick way of creating a new UIBuilder and opening a stack (NOT an InputStack).
 CellPanel open()
          Open a new CellPanel within the current open CellPanel.
 CellPanel open(CellPanel cp, MultiPanel mp, String tabName, String longName)
          Open a specified CellPanel within an already added Multipanel.
 CellPanel open(CellPanel cp, String text)
          Set a new CellPanel as the current open panel and add it to the previously open panel.
 CellPanel open(MultiPanel mp, String tabName, String longName)
          Open a new CellPanel within an already added Multipanel.
 CellPanel open(String text)
          Open a new CellPanel within the current open CellPanel.
 InputStack openInputStack()
          Open a new ewe.ui.InputStack within the current open CellPanel.
 InputStack openInputStack(String text)
          Open a new ewe.ui.InputStack within the current open CellPanel.
 CellPanel openStack()
          Open a new Stack within the current open CellPanel.
 CellPanel openStack(String text)
          Open a new Stack within the current open CellPanel.
 UIBuilder set(Object properties)
          This sets the properties of the next control to be added.
 void setEditedObject(Object object)
          This is used to set an example of the data being edited.
 UIBuilder setFormats(String formats)
          Set the formats for the fields that will be added.
 void setObjectClass(Object objectOrClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

editor

public Editor editor
This is the Editor that the UIBuilder is building.


objectClass

public Reflect objectClass
This is a ewe.reflect.Reflect object representing the object being edited.


editedObject

public Object editedObject
This is an instance of the object being edited (this is allowed to be null).


inputStackLength

public static int inputStackLength

openPanels

protected Vector openPanels

properties

protected Object properties
Constructor Detail

UIBuilder

public UIBuilder()

UIBuilder

public UIBuilder(Editor ed)
Create a UIBuilder for an Editor.

Parameters:
ed - The editor being built. It assumes that the object being edited is the editor itself.

UIBuilder

public UIBuilder(Editor ed,
                 Object classOrObject)
Create a UIBuilder for an Editor which will edit a specific type of object.

Parameters:
ed - The editor being built
classOrObject - This is either a java.lang.Class object representing the object to be edited, or a ewe.reflect.Reflect representing the object to be edited, or an instance of the object to be edited.

UIBuilder

public UIBuilder(Editor ed,
                 Object classOrObject,
                 CellPanel cp)
Create a UIBuilder for an Editor which will edit a specific type of object, given a CellPanel that has already been added to the Editor as the starting point.

Parameters:
ed - The editor being built
classOrObject - This is either a java.lang.Class object representing the object to be edited, or a ewe.reflect.Reflect representing the object to be edited, or an instance of the object to be edited.
cp - A CellPanel that has already been added to the Editor and that will be used as the start point for adding controls.
Method Detail

setFormats

public UIBuilder setFormats(String formats)
Set the formats for the fields that will be added.

Parameters:
formats - A format specifier string or null to clear the formats.
Returns:
This UIBuilder.

setEditedObject

public void setEditedObject(Object object)
This is used to set an example of the data being edited. This is necessary only if you are adding a field that is of type LiveData, and you are asking the UIBuilder to automatcially create and add the editor for it.

Parameters:
object - An example of the object to be edited.

setObjectClass

public void setObjectClass(Object objectOrClass)

getOpenPanel

public CellPanel getOpenPanel()
Return the current open CellPanel.


close

public CellPanel close()
Close the current cell panel. Any further controls will be added to the cell panel that was open before this panel was opened.

Returns:
The current cell panel that was closed.

close

public CellPanel close(boolean endRow)
Close the current cell panel. Any further controls will be added to the cell panel that was open before this panel was opened.

Parameters:
endRow - If this is true then the previous open panel will have its current row ended.
Returns:
The current CellPanel that was closed.

addTo

public CellPanel addTo(CellPanel cp)
Set the specified CellPanel as being the current open panel. This is only used under special circumstances. The CellPanel specified is not added to any open panel - you will have to add it into the editor yourself.

Parameters:
cp - The CellPanel to be considered the current open panel.
Returns:
The CellPanel provided.

open

public CellPanel open(CellPanel cp,
                      String text)
Set a new CellPanel as the current open panel and add it to the previously open panel.

Parameters:
cp - The CellPanel to be added to the current open panel.
text - Optional text for the CellPanel.
Returns:
The opened CellPanel.

open

public CellPanel open(MultiPanel mp,
                      String tabName,
                      String longName)
Open a new CellPanel within an already added Multipanel.

Parameters:
mp - The MultiPanel you have added already.
tabName - The tabName for the new panel to add.
longName - The longName for the new panel to add.
Returns:
The newly created and added CellPanel.

open

public CellPanel open(CellPanel cp,
                      MultiPanel mp,
                      String tabName,
                      String longName)
Open a specified CellPanel within an already added Multipanel.

Parameters:
mp - The MultiPanel you have added already.
tabName - The tabName for the new panel to add.
longName - The longName for the new panel to add.
Returns:
The CellPanel provided.

open

public CellPanel open()
Open a new CellPanel within the current open CellPanel.

Returns:
The newly created and added CellPanel.

openStack

public CellPanel openStack()
Open a new Stack within the current open CellPanel. A Stack is a CellPanel that always places controls one on top the other. This is DIFFERENT to an InputStack which handles both inputs and prompts.

Returns:
The newly created and added CellPanel.

openInputStack

public InputStack openInputStack()
Open a new ewe.ui.InputStack within the current open CellPanel. An InputStack handles aligning prompts with inputs stacked in rows and columns.

Returns:
The newly created and added InputStack.

open

public CellPanel open(String text)
Open a new CellPanel within the current open CellPanel.

Parameters:
text - A text that is used as a heading with etched border for the CellPanel.
Returns:
The newly created and added CellPanel.

openStack

public CellPanel openStack(String text)
Open a new Stack within the current open CellPanel. A Stack is a CellPanel that always places controls one on top the other. This is DIFFERENT to an InputStack which handles both inputs and prompts.

Parameters:
text - A text that is used as a heading with etched border for the Stack.
Returns:
The newly created and added CellPanel.

openInputStack

public InputStack openInputStack(String text)
Open a new ewe.ui.InputStack within the current open CellPanel. An InputStack handles aligning prompts with inputs stacked in rows and columns.

Parameters:
text - A text that is used as a heading with etched border for the InputStack.
Returns:
The newly created and added InputStack.

endRow

public void endRow()
This ends the row in the current open CellPanel. This is not necessary if you used openInputStack() or openStack().


getControlFor

public Control getControlFor(String prompt,
                             FieldTransfer ft,
                             boolean forInputStack,
                             Object properties,
                             FieldData fd)
This returns the appropriate Control for a given field.

Parameters:
prompt - The prompt for the control (may be null).
ft - The FieldTransfer representing the field for the control.
forInputStack - This should be true if the control is to be added to an InputStack.
properties - This is either a ewe.data.PropertyList object, or a set of properties encoded as a String separated by '|' characters. (e.g. "rows|10|columns|30").
Returns:
The appropriate Control for the field or null if no appropriate control could be found.

getControlFor

public Control getControlFor(String prompt,
                             String field,
                             boolean forInputStack,
                             Object properties)
                      throws RuntimeException
This returns the appropriate Control for a given field.

Parameters:
prompt - The prompt for the control (may be null).
forInputStack - This should be true if the control is to be added to an InputStack.
properties - This is either a ewe.data.PropertyList object, or a set of properties encoded as a String separated by '|' characters. (e.g. "rows|10|columns|30").
Returns:
The appropriate Control for the field or null if no appropriate control could be found.
Throws:
RuntimeException - If no Control could be created.

getControlFor

protected Control getControlFor(String prompt,
                                String field,
                                boolean forInputStack)
                         throws RuntimeException
Throws:
RuntimeException

set

public UIBuilder set(Object properties)
This sets the properties of the next control to be added. It should be called immediately before one of the add() methods.

Parameters:
properties - This is either a ewe.data.PropertyList object, or a set of properties encoded as a String separated by '|' characters. (e.g. "rows|10|columns|30").
Returns:
This UIBuilder.

addChoice

public Control addChoice(String prompt,
                         String field,
                         String[] choices)

addCombo

public Control addCombo(String prompt,
                        String field,
                        String[] choices)

add

public Control add(String prompt,
                   String field)

add

public Control add(String field,
                   Control c)

add

public Control add(Control c)

add

public Control add(String prompt,
                   String field,
                   Control c)

add

public Control add(String field)

addAll

public Control[] addAll(String promptsAndFields)
Add all the specified fields.

Parameters:
promptsAndFields - If this string contains the '|' (pipe) character, then it is assumed to be a list of the form: "Prompt1|Field1|Prompt2|Field2|..." If there are no '|' characters then it is assumed to be a comma separated list of fields in the form "Field1,Field2,..." and the field names will then be converted to prompt names.
Returns:
An array of the controls added.

newInputStack

public static UIBuilder newInputStack(CellPanel cp,
                                      Editor ed,
                                      Object objectOrClass)
A quick way of creating a new UIBuilder and opening an InputStack.

Parameters:
ed - The editor being added to.
objectOrClass - The objectOrClass being edited.
Returns:
A new UIBuilder for the editor.

newPanel

public static UIBuilder newPanel(CellPanel cp,
                                 Editor ed,
                                 Object objectOrClass)
A quick way of creating a new UIBuilder and opening a panel.

Parameters:
ed - The editor being added to.
objectOrClass - The objectOrClass being edited.
Returns:
A new UIBuilder for the editor.

newStack

public static UIBuilder newStack(CellPanel cp,
                                 Editor ed,
                                 Object objectOrClass)
A quick way of creating a new UIBuilder and opening a stack (NOT an InputStack).

Parameters:
ed - The editor being added to.
objectOrClass - The objectOrClass being edited.
Returns:
A new UIBuilder for the editor.

askClassName

public static String askClassName(String pathToClass,
                                  StringBuffer programDir,
                                  Frame parent)