JET

edu.utep.cs.et.gui
Class ToolActionFactory

java.lang.Object
  extended by edu.utep.cs.et.gui.FileActionFactory
      extended by edu.utep.cs.et.gui.ToolActionFactory
All Implemented Interfaces:
Constants

public class ToolActionFactory
extends FileActionFactory

A factory class to create various tool actions such as compile and run. These actions may be used for creating menu items or tool bar items (see MenuFactory).


Nested Class Summary
private static class ToolActionFactory.ClassFileReader
          A utility class to parse bytecode files.
private static interface ToolActionFactory.Commandable
          An interface to the commands that can be run in separate threads.
private  class ToolActionFactory.CommandThread
          A thread class to execute a shell command in a particular directory.
private  class ToolActionFactory.MessageThread
          A thread class to wire an input stream to the message pane of the main GUI.
 
Field Summary
private static AbstractAction actCheckJml
          The action for the Check JML menu item.
private static AbstractAction actCompile
          The action for the Ccmpile Java menu item.
private static AbstractAction actCompileJml
          The action for the Compile JML menu item.
private static AbstractAction actRun
          The action for the Run menu item.
private  File compilationDirectory
          The directory in which the last compilation was performed.
private  Outputer outputer
          The display area where all console outputs should go.
 
Fields inherited from class edu.utep.cs.et.gui.FileActionFactory
currentFile, et, frame
 
Fields inherited from interface edu.utep.cs.et.gui.Constants
CLASS_EXTENSION, COLOR_EXPLORER, COLOR_OUTPUT, COPYRIGHT, DEBUG, DIVIDER_SIZE, EDIT_MENU_NAME, EXPLORER_DIR, EXPLORER_ROOT, FILE_MENU_NAME, HELP_MENU_NAME, ICON_ABOUT, ICON_ABSTRACT_CLASS, ICON_BROWSER, ICON_CLASS, ICON_CLASS_DISABLED, ICON_DELETE, ICON_ERROR, ICON_FILE, ICON_FOLDER, ICON_GEN_APP, ICON_HOME, ICON_INFORM, ICON_INTERFACE, ICON_JAVA_FILE, ICON_JML_LOGO, ICON_METHOD, ICON_METHOD_GREEN, ICON_METHOD_ORANGE, ICON_METHOD_RED, ICON_MINER, ICON_NEW, ICON_NEWTESTSUITE, ICON_NOTE, ICON_OPEN, ICON_OUTPUT, ICON_PREFERENCES, ICON_QUESTION, ICON_REDO, ICON_SAVE_AS, ICON_TEST_FILE, ICON_UNDO, ICON_UNKOWN, ICON_WARN, JAVA, JAVA_EXTENSION, JAVAC, JUNIT_SWINGGUI_TESTRUNNER, NEWLINE, OPTION_MENU_NAME, TEST_MENU_NAME, TITLE, TOOL_MENU_NAME, VERSION, WEB_PAGE_LOCATION, WEB_PAGE_NAME, WINDOW_HEIGHT, WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH, WINDOW_WIDTH
 
Constructor Summary
ToolActionFactory(Mainable et)
          Creates a new instance for the given main program.
 
Method Summary
private  void checkJml()
          Checks the current file with the JML checker.
private  String classPath()
          Returns the class path option for Java and JML compilers
 boolean compilable(String msg)
          Is the current file compilable with JML?
private  boolean compileJml()
          Compiles the current file with the UTJML compiler.
private  void doCompile()
          Compiles the file associated with the editing buffer.
private  Thread doCompile(String cmd)
          Compiles the file associated with the editing buffer.
private  void doRun()
          Runs the file associated with the editing buffer.
static String getBaseName(File file)
          Returns the base name of the give file.
 AbstractAction getCheckJml()
          Returns an action for the Check JML menu item.
 AbstractAction getCompile()
          Returns an action for the Compile Java menu item.
 AbstractAction getCompileJml()
          Returns an action for the Compile JML menu item.
 FileChangeListener getFileChangeListener()
          Returns a file change listener that listens to the opening and closing of the file being edited by the editor.
 AbstractAction getRun()
          Returns an action for the Run menu item.
 File locateFile(String filename)
          Given a relative path name, finds the file.
private  boolean runCommand(ToolActionFactory.Commandable cmd, String[] args, String beforeMsg, String afterMsg, boolean refresh)
          Runs the given command cmd by supplying the given arguments args.
protected  void setCurrentFile(File file)
          Sets the given file to be the current file being edited.
 
Methods inherited from class edu.utep.cs.et.gui.FileActionFactory
getClose, getDropTarget, getExit, getIcon, getNew, getOpen, getPopDelete, getPopNew, getPopOpen, getPopRefresh, getPopRootDir, getPopTest, getPrint, getPrinterSetup, getSave, getSaveAs, saveIfModified, updatePopupActions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outputer

private Outputer outputer
The display area where all console outputs should go.


actCompile

private static AbstractAction actCompile
The action for the Ccmpile Java menu item.


actCheckJml

private static AbstractAction actCheckJml
The action for the Check JML menu item.


actCompileJml

private static AbstractAction actCompileJml
The action for the Compile JML menu item.


actRun

private static AbstractAction actRun
The action for the Run menu item.


compilationDirectory

private File compilationDirectory
The directory in which the last compilation was performed. It is used to locate the source code files mentioned in the error messages.

Constructor Detail

ToolActionFactory

public ToolActionFactory(Mainable et)
Creates a new instance for the given main program.

Method Detail

getFileChangeListener

public FileChangeListener getFileChangeListener()
Returns a file change listener that listens to the opening and closing of the file being edited by the editor. The file name is displayed on the status bar.


locateFile

public File locateFile(String filename)
Given a relative path name, finds the file. If the file can't be found, null is returned. The file name is parsed from an error message and supposed to be relative to the directory in which the last compilation was done.


getCompile

public AbstractAction getCompile()
Returns an action for the Compile Java menu item.


getCheckJml

public AbstractAction getCheckJml()
Returns an action for the Check JML menu item.


compilable

public boolean compilable(String msg)
Is the current file compilable with JML?


getCompileJml

public AbstractAction getCompileJml()
Returns an action for the Compile JML menu item.


getRun

public AbstractAction getRun()
Returns an action for the Run menu item.


getBaseName

public static String getBaseName(File file)
Returns the base name of the give file.


doCompile

private Thread doCompile(String cmd)
Compiles the file associated with the editing buffer. If there are unsaved edits, they must be saved prior to calling this method. The compilation messages, if any, are wired to the message pane. The file is compiled on a separate JVM by a separate thread; this separate thread is returned as the result.

Parameters:
cmd - String specifying the compiler and options, if any; e.g., javac -d foo.

checkJml

private void checkJml()
Checks the current file with the JML checker.


compileJml

private boolean compileJml()
Compiles the current file with the UTJML compiler.


runCommand

private boolean runCommand(ToolActionFactory.Commandable cmd,
                           String[] args,
                           String beforeMsg,
                           String afterMsg,
                           boolean refresh)
Runs the given command cmd by supplying the given arguments args.

Parameters:
beforeMsg - Message to be printed before executing the command.
afterMsg - Message to be printed after executing the command.
refresh - True if the directory browser needs to be refreshed upon the completion of the command.

setCurrentFile

protected void setCurrentFile(File file)
Sets the given file to be the current file being edited. This method is overridden here to enable or disable various actions.

Overrides:
setCurrentFile in class FileActionFactory

classPath

private String classPath()
Returns the class path option for Java and JML compilers


doCompile

private void doCompile()
Compiles the file associated with the editing buffer. If there are unsaved changes, such changes must be saved prior to calling this method. The compilation messages, if any, are wired to the message pane.


doRun

private void doRun()
Runs the file associated with the editing buffer. If there are unsaved changes, such changes must be saved prior to calling this method. The execution output and error messages, if any, are wired to the message pane.


JET

JET is Copyright (C) 2005-2007 by The University of Texas at El Paso and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.