Package weka.gui.scripting
Class Script
java.lang.Object
weka.gui.scripting.Script
- All Implemented Interfaces:
Serializable
,OptionHandler
- Direct Known Subclasses:
GroovyScript
,JythonScript
A simple helper class for loading, saving scripts.
- Version:
- $Revision: 10222 $
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The Thread for running a script. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given listener to its internal list.void
empty()
Empties the document.Returns the content.abstract String
Returns the default extension.Returns the current filename.abstract ExtensionFileFilter[]
Returns the extension filters for this type of script.Returns the new line string in use.String[]
Gets the current settings of the script.boolean
Returns whether the script is modified.boolean
Returns whether the script is still running.Returns an enumeration describing the available options.abstract Script.ScriptThread
Returns a new thread to execute.boolean
Tries to open the file.void
Removes the given listener from its internal list.void
Executes the script without loading it first.static void
Runs the specified script.boolean
save()
Saves the file under with the current filename.boolean
Saves the file under with the given filename (and updates the internal filename).void
setContent
(String value) Sets the content.void
setOptions
(String[] options) Parses a given list of options.void
Executes the script.void
stop()
Stops the execution of the script.toString()
Returns the content as string.
-
Field Details
-
BACKUP_EXTENSION
the backup extension.- See Also:
-
-
Constructor Details
-
Script
public Script()Initializes the script. -
Script
Initializes the script.- Parameters:
doc
- the document to use as basis
-
Script
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 Details
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Returns:
- an enumeration of all the available options
-
setOptions
Parses a given list of options.- Specified by:
setOptions
in interfaceOptionHandler
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getOptions
Gets the current settings of the script.- Specified by:
getOptions
in interfaceOptionHandler
- Returns:
- an array of strings suitable for passing to setOptions
-
getFilters
Returns the extension filters for this type of script.- Returns:
- the filters
-
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:
-
getFilename
Returns the current filename.- Returns:
- the filename, null if no file loaded/saved
-
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
Returns the content.- Returns:
- the content or null in case of an error
-
setContent
Sets the content.- Parameters:
value
- the new content
-
empty
public void empty()Empties the document. -
open
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
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
Returns a new thread to execute.- Parameters:
args
- optional commandline arguments- Returns:
- the new thread object
-
start
Executes the script.- Parameters:
args
- optional commandline arguments, can be null- Throws:
Exception
- if checks or execution fail
-
stop
public void stop()Stops the execution of the script. -
run
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
Adds the given listener to its internal list.- Parameters:
l
- the listener to add
-
removeScriptFinishedListener
Removes the given listener from its internal list.- Parameters:
l
- the listener to remove
-
toString
Returns the content as string. -
runScript
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:
Exception
- if execution fails
-