public class CommandThread
extends java.lang.Object
implements java.awt.event.ActionListener, java.lang.Runnable
Class used for making abstract actions which launch threads.
This class currently uses the OS's native shell for command execution. To use Turtle SHELL instead, you must uncomment 3 lines in this file. Each of these lines is marked in the source code with:
UNCOMMENT BELOW FOR TURTLESHELL
- AND -
UNCOMMENT ABOVE FOR TURTLESHELL
Constructor and Description |
---|
CommandThread(java.lang.String command)
Creates a new instance of CommandThread.
|
CommandThread(java.lang.String command,
java.util.Map<java.lang.String,Widget> widgets)
Creates a new instance of CommandThread.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Runs the command.
|
static java.lang.String |
quote(java.lang.String str)
Quotes a string, so it will not be modified by replaceArguments
|
protected java.lang.String |
replaceArguments(java.lang.String run,
java.util.Map<java.lang.String,WidgetInstance> widgetInstances)
Replaces the variables in the command string with
their corresponding values.
|
void |
run()
Used for running the command.
|
static void |
shellCommand(java.lang.String cmd,
java.lang.String data)
Runs simple shell commands.
|
static java.lang.String |
unquote(java.lang.String str)
Removes quotations added to a string by the 'quote' method
|
public CommandThread(java.lang.String command)
Creates a new instance of CommandThread.
This version of the constructor should be used if there are no command variables that need to be handled within the command string.
See 'widgets' variable for more information about command line variables.
command
- the command for the thread to runpublic CommandThread(java.lang.String command, java.util.Map<java.lang.String,Widget> widgets)
Creates a new instance of CommandThread.
Please note that this version of the command thread constructor takes a map called 'widgets'.
Here is a brief overview of how 'widgets' works: A hashmap containing mapings for all of the widgets. The mapings within the hash map are as follows:
The key is what we will search for when we do a string replace of the command string This is what we perform when we modify the command string, replacing the values of keys with the values of their associated widgets. For example, in the case of:
numseq $START $END in1 ......
'in1', '$START' and '$END' would be valid keys within the hashmap. These keys will then be mapped to the widgets from which values would be obtained. For instance, if the widget for '$START' is set to 10, and the widget for '$END' is set to 20, then the command would be as follows:
numseq 10 20 bio1431242.tmp .....
Note that 'in1' also gets replaced; however, it is not visible. This is because, in this example, 'in1' is a "file widget". These are objects which create files based on the data within the canvas, and the data selected by the user. This data gets passed to the program through a file (in this case 'bio1431242.tmp').
It is important to note that some file widgets can also capture data obtained from running a program, and pass that program into BioLegato. To find out more about how such file widgets work, please look at "TempFile.java" and any additional menu documentation.
command
- the command for the thread to runwidgets
- a map used for mapping command line variables (see above).public void actionPerformed(java.awt.event.ActionEvent e)
Runs the command.
A fairly straightforward method; this method runs the 'run' method as a separate thread. Please see the 'run' method for more information.
actionPerformed
in interface java.awt.event.ActionListener
e
- ignored by this functionpublic void run()
Used for running the command.
This function gathers all of the parameter settings from the widgets, then generates and executes the corresponding command string.
Turtle SHELL can be enabled/disabled here through commenting. See the README file for more information.
run
in interface java.lang.Runnable
protected java.lang.String replaceArguments(java.lang.String run, java.util.Map<java.lang.String,WidgetInstance> widgetInstances)
run
- the command to do the replacements on.widgetInstances
- the widget instance variables
to use for string replacement.public static java.lang.String quote(java.lang.String str)
str
- the string to add quotation topublic static java.lang.String unquote(java.lang.String str)
str
- the string to remove quotation frompublic static void shellCommand(java.lang.String cmd, java.lang.String data)
cmd
- the command string to rundata
- the data to use as standard input (System.in)Copyright © 2008-2022 University of Manitoba.