public class UIBuilder extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BACK_COMMAND_ID |
static String |
FORM_STATE_KEY_FOCUS
A key in the form state hashtable used in the back command navigation
|
static String |
FORM_STATE_KEY_NAME
A key in the form state hashtable used in the back command navigation
|
static String |
FORM_STATE_KEY_SELECTION
A key in the form state hashtable used in the back command navigation
|
static String |
FORM_STATE_KEY_TITLE
A key in the form state hashtable used in the back command navigation
|
Constructor and Description |
---|
UIBuilder() |
Modifier and Type | Method and Description |
---|---|
void |
addCommandListener(ActionListener l)
Adds a command listener that would be bound to all forms in the GUI seamlessly
|
void |
addCommandListener(String formName,
ActionListener l)
Adds a command listener to be invoked for commands on a specific form
|
void |
addComponentListener(String formName,
String componentName,
Object listener)
Adds a component listener that would be bound when a UI for this form is created.
|
protected boolean |
allowBackTo(String formName)
Indicates whether a back command to this form should be generated automatically when
leaving said form.
|
protected void |
analyticsCallback(String page,
String referrer)
Invokes the analytics service if it is enabled and if
|
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,
Object listener)
Binds the given listener object to the component, this works seamlessly for
common Codename One 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.
|
LazyValue<Form> |
createBackLazyValue(Form f)
This is useful for swipe back navigation behavior
|
protected Command |
createCommand(String commandName,
Image icon,
int commandId,
String action)
Creates a command instance.
|
protected Component |
createComponentInstance(String componentType,
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,
String resourceName)
Creates the container defined under the given name in the res file
|
Container |
createContainer(String resPath,
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.
|
protected Resources |
fetchResourceFile()
This method may be overriden by subclasses to provide a way to dynamically load
a resource file.
|
Component |
findByName(String name,
Component rootComponent)
Finds the given component by its name
|
Component |
findByName(String name,
Container rootComponent)
Finds the given component by its name
|
protected String |
formNavigationStackDebug()
Useful method for logging form navigation, it returns a string representing the navigation state which
can be used to analyze crash reports
|
protected String |
getBackCommandText(String previousFormTitle)
Returns the text for the back command string.
|
protected Hashtable |
getContainerState(Container cnt)
This method is the container navigation equivalent of getFormState() see
that method for details.
|
protected Hashtable |
getFormState(Form f)
Returns the state of the current form which we are about to leave as part
of the navigation logic.
|
String |
getHomeForm()
When reaching the home form the navigation stack is cleared
|
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 below 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
|
static boolean |
isBlockAnalytics()
Enables blocking analytics in the UIBuilder, this is useful for the designer tool.
|
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 |
onBackNavigation()
This callback is invoked to indicate that the upcoming form is shown as part of a "back" navigation.
|
protected void |
onCreateRoot(String rootName)
This method allows binding logic that should occur before creating the root object
e.g.
|
protected void |
popNavigationStack()
Removes a navigation frame from the stack, this is useful in case you
want to go back to a form in the middle of the navigation stack.
|
protected void |
postAsyncCommand(Command cmd,
ActionEvent sourceEvent)
This method is invoked in conjunction with asyncCommandProcess after the
command was handled asynchronously 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(String name,
Class cmp)
This method allows the UIBuilder to package a smaller portion of Codename One 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(String formName,
ActionListener l)
Removes a command listener on a specific form
|
void |
removeComponentListener(String formName,
String componentName,
Object listener)
Removes a component listener bound to a specific component
|
protected void |
restoreComponentState(Component c,
Hashtable destination)
By default Codename One stores the states of components in the navigation graph
as it moves between forms.
|
protected void |
setBackCommand(Form f,
Command backCommand)
Invoked internally to set the back command on the form, this method allows subclasses
to change the behavior of back command adding or disable it
|
void |
setBackCommandEnabled(boolean back)
Seamlessly inserts a back command to all the forms
|
protected void |
setBackDestination(String formName)
Pops the navigation stack until it finds form name and the back button will match form name
if form name isn't in the stack this method will fail
|
static void |
setBlockAnalytics(boolean aBlockAnalytics)
Enables blocking analytics in the UIBuilder, this is useful for the designer tool.
|
protected void |
setContainerState(Container cnt,
Hashtable state)
This method is the container navigation equivalent of setFormState() see
that method for details.
|
protected void |
setFormState(Form f,
Hashtable state)
Sets the state of the current form to which we are returing as part
of the navigation logic.
|
void |
setHomeForm(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(ContainerList cmp)
Allows a subclass to set the list model for the given component
|
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(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
|
protected boolean |
shouldAddBackCommandToMenu()
Back commands are set implicitly (see allowBackTo to disable that), this method allows subclasses
to disable the behavior where the back command is also added to the menu (not just set to the back button).
|
protected boolean |
shouldAutoStoreState()
Indicates whether the UIBuilder should try storing states for forms on its own
by seeking lists, tabs and other statefull elements and keeping their selection
|
Container |
showContainer(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(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.
|
protected void |
storeComponentState(Component c,
Hashtable destination)
By default Codename One stores the states of components in the navigation graph
as it moves between forms.
|
public static final String FORM_STATE_KEY_NAME
public static final String FORM_STATE_KEY_TITLE
public static final String FORM_STATE_KEY_FOCUS
public static final String FORM_STATE_KEY_SELECTION
public static final int BACK_COMMAND_ID
public static boolean isBlockAnalytics()
public static void setBlockAnalytics(boolean aBlockAnalytics)
aBlockAnalytics
- the blockAnalytics to setpublic void setBackCommandEnabled(boolean back)
back
- true to automatically add a back commandprotected void popNavigationStack()
protected void setBackDestination(String formName)
formName
- the name of the form to navigate back to.protected String formNavigationStackDebug()
public boolean isBackCommandEnabled()
public static void registerCustomComponent(String name, Class cmp)
name
- the name of the component (UIID)cmp
- the class for the given componentprotected void analyticsCallback(String page, String referrer)
page
- the page visitedreferrer
- the source pagepublic Container createContainer(String resPath, String resourceName)
resPath
- the path to the res file containing the UI widgetresourceName
- the name of the widget in the res filepublic Container createContainer(Resources res, String resourceName)
res
- the res file containing the UI widgetresourceName
- the name of the widget in the res filepublic Component findByName(String name, Component rootComponent)
name
- the name of the component as defined in the resource editorrootComponent
- the root containerpublic Component findByName(String name, Container rootComponent)
name
- the name of the component as defined in the resource editorrootComponent
- the root containerprotected Component createComponentInstance(String componentType, Class cls)
componentType
- the type of the component from the UI buildercls
- assumed component class based on the component registryprotected void postCreateComponent(Component cmp)
cmp
- the componentprotected void bindListenerToComponent(Component cmp, Object listener)
cmp
- the component to bind the listener tolistener
- the listener objectprotected boolean setListModel(List cmp)
cmp
- the list whose model may be setprotected boolean setListModel(ContainerList cmp)
cmp
- the list whose model may be setprotected Command createCommand(String commandName, Image icon, int commandId, 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 definedprotected Resources fetchResourceFile()
public String getResourceFilePath()
public void setResourceFilePath(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(String formName, String componentName, 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(String formName, String componentName, Object listener)
formName
- the name of the formcomponentName
- the name of the componentlistener
- the listener instancepublic void addCommandListener(String formName, ActionListener l)
formName
- the name of the form to which the listener should be boundl
- the listener to bindpublic void removeCommandListener(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 Hashtable getFormState(Form f)
f
- the form whose state should be preservedprotected void restoreComponentState(Component c, Hashtable destination)
c
- the component whose state should be restoreddestination
- the hashtable containing the stateprotected void storeComponentState(Component c, Hashtable destination)
c
- the component whose state should be storeddestination
- the destination hashtableprotected boolean shouldAutoStoreState()
protected void setFormState(Form f, Hashtable state)
f
- the form whose state should be preservedstate
- arbitrary state objectprotected Hashtable getContainerState(Container cnt)
cnt
- the containerprotected void setContainerState(Container cnt, Hashtable state)
cnt
- the containerstate
- the statepublic String getHomeForm()
public void setHomeForm(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.protected String getBackCommandText(String previousFormTitle)
previousFormTitle
- the title of the previous formprotected void setBackCommand(Form f, Command backCommand)
f
- the formbackCommand
- the back commandpublic Container showContainer(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()
public LazyValue<Form> createBackLazyValue(Form f)
f
- the form from which we should go backprotected boolean allowBackTo(String formName)
formName
- the name of the formprotected boolean isSameBackDestination(Container source, Container destination)
source
- the form or container we are leavingdestination
- the container or form we are navigating topublic Form showForm(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 onBackNavigation()
protected boolean shouldAddBackCommandToMenu()
protected 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(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 set