|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.lwuit.util.UIBuilder
public class UIBuilder
The UI builder can create a user interface based on the UI designed in the resource editor and allows us to bind to said UI. Notice that if a Component was used in the GUI that is not a part of the com.sun.lwuit package (even a Component from sub packages such as table or tree) it MUST be registered before loading a GUI!
Field Summary | |
---|---|
static int |
BACK_COMMAND_ID
|
static java.lang.String |
FORM_STATE_KEY_FOCUS
A key in the form state hashtable used in the back command navigation |
static java.lang.String |
FORM_STATE_KEY_NAME
A key in the form state hashtable used in the back command navigation |
static java.lang.String |
FORM_STATE_KEY_SELECTION
A key in the form state hashtable used in the back command navigation |
Constructor Summary | |
---|---|
UIBuilder()
|
Method Summary | |
---|---|
void |
addCommandListener(ActionListener l)
Adds a command listener that would be bound to all forms in the GUI seamlessly |
void |
addCommandListener(java.lang.String formName,
ActionListener l)
Adds a command listener to be invoked for commands on a specific form |
void |
addComponentListener(java.lang.String formName,
java.lang.String componentName,
java.lang.Object listener)
Adds a component listener that would be bound when a UI for this form is created. |
protected boolean |
allowBackTo(java.lang.String formName)
Indicates whether a back command to this form should be generated automatically when leaving said form. |
protected void |
asyncCommandProcess(Command cmd,
ActionEvent sourceEvent)
Warning: This method is invoked OFF the EDT and is intended for usage with asynchronous command processing. |
void |
back()
This method effectively pops the form navigation stack and goes back to the previous form if back navigation is enabled and there is a previous form. |
void |
back(Component sourceComponent)
This method effectively pops the form navigation stack and goes back to the previous form if back navigation is enabled and there is a previous form. |
protected void |
beforeShow(Form f)
This method allows binding an action that should occur before showing the given form |
protected void |
beforeShowContainer(Container c)
This method allows binding an action that should occur before showing the given container |
protected void |
bindListenerToComponent(Component cmp,
java.lang.Object listener)
Binds the given listener object to the component, this works seamlessly for common LWUIT events but might be an issue with custom components and custom listener types so this method can be overloaded to add support for such cases. |
protected Command |
createCommand(java.lang.String commandName,
Image icon,
int commandId,
java.lang.String action)
Creates a command instance. |
protected Component |
createComponentInstance(java.lang.String componentType,
java.lang.Class cls)
This method can be overriden to create custom components in a custom way, the component type is a shorthand for the component name and not the full name of the class. |
Container |
createContainer(Resources res,
java.lang.String resourceName)
Creates the container defined under the given name in the res file |
Container |
createContainer(java.lang.String resPath,
java.lang.String resourceName)
Creates the container defined under the given name in the res file |
protected void |
exitForm(Form f)
This method allows binding an action that should occur before leaving the given form, e.g. memory cleanup |
protected Resources |
fetchResourceFile()
This method may be overriden by subclasses to provide a way to dynamically load a resource file. |
Component |
findByName(java.lang.String name,
Container rootComponent)
Finds the given component by its name |
protected java.util.Hashtable |
getContainerState(Container cnt)
This method is the container navigation equivalent of getFormState() see that method for details. |
protected java.util.Hashtable |
getFormState(Form f)
Returns the state of the current form which we are about to leave as part of the navigation logic. |
java.lang.String |
getHomeForm()
When reaching the home form the navigation stack is cleared |
java.lang.String |
getResourceFilePath()
Allows the navigation code to avoid storing the resource file and lets the GC remove it from memory when its not in use |
protected Container |
getRootAncestor(Component c)
Returns either the parent form or the component bellow the embedded container above c. |
protected void |
handleComponentAction(Component c,
ActionEvent event)
This method is invoked for every component to which an action event listener can be bound and delivers the event data for the given component seamlessly. |
boolean |
isBackCommandEnabled()
Seamlessly inserts a back command to all the forms |
boolean |
isKeepResourcesInRam()
Indicates that the UIBuilder should cache resources in memory and never release them. |
protected boolean |
isSameBackDestination(Container source,
Container destination)
When navigating from one form/container to another we sometimes might not want the back command to return to the previous container/form but rather to the one before source. |
protected void |
onCreateRoot(java.lang.String rootName)
This method allows binding logic that should occur before creating the root object e.g. a case where a created form needs data fetched for it. |
protected void |
postAsyncCommand(Command cmd,
ActionEvent sourceEvent)
This method is invoked in conjunction with asyncCommandProcess after the command was handled asynchroniously on the separate thread. |
protected void |
postCreateComponent(Component cmp)
Callback to allow binding custom logic/listeners to a component after its major properties were set (notice that not all properties or the full hierarchy will be available at this stage). |
protected void |
postShow(Form f)
This method allows binding an action that should occur immediately after showing the given form |
protected void |
postShowContainer(Container c)
This method allows binding an action that should occur immediately after showing the given container |
protected boolean |
processBackground(Form f)
Warning: this method is invoked on a separate thread. |
protected void |
processCommand(ActionEvent ev,
Command cmd)
Invoked to process a given command before naviation or any other internal processing occurs. |
static void |
registerCustomComponent(java.lang.String name,
java.lang.Class cmp)
This method allows the UIBuilder to package a smaller portion of LWUIT into the JAR and add support for additional 3rd party components to the GUI builder. |
void |
reloadContainer(Component cnt)
Useful tool to refresh the current state of a container shown using show container without pushing another instance to the back stack |
void |
reloadForm()
Useful tool to refresh the current state of a form shown using show form without pushing another instance to the back stack |
void |
removeCommandListener(ActionListener l)
Removes a command listener |
void |
removeCommandListener(java.lang.String formName,
ActionListener l)
Removes a command listener on a specific form |
void |
removeComponentListener(java.lang.String formName,
java.lang.String componentName,
java.lang.Object listener)
Removes a component listener bound to a specific component |
void |
setBackCommandEnabled(boolean back)
Seamlessly inserts a back command to all the forms |
protected void |
setContainerState(Container cnt,
java.util.Hashtable state)
This method is the container navigation equivalent of setFormState() see that method for details. |
protected void |
setFormState(Form f,
java.util.Hashtable state)
Sets the state of the current form to which we are returing as part of the navigation logic. |
void |
setHomeForm(java.lang.String homeForm)
When reaching the home form the navigation stack is cleared |
void |
setKeepResourcesInRam(boolean keepResourcesInRam)
Indicates that the UIBuilder should cache resources in memory and never release them. |
protected boolean |
setListModel(List cmp)
Allows a subclass to set the list model for the given component |
protected void |
setResourceFile(Resources res)
Sets the resource file if keep in rum or no path is defined |
void |
setResourceFilePath(java.lang.String resourceFilePath)
Allows the navigation code to avoid storing the resource file and lets the GC remove it from memory when its not in use |
Container |
showContainer(java.lang.String resourceName,
Command sourceCommand,
Component sourceComponent)
This method is equivalent to the internal navigation behavior, it adds functionality such as the back command into the given form resource and shows it. |
Form |
showForm(java.lang.String resourceName,
Command sourceCommand)
This method is equivalent to the internal navigation behavior, it adds functionality such as the back command into the given form resource and shows it. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String FORM_STATE_KEY_NAME
public static final java.lang.String FORM_STATE_KEY_FOCUS
public static final java.lang.String FORM_STATE_KEY_SELECTION
public static final int BACK_COMMAND_ID
Constructor Detail |
---|
public UIBuilder()
Method Detail |
---|
public void setBackCommandEnabled(boolean back)
back
- true to automatically add a back commandpublic boolean isBackCommandEnabled()
public static void registerCustomComponent(java.lang.String name, java.lang.Class cmp)
name
- the name of the component (UIID)cmp
- the class for the given componentpublic Container createContainer(java.lang.String resPath, java.lang.String resourceName)
resPath
- the path to the res file containing the UI widgetresourceName
- the name of the widget in the res file
public Container createContainer(Resources res, java.lang.String resourceName)
res
- the res file containing the UI widgetresourceName
- the name of the widget in the res file
public Component findByName(java.lang.String name, Container rootComponent)
name
- the name of the component as defined in the resource editorrootComponent
- the root container
protected Component createComponentInstance(java.lang.String componentType, java.lang.Class cls)
componentType
- the type of the component from the UI buildercls
- assumed component class based on the component registry
protected void postCreateComponent(Component cmp)
cmp
- the componentprotected void bindListenerToComponent(Component cmp, java.lang.Object listener)
cmp
- the component to bind the listener tolistener
- the listener objectprotected boolean setListModel(List cmp)
cmp
- the list whose model may be set
protected Command createCommand(java.lang.String commandName, Image icon, int commandId, java.lang.String action)
commandName
- the label on the commandicon
- the icon for the commandcommandId
- the id of the commandaction
- the action assigned to the command if such an action is defined
protected Resources fetchResourceFile()
public java.lang.String getResourceFilePath()
public void setResourceFilePath(java.lang.String resourceFilePath)
resourceFilePath
- the resourceFilePath to setprotected void setResourceFile(Resources res)
res
- the resource fileprotected void processCommand(ActionEvent ev, Command cmd)
ev
- the action event source of the commandcmd
- the command to processpublic void addCommandListener(ActionListener l)
l
- the listener to bindpublic void removeCommandListener(ActionListener l)
l
- the listener to removepublic void addComponentListener(java.lang.String formName, java.lang.String componentName, java.lang.Object listener)
formName
- the name of the form to which the listener should be boundcomponentName
- the name of the component to bind tolistener
- the listener to bind, common listener types are supportedpublic void removeComponentListener(java.lang.String formName, java.lang.String componentName, java.lang.Object listener)
formName
- the name of the formcomponentName
- the name of the componentlistener
- the listener instancepublic void addCommandListener(java.lang.String formName, ActionListener l)
formName
- the name of the form to which the listener should be boundl
- the listener to bindpublic void removeCommandListener(java.lang.String formName, ActionListener l)
formName
- the name of the forml
- the listener to removeprotected void handleComponentAction(Component c, ActionEvent event)
c
- the component broadcasting the eventevent
- the event meta dataprotected void asyncCommandProcess(Command cmd, ActionEvent sourceEvent)
cmd
- the command requiring background processingsourceEvent
- the triggering eventprotected void postAsyncCommand(Command cmd, ActionEvent sourceEvent)
cmd
- the commandsourceEvent
- the source eventprotected boolean processBackground(Form f)
f
- the form for which the background thread was constructed, notice
that most methods are not threadsafe and one should use callSerially* in this
method when mutating the form.
protected java.util.Hashtable getFormState(Form f)
f
- the form whose state should be preserved
protected void setFormState(Form f, java.util.Hashtable state)
f
- the form whose state should be preservedstate
- arbitrary state objectprotected java.util.Hashtable getContainerState(Container cnt)
cnt
- the container
protected void setContainerState(Container cnt, java.util.Hashtable state)
cnt
- the containerstate
- the statepublic java.lang.String getHomeForm()
public void setHomeForm(java.lang.String homeForm)
homeForm
- the homeForm to setpublic void back()
public void back(Component sourceComponent)
sourceComponent
- the component that triggered the back command which effectively
allows us to find the EmbeddedContainer for a case of container navigation. Null
can be used if not applicable.public Container showContainer(java.lang.String resourceName, Command sourceCommand, Component sourceComponent)
resourceName
- the name of the resource for the form to showsourceCommand
- the command of the resource (may be null)sourceComponent
- the component that activated the show (may be null)
public void reloadContainer(Component cnt)
cnt
- the container thats embedded into the applicationpublic void reloadForm()
protected boolean allowBackTo(java.lang.String formName)
formName
- the name of the form
protected boolean isSameBackDestination(Container source, Container destination)
source
- the form or container we are leavingdestination
- the container or form we are navigating to
public Form showForm(java.lang.String resourceName, Command sourceCommand)
resourceName
- the name of the resource for the form to showsourceCommand
- the command of the resource (may be null)
protected void exitForm(Form f)
f
- the form being leftprotected void beforeShow(Form f)
f
- the form about to be shownprotected void postShow(Form f)
f
- the form that was just shownprotected void beforeShowContainer(Container c)
c
- the container about to be shownprotected void postShowContainer(Container c)
c
- the container that was just shownprotected void onCreateRoot(java.lang.String rootName)
rootName
- the name of the root to be created from the resource filepublic boolean isKeepResourcesInRam()
public void setKeepResourcesInRam(boolean keepResourcesInRam)
keepResourcesInRam
- the keepResourcesInRam to setprotected Container getRootAncestor(Component c)
c
- the component whose root ancestor we should find
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |