public abstract class ALcyGUIFactory<T> extends Object
Abstract factory for the creation of a GUI panel. This factory was designed so that it is easy to modify small parts of the creation process. By overriding certain methods, parts can be removed, changed or added.
The entry point createGUI
does:
setup
createAction
and insert them in all configured
action bars using TLcyActionBarUtil.insertInConfiguredActionBars(com.luciad.gui.ILcdAction,
Object, TLcyActionBarManager, com.luciad.lucy.util.properties.ALcyProperties)
. The context is
determined by calling getActionContext(int, com.luciad.lucy.util.properties.ALcyProperties)
.
createActiveSettable
and insert
them in all configured action bars using TLcyActionBarUtil.insertInConfiguredActionBars(ILcyActiveSettable,
Object, TLcyActionBarManager, com.luciad.lucy.util.properties.ALcyProperties)
. The context is
determined by calling getActiveSettableContext(int, com.luciad.lucy.util.properties.ALcyProperties)
.createComponent
createPanel
createGUIContent
cleanup
Note that as soon as any of the actions etc. are created, they can be retrieved using the
matching get
method. For example while creating panels, the created components can
be used to do so.
Note that ID's are used. This is because there are different types of, for example, panels
that can be created. All possible ID's that can be passed to the createPanel
method should all end with the same suffix "PANEL". The same thing goes for
"COMPONENT" (createComponent
, getComponent
), "ACTIVE_SETTABLE" (createActiveSettable
, getActiveSettable
) and "ACTION" (createAction
, getAction
). Duplicate IDs are not allowed. Customer code should
use ID's above 10000.
If sub-classes would like to specify which ID's are to be used, they can do so using the
constructor or by simply adding to the existing list of ID's (e.g. see getActionIDs()
).
Modifier | Constructor and Description |
---|---|
protected |
ALcyGUIFactory(ILcyLucyEnv aLucyEnv,
ILcdIntList aActionIDs,
ILcdIntList aActiveSettableIDs,
ILcdIntList aComponentIDs,
ILcdIntList aPanelIDs)
Creates a new
ALcyGUIFactory . |
protected |
ALcyGUIFactory(ILcyLucyEnv aLucyEnv,
int[] aActionIDs,
int[] aActiveSettableIDs,
int[] aComponentIDs,
int[] aPanelIDs)
Creates a new
ALcyGUIFactory . |
Modifier and Type | Method and Description |
---|---|
protected void |
cleanup(ALcyProperties aProperties)
Performs cleanup operations, such as nullifying fields that are no longer needed.
|
protected abstract ILcdAction |
createAction(int aActionID,
ALcyProperties aProperties)
Creates an
ILcdAction for the given ID. |
protected abstract ILcyActiveSettable |
createActiveSettable(int aActiveSettableID,
ALcyProperties aProperties)
Creates an
ILcyActiveSettable for the given ID. |
protected abstract Component |
createComponent(int aComponentID,
ALcyProperties aProperties)
Creates a widget for the given ID.
|
T |
createGUI(ALcyProperties aProperties)
This function calls
setup , which creates all sub-parts such as actions, components and panels. |
protected abstract T |
createGUIContent(ALcyProperties aProperties)
Retrieves all panels and lays them out in a
java.awt.Component . |
protected abstract Component |
createPanel(int aPanelID,
ALcyProperties aProperties)
Creates a panel for the given ID.
|
protected ILcdAction |
getAction(int aActionID)
Returns the
ILcdAction for the given ID. |
protected Object |
getActionContext(int aActionID,
ALcyProperties aProperties)
Returns the context of the action bars in which the action with the specified ID should be
inserted.
|
protected ILcdIntList |
getActionIDs()
Returns the list with all action IDs.
|
protected ILcyActiveSettable |
getActiveSettable(int aActiveSettableID)
Returns the
ILcyActiveSettable for the given ID. |
protected Object |
getActiveSettableContext(int aActiveSettableID,
ALcyProperties aProperties)
Returns the context of the action bars in which the active settable with the specified ID
should be inserted.
|
protected ILcdIntList |
getActiveSettableIDs()
Returns the list with all active settable IDs.
|
protected Component |
getComponent(int aComponentID)
Returns the
java.awt.Component for the given ID. |
protected ILcdIntList |
getComponentIDs()
Returns the list with all component IDs.
|
ILcyLucyEnv |
getLucyEnv()
Returns the
ILcyLucyEnv . |
protected Component |
getPanel(int aPanelID)
Returns the panel as a
java.awt.Component for the given ID. |
protected ILcdIntList |
getPanelIDs()
Returns the list with all panel IDs.
|
protected boolean |
isActiveSettableDeactivatePossible(int aActiveSettableID,
ALcyProperties aProperties)
Returns whether the active settable can be deactivated or not through the action bar in
which it is inserted.
|
protected void |
setup(ALcyProperties aProperties)
This functions creates all the components for the user interface, in a certain order.
|
protected ALcyGUIFactory(ILcyLucyEnv aLucyEnv, int[] aActionIDs, int[] aActiveSettableIDs, int[] aComponentIDs, int[] aPanelIDs)
ALcyGUIFactory
.aLucyEnv
- The Lucy environment.aActionIDs
- All action ID's.aActiveSettableIDs
- All active settable ID's.aComponentIDs
- All component ID's.aPanelIDs
- All panel ID's.protected ALcyGUIFactory(ILcyLucyEnv aLucyEnv, ILcdIntList aActionIDs, ILcdIntList aActiveSettableIDs, ILcdIntList aComponentIDs, ILcdIntList aPanelIDs)
ALcyGUIFactory
.aLucyEnv
- The Lucy environment.aActionIDs
- All action ID's.aActiveSettableIDs
- All active settable ID's.aComponentIDs
- All component ID's.aPanelIDs
- All panel ID's.public ILcyLucyEnv getLucyEnv()
ILcyLucyEnv
.ILcyLucyEnv
.public T createGUI(ALcyProperties aProperties)
setup
, which creates all sub-parts such as actions, components and panels. createGUIContent
, which
creates the content of the panel by laying out all panels created in the previous step.
cleanup
to perform
some cleanup tasks. The Component
created in the second step is returned. It is up to the user of
this factory to make the returned Component
visible in for example an
ILcyApplicationPane
or a dialog.
Warning: There is normally no need to override this method, instead overwrite one of the three methods that it calls. Also note that it is possible that this method is called an a worker thread. If you override it, be sure to call the super function and to invoke any Swing or other EDT dependent code on the EDT thread.
aProperties
- a properties object that can be used to tune the behavior of this factory.createGUIContent(com.luciad.lucy.util.properties.ALcyProperties)
.protected void setup(ALcyProperties aProperties)
This functions creates all the components for the user interface, in a certain order. It
createAction
with all given action ID's (see
getActionIDs()
) and insert them in all configured action bars using TLcyActionBarUtil.insertInConfiguredActionBars(com.luciad.gui.ILcdAction,
Object, TLcyActionBarManager, com.luciad.lucy.util.properties.ALcyProperties)
with the
specified properties. The context is determined by calling getActionContext(int, com.luciad.lucy.util.properties.ALcyProperties)
. TLcyActionBarUtil.ID_KEY
).createActiveSettable
with all
given active settable ID's (see getActiveSettableIDs()
and insert them in all
configured action bars using TLcyActionBarUtil.insertInConfiguredActionBars(ILcyActiveSettable,
Object, TLcyActionBarManager, com.luciad.lucy.util.properties.ALcyProperties)
with the
specified properties. The context is determined by calling getActiveSettableContext(int, com.luciad.lucy.util.properties.ALcyProperties)
.TLcyActionBarUtil.ID_KEY
).createComponent(int, com.luciad.lucy.util.properties.ALcyProperties)
with all given component ID's (see
getComponentIDs()
).createPanel(int, com.luciad.lucy.util.properties.ALcyProperties)
with all given panel ID's (see getPanelIDs()
). Note that because of this order, panels can be composed of components, and components can
use the active settables and actions. So the createPanel(int, com.luciad.lucy.util.properties.ALcyProperties)
method can use getComponent(int)
to retrieve its sub components, and the createComponent(int, com.luciad.lucy.util.properties.ALcyProperties)
method can use
getAction(int)
and getActiveSettable(int)
to retrieve needed actions and active
settables.
Warning: It is possible that this method is called on a worker thread. When
overriding this method, care should be taken to ensure that all code that should be run on the
EDT thread (Swing code etc...) is invoked using for example TLcdAWTUtil.invokeAndWait(java.lang.Runnable)
.
Also, don't override this method without calling the super function.
aProperties
- a properties object that can be used to tune the behavior of this factory.protected abstract T createGUIContent(ALcyProperties aProperties)
Retrieves all panels and lays them out in a java.awt.Component
. Therefore, this
method uses getPanel(int)
with all ID's that end in PANEL
, and lays out
those components in for example a javax.swing.JPanel
.
This function should be overridden when the global layout of the panel needs to be changed, for example when the main panels need to be rearranged, or when a new panel needs to be added.
An example implementation could be:
public Component createGUIContent( ALcyProperties aProperties ) {
JPanel content = new JPanel( new BorderLayout() );
Component somePanel = getPanel( SOME_PANEL );
if ( somePanel != null ) content.add( somePanel, BorderLayout.NORTH );
Component otherPanel = getPanel( OTHER_PANEL );
if ( otherPanel != null ) content.add( otherPanel, BorderLayout.CENTER );
return content;
}
aProperties
- a properties object that can be used to tune the behavior of this factory.protected void cleanup(ALcyProperties aProperties)
Performs cleanup operations, such as nullifying fields that are no longer needed.
Warning: Should not be overridden without calling the super function.
aProperties
- a properties object that can be used to tune the behavior of this factory.protected abstract ILcdAction createAction(int aActionID, ALcyProperties aProperties)
Creates an ILcdAction
for the given ID.
Note: if the action should be inserted in the configured action bars, the ID_KEY of the
returned action must be set (see TLcyActionBarUtil.ID_KEY
).
aActionID
- the ID describing which action to create. This is normally a constant that
ends with ACTION
.aProperties
- a properties object that can be used to tune the behavior of this factory.ILcdAction
, or null
.setup(com.luciad.lucy.util.properties.ALcyProperties)
protected abstract ILcyActiveSettable createActiveSettable(int aActiveSettableID, ALcyProperties aProperties)
Creates an ILcyActiveSettable
for the given ID.
Note: if the active settable should be inserted in the configured action bars, the ID_KEY of
the returned active settable must be set (see TLcyActionBarUtil.ID_KEY
).
aActiveSettableID
- the ID describing which active settable to create. This is normally a
constant that ends with ACTIVE_SETTABLE
.aProperties
- a properties object that can be used to tune the behavior of this
factory.ILcyActiveSettable
, or null
.protected abstract Component createComponent(int aComponentID, ALcyProperties aProperties)
Creates a widget for the given ID. It is safe to use the getAction(int)
and getActiveSettable(int)
methods in this method, to build widgets that use an action or active
settable.
These widgets might interact with the given properties object, to retrieve or store some state. Such a widget could for example be a check box whose 'selected' state is synchronized with some property.
aComponentID
- the ID describing which component to create. This is normally a constant
that ends with COMPONENT
.aProperties
- a properties object that can be used to tune the behavior of this factory.
state.java.awt.Component
, or null.protected abstract Component createPanel(int aPanelID, ALcyProperties aProperties)
Creates a panel for the given ID. It is safe to use getComponent(int)
in this method, to
build panels that are composed of components.
An example implementation could be:
protected Component createPanel( int aPanelID, ALcyProperties aProperties ) {
if ( aPanelID == SOME_PANEL ) {
JPanel content = new JPanel( new BorderLayout() );
Component someComponent = getComponent( SOME_COMPONENT );
if ( someComponent != null ) content.add( someComponent, BorderLayout.NORTH );
Component otherComponent = getComponent( OTHER_COMPONENT );
if ( otherComponent != null ) content.add( otherComponent, BorderLayout.CENTER );
return content;
}
else if ( aPanelID == ... ) {
...
}
}
aPanelID
- the ID describing which panel to create. This is normally a constant that
ends with PANEL
.aProperties
- a properties object that can be used to tune the behavior of this factory.java.awt.Component
, or null.protected ILcdAction getAction(int aActionID)
Returns the ILcdAction
for the given ID.
Please refer to createGUIContent
to know when this method can be used.
aActionID
- The id describing which action to return. This is normally a constant that
ends in ACTION
.ILcdAction
for the given ID.protected ILcyActiveSettable getActiveSettable(int aActiveSettableID)
Returns the ILcyActiveSettable
for the given ID.
Please refer to createGUIContent
to know when this method can be used.
aActiveSettableID
- the id describing which ILcyActiveSettable
to return.
This is normally a constant that ends in ACTIVE_SETTABLE
.ILcyActiveSettable
for the given ID.protected Component getComponent(int aComponentID)
Returns the java.awt.Component
for the given ID.
Please refer to createGUIContent
to know when this method can be used.
aComponentID
- the id describing which component to return. This is normally a constant
that ends with COMPONENT
.java.awt.Component
for the given ID.protected Component getPanel(int aPanelID)
Returns the panel as a java.awt.Component
for the given ID.
Please refer to createGUIContent
to know when this method can be used.
aPanelID
- the ID describing which panel to return. This is normally a constant that ends
with PANEL
.java.awt.Component
for the given ID.protected ILcdIntList getActionIDs()
Returns the list with all action IDs.
By default, this list only contains the IDs passed in the constructor. Adding and/or removing action IDs to/from this factory is achieved by altering this list.
Warning: do not alter the list when the factory is creating the GUI. Only modify it before
or after the createGUI(com.luciad.lucy.util.properties.ALcyProperties)
method.
protected ILcdIntList getActiveSettableIDs()
Returns the list with all active settable IDs.
By default, this list only contains the IDs passed in the constructor. Adding and/or removing active settable IDs to/from this factory is achieved by altering this list.
Warning: do not alter the list when the factory is creating the GUI. Only modify it before
or after the createGUI(com.luciad.lucy.util.properties.ALcyProperties)
method.
protected ILcdIntList getComponentIDs()
Returns the list with all component IDs.
By default, this list only contains the IDs passed in the constructor. Adding and/or removing component IDs to/from this factory is achieved by altering this list.
Warning: do not alter the list when the factory is creating the GUI. Only modify it before
or after the createGUI(com.luciad.lucy.util.properties.ALcyProperties)
method.
protected ILcdIntList getPanelIDs()
Returns the list with all panel IDs.
By default, this list only contains the IDs passed in the constructor. Adding and/or removing panel IDs to/from this factory is achieved by altering this list.
Warning: do not alter the list when the factory is creating the GUI. Only modify it before
or after the createGUI(com.luciad.lucy.util.properties.ALcyProperties)
method.
protected Object getActionContext(int aActionID, ALcyProperties aProperties)
Returns the context of the action bars in which the action with the specified ID should be inserted.
All actions are inserted in the action bars by TLcyActionBarUtil.insertInConfiguredActionBars(com.luciad.gui.ILcdAction,
Object, com.luciad.lucy.gui.TLcyActionBarManager, com.luciad.lucy.util.properties.ALcyProperties)
.
This method specifies the context for which the action with ID aActionID
is
inserted.
By default this method returns null
.
aActionID
- the ID of the action.aProperties
- The properties. Can be used to tune the behavior of this factory.protected Object getActiveSettableContext(int aActiveSettableID, ALcyProperties aProperties)
Returns the context of the action bars in which the active settable with the specified ID should be inserted.
All active settables are inserted in the action bars by TLcyActionBarUtil#insertInConfiguredActionBars
. This method
specifies the context for which the active settable with ID aActiveSettableID
is
inserted.
By default this method returns null
.
aActiveSettableID
- the ID of the active settableaProperties
- The properties. Can be used to tune the behavior of this factory.protected boolean isActiveSettableDeactivatePossible(int aActiveSettableID, ALcyProperties aProperties)
Returns whether the active settable can be deactivated or not through the action bar in which it is inserted.
All active settables are inserted in the action bars by TLcyActionBarUtil#insertInConfiguredActionBars
. This method specifies the value of the
isDeactivatePossible
parameter for the active settable with ID
aActiveSettableID
is inserted.
aActiveSettableID
- the ID of the active settableaProperties
- The properties. Can be used to tune the behavior of this factorytrue
when the active settable can be deactivated through the action bar,
false
otherwiseTLcyActionBarUtil.insertInConfiguredActionBars(ILcyActiveSettable, Object, TLcyActionBarManager, com.luciad.lucy.util.properties.ALcyProperties, boolean)