com.swath
Class UserDefinedScript

java.lang.Object
  extended bycom.swath.UserDefinedScript
Direct Known Subclasses:
ExampleScript1, ExampleScript2, ExampleScript3, ExampleScript4, ExampleScript5, ExampleScript6, ExampleScript7

public abstract class UserDefinedScript
extends java.lang.Object

User Defined Script base class.

Since:
SWATH 1.3

Constructor Summary
UserDefinedScript()
          Constructor.
 
Method Summary
 boolean atPrompt(int validPrompts)
          Checks if you are at any of the valid prompts.
 void endScript(boolean finished)
          Called by the framework when the script is finished.
 void execInstance()
          Executes a script instance.
 java.lang.String getClassName()
          Gets the class name.
 java.lang.String getDescription()
          Called by the framework to get the description of the script.
 java.lang.String getName()
          Called by the framework to get the name of the script.
 java.util.Enumeration getParams()
          Gets the script parameters.
 java.net.URL getResource(java.lang.String resource)
          Finds a resource with a given name.
 void initInstance()
          Initialises a script instance.
 boolean initScript()
          Called by the framework to initialise the script.
 void postEvent(UserDefinedEvent event)
          This method posts an event in the SWATH event queue.
 void printTrace(java.lang.Exception e)
          Print an exception and the complete stack trace in the SWATH console window.
 void printTrace(java.lang.String text)
          Print trace text in the SWATH console window.
 void registerParam(Parameter param)
          This method is used to register a script parameter.
 boolean runScript()
          Called by the framework to run the script.
 boolean showUserParamWindow(javax.swing.JPanel panel, int width, int height)
          Displays a Swing frame window for script parameter input.
 boolean showUserParamWindow(java.awt.Panel panel, int width, int height)
          Displays an AWT frame window for script parameter input.
 void sleep(long ms)
          Wait and sleep for a while.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserDefinedScript

public UserDefinedScript()
Constructor.

Method Detail

getClassName

public final java.lang.String getClassName()
Gets the class name.

Returns:
The script class name.
Since:
SWATH 1.3

registerParam

public final void registerParam(Parameter param)
                         throws ScriptException
This method is used to register a script parameter.

Parameters:
param - The parameter to register.
Throws:
ScriptException - If no more parameters could be added.
Since:
SWATH 1.3

getParams

public final java.util.Enumeration getParams()
Gets the script parameters.

Returns:
The script parameters.
Since:
SWATH 1.3

initInstance

public final void initInstance()
                        throws ScriptException,
                               java.lang.Exception
Initialises a script instance.
Should only be called from static exec() methods.

Throws:
ScriptException - If the script initialisation fails for some reason.
java.lang.Exception
Since:
SWATH 1.6.2
See Also:
execInstance()

execInstance

public final void execInstance()
                        throws ScriptException,
                               java.lang.Exception
Executes a script instance.
Should only be called from static exec() methods.

Throws:
ScriptException - If the script execution fails for some reason.
java.lang.Exception
Since:
SWATH 1.6.2
See Also:
initInstance()

atPrompt

public final boolean atPrompt(int validPrompts)
                       throws java.lang.Exception
Checks if you are at any of the valid prompts.

Parameters:
validPrompts - The valid prompts. (Combine several prompts with logical OR)
Returns:
true if you are at a valid prompt, otherwise false.
Throws:
java.lang.Exception
Since:
SWATH 1.3
See Also:
Swath.NO_PROMPT, Swath.COMMAND_PROMPT, Swath.COMPUTER_PROMPT, Swath.PLANET_PROMPT, Swath.CITADEL_PROMPT, Swath.CORP_PROMPT, Swath.STARDOCK_PROMPT, Swath.ALL_PROMPTS

sleep

public final void sleep(long ms)
Wait and sleep for a while.

Parameters:
ms - The time to sleep in milliseconds.
Since:
SWATH 1.5

getResource

public final java.net.URL getResource(java.lang.String resource)
Finds a resource with a given name. The search is done using the class path.

Parameters:
resource - The name of the wanted resource.
Returns:
The URL to the wanted resource or null if not found.
Since:
SWATH 1.5

postEvent

public final void postEvent(UserDefinedEvent event)
This method posts an event in the SWATH event queue. Everyone that listens for this event will be notified.

Parameters:
event - The event to post.
Since:
SWATH 1.7

printTrace

public final void printTrace(java.lang.String text)
                      throws java.lang.Exception
Print trace text in the SWATH console window.

Parameters:
text - The text to print.
Throws:
java.lang.Exception
Since:
SWATH 1.7

printTrace

public final void printTrace(java.lang.Exception e)
                      throws java.lang.Exception
Print an exception and the complete stack trace in the SWATH console window.

Parameters:
e - The exception to print.
Throws:
java.lang.Exception
Since:
SWATH 1.7

showUserParamWindow

public final boolean showUserParamWindow(java.awt.Panel panel,
                                         int width,
                                         int height)
                                  throws java.lang.Exception
Displays an AWT frame window for script parameter input.

Parameters:
panel - The user defined panel that holds all components that should be displayed in the client area of the window.
width - The width of the window.
height - The height of the window.
Returns:
true if the user choosed to start the script, otherwise false.
Throws:
java.lang.Exception
Since:
SWATH 1.4
See Also:
Tools.createPanel(), showUserParamWindow(JPanel,int,int)

showUserParamWindow

public final boolean showUserParamWindow(javax.swing.JPanel panel,
                                         int width,
                                         int height)
                                  throws java.lang.Exception
Displays a Swing frame window for script parameter input.

Parameters:
panel - The user defined panel that holds all components that should be displayed in the client area of the window.
width - The width of the window.
height - The height of the window.
Returns:
true if the user choosed to start the script, otherwise false.
Throws:
java.lang.Exception
Since:
SWATH 1.5
See Also:
Tools.createJPanel(), showUserParamWindow(Panel,int,int)

getName

public java.lang.String getName()
Called by the framework to get the name of the script.
You should override this method.

Returns:
The script name.
Since:
SWATH 1.3

getDescription

public java.lang.String getDescription()
Called by the framework to get the description of the script.
You should override this method to provide a script description.

The script description can be an URL to a HTML page or file. It can also be normal HTML text or plain text.

By default, a file named ScriptClass.html or ScriptClass.txt is used if found.

Examples:

Returns:
The script description.
Since:
SWATH 1.5

initScript

public boolean initScript()
                   throws java.lang.Exception
Called by the framework to initialise the script.
You should override this method to make your own initialisation.

Returns:
true if the initialisation was successful, otherwise false.
Throws:
java.lang.Exception
Since:
SWATH 1.3
See Also:
atPrompt(int), showUserParamWindow(Panel,int,int), showUserParamWindow(JPanel,int,int)

runScript

public boolean runScript()
                  throws java.lang.Exception
Called by the framework to run the script.
You should override this method to define the script body.

Returns:
true if the script finished correctly, otherwise false.
Throws:
java.lang.Exception
Since:
SWATH 1.3

endScript

public void endScript(boolean finished)
               throws java.lang.Exception
Called by the framework when the script is finished.
You can override this method to clean up after the script if needed.

Parameters:
finished - true if the script finished correctly or false if the script was interrupted in some way.
Throws:
java.lang.Exception
Since:
SWATH 1.3