Clover coverage report - clover
Coverage timestamp: Sat Oct 8 2005 22:54:17 EDT
file stats: LOC: 147   Methods: 12
NCLOC: 78   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SemanticRecorder.java 70% 83.3% 100% 84.6%
coverage coverage
 1   
 package abbot.editor.recorder;
 2   
 
 3   
 import java.awt.AWTEvent;
 4   
 import java.awt.event.*;
 5   
 import java.util.ArrayList;
 6   
 
 7   
 import abbot.*;
 8   
 import abbot.finder.ComponentFinder;
 9   
 import abbot.script.*;
 10   
 import abbot.script.Resolver;
 11   
 
 12   
 /**
 13   
  * Template for recording AWTEvents and converting them into an appropriate
 14   
  * semantic event.  The EventRecorder class decides which SemanticRecorder to
 15   
  * use and handles cancel/termination.  Implementations should be named
 16   
  * AbstractButtonRecorder, JTableRecorder, etc.  The semantic recorders will
 17   
  * be dynamically loaded based on the component receiving a given event
 18   
  * (compare to ComponentTester).<p>
 19   
  * See EventRecorder for implementation details.
 20   
  */
 21   
 public abstract class SemanticRecorder implements SemanticEvents {
 22   
     private ActionListener al;
 23   
     private Resolver resolver;
 24   
     protected ArrayList events = new ArrayList();
 25   
     private Step step = null;
 26   
     private int recordingType = SE_NONE;
 27   
     private BugReport bug;
 28   
     private volatile boolean isFinished;
 29   
 
 30   
     /** Create a SemanticRecorder for use in capturing the semantics of a GUI
 31   
      * action.
 32   
      */ 
 33  854
     public SemanticRecorder(Resolver resolver) {
 34  854
         this.resolver = resolver;
 35   
     }
 36   
 
 37   
     /** Supports at most one listener. */
 38  305
     public void addActionListener(ActionListener al) {
 39  305
         this.al = al;
 40   
     }
 41   
 
 42  2782
     public int getRecordingType() {
 43  2782
         return recordingType;
 44   
     }
 45   
 
 46  757
     protected void setRecordingType(int type) {
 47  757
         recordingType = type;
 48   
     }
 49   
 
 50  729
     protected void init(int recordingType) {
 51  729
         events.clear();
 52  729
         step = null;
 53  729
         bug = null;
 54  729
         setFinished(false);
 55  729
         setRecordingType(recordingType);
 56   
     }
 57   
 
 58   
     /** Returns whether this SemanticRecorder wishes to accept the given event
 59   
      * and subsequent events.
 60   
      */
 61   
     public abstract boolean accept(AWTEvent event);
 62   
 
 63   
     /**
 64   
      * Handle an event.  Returns whether the event was consumed.
 65   
      */
 66  1347
     final public boolean record(java.awt.AWTEvent event) {
 67  1347
         if (!isFinished()) {
 68  1347
             try {
 69  1347
                 if (parse(event)) {
 70   
                     // Maintain a list of all events parsed for future
 71   
                     // reference 
 72  1338
                     events.add(event);
 73  1338
                     return true;
 74   
                 }
 75   
             }
 76   
             catch(BugReport br) {
 77  0
                 setFinished(true);
 78  0
                 bug = br;
 79   
             }
 80   
         }
 81  9
         return false;
 82   
     }
 83   
 
 84   
     /** Handle an event.  Return true if the event has been consumed.
 85   
      * Returning false usually means that isFinished() will return true.
 86   
      */
 87   
     public abstract boolean parse(AWTEvent event);
 88   
 
 89   
     /** Return the Resolver to be used by this recorder. */
 90  409
     protected Resolver getResolver() { return resolver; }
 91   
 
 92   
     /** Returns the script step generated from the events recorded so far.  If
 93   
      * no real action resulted, may return null (for example, a mouse press on
 94   
      * a button which releases outside the button).
 95   
      */
 96  180
     public synchronized Step getStep() throws BugReport { 
 97  180
         if (bug != null)
 98  0
             throw bug;
 99   
 
 100  180
         if (step == null) {
 101  77
             step = createStep();
 102   
         }
 103  180
         return step;
 104   
     }
 105   
 
 106   
     /** Create a step based on the events received thus far.  Returns null if
 107   
      * no semantic event or an imcomplete event has been detected. */
 108   
     protected abstract Step createStep();
 109   
 
 110   
     /**
 111   
      * Add the given step.  Should be used when the recorder detects a
 112   
      * complete semantic event sequence.  After this point, the recorder will
 113   
      * no longer accept events.
 114   
      */
 115  111
     protected synchronized void setStep(Step newStep) {
 116  111
         events.clear();
 117  111
         step = newStep;
 118   
     }
 119   
 
 120   
     /** Return whether this recorder has finished recording the current
 121   
      * semantic event.
 122   
      */
 123  6650
     public synchronized boolean isFinished() { return isFinished; }
 124   
 
 125   
     /** Invoke when end of the semantic event has been seen. */
 126  871
     protected synchronized void setFinished(boolean state) {
 127  871
         isFinished = state;
 128   
     }
 129   
 
 130   
     /** Indicate the current recording state, so that the status may be
 131   
      * displayed elsewhere.
 132   
      */
 133  20
     protected void setStatus(String msg) {
 134  20
         if (al != null) {
 135  0
             ActionEvent event = 
 136   
                 new ActionEvent(this, ActionEvent.ACTION_PERFORMED, msg);
 137  0
             al.actionPerformed(event);
 138   
         }
 139   
     }
 140   
 
 141   
     /*
 142   
     public String toString() {
 143   
         return getClass().toString();
 144   
     }
 145   
     */
 146   
 }
 147