org.fife.rtext.plugins.tools
Class Tool

java.lang.Object
  extended by org.fife.rtext.plugins.tools.Tool
All Implemented Interfaces:
java.lang.Comparable<Tool>

public class Tool
extends java.lang.Object
implements java.lang.Comparable<Tool>

An "external tool."

Version:
1.0
Author:
Robert Futrell

Constructor Summary
Tool()
          Constructor.
Tool(java.lang.String name, java.lang.String desc)
          Constructor.
 
Method Summary
 void addArg(java.lang.String arg)
          Adds a command line argument for this tool.
 java.lang.String checkForErrors()
          Does basic checking to ensure that this program can run (the program exists, the directory to run in exists, etc.).
 void clearArgs()
          Clears the command line arguments.
 void clearEnvVars()
          Clears the environment variables associated with this tool.
 int compareTo(Tool t2)
          Compares this tool to another by name, lexicographically.
 boolean equals(java.lang.Object o)
          Returns whether this tool and another have the same name.
 void execute(ProcessRunnerOutputListener l)
          Runs this tool in a separate thread.
 java.lang.String getAccelerator()
          Returns the accelerator to use to activate this tool in a menu.
 boolean getAppendEnvironmentVars()
          Returns whether this tool should append any environment variables it defines to RText's current environment.
 java.lang.String[] getArgs()
          Returns the command line arguments for this Tool, as an array.
 java.lang.String getDescription()
          Returns a description of this tool.
 java.lang.String getDirectory()
          Returns the directory the tool will run in.
 java.util.Map<java.lang.String,java.lang.String> getEnvVars()
          Returns a copy of the environment variable map for this tool.
 java.lang.String getName()
          Returns the name of this tool.
 java.lang.String getProgram()
          Returns the program to launch.
 int hashCode()
          Returns the hash code of this tool.
 boolean kill()
          Forcibly terminates this tool's external process, if it is running.
static void main(java.lang.String[] args)
           
 void putEnvVar(java.lang.String name, java.lang.String value)
          Sets an environment variable for this tool.
 void setAccelerator(java.lang.String accelerator)
          Sets the accelerator to use to activate this tool in a menu.
 void setAppendEnvironmentVars(boolean append)
          Sets whether this tool should append any environment variables it defines to RText's current environment.
 void setArgs(java.lang.String[] args)
          Sets the command line arguments to this tool.
 void setDescription(java.lang.String desc)
          Sets a description of this tool.
 void setDirectory(java.lang.String dir)
          Sets the directory for this tool to run in.
 void setEnvVars(java.util.Map<java.lang.String,java.lang.String> vars)
          Sets the environment variables for this tool.
 void setName(java.lang.String name)
          Sets the name of this tool.
 void setProgram(java.lang.String program)
          Sets the program to launch.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tool

public Tool()
Constructor. This is really only here to make this class a JavaBean to facilitate easy serializing; the Tool(String, String) constructor is preferred over this one.


Tool

public Tool(java.lang.String name,
            java.lang.String desc)
Constructor.

Parameters:
name - The name of this tool.
desc - A description of this tool. This may be null.
Method Detail

addArg

public void addArg(java.lang.String arg)
Adds a command line argument for this tool.

Parameters:
arg - The argument. This cannot be null.
See Also:
clearArgs(), setProgram(String)

checkForErrors

public java.lang.String checkForErrors()
Does basic checking to ensure that this program can run (the program exists, the directory to run in exists, etc.). Applications can call this method before running this tool as a sanity check, and to give nice error messages for common failure cases.

Returns:
A localized error message, or null if the program should be able to run.
See Also:
execute(ProcessRunnerOutputListener)

clearArgs

public void clearArgs()
Clears the command line arguments.

See Also:
addArg(String)

clearEnvVars

public void clearEnvVars()
Clears the environment variables associated with this tool. Note that if this tool is appending its environment to RText's environment, this does not clear the RText environment that is appended to; it only clears the environment variables to add.

See Also:
putEnvVar(String, String)

compareTo

public int compareTo(Tool t2)
Compares this tool to another by name, lexicographically.

Specified by:
compareTo in interface java.lang.Comparable<Tool>
Parameters:
t2 - The other tool.
Returns:
The sort order of this tool, compared to another.

equals

public boolean equals(java.lang.Object o)
Returns whether this tool and another have the same name.

Overrides:
equals in class java.lang.Object
Returns:
Whether this tool and another have the same name.

execute

public void execute(ProcessRunnerOutputListener l)
Runs this tool in a separate thread.

Parameters:
l - Listens for events as this tool runs. This may be null.
See Also:
checkForErrors()

getAccelerator

public java.lang.String getAccelerator()
Returns the accelerator to use to activate this tool in a menu.

Returns:
The accelerator, or null if there is none.
See Also:
setAccelerator(String)

getAppendEnvironmentVars

public boolean getAppendEnvironmentVars()
Returns whether this tool should append any environment variables it defines to RText's current environment.

Returns:
Whether to append the environment variables defined. If this value is false, RText's environment is not appended.
See Also:
setAppendEnvironmentVars(boolean)

getArgs

public java.lang.String[] getArgs()
Returns the command line arguments for this Tool, as an array.

Returns:
An array of command line arguments, or an empty array if there are none.
See Also:
setArgs(String[])

getDescription

public java.lang.String getDescription()
Returns a description of this tool.

Returns:
A description of this tool, or null if none is defined.
See Also:
setDescription(String)

getEnvVars

public java.util.Map<java.lang.String,java.lang.String> getEnvVars()
Returns a copy of the environment variable map for this tool.

Returns:
The environment variables.
See Also:
setEnvVars(Map)

getName

public java.lang.String getName()
Returns the name of this tool.

Returns:
The name of this tool.
See Also:
setName(String)

getProgram

public java.lang.String getProgram()
Returns the program to launch.

Returns:
The program to launch.
See Also:
setProgram(String)

getDirectory

public java.lang.String getDirectory()
Returns the directory the tool will run in.

Returns:
The directory.
See Also:
setDirectory(String)

hashCode

public int hashCode()
Returns the hash code of this tool.

Overrides:
hashCode in class java.lang.Object
Returns:
This tool's hash code.

kill

public boolean kill()
Forcibly terminates this tool's external process, if it is running.

Returns:
If the process was running and killed.

putEnvVar

public void putEnvVar(java.lang.String name,
                      java.lang.String value)
Sets an environment variable for this tool.

Parameters:
name - The name of the environment variable.
value - The value of the variable. If this is null, then this variable will not be set with a special value.
See Also:
clearEnvVars()

setAccelerator

public void setAccelerator(java.lang.String accelerator)
Sets the accelerator to use to activate this tool in a menu.

Parameters:
accelerator - The accelerator to use, or null for none.
See Also:
getAccelerator()

setAppendEnvironmentVars

public void setAppendEnvironmentVars(boolean append)
Sets whether this tool should append any environment variables it defines to RText's current environment.

Parameters:
append - Whether to append the environment variables defined. If this value is false, RText's environment is not appended.
See Also:
getAppendEnvironmentVars()

setArgs

public void setArgs(java.lang.String[] args)
Sets the command line arguments to this tool. Old command line arguments are discarded.

Parameters:
args - The new command line arguments.
See Also:
getArgs()

setDescription

public void setDescription(java.lang.String desc)
Sets a description of this tool.

Parameters:
desc - A description of this tool. This may be null.
See Also:
getDescription()

setDirectory

public void setDirectory(java.lang.String dir)
Sets the directory for this tool to run in.

Parameters:
dir - The directory. This cannot be null.
See Also:
getDirectory()

setEnvVars

public void setEnvVars(java.util.Map<java.lang.String,java.lang.String> vars)
Sets the environment variables for this tool.

Parameters:
vars - The new environment variables for this tool.
See Also:
getEnvVars()

setName

public void setName(java.lang.String name)
Sets the name of this tool.

Parameters:
name - The name of this tool.
See Also:
getName()

setProgram

public void setProgram(java.lang.String program)
Sets the program to launch.

Parameters:
program - The program. This cannot be null.
See Also:
getProgram(), addArg(String)

main

public static void main(java.lang.String[] args)