Package weka.gui.scripting
Class Script
- java.lang.Object
-
- weka.gui.scripting.Script
-
- All Implemented Interfaces:
java.io.Serializable,OptionHandler
- Direct Known Subclasses:
GroovyScript,JythonScript
public abstract class Script extends java.lang.Object implements OptionHandler, java.io.Serializable
A simple helper class for loading, saving scripts.- Version:
- $Revision: 10222 $
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classScript.ScriptThreadThe Thread for running a script.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBACKUP_EXTENSIONthe backup extension.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddScriptFinishedListener(ScriptExecutionListener l)Adds the given listener to its internal list.voidempty()Empties the document.java.lang.StringgetContent()Returns the content.abstract java.lang.StringgetDefaultExtension()Returns the default extension.java.io.FilegetFilename()Returns the current filename.abstract ExtensionFileFilter[]getFilters()Returns the extension filters for this type of script.java.lang.StringgetNewLine()Returns the new line string in use.java.lang.String[]getOptions()Gets the current settings of the script.booleanisModified()Returns whether the script is modified.booleanisRunning()Returns whether the script is still running.java.util.Enumeration<Option>listOptions()Returns an enumeration describing the available options.abstract Script.ScriptThreadnewThread(java.lang.String[] args)Returns a new thread to execute.booleanopen(java.io.File file)Tries to open the file.voidremoveScriptFinishedListener(ScriptExecutionListener l)Removes the given listener from its internal list.voidrun(java.io.File file, java.lang.String[] args)Executes the script without loading it first.static voidrunScript(Script script, java.lang.String[] args)Runs the specified script.booleansave()Saves the file under with the current filename.booleansaveAs(java.io.File file)Saves the file under with the given filename (and updates the internal filename).voidsetContent(java.lang.String value)Sets the content.voidsetOptions(java.lang.String[] options)Parses a given list of options.voidstart(java.lang.String[] args)Executes the script.voidstop()Stops the execution of the script.java.lang.StringtoString()Returns the content as string.
-
-
-
Field Detail
-
BACKUP_EXTENSION
public static final java.lang.String BACKUP_EXTENSION
the backup extension.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Script
public Script()
Initializes the script.
-
Script
public Script(javax.swing.text.Document doc)
Initializes the script.- Parameters:
doc- the document to use as basis
-
Script
public Script(javax.swing.text.Document doc, java.io.File file)Initializes the script. Automatically loads the specified file, if not null.- Parameters:
doc- the document to use as basisfile- the file to load (if not null)
-
-
Method Detail
-
listOptions
public java.util.Enumeration<Option> listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Returns:
- an enumeration of all the available options
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionParses a given list of options.- Specified by:
setOptionsin interfaceOptionHandler- Parameters:
options- the list of options as an array of strings- Throws:
java.lang.Exception- if an option is not supported
-
getOptions
public java.lang.String[] getOptions()
Gets the current settings of the script.- Specified by:
getOptionsin interfaceOptionHandler- Returns:
- an array of strings suitable for passing to setOptions
-
getFilters
public abstract ExtensionFileFilter[] getFilters()
Returns the extension filters for this type of script.- Returns:
- the filters
-
getDefaultExtension
public abstract java.lang.String getDefaultExtension()
Returns the default extension. Gets automatically added to files if their name doesn't end with this.- Returns:
- the default extension (incl. the dot)
- See Also:
saveAs(File)
-
getFilename
public java.io.File getFilename()
Returns the current filename.- Returns:
- the filename, null if no file loaded/saved
-
getNewLine
public java.lang.String getNewLine()
Returns the new line string in use.- Returns:
- the new line string
-
isModified
public boolean isModified()
Returns whether the script is modified.- Returns:
- true if the script is modified
-
getContent
public java.lang.String getContent()
Returns the content.- Returns:
- the content or null in case of an error
-
setContent
public void setContent(java.lang.String value)
Sets the content.- Parameters:
value- the new content
-
empty
public void empty()
Empties the document.
-
open
public boolean open(java.io.File file)
Tries to open the file.- Parameters:
file- the file to open- Returns:
- true if successfully read
-
save
public boolean save()
Saves the file under with the current filename.- Returns:
- true if successfully written
-
saveAs
public boolean saveAs(java.io.File file)
Saves the file under with the given filename (and updates the internal filename).- Parameters:
file- the filename to write the content to- Returns:
- true if successfully written
-
newThread
public abstract Script.ScriptThread newThread(java.lang.String[] args)
Returns a new thread to execute.- Parameters:
args- optional commandline arguments- Returns:
- the new thread object
-
start
public void start(java.lang.String[] args) throws java.lang.ExceptionExecutes the script.- Parameters:
args- optional commandline arguments, can be null- Throws:
java.lang.Exception- if checks or execution fail
-
stop
public void stop()
Stops the execution of the script.
-
run
public void run(java.io.File file, java.lang.String[] args)Executes the script without loading it first.- Parameters:
file- the script to executeargs- the commandline parameters for the script
-
isRunning
public boolean isRunning()
Returns whether the script is still running.- Returns:
- true if the script is still running
-
addScriptFinishedListener
public void addScriptFinishedListener(ScriptExecutionListener l)
Adds the given listener to its internal list.- Parameters:
l- the listener to add
-
removeScriptFinishedListener
public void removeScriptFinishedListener(ScriptExecutionListener l)
Removes the given listener from its internal list.- Parameters:
l- the listener to remove
-
toString
public java.lang.String toString()
Returns the content as string.- Overrides:
toStringin classjava.lang.Object- Returns:
- the current content
-
runScript
public static void runScript(Script script, java.lang.String[] args) throws java.lang.Exception
Runs the specified script. All options that weren't "consumed" (like "-s" for the script filename), will be used as commandline arguments for the actual script.- Parameters:
script- the script object to useargs- the commandline arguments- Throws:
java.lang.Exception- if execution fails
-
-