ewe.data
Class LiveObject

java.lang.Object
  extended byewe.data.DataObject
      extended byewe.data.LiveObject
All Implemented Interfaces:
Comparable, Copyable, DataUnit, FieldListener, LiveData
Direct Known Subclasses:
FieldTableExportSpecs, FileChooserDemo, FontChooser, InputObject, ListObject, LiveTreeNode, NewShortcut, PageFormatData, ResolveConflict, SaveableObject, SocketMaker, TestData, TestSocket, VMApp, VMApps, VMOptions

public class LiveObject
extends DataObject
implements LiveData

This is a complete implementation of LiveData which you can use as a base for creating new LiveData Objects.


Constructor Summary
LiveObject()
           
 
Method Summary
 void action(FieldTransfer ft, Editor ed)
          This implements the action() method in FieldListener.
 void action(String fieldName, Editor ed)
          This gets called by action(FieldTransfer ft,Editor ed) and by fieldChanged(FieldTransfer ft,Editor ed) if the field changed is a menu item.
protected  UIBuilder addMeToPanel(CellPanel cp, Editor ed, String baseClassName)
          Use this within addToPanel() if you still want it's default of creating a new UIBuilder and adding an InputStack.
static UIBuilder addObjectToPanel(CellPanel cp, Editor ed, Object objectOrClass, boolean declaredOnly)
          This works on any object.
 void addToPanel(CellPanel cp, Editor ed, int options)
          Override this to provide the user interface for editing the Object.
protected  TextDecoder decode(TextDecoder td)
          Override this to decode the fields that you want to decode.
protected  void decoded(String from)
          This method is called after the base implementation of textDecode() is executed.
 TextDecoder decodeFields(String fieldNames, TextDecoder td, String baseName)
          You can call this within your decode(TextDecoder te) method to encode specific fields.
static void enableEditorScrolling(Editor ed, boolean enable)
          Enable/Disable an Editors main scrollbar panel.
protected  TextEncoder encode(TextEncoder te)
          Override this to encode the fields that you want to encode.
protected  String encoded(String to)
          This method is called after the base implementation of textEncode() is executed.
 TextEncoder encodeFields(String fieldNames, TextEncoder te, String baseName)
          You can call this within your encode(TextEncoder te) method to encode specific fields.
 void fieldChanged(FieldTransfer ft, Editor ed)
          This implements the fieldChanged() method in FieldListener.
 void fieldChanged(String fieldName, Editor ed)
          This gets called by fieldChanged(FieldTransfer ft,Editor ed).
 void fieldEvent(FieldTransfer ft, Editor ed, Object event)
          This implements the fieldEvent() method in FieldListener.
 Editor getEditor(int options)
          This creates a new Editor Object - you should not override this method, rather you should override the addToPanel() method to provide a custom Editor for your LiveData.
protected  ScrollablePanel getEditorScroller(CellPanel cp)
          This is called by the default getEditor() should return a ScrollBarPanel for the CellPanel that the editor is being placed in.
 IImage getIcon()
          This returns null by default.
 String getName()
          By default this returns the String "unnamed".
 boolean input(String title, int editorOption)
          This opens an Editor for this object.
protected  Editor makeNewEditor(int options)
          This shoudl create the new Editor object but not add anything to it.
 Form runAsApp()
          Get a Form to run this LiveObject as a stand-alone application.
 void textDecode(String txt)
          You can override this to decode a String representation of the Object as encoded by textEncode, but it is easier to override decode(TextDecoder te).
 String textEncode()
          You can override this to encode the object as a String, but it is easier to override encode(TextEncoder te).
 
Methods inherited from class ewe.data.DataObject
_getSetField, appendAllFields, compareTo, copied, copyFrom, equals, getCopy, getDeclaredField, getDeclaredFieldValue, getDeclaredFieldValue, getFieldList, getFieldList, getMyFieldList, getNew
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, toString
 
Methods inherited from interface ewe.data.DataUnit
copyFrom, getNew
 
Methods inherited from interface ewe.util.Copyable
getCopy
 
Methods inherited from interface ewe.util.Comparable
compareTo
 

Constructor Detail

LiveObject

public LiveObject()
Method Detail

getName

public String getName()
By default this returns the String "unnamed".

Specified by:
getName in interface LiveData

makeNewEditor

protected Editor makeNewEditor(int options)
This shoudl create the new Editor object but not add anything to it. This is called by getEditor(). By default it returns a standard Editor object.


getEditorScroller

protected ScrollablePanel getEditorScroller(CellPanel cp)
This is called by the default getEditor() should return a ScrollBarPanel for the CellPanel that the editor is being placed in. By default, this is a ScrollBarPanel except on a SmartPhone, where it will be a VerticalScrollPanel.

You may return null from this.


getEditor

public Editor getEditor(int options)
This creates a new Editor Object - you should not override this method, rather you should override the addToPanel() method to provide a custom Editor for your LiveData.

Specified by:
getEditor in interface LiveData

enableEditorScrolling

public static void enableEditorScrolling(Editor ed,
                                         boolean enable)
Enable/Disable an Editors main scrollbar panel.

By default, the getEditor() method will place a CellPanel into a ScrollBarPanel and then add it the Editor before calling addToPanel(). However initially this ScrollBarPanel is disabled (i.e. it's "shrinkComponent" variable is true - which results in ScrollBars never appearing). This method is used to enable it.

Parameters:
ed - The editor created by getEditor().
enable - true to enable scrolling, false to disable it.

action

public void action(String fieldName,
                   Editor ed)
This gets called by action(FieldTransfer ft,Editor ed) and by fieldChanged(FieldTransfer ft,Editor ed) if the field changed is a menu item. By default it will look for a method called void _action(Editor ed) and if it finds it, it will be executed.


fieldChanged

public void fieldChanged(String fieldName,
                         Editor ed)
This gets called by fieldChanged(FieldTransfer ft,Editor ed). By default it will look for a method called void _changed(Editor ed) and if it finds it, it will be executed.


action

public void action(FieldTransfer ft,
                   Editor ed)
This implements the action() method in FieldListener. By default it calls action(String name,Editor ed)

Specified by:
action in interface FieldListener
Parameters:
ft - The FieldTransfer object representing the changed field.
ed - The Editor from which the event came.

fieldChanged

public void fieldChanged(FieldTransfer ft,
                         Editor ed)
This implements the fieldChanged() method in FieldListener. It operates like like this:

If the field is of type ewe.ui.MenuItem then the method action(String name,Editor ed) is called with the "name" parameter being set to the "action" member of the selected MenuItem.

Otherwise the fieldChanged(String fieldName,Editor ed) method is called with the fieldName of the FieldTransfer object.

Specified by:
fieldChanged in interface FieldListener
Parameters:
ft - The FieldTransfer object representing the changed field.
ed - The Editor from which the event came.

fieldEvent

public void fieldEvent(FieldTransfer ft,
                       Editor ed,
                       Object event)
This implements the fieldEvent() method in FieldListener. By default it calls fieldChanged(String name,Editor ed) UNLESS the field is a MenuItem, in which case it will call action(String menuItemAction,Editor ed);

Specified by:
fieldEvent in interface FieldListener

addToPanel

public void addToPanel(CellPanel cp,
                       Editor ed,
                       int options)
Override this to provide the user interface for editing the Object. Add all your controls to the CellPanel cp, and your fields to the Editor ed. The options parameter may be used to specify a different Editor for the Object for different situations - it is the same parameter that is passed to the LiveData.getEditor(int options) call.


addMeToPanel

protected UIBuilder addMeToPanel(CellPanel cp,
                                 Editor ed,
                                 String baseClassName)
                          throws IllegalArgumentException
Use this within addToPanel() if you still want it's default of creating a new UIBuilder and adding an InputStack. It will also add in the fields for this object if needed.

Parameters:
cp - The CellPanel passed to addToPanel()
ed - The Editor passed to addToPanel()
baseClassName - The base class being added.
Returns:
The UIBuilder for the Editor with an open InputStack.
Throws:
IllegalArgumentException - if the baseClassName is not valid for this object.

textEncode

public String textEncode()
You can override this to encode the object as a String, but it is easier to override encode(TextEncoder te).

Specified by:
textEncode in interface LiveData

textDecode

public void textDecode(String txt)
You can override this to decode a String representation of the Object as encoded by textEncode, but it is easier to override decode(TextDecoder te).

Specified by:
textDecode in interface LiveData

encodeFields

public TextEncoder encodeFields(String fieldNames,
                                TextEncoder te,
                                String baseName)
You can call this within your encode(TextEncoder te) method to encode specific fields.

Parameters:
fieldNames - A comma separated list of field names.
te - A TextEncoder object.
baseName - Either the fully qualified class and package name or the class name (without package) of the object.
Returns:
The te parameter is returned after the fields are added.

decodeFields

public TextDecoder decodeFields(String fieldNames,
                                TextDecoder td,
                                String baseName)
You can call this within your decode(TextDecoder te) method to encode specific fields.

Parameters:
fieldNames - A comma separated list of field names.
td - A TextDecoder object.
baseName - Either the fully qualified class and package name or the class name (without package) of the object.
Returns:
The td parameter is returned after the fields are extracted.

getIcon

public IImage getIcon()
This returns null by default.

Specified by:
getIcon in interface LiveData

encode

protected TextEncoder encode(TextEncoder te)
Override this to encode the fields that you want to encode. The LiveObject implementation of this automatically encodes all the fields for each class in the hierarchy that does not override encode(TextEncoder te);


decode

protected TextDecoder decode(TextDecoder td)
Override this to decode the fields that you want to decode. The LiveObject implementation of this automatically decodes all the fields for each class in the hierarchy that does not override decode(TextDecoder td);


input

public boolean input(String title,
                     int editorOption)
This opens an Editor for this object.

Parameters:
title - The title for the editor. Can be null to leave as is.
editorOption - Options to pass to getEditor().
Returns:
true if the user pressed OK, false if the user pressed cancel.

decoded

protected void decoded(String from)
This method is called after the base implementation of textDecode() is executed. It gives you a chance to do extra work after the fields are decoded.

Parameters:
from - The String this object was decoded from.

encoded

protected String encoded(String to)
This method is called after the base implementation of textEncode() is executed. It gives you a chance to do extra work and maybe modify the data after the fields are encoded.

Parameters:
to - the String the object has been encoded to.
Returns:
the String that should be used as the encoded text for the object. By default this method simply returns the to parameter.

addObjectToPanel

public static UIBuilder addObjectToPanel(CellPanel cp,
                                         Editor ed,
                                         Object objectOrClass,
                                         boolean declaredOnly)
                                  throws IllegalArgumentException
This works on any object. It adds the fields for an object into a CellPanel that itself is added to the editor (or which itself may be the Editor).

Parameters:
cp - A CellPanel to add the object fields to.
ed - The Editor to be used to edit the object.
objectOrClass - The object or the Class/Reflect of the object.
declaredOnly - if this is true then only the declared fields will be added and not the fields of the superclass.
Returns:
the UIBuilder that was used to add the fields. The builder will have an open InputStack which contains the fields added.
Throws:
IllegalArgumentException

runAsApp

public Form runAsApp()
Get a Form to run this LiveObject as a stand-alone application.