|
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--com.droplets.api.InvalidationEventSource
|
+--com.droplets.api.Window
The base class of all windows in Droplet applications. This class should
not be constructed directly. Use Dialog or Frame instead.
Each application must have one unique window designated as its main window.
The main window is handled differently from others by the Droplet Server in
certain ways. In particular, calling close on the main window
terminates the application, whereas calling close on any other
window just closes that window. To distinguish the main window from the rest,
you must pass true to the constructor as the
isMainWindow parameter.
Note that there is a restriction on the usage of Window objects.
After the Droplet Client corresponding to an Application object is no longer
connected to the Server, all open windows that belong to that Application
may be deallocated, either immediately when the Client disconnects or after
a specified period of time. In addition, Windows are always deallocated
after they are closed. When a Window is deallocated, the Java object that
represents it is said to become "invalid." All subsequent
public method calls will throw an IllegalStateException.
Any other objects that hold a reference to this one should register using
InvalidationEventSource.addInvalidationListener(com.droplets.api.event.ObjectInvalidationListener) to be notified
when the object becomes invalid so that they can release their references.
In all cases, this notification will come after a call to
stop().
Note that in the ObjectInvalidationListener's event handling
code, you must not rely on the fact that the Window's Application object
is still valid. However, the Window's Components are guaranteed to be
valid.
Since window information is cached, it is not possible to simply add if/else
logic to generate different component layouts based on context. See addAllComponents()
method documentation for important restrictions on adding components in windows, and for
more information on how to generate window layouts at runtime.
There are some concepts that you must understand about how Droplet Windows work. Refer to the Droplet SDK's Hello World and Sub-windows tutorials for a full explanation.
| Field Summary | |
protected int |
m_token
The token that represents this object's native peer. |
protected com.droplets.api.WindowComponent |
m_windowComp
The component used to communicate attributes and commands for Windows to clients. |
| Constructor Summary | |
Window(Application application,
boolean isMainWindow)
Deprecated. Construct a Frame or Dialog instead of this class. They both derive from this class, so the usage is the same, but each class is more explicit about the type of Window you would get. Constructs a new Window. |
|
Window(Application application,
boolean isMainWindow,
boolean isFrame)
Deprecated. Construct a Frame or Dialog instead of this class. They both derive from this class, so the usage is the same, but each class is more explicit about the type of Window you would get. Constructs a new Window. |
|
| Method Summary | |
protected void |
addAllComponents()
Called by the Droplet Server after the window has been created. |
void |
addCloseListener(WindowCloseListener l)
Adds a listener to be notified when this window is about to close. |
void |
addComponent(Component c)
Deprecated. Replaced by Panel.addComponent().
To add a component to a Window, use
getMainPanel().addComponent() instead. |
void |
addOpenDialogListener(OpenDialogListener pl)
Adds a listener to be notified when a file is chosen from an open dialog |
void |
close()
Closes this window. |
protected boolean |
doRetrieve(java.io.InputStream is)
A hook for your application to read its own data from a persistent stream as part of the application deserialization process. |
protected boolean |
doStore(java.io.OutputStream os)
A hook for your application to write its own data to a persistent stream as part of the application serialization process. |
protected void |
fireWindowClosedEvent()
Notifies all listeners that the window is closing. |
protected void |
flush()
Sends all UI changes to the client. |
protected java.lang.String |
generateTypeString()
Generates a name for the Droplet Server specification of this window. |
Application |
getApplication()
Gets the Application object that contains this window. |
protected Component |
getComponentByName(java.lang.String name)
Returns a reference to a component in this window given its internal name. |
MainPanel |
getMainPanel()
Gets the window's main panel. |
MenuBar |
getMenuBar()
Returns the menu bar for this window, or null if none exists. |
int |
getProtocolVersion()
Returns the version number of the protocol currently in use. |
java.lang.String |
getTitle()
Gets the title of the window (the text that appears in the title bar). |
boolean |
isMainWindow()
Determines whether this is the application's main window. |
protected boolean |
isWindowTypeCacheable()
Called to determine if the window-type is cacheable. |
void |
locate(int left,
int top,
int width,
int height)
Sets the dimensions and location of this window. |
void |
print(java.lang.String text)
Prints the string to the printer. |
void |
removeCloseListener(WindowCloseListener l)
Removes a close listener. |
void |
removeOpenDialogListener(OpenDialogListener pl)
Removes a listener to be notified when a file is chosen from an open dialog (previously added with addOpenDialogListener(com.droplets.api.event.OpenDialogListener)). |
MenuBar |
setMenuBar(MenuBar menuBar)
Sets the menu bar for this window. |
void |
setTitle(java.lang.String title)
Sets the title of the window (the text that appears in the title bar). |
void |
signalAttentionRequired()
Request a visual cue to signal that attention is required on the window. |
protected void |
start()
Called by the Droplet Server each time the client becomes available. |
protected void |
stop()
Called by the Droplet Server each time the client becomes unavailable. |
| Methods inherited from class com.droplets.api.InvalidationEventSource |
addInvalidationListener, ensureValid, fireInvalidationEvent, invalidate, isValid, removeInvalidationListener |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected com.droplets.api.WindowComponent m_windowComp
protected int m_token
| Constructor Detail |
public Window(Application application,
boolean isMainWindow)
Window.
application - the application object representing the user
session in which this window will appearisMainWindow - pass true if this is the main window of the
application, otherwise false. Only one window per Application
object (i.e. in each user session) can be the main window.
public Window(Application application,
boolean isMainWindow,
boolean isFrame)
Window.
application - the application object representing the user
session in which this window will appearisMainWindow - pass true if this is the main window of the
application, otherwise false. Only one window per Application
object (i.e. in each user session) can be the main window.isFrame - pass true if the window is a Frame, false if it's a Dialog.| Method Detail |
protected void start()
start() method and the stop()
methods are analogous the methods by the same name
in java.applet.Applet. The idea is that within a given
usage session, the client may periodically be unavailable to receive
information from the server. Each time the client state changes from
an unavailable state to an available state, start() is
called. When the opposite transition occurs, stop() is
called.
This default implementation does nothing. Subclasses should override it to do whatever is appropriate.
Typically, a subclass would set the instance-specific values of any
components during the first call to this method, while class-specific
values would be set in the addAllComponents() method.
protected void stop()
start() method and the stop()
methods are analogous the methods by the same name
in java.applet.Applet. The idea is that within a given
usage session, the client may periodically be unavailable to receive
information from the server. Each time the client state changes from
an unavailable state to an available state, start() is
called. When the opposite transition occurs, stop() is
called.
This default implementation does nothing. Subclasses should override it to do whatever is appropriate.
protected void addAllComponents()
In a typical application, each Window subclass will generate the same set of components (with the same attributes) for every instance of the class when this method is called. This allows the window description to be cached on the client, greatly reducing the bandwidth required to open a second window of this class.
Important Note!: Because the window description is cached on the client,
you must set instance-specific values for components in the
start() method, and NOT in addAllComponents().
For example, if a window contains TextFields for entering
data, the values of the TextFields should be set in the
start() method, while the values of the Labels
explaining what data each TextField contains would be set in
addAllComponents().
If this is impossible -- typically because your window's contents are determined at runtime -- your window subclass must instead override two Window methods:
1. generateTypeString(). This method sets the key for the hash which the
caches are using. You can provide a different name for each window configuration by
using a different type string for each different window.
2. isWindowTypeCacheable(). This method disables the client side cache.
You must override and return false, if the window has an unknown or large number
of possible component sets.
See Building
Windows at Runtime for more information on this.
protected final void flush()
protected Component getComponentByName(java.lang.String name)
Component
sometimes get called with names of components
rather than references (the action method, for example).
Note that this is a case where we actually want to grant package and subclass access at the same time, which is exactly what the protected keyword does.
name - name of the component to getpublic MainPanel getMainPanel()
The main panel is lazily constructed.
public void signalAttentionRequired()
If the window is a Dialog, the signal stops if either the dialog
or its parent window is activated.
Call this method anytime after addAllComponents(). The Droplets
platform throws an exception if it is called before or within
addAllComponents().
public boolean isMainWindow()
public Application getApplication()
Application object that contains this window. Note:
this method should not be called in your stop() method.Application objectpublic java.lang.String getTitle()
public void setTitle(java.lang.String title)
title - the title of the window (the text that appears in the
title bar)public MenuBar getMenuBar()
public MenuBar setMenuBar(MenuBar menuBar)
menuBar - the menu bar to attach to the frame of this window.public void print(java.lang.String text)
text - the text to print with component tag substitutionspublic void addComponent(Component c)
Panel.addComponent().
To add a component to a Window, use
getMainPanel().addComponent() instead.
addAllComponents method, which is called by
the server. Calling this method after that one
has returned results in an IllegalStateException.c - The component to add to this windowjava.lang.IllegalStateException - if this method is invoked after
addAllComponents has returned.Panelpublic void close()
Application.requestExit,
eventually causing the session to be suspended and the Client to exit.
This is the method that clients should call to programmatically close the window. It is not a callback method and does not get called when the server closes the window (including when the user clicks on the close box).
public void locate(int left,
int top,
int width,
int height)
left - Number of pixels in from the left side of the screen, or -1
to place it in the centertop - Number of pixels down from the top of the screen, or -1 to
place it in the centerwidth - Width of the window in pixelsheight - Height of the window in pixelspublic int getProtocolVersion()
protected boolean doStore(java.io.OutputStream os)
throws java.lang.Exception
doRetrieve(java.io.InputStream) to read whatever you write here.
If your application does not support serialization, or if an error occurs while storing your data, return false. Be aware that this will cause the entire serialization process to fail.
Throwing any kind of exception is equivalent to returning false.
os - OutputStream to which data can be written
protected boolean doRetrieve(java.io.InputStream is)
throws java.lang.Exception
doStore(java.io.OutputStream), it should implement
doRetrieve(java.io.InputStream) to read whatever data it wrote in doStore(java.io.OutputStream).
If your application does not support serialization, or if an error occurs while storing your data, return false. Be aware that this will cause the entire serialization process to fail.
Throwing any kind of exception is equivalent to returning false.
is - InputStream from which data should be readpublic void addCloseListener(WindowCloseListener l)
l - the listener to addpublic void removeCloseListener(WindowCloseListener l)
l - the listener to removepublic void addOpenDialogListener(OpenDialogListener pl)
pl - the listener to addApplication.showOpenDialog(com.droplets.api.Window)public void removeOpenDialogListener(OpenDialogListener pl)
addOpenDialogListener(com.droplets.api.event.OpenDialogListener)).pl - the listener to removeApplication.sendFile(com.droplets.api.Window, java.lang.String, int, java.lang.String)protected void fireWindowClosedEvent()
protected java.lang.String generateTypeString()
This default implementation simply returns the fully qualified concrete
class name of the object it is called on. If you do not override this
implementation, then all objects created from a given concrete subclass
of Window will be expected to conform to the same window
specification -- in other words, they will all need to contain the
same components in the same initial configuration.
If you override this method, make sure to return a unique string for each different initial configuration of components within the window.
The Droplets Platform caches window configurations using this string
as a key. If your window configuration should not be cached, then you
must override isWindowTypeCacheable() to return false.
protected boolean isWindowTypeCacheable()
false.
true if the window-type is cacheable, false
otherwise.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||