ti.chimera.service
Class Prompt

java.lang.Object
  extended byti.chimera.Service
      extended byti.chimera.service.Prompt

public abstract class Prompt
extends Service

The "prompt" service, used to implement a mechanism to display info/warning/ error messages to the user, or prompt the user for input. The purpose is to seperate the decision of how to interact with user from code that needs to interact with the user. This service could be implemented, for example, either by poping up dialogs, or with console I/O... it is even possible that an "expect"-like implementation of this service could be used to automate things.

Version:
0.1
Author:
Rob Clark

Nested Class Summary
static interface Prompt.Progress
          An object implementing this interface is returned by showProgress(java.lang.String) in order to allow the client code to programatically update or dismiss the progress.
 
Constructor Summary
Prompt()
          Class Constructor.
 
Method Summary
abstract  java.lang.String askQuestion(java.lang.String msg, java.lang.String[] choices)
          Ask a question of the user.
abstract  void showErrorMessage(java.lang.String msg)
          Display an error message to the user.
abstract  void showInfoMessage(java.lang.String msg)
          Display an info message to the user.
abstract  Prompt.Progress showProgress(java.lang.String msg)
          Display a progress message to the user.
abstract  void showWarningMessage(java.lang.String msg)
          Display a warning message to the user.
 
Methods inherited from class ti.chimera.Service
getName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Prompt

public Prompt()
Class Constructor.

Method Detail

showErrorMessage

public abstract void showErrorMessage(java.lang.String msg)
Display an error message to the user. This method blocks until the user dismisses the message.

Parameters:
msg - the error message to display

showWarningMessage

public abstract void showWarningMessage(java.lang.String msg)
Display a warning message to the user. This method blocks until the user dismisses the message.

Parameters:
msg - the warning message to display

showInfoMessage

public abstract void showInfoMessage(java.lang.String msg)
Display an info message to the user. This method blocks until the user dismisses the message.

Parameters:
msg - the info message to display

showProgress

public abstract Prompt.Progress showProgress(java.lang.String msg)
Display a progress message to the user. A progress message has a progress bar to display progress. This returns a Prompt.Progress to allow the client code to programatically update the progress, and dispose of the progress message once complete.

The progress displayed to the user is initially in "indeterminate" mode to indicate that the length of time to take is unknown. Once the length of time is known, Prompt.Progress.setRange(int, int) and Prompt.Progress.setValue(int) can be used to update the progress display.

For example:

   var progress = services["prompt"].showProgress("This will take a while");
   
   // progress is in "indeterminate" mode until you compute length of time:
   progress.setRange( 0, computeTime() );
   
   var t = currentTimeMillis();
   while( !done() )
   {
     doSomeWork();
     p.setValue( currentTimeMillis() - t );
   }
   
   // done, so dismiss progress dialog:
   progress.dispose();
 

Parameters:
msg - the message to display
Returns:
an object allowing the progress display to be programatically updated by the client code

askQuestion

public abstract java.lang.String askQuestion(java.lang.String msg,
                                             java.lang.String[] choices)
Ask a question of the user. The msg is displayed to the user, who must then choose one of the choices. The choice selected by the user is returned. This method blocks until a result is choisen. For example:
   var result = services["prompt"].askQuestion( "Do you want to continue?", [ "Yes", "No" ] );
   if( result == "No" )
     return;
   ....
 

Parameters:
msg - the message to display
choices - array of choices presented to the user
Returns:
one of the elements from choices