Clover coverage report - clover
Coverage timestamp: Sat Oct 8 2005 22:54:17 EDT
file stats: LOC: 126   Methods: 7
NCLOC: 94   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ChoiceRecorder.java 75% 76.6% 85.7% 77%
coverage coverage
 1   
 package abbot.editor.recorder;
 2   
 
 3   
 import java.awt.*;
 4   
 import java.awt.event.*;
 5   
 
 6   
 import abbot.Log;
 7   
 import abbot.script.*;
 8   
 
 9   
 /**
 10   
  * Record basic semantic events you might find on an Choice component. <p>
 11   
  */
 12   
 public class ChoiceRecorder extends ComponentRecorder {
 13   
 
 14   
     private Choice choice = null;
 15   
     /** If selection is null when finished, no step will be generated. */
 16   
     private String selection = null;
 17   
     private ItemListener listener = null;
 18   
 
 19  7
     public ChoiceRecorder(Resolver resolver) {
 20  7
         super(resolver);
 21   
     }
 22   
 
 23  7
     protected void init(int recordingType) {
 24  7
         super.init(recordingType);
 25  7
         choice = null;
 26  7
         selection = null;
 27  7
         listener = null;
 28   
     }
 29   
 
 30   
     /** Also accept ItemEvents, since the ChoiceTester will not generate any
 31   
         explicit clicks to control the component. */
 32  7
     protected boolean isClick(AWTEvent e) {
 33  7
         if (e instanceof ItemEvent) {
 34  3
             return true;
 35   
         }
 36  4
         return super.isClick(e);
 37   
     }
 38   
 
 39   
     /** Track click -> select ->click, cancelable by ESC or by clicking away
 40   
         from the component.<p>
 41   
         NOTE: press->drag->release produces an identical set of events<br>
 42   
         OSX 1.3.1:<br>
 43   
         MOUSE_PRESSED<br>
 44   
         (ITEM_STATE_CHANGED)|MOUSE_RELEASED|KEY_RELEASED<br>
 45   
         The ItemEvent never makes it to the AWT listener.
 46   
     */
 47  15
     protected boolean parseClick(AWTEvent event) {
 48   
         // Have to check here since we handle the ItemEvent artificially
 49  15
         if (isFinished()) {
 50  0
             Log.debug("already finished");
 51  0
             return false;
 52   
         }
 53   
 
 54  15
         if (choice == null) {
 55   
             // Parse immediate selections (programmatic/tester driven)
 56  5
             if (event instanceof ItemEvent) {
 57  3
                 choice = (Choice)event.getSource();
 58  3
                 selection = ((ItemEvent)event).getItem().toString();
 59  3
                 Log.debug("selection=" + selection);
 60  3
                 setFinished(true);
 61   
             }
 62   
             else {
 63  2
                 choice = (Choice)event.getSource();
 64  2
                 listener = new ItemListener() {
 65  0
                     public void itemStateChanged(ItemEvent ev) {
 66  0
                         Log.debug("item event");
 67  0
                         if (ev.getStateChange() == ItemEvent.SELECTED) {
 68  0
                             selection = ev.getItem().toString();
 69  0
                             Log.debug("selection=" + selection);
 70  0
                             choice.removeItemListener(this);
 71  0
                             setFinished(true);
 72   
                         }
 73   
                     }
 74   
                 };
 75  2
                 choice.addItemListener(listener);
 76  2
                 setStatus("Waiting for selection");
 77   
             }
 78   
         }
 79  10
         else if (event.getID() == KeyEvent.KEY_RELEASED
 80   
                  && (((KeyEvent)event).getKeyCode() == KeyEvent.VK_SPACE
 81   
                      || ((KeyEvent)event).getKeyCode() == KeyEvent.VK_ENTER)) {
 82  0
             Log.debug("enter");
 83  0
             setFinished(true);
 84   
         }
 85  10
         else if (event.getID() == KeyEvent.KEY_RELEASED
 86   
                  && ((KeyEvent)event).getKeyCode() == KeyEvent.VK_ESCAPE) {
 87  1
             Log.debug("cancel");
 88  1
             selection = null;
 89  1
             setFinished(true);
 90   
         }
 91   
         else {
 92  9
             Log.debug("Event ignored");
 93   
         }
 94   
 
 95  15
         if (isFinished() && choice != null) {
 96  4
             choice.removeItemListener(listener);
 97  4
             listener = null;
 98   
         }
 99   
 
 100   
         // Events are always consumed by the Choice
 101  15
         return true;
 102   
     }
 103   
 
 104  6
     protected Step createStep() {
 105  6
         Step step = null;
 106  6
         if (getRecordingType() == SE_CLICK) {
 107  6
             if (selection != null) 
 108  3
                 step = createSelection(choice, selection);
 109   
         }
 110   
         else {
 111  0
             step = super.createStep();
 112   
         }
 113  6
         return step;
 114   
     }
 115   
 
 116  3
     protected Step createSelection(Choice target, String selection) {
 117  3
         ComponentReference cr = getResolver().addComponent(choice);
 118  3
         return new Action(getResolver(), 
 119   
                           null, "actionSelectItem",
 120   
                           new String[] {
 121   
                               cr.getID(), selection
 122   
                           }, java.awt.Choice.class);
 123   
     }
 124   
 }
 125   
 
 126