|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--one.world.core.Component
|
+--one.gui.Application
Implementation of an application's main component. This class serves as a userful base class for building one.world applications with a Swing UI.
An application has three states. In the inactive state, it is not running. In the activating state, the application has received an activated,
moved, cloned, or restored environment
event and is acquiring the resources it requires to run. Finally,
in the active state, an application is showing its
main window and reacting to user input.
The state transition from the inactive to the activating state
is performed by the main exported event handler, which starts the
resource acquisition process by invoking acquire(). The
state transition from the activating to the active state is
performed by the start() method. Finally, the state
transition from the active to the inactive state is performed by
the stop(boolean) method, which relies on release() to release an application's resources.
Subclasses typically need to override only the acquire() and release() methods to manage an
application's resources and the createMainWindow() method
to create the application's main window.
| Inner Class Summary | |
static class |
Application.Window
Implementation of an application's main window. |
| Inner classes inherited from class one.world.core.Component |
Component.HandlerReference, Component.Importer |
| Field Summary | |
static int |
ACTIVATING
The flag for the activating status. |
static int |
ACTIVE
The flag for the active status. |
String |
appName
The name of this application. |
int |
height
The height of the main window. |
static int |
INACTIVE
The flag for the inactive status. |
int |
locationX
The x coordinate for the main window location. |
int |
locationY
The y coordinate for the main window location. |
Object |
lock
The lock protecting the application's internal state. |
EventHandler |
main
The main exported event handler. |
Application.Window |
mainWindow
The application's main window. |
Operation |
operation
The application's main operation. |
Component.Importer |
request
The request imported event handler. |
int |
status
The application's current status. |
Timer |
timer
The timer for this application. |
int |
width
The width of the main window. |
| Constructor Summary | |
Application(Environment env)
Create a new application in the specified environment. |
|
| Method Summary | |
void |
acquire()
Acquire the resources needed by this application. |
EventHandler |
createMainHandler()
Create the main exported event handler. |
Application.Window |
createMainWindow()
Create the application's main window. |
ComponentDescriptor |
getDescriptor()
Get the component descriptor. |
static void |
init(Environment env,
Object closure)
Initialize an application. |
void |
release()
Release all resources. |
void |
signalError(String msg)
Signal an error condition to the user. |
void |
start()
Start the application. |
void |
stop(boolean notify)
Stop the application. |
| Methods inherited from class one.world.core.Component |
declareExported, declareImported, equals, eventHandlers, getDescriptor, getEnvironment, getLinkedHandlers, getLinkedNumber, getTimer, hasEventHandler, hashCode, isFullyLinked, isLinked, isSealed, link, link, run, seal, unbox, undeclare, unlink, wrap |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int INACTIVE
status.public static final int ACTIVATING
status.public static final int ACTIVE
status.public String appName
public final EventHandler main
public final Component.Importer request
public final Timer timer
public volatile int locationX
public volatile int locationY
public volatile int width
public volatile int height
public transient int status
INACTIVE, ACTIVATING, or ACTIVE. Access to this field must be synchronized by the
application's lock. Upon deserialization of an
application, this field is restored to the inactive state.public transient Object lock
statuspublic transient Application.Window mainWindow
start() and set to
null again by stop(boolean).public transient Operation operation
| Constructor Detail |
public Application(Environment env)
env - The environment.| Method Detail |
public EventHandler createMainHandler()
The default implementation returns an event handler that
handles activated, restored, moved, cloned, and stop environment
events. On an activated, restored, moved, or cloned environment
event, the returned event handler enters the activating state and
then invokes acquire(). On a stop environment event, the
returned event handler, invokes stop(false) and then responds to the stop environment event with
a stopped environment event.
EnvironmentEventpublic ComponentDescriptor getDescriptor()
This method returns a component descriptor suitable for thread-safe applications. Subclasses are encouraged to overwrite this method, as the descriptor returned by this method uses the name of this component. However, they need not do so, because the component name is not currently utilized. Note that UI-based applications must be thread-safe, because Swing UI events are generated by a thread separate from all one.world threads.
getDescriptor in class Componentone.world.core.Componentpublic void acquire()
main exported event handler after entering
the activating state.
An application must be prepared to stop while it is still
acquiring the resources it needs. It can detect whether it has
been concurrently stopped by checking for the inactive state.
The default implementation directly transitions to the active state by calling start().
public void start()
The default implementation creates a new main window,
transitions to the active state, and then
displays the window (if it is not null). Calling
this method has no effect, if this application is not in the
activating state or already has a main
window.
Applications typically need not override this method.
locationX,
locationY,
createMainWindow()public void stop(boolean notify)
The default implementation transitions to the inactive state, closes the application's main window, releases
all resources by calling release(), and, if specified,
notifies the application's environment of having stopped, all
while holding the application's lock. Calling this method has no
effect, if the application already is in the inactive state.
Applications typically need not override this method.
notify - The flag for whether to notify this
application's environment of having stopped.public void release()
stop(boolean) after transitioning to the inactive state and closing the main window, while holding the
application's lock.
An application must be prepared for the fact that not all of its resource have been acquired.
The default implementation does nothing.
public Application.Window createMainWindow()
start() to create the application's main window. It can
return null if the application does not have a main
window. This method should only create the main window, but not
make it visible.
The default implementation creates an empty window, titled
"Main Window", with the current width and height.
null
if the application does not have a main window.public void signalError(String msg)
msg - The error message.
public static void init(Environment env,
Object closure)
env - The environment.closure - The closure, which is ignored.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||