|
||||||||
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.Application
Represents an individual client's session with a particular Droplet
application. Instances should be created by your ApplicationFactory
in response to requests by the server. When you create a new window,
you will need to add it to this object using addWindow(Window)
.
This class also provides some general-purpose utility methods to accomplish
tasks specific to a client session.
Note that there is a restriction on the usage of Application objects.
After the Droplet Client corresponding to an Application is no longer
connected to the Server, the object's resources may be deallocated,
either immediately when the Client disconnects or after a specified
period of time. At that point, the object becomes "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.
This notification will always come after stop()
is called on
all of the Application's active windows.
Note that in the ObjectInvalidationListener
's event handling
code, you must not rely on the fact that the Application's window objects
are still valid.
Field Summary | |
static java.lang.String |
MENU_ABOUT
Causes the About Droplets dialog box to be displayed. |
static java.lang.String |
MENU_ADD_TO_WEBPAGE
Brings up a dialog with the HTML necessary for embedding this Droplet in a web page. |
static java.lang.String |
MENU_EMAIL_A_FRIEND
Causes the "Send this Droplet to a friend..." dialog box to be displayed. |
static java.lang.String |
MENU_GO_TO_WEBTOP
Sends the user to the www.mydroplets.com website. |
static java.lang.String |
MENU_HELP
Sends the user to the general Droplets help page. |
static java.lang.String |
MENU_HELP_WITH_DROPLET
Sends the user to the help page for this particular Droplet application. |
static java.lang.String |
MENU_LOG_OFF_AND_EXIT
Logs off the user and exits the application. |
static java.lang.String |
MENU_SAVE_TO_WEBTOP
Sends the user to the Droplet Webtop site in order to save the current Droplet. |
Constructor Summary | |
Application(int appToken)
Creates an Application object to handle a user's session
with this application. |
Method Summary | |
void |
addPollListener(PollListener pl)
Adds a listener to be notified when the client polls this application. |
void |
addWindow(Window window)
Adds a window to the application. |
void |
closeWorkingDialog()
Closes the "working" dialog. |
void |
executeDropletMenuItem(java.lang.String menuItem)
Programmatically selects one of the options on the Droplet menu. |
java.lang.String |
getAuthenticatedUserName()
Gets the username by which this user has authenticated |
Dripline |
getDripline()
Gets the Dripline object. |
static java.lang.String[] |
getDropletMenuItemStrings()
Gets an array of all of the valid Droplet menu item string constants that may be passed to executeDropletMenuItem . |
int |
getPollTime()
Returns the poll time in centiseconds. |
int |
getProtocolVersion()
Returns the version number of the protocol currently in use. |
java.lang.String |
getVariableValue(java.lang.String variableName)
Queries the value of one of the variables associated with this application. |
WindowFactory |
getWindowFactory()
Gets the registered window factory. |
void |
messageBox(java.lang.String title,
java.lang.String message)
Displays a modal dialog box with an OK button. |
void |
messageBox(java.lang.String title,
java.lang.String message,
DialogCloseListener dc)
Displays a modal dialog box with an OK button. |
void |
playSound(java.lang.String sound)
Requests that the client play the specified sound. |
void |
postEvent(java.lang.Runnable event)
Posts an event to the Server's internal event queue that will result in the run method being called on the provided object. |
void |
printPdf(java.lang.String url)
Prints the .pdf file pointed to by url . |
void |
removePollListener(PollListener pl)
Removes a poll listener. |
void |
reportServerError(java.lang.String msg)
Tells the Droplet client that a severe server error has occurred. |
void |
requestAuthentication(java.lang.String message,
AuthenticationHandler handler)
Pops up a dialog box requesting that the user supply a username and password. |
void |
requestExit()
Tells the Droplet Client to exit, suspending the user's session. |
void |
saveUrlToFile(java.lang.String url,
java.lang.String filename)
Asks the client to download a URL and save it into a file that the user chooses. |
void |
sendFile(Window w,
java.lang.String server,
int port,
java.lang.String fileName)
Sends a file to the server that was previously chosen with the file open dialog. |
void |
setPollTime(int centiseconds)
Sets the poll time in centiseconds. |
void |
setWindowFactory(WindowFactory factory)
Registers an object that will be invoked by the Server to recreate the windows in a stored session when the session is deserialized. |
void |
showDocument(java.lang.String documentUrl,
java.lang.String target)
Shows a URL in a browser. |
void |
showErrorDialog(java.lang.String message)
Displays a modal error dialog box with an OK button and an error icon. |
void |
showErrorDialog(java.lang.String message,
DialogCloseListener dc)
Displays a modal error dialog box with an OK button and an error icon. |
void |
showOpenDialog(Window w)
Puts up a File Open dialog on the client. |
void |
showWorkingDialog(java.lang.String title,
java.lang.String message,
boolean autoClose)
Displays a "working" dialog with the given title and message. |
void |
startDroplet(java.lang.String address,
int port,
java.lang.String imageDir,
java.lang.String calc,
java.lang.String title,
java.lang.String vars)
Starts a Droplet on the client with the given Droplet parameters. |
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 |
public static final java.lang.String MENU_ABOUT
public static final java.lang.String MENU_EMAIL_A_FRIEND
public static final java.lang.String MENU_GO_TO_WEBTOP
public static final java.lang.String MENU_SAVE_TO_WEBTOP
public static final java.lang.String MENU_HELP
public static final java.lang.String MENU_HELP_WITH_DROPLET
public static final java.lang.String MENU_ADD_TO_WEBPAGE
public static final java.lang.String MENU_LOG_OFF_AND_EXIT
Constructor Detail |
public Application(int appToken)
Application
object to handle a user's session
with this application.appToken
- the token that the server passed into
ApplicationFactory.createApplication(int)
Method Detail |
public void setWindowFactory(WindowFactory factory)
WindowFactory
must be registered in order to
support serialization.factory
- the WindowFactory objectpublic WindowFactory getWindowFactory()
public void addWindow(Window window)
window
- the windowpublic void messageBox(java.lang.String title, java.lang.String message)
title
- text to be displayed in the title bar of the dialog boxmessage
- text in the main panel of the dialog boxpublic void messageBox(java.lang.String title, java.lang.String message, DialogCloseListener dc)
title
- text to be displayed in the title bar of the dialog boxmessage
- text in the main panel of the dialog boxdc
- the close listener that will be notified on close. Its
handleClose method is called with true if the client supports the call
and false if it does not.public void showErrorDialog(java.lang.String message)
message
- text in the main panel of the dialog boxpublic void showErrorDialog(java.lang.String message, DialogCloseListener dc)
message
- text in the main panel of the dialog boxdc
- the close listener that will be notified on close. Its
handleClose method is called with true if the client supports the call
and false if it does not.public void showWorkingDialog(java.lang.String title, java.lang.String message, boolean autoClose)
closeWorkingDialog()
when you want the dialog to close.title
- text to be displayed in the title bar of the dialog boxmessage
- the message that appears on the dialog.autoClose
- true if you want the dialog to automatically close
when the event is handled. If autoClose is false, then call
closeWorkingDialog()
when you want the dialog to close.closeWorkingDialog()
public void closeWorkingDialog()
showWorkingDialog(java.lang.String, java.lang.String, boolean)
public void requestExit()
public static java.lang.String[] getDropletMenuItemStrings()
executeDropletMenuItem
.public void executeDropletMenuItem(java.lang.String menuItem)
menuItem
- must be one of the valid values representing items in
the menu, all of which are stored in public static final Strings in
this class (see Application
above).public java.lang.String getAuthenticatedUserName()
public void reportServerError(java.lang.String msg)
msg
- text for the Droplet Client to write to its log. It is
also displayed to the user while the reconnect takes place.public void saveUrlToFile(java.lang.String url, java.lang.String filename)
This method operates asynchronously, returning before the client has completed the operation. Therefore, the fact that this method returns does not necessarily mean that the operation succeeded. If the provided URL is invalid, an error dialog will be shown to the user.
url
- the URL to downloadfilename
- the filename to suggest to the user, or null to
suggest nothing in particularpublic void showOpenDialog(Window w)
addOpenDialogListener
will be notified with the filename. They may opt to call
sendFile
to have the client send the file to the server.w
- The window to associate this open dialog withsendFile(com.droplets.api.Window, java.lang.String, int, java.lang.String)
,
Window.addOpenDialogListener(com.droplets.api.event.OpenDialogListener)
public void sendFile(Window w, java.lang.String server, int port, java.lang.String fileName)
addOpenDialogListener
will be notified with the filename.
The client will use the PUT method of the web server you specify.w
- The window to associated with this open dialogserver
- The internet address of the machine with the web server
to PUT the file toport
- The port the web server is listening onfileName
- the server file name.showOpenDialog(com.droplets.api.Window)
,
Window.addOpenDialogListener(com.droplets.api.event.OpenDialogListener)
public java.lang.String getVariableValue(java.lang.String variableName)
There are two sets of variables that can be queried with this method:
vars
Droplet parameter and may have any arbitrary
name and value.Variables which can be read include the following:
params.txt
file will be available as well.attributeName
- the name of the variable to querypublic void requestAuthentication(java.lang.String message, AuthenticationHandler handler)
Authentication is an asynchronous operation. Instead of this function
returning a flag for whether the authentication succeeded or not, the
caller supplies an AuthenticationHandler
that will be
called when the operation completes. This method simply returns
immediately. See AuthenticationHandler
for details on how to
interpret the results of the authentication request.
Note that this function allows for deferred authentication: you can
allow the user to begin using the application without authenticating,
only calling this method when the user requests an operation that
requires authentication. If your application requires that the user
authenticate herself to run at all, you should implement the
ApplicationFactory.getRequiresImmediateAuthentication()
method
in your ApplicationFactory
to return true. If you do that,
then the fact that the application has started guarantees that the user
is already authenticated.
message
- a message to display to the user in the authentication
dialog boxhandler
- an object that will be called when the user
completes (or cancels) the authentication. If you have already
called this method on this object and supplied an
AuthenticationHandler
, pass null to leave that
handler in place.NullPointerException
- if no handler has ever been passed
in and the handler
argument is nullpublic void postEvent(java.lang.Runnable event)
run
method being called on the provided object.
This allows you to designate arbitrary code to be executed in a Server
event-processing thread.
If your application code creates any threads that need to update the
state of GUI components or call methods on the Application
object, you should make sure that those threads never do so directly.
Instead, wrap the calls in Runnable
objects and pass them
to this method. Otherwise, data corruption is likely to occur.
If the run
method throws an unchecked exception, it will
be caught and logged by the Server. Execution of other events will
continue normally.
Note that the event that you pass in is posted to the end of the queue. Therefore, all other events that have already arrived (for example, actions the user has taken on the front end) are processed before this one. Even if there are no others on the queue, this method returns immediately, before the newly posted event is processed.
Also note that although it is unnecessary, calling this method from a Server thread has no harmful effects and functions in exactly the same way as when it is called from an application thread. The event is still be posted to the end of the queue.
This mechanism for avoiding integrity problems between threads is
essentially the same as the one used by AWT and Swing. The Droplet
Server event queue is analogous to java.awt.EventQueue
,
Server threads are analogous to the EventDispatchThread
,
and the postEvent
method is analogous to both
java.awt.EventQueue.invokeLater()
and
javax.swing.SwingUtilities.invokeLater()
. Therefore,
explanations in any documentation or texts about those packages will
generally apply to the Droplet environment as well.
event
- the Runnable
to be executed by a Server
threadNullPointerException
- if the argument is nullpublic void showDocument(java.lang.String documentUrl, java.lang.String target)
documentUrl
- a url to the document to be showedtarget
- the target frame in the browserpublic void printPdf(java.lang.String url)
url
.url
- the .pdf file to printpublic void startDroplet(java.lang.String address, int port, java.lang.String imageDir, java.lang.String calc, java.lang.String title, java.lang.String vars)
address
- the network address of the Droplet Server.
Use null or "" to indicate that the address is the same as the calling Dropletport
- the network port of the Droplet Server. Use -1 to indicate
that the port is the same as the calling Droplet.imageDir
- the base URL of images for the Droplet. Use null to indicate
that the imageDir is the same as the calling Droplet.calc
- the calc (Droplet Application Name) of the Droplet. Use null or ""
to indicate that the calc is the same as the calling Droplet.title
- the text on the title bar of the Droplet. Use null to indicate that
the title is the same as the calling Droplet.vars
- the user variables of the Droplet. Use null to indicate that the vars
is the same as the calling Droplet.public int getPollTime()
public int getProtocolVersion()
public void setPollTime(int centiseconds)
centiseconds
- the desired poll time (or -1 for no polling)addPollListener(com.droplets.api.event.PollListener)
,
removePollListener(com.droplets.api.event.PollListener)
public void playSound(java.lang.String sound)
The sound
parameter may be either a URL, or the name
of a sound file in the application's imageDir. The file extension
must be provided, it will not be assumed.
Example:
myApp.playSound("http://www.sdkhfksjfhskafh.com/capybara.au");
myApp.playSound("capybara.au"); // From imageDir
sound
- the sound to playpublic void addPollListener(PollListener pl)
pl
- the listener to addsetPollTime(int)
,
removePollListener(com.droplets.api.event.PollListener)
public void removePollListener(PollListener pl)
pl
- the listener to removesetPollTime(int)
,
addPollListener(com.droplets.api.event.PollListener)
public Dripline getDripline()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |