edu.jhu.pha.ivoa
Class TaskManager

java.lang.Object
  |
  +--edu.jhu.pha.ivoa.TaskManager
All Implemented Interfaces:
java.util.EventListener, java.beans.PropertyChangeListener

public class TaskManager
extends java.lang.Object
implements java.beans.PropertyChangeListener

   Current Version
   ===============
   ID:            $Id: TaskManager.html,v 1.3 2003/08/18 18:05:02 carliles Exp $
   Revision:      $Revision: 1.3 $
   Date/time:     $Date: 2003/08/18 18:05:02 $
   
This class encapsulates a JFrame which displays Task name, status, and message information, as well as giving users a button with which to cancel selected Tasks. As currently implemented, if the TaskManager's JFrame is not visible when a Task is added, it will be made visible. Here is a simple, yet complete application showing how to use these classes.
     import java.io.*;

     import edu.jhu.pha.ivoa.*;


     // prints lines from specified files to the screen, with each
     // file being printed in a different Thread, so the output
     // won't necessarily come out in any order that makes sense.
     public class TaskManagerTest
     {
       public static void main(String[] args) throws Exception
       {
         TaskManager tm = new TaskManager();

         for(int i = 0; i < args.length; ++i)
         {
           tm.addTask(new FileTask(args[i]));
         }
       }

       public static class FileTask extends Task
       {
         public FileTask(String filename)
         {
           super("Printing " + filename);
           _filename = filename;
         }

         public void execute()
         {
           try
           {
             int linesRead = 0;
             BufferedReader in =
               new BufferedReader(new FileReader(_filename));

             for(String line = in.readLine(); line != null; line = in.readLine())
             {
               if(line != null)
               {
                 System.out.println(line);
                 setMessage((++linesRead) + " lines read.");
               }
             }
             System.out.flush();
           }
           catch(IOException e)
           {
             e.printStackTrace();
           }
         }

         protected String _filename;
       };
     }
   


Constructor Summary
TaskManager()
          Initializes this TaskManager.
 
Method Summary
 void addTask(edu.jhu.pha.ivoa.Task task)
          Adds a Task to this TaskManager and starts it.
 void cancelSelectedTasks(int[] rowNumbers)
          Cancels the Tasks in the specified rows of the JTable in this TaskManager's JFrame.
 boolean isVisible()
           
static void main(java.lang.String[] args)
          For testing purposes.
 void propertyChange(java.beans.PropertyChangeEvent e)
           
static java.lang.String revision()
           
 void setVisible(boolean visible)
          Sets the visibility of the JFrame representing this TaskManager to the value of visible.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskManager

public TaskManager()
Initializes this TaskManager. Initially the JFrame representing this TaskManager is not visible.

Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
For testing purposes.

Throws:
java.lang.Exception

setVisible

public void setVisible(boolean visible)
Sets the visibility of the JFrame representing this TaskManager to the value of visible.

Parameters:
visible - boolean value representing whether to show the JFrame for this TaskManager.

isVisible

public boolean isVisible()

addTask

public void addTask(edu.jhu.pha.ivoa.Task task)
Adds a Task to this TaskManager and starts it. If this TaskManager's JFrame is not visible, it will be made visible.

Parameters:
task - The Task to be added.

cancelSelectedTasks

public void cancelSelectedTasks(int[] rowNumbers)
Cancels the Tasks in the specified rows of the JTable in this TaskManager's JFrame.

Parameters:
rowNumbers - The indices of the JTable rows containing Tasks to be cancelled.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

revision

public static java.lang.String revision()
Returns:
CVS Revision number.