Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 779   Methods: 35
NCLOC: 339   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JTreeMouseEventData.java 69.2% 90.6% 94.3% 86.6%
coverage coverage
 1   
 package junit.extensions.jfcunit.eventdata;
 2   
 
 3   
 import junit.extensions.jfcunit.JFCTestCase;
 4   
 import junit.extensions.jfcunit.xml.JFCXMLConstants;
 5   
 
 6   
 import org.w3c.dom.Element;
 7   
 
 8   
 import java.awt.AWTEvent;
 9   
 import java.awt.Component;
 10   
 import java.awt.Point;
 11   
 import java.awt.Rectangle;
 12   
 import java.awt.event.MouseEvent;
 13   
 
 14   
 import java.util.ArrayList;
 15   
 import java.util.Iterator;
 16   
 import java.util.List;
 17   
 
 18   
 import javax.swing.JTree;
 19   
 import javax.swing.tree.TreeModel;
 20   
 import javax.swing.tree.TreeNode;
 21   
 import javax.swing.tree.TreePath;
 22   
 
 23   
 
 24   
 /**
 25   
  * Data container class that holds all the data necessary for jfcUnit to fire mouse events.
 26   
  * This class is specific to events on a JTree.
 27   
  *
 28   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 29   
  */
 30   
 public class JTreeMouseEventData extends AbstractMouseEventData {
 31   
     /**
 32   
      * The JTree on which to trigger the event.
 33   
      */
 34   
     private JTree m_tree;
 35   
 
 36   
     /**
 37   
      * The String value of the specific node on which to trigger the event.
 38   
      */
 39   
     private String m_nodeValue;
 40   
 
 41   
     /**
 42   
      * The path of the specific node on which to trigger the event.
 43   
      */
 44   
     private TreePath m_treePath;
 45   
 
 46   
     /**
 47   
      * Constructor.
 48   
      */
 49  4
     public JTreeMouseEventData() {
 50  4
         super();
 51  4
         setValid(false);
 52   
     }
 53   
 
 54   
     /**
 55   
      * Constructor.
 56   
      *
 57   
      * @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 58   
      * @param tree     The component on which to trigger the event.
 59   
          * @param treePath The path of the specific node on which to trigger the event.
 60   
      * @param numberOfClicks
 61   
      *                  Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 62   
      */
 63  2
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 64   
         final TreePath treePath, final int numberOfClicks) {
 65  2
         this(testCase, tree, treePath, numberOfClicks, DEFAULT_SLEEPTIME);
 66   
     }
 67   
 
 68   
     /**
 69   
      * Constructor.
 70   
      *
 71   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 72   
      * @param tree      The component on which to trigger the event.
 73   
      * @param nodeValue The String value of the specific node on which to trigger the event.
 74   
      * @param numberOfClicks
 75   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 76   
      */
 77  10
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 78   
         final String nodeValue, final int numberOfClicks) {
 79  10
         this(testCase, tree, nodeValue, numberOfClicks, DEFAULT_SLEEPTIME);
 80   
     }
 81   
 
 82   
     /**
 83   
      * Constructor.
 84   
      *
 85   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 86   
      * @param tree      The component on which to trigger the event.
 87   
          * @param treePath  The path of the specific node on which to trigger the event.
 88   
      * @param numberOfClicks
 89   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 90   
      * @param sleepTime
 91   
      *                   The wait time in ms between each event.
 92   
      */
 93  4
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 94   
         final TreePath treePath, final int numberOfClicks, final long sleepTime) {
 95  4
         this(testCase, tree, treePath, numberOfClicks, DEFAULT_ISPOPUPTRIGGER,
 96   
             sleepTime);
 97   
     }
 98   
 
 99   
     /**
 100   
      * Constructor.
 101   
      *
 102   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 103   
      * @param tree      The component on which to trigger the event.
 104   
      * @param nodeValue The String value of the specific node on which to trigger the event.
 105   
      * @param numberOfClicks
 106   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 107   
      * @param sleepTime
 108   
      *                   The wait time in ms between each event.
 109   
      */
 110  12
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 111   
         final String nodeValue, final int numberOfClicks, final long sleepTime) {
 112  12
         this(testCase, tree, nodeValue, numberOfClicks, DEFAULT_ISPOPUPTRIGGER,
 113   
             sleepTime);
 114   
     }
 115   
 
 116   
     /**
 117   
      * Constructor.
 118   
      *
 119   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 120   
      * @param tree      The component on which to trigger the event.
 121   
          * @param treePath  The path of the specific node on which to trigger the event.
 122   
      * @param numberOfClicks
 123   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 124   
      * @param isPopupTrigger
 125   
      *                   boolean specifying whether this event will show a popup.
 126   
      */
 127  2
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 128   
         final TreePath treePath, final int numberOfClicks,
 129   
         final boolean isPopupTrigger) {
 130  2
         this(testCase, tree, treePath, numberOfClicks, isPopupTrigger,
 131   
             DEFAULT_SLEEPTIME);
 132   
     }
 133   
 
 134   
     /**
 135   
      * Constructor.
 136   
      *
 137   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 138   
      * @param tree      The component on which to trigger the event.
 139   
      * @param nodeValue The String value of the specific node on which to trigger the event.
 140   
      * @param numberOfClicks
 141   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 142   
      * @param isPopupTrigger
 143   
      *                   boolean specifying whether this event will show a popup.
 144   
      */
 145  2
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 146   
         final String nodeValue, final int numberOfClicks,
 147   
         final boolean isPopupTrigger) {
 148  2
         this(testCase, tree, nodeValue, numberOfClicks, isPopupTrigger,
 149   
             DEFAULT_SLEEPTIME);
 150   
     }
 151   
 
 152   
     /**
 153   
      * Constructor.
 154   
      *
 155   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 156   
      * @param tree      The component on which to trigger the event.
 157   
      * @param treePath  The path of the specific node on which to trigger the event.
 158   
      * @param numberOfClicks
 159   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 160   
      * @param isPopupTrigger
 161   
      *                   boolean specifying whether this event will show a popup.
 162   
      * @param sleepTime
 163   
      *                   The wait time in ms between each event.
 164   
      */
 165  8
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 166   
         final TreePath treePath, final int numberOfClicks,
 167   
         final boolean isPopupTrigger, final long sleepTime) {
 168  8
         this(testCase, tree, treePath, numberOfClicks,
 169   
             getDefaultModifiers(isPopupTrigger), isPopupTrigger, sleepTime);
 170   
     }
 171   
 
 172   
     /**
 173   
      * Constructor.
 174   
      *
 175   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 176   
      * @param tree      The component on which to trigger the event.
 177   
      * @param nodeValue The String value of the specific node on which to trigger the event.
 178   
      * @param numberOfClicks
 179   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 180   
      * @param isPopupTrigger
 181   
      *                   boolean specifying whether this event will show a popup.
 182   
      * @param sleepTime
 183   
      *                   The wait time in ms between each event.
 184   
      */
 185  16
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 186   
         final String nodeValue, final int numberOfClicks,
 187   
         final boolean isPopupTrigger, final long sleepTime) {
 188  16
         this(testCase, tree, nodeValue, numberOfClicks,
 189   
             getDefaultModifiers(isPopupTrigger), isPopupTrigger, sleepTime);
 190   
     }
 191   
 
 192   
     /**
 193   
      * Constructor.
 194   
      *
 195   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 196   
      * @param tree      The component on which to trigger the event.
 197   
      * @param treePath  The path of the specific node on which to trigger the event.
 198   
      * @param numberOfClicks
 199   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 200   
      * @param modifiers The modifier key values that need to be passed onto the event.
 201   
      * @param isPopupTrigger
 202   
      *                   boolean specifying whether this event will show a popup.
 203   
      * @param sleepTime
 204   
      *                   The wait time in ms between each event.
 205   
      */
 206  10
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 207   
         final TreePath treePath, final int numberOfClicks, final int modifiers,
 208   
         final boolean isPopupTrigger, final long sleepTime) {
 209  10
         this(testCase, tree, treePath, numberOfClicks, modifiers,
 210   
             isPopupTrigger, sleepTime, DEFAULT_POSITION, null);
 211   
     }
 212   
 
 213   
     /**
 214   
      * Constructor.
 215   
      *
 216   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 217   
      * @param tree      The component on which to trigger the event.
 218   
      * @param nodeValue The String value of the specific node on which to trigger the event.
 219   
      * @param numberOfClicks
 220   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 221   
      * @param modifiers The modifier key values that need to be passed onto the event.
 222   
      * @param isPopupTrigger
 223   
      *                   boolean specifying whether this event will show a popup.
 224   
      * @param sleepTime
 225   
      *                   The wait time in ms between each event.
 226   
      */
 227  18
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 228   
         final String nodeValue, final int numberOfClicks, final int modifiers,
 229   
         final boolean isPopupTrigger, final long sleepTime) {
 230  18
         this(testCase, tree, nodeValue, numberOfClicks, modifiers,
 231   
             isPopupTrigger, sleepTime, DEFAULT_POSITION, null);
 232   
     }
 233   
 
 234   
     /**
 235   
      * Constructor.
 236   
      *
 237   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 238   
      * @param tree      The component on which to trigger the event.
 239   
          * @param treePath  The path of the specific node on which to trigger the event.
 240   
      * @param numberOfClicks
 241   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 242   
      * @param modifiers The modifier key values that need to be passed onto the event.
 243   
      * @param isPopupTrigger
 244   
      *                   boolean specifying whether this event will show a popup.
 245   
      * @param sleepTime
 246   
      *                   The wait time in ms between each event.
 247   
      * @param position  The relative mouse position within the cell.
 248   
      */
 249  2
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 250   
         final TreePath treePath, final int numberOfClicks, final int modifiers,
 251   
         final boolean isPopupTrigger, final long sleepTime, final int position) {
 252  2
         this(testCase, tree, treePath, numberOfClicks, modifiers,
 253   
             isPopupTrigger, sleepTime, position, null);
 254   
     }
 255   
 
 256   
     /**
 257   
      * Constructor.
 258   
      *
 259   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 260   
      * @param tree      The component on which to trigger the event.
 261   
      * @param nodeValue The String value of the specific node on which to trigger the event.
 262   
      * @param numberOfClicks
 263   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 264   
      * @param modifiers The modifier key values that need to be passed onto the event.
 265   
      * @param isPopupTrigger
 266   
      *                   boolean specifying whether this event will show a popup.
 267   
      * @param sleepTime
 268   
      *                   The wait time in ms between each event.
 269   
      * @param position  The relative mouse position within the cell.
 270   
      */
 271  2
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 272   
         final String nodeValue, final int numberOfClicks, final int modifiers,
 273   
         final boolean isPopupTrigger, final long sleepTime, final int position) {
 274  2
         this(testCase, tree, nodeValue, numberOfClicks, modifiers,
 275   
             isPopupTrigger, sleepTime, position, null);
 276   
     }
 277   
 
 278   
     /**
 279   
      * Constructor.
 280   
      *
 281   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 282   
      * @param tree      The component on which to trigger the event.
 283   
      * @param treePath  The path of the specific node on which to trigger the event.
 284   
      * @param numberOfClicks
 285   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 286   
      * @param modifiers The modifier key values that need to be passed onto the event.
 287   
      * @param isPopupTrigger
 288   
      *                   boolean specifying whether this event will show a popup.
 289   
      * @param sleepTime
 290   
      *                   The wait time in ms between each event.
 291   
      * @param referencePoint
 292   
      *                   The custom mouse position within the cell.
 293   
      */
 294  2
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 295   
         final TreePath treePath, final int numberOfClicks, final int modifiers,
 296   
         final boolean isPopupTrigger, final long sleepTime,
 297   
         final Point referencePoint) {
 298  2
         this(testCase, tree, treePath, numberOfClicks, modifiers,
 299   
             isPopupTrigger, sleepTime, CUSTOM, referencePoint);
 300   
     }
 301   
 
 302   
     /**
 303   
      * Constructor.
 304   
      *
 305   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 306   
      * @param tree      The component on which to trigger the event.
 307   
      * @param nodeValue The String value of the specific node on which to trigger the event.
 308   
      * @param numberOfClicks
 309   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 310   
      * @param modifiers The modifier key values that need to be passed onto the event.
 311   
      * @param isPopupTrigger
 312   
      *                   boolean specifying whether this event will show a popup.
 313   
      * @param sleepTime
 314   
      *                   The wait time in ms between each event.
 315   
      * @param referencePoint
 316   
      *                        The CUSTOM mouse position within the cell.
 317   
      */
 318  2
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 319   
         final String nodeValue, final int numberOfClicks, final int modifiers,
 320   
         final boolean isPopupTrigger, final long sleepTime,
 321   
         final Point referencePoint) {
 322  2
         this(testCase, tree, nodeValue, numberOfClicks, modifiers,
 323   
             isPopupTrigger, sleepTime, CUSTOM, referencePoint);
 324   
     }
 325   
 
 326   
     /**
 327   
      * Constructor.
 328   
      *
 329   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 330   
      * @param tree      The component on which to trigger the event.
 331   
          * @param treePath  The path of the specific node on which to trigger the event.
 332   
      * @param numberOfClicks
 333   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 334   
      * @param modifiers The modifier key values that need to be passed onto the event.
 335   
      * @param isPopupTrigger
 336   
      *                   boolean specifying whether this event will show a popup.
 337   
      * @param sleepTime
 338   
      *                   The wait time in ms between each event.
 339   
      * @param position  The relative mouse position within the cell.
 340   
      * @param referencePoint
 341   
      *                                   If position is CUSTOM then the point is a offset from
 342   
      *                                   the location of the component. If the position is PERCENT
 343   
      *                                   then the location is a percentage offset of the hight and width.
 344   
      *                                   Otherwise, the referencePoint is unused.
 345   
      */
 346  16
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 347   
         final TreePath treePath, final int numberOfClicks, final int modifiers,
 348   
         final boolean isPopupTrigger, final long sleepTime, final int position,
 349   
         final Point referencePoint) {
 350  16
         setTestCase(testCase);
 351  16
         setSource(tree);
 352  16
         setNumberOfClicks(numberOfClicks);
 353  16
         setModifiers(modifiers);
 354  16
         setPopupTrigger(isPopupTrigger);
 355  16
         setTreePath(treePath);
 356  16
         setSleepTime(sleepTime);
 357  16
         setPosition(position);
 358  16
         setReferencePoint(referencePoint);
 359  16
         setValid(true);
 360   
     }
 361   
 
 362   
     /**
 363   
      * Constructor.
 364   
      *
 365   
      * @param testCase  The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
 366   
      * @param tree      The component on which to trigger the event.
 367   
      * @param nodeValue The String value of the specific node on which to trigger the event.
 368   
      * @param numberOfClicks
 369   
      *                   Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
 370   
      * @param modifiers The modifier key values that need to be passed onto the event.
 371   
      * @param isPopupTrigger
 372   
      *                   boolean specifying whether this event will show a popup.
 373   
      * @param sleepTime
 374   
      *                   The wait time in ms between each event.
 375   
      * @param position  The relative mouse position within the cell.
 376   
      * @param referencePoint
 377   
      *                                   If position is CUSTOM then the point is a offset from
 378   
      *                                   the location of the component. If the position is PERCENT
 379   
      *                                   then the location is a percentage offset of the hight and width.
 380   
      *                                   Otherwise, the referencePoint is unused.
 381   
      */
 382  48
     public JTreeMouseEventData(final JFCTestCase testCase, final JTree tree,
 383   
         final String nodeValue, final int numberOfClicks, final int modifiers,
 384   
         final boolean isPopupTrigger, final long sleepTime, final int position,
 385   
         final Point referencePoint) {
 386  48
         setTestCase(testCase);
 387  48
         setSource(tree);
 388  48
         setNumberOfClicks(numberOfClicks);
 389  48
         setModifiers(modifiers);
 390  48
         setPopupTrigger(isPopupTrigger);
 391  48
         setNodeValue(nodeValue);
 392  48
         setSleepTime(sleepTime);
 393  48
         setPosition(position);
 394  48
         setReferencePoint(referencePoint);
 395  48
         setValid(true);
 396   
     }
 397   
 
 398   
     /**
 399   
      * Set the attribute value.
 400   
      *
 401   
      * @param nodeValue The new value of the attribute.
 402   
      */
 403  57
     public final void setNodeValue(final String nodeValue) {
 404  57
         m_nodeValue = nodeValue;
 405   
     }
 406   
 
 407   
     /**
 408   
      * Get the attribute value.
 409   
      *
 410   
      * @return String    The value of the attribute.
 411   
      */
 412  64
     public final String getNodeValue() {
 413  64
         return m_nodeValue;
 414   
     }
 415   
 
 416   
     /**
 417   
      * Set the attribute value.
 418   
      *
 419   
      * @param tree  The new value of the attribute.
 420   
      */
 421  73
     public final void setSource(final JTree tree) {
 422  73
         m_tree = tree;
 423   
     }
 424   
 
 425   
     /**
 426   
      * Get the attribute value.
 427   
      *
 428   
      * @return JTree    The value of the attribute.
 429   
      */
 430  143
     public final JTree getSource() {
 431  143
         return m_tree;
 432   
     }
 433   
 
 434   
     /**
 435   
      * The component on which the event has to be fired.
 436   
      *
 437   
      * @return The component.
 438   
      */
 439  88
     public Component getComponent() {
 440   
         // by default, the component is the same as the source
 441  88
         return getSource();
 442   
     }
 443   
 
 444   
     /**
 445   
      * Set the attribute value.
 446   
      *
 447   
      * @param treePath The new value of the attribute.
 448   
      */
 449  25
     public final void setTreePath(final TreePath treePath) {
 450  25
         m_treePath = treePath;
 451   
     }
 452   
 
 453   
     /**
 454   
      * Get the attribute value.
 455   
      *
 456   
      * @return TreePath    The value of the attribute.
 457   
      */
 458  67
     public final TreePath getTreePath() {
 459  67
         return m_treePath;
 460   
     }
 461   
 
 462   
     /**
 463   
      * Returns true if the event can be consumed by
 464   
      * this instnace of event data.
 465   
      *
 466   
      * @param ae Event to be consumed.
 467   
      * @return true if the event was consumed.
 468   
      */
 469  12
     public boolean canConsume(final AWTEvent ae) {
 470  12
         if (!(ae.getSource() instanceof JTree)
 471   
                 || !super.canConsume(ae)
 472   
                 || !sameSource(ae)) {
 473  1
             return false;
 474   
         }
 475   
 
 476  11
         if (isValid()) {
 477  7
             int row = ((JTree) ae.getSource()).getRowForLocation(
 478   
                     ((MouseEvent) ae).getX(),
 479   
                     ((MouseEvent) ae).getY());
 480  7
             TreePath path = ((JTree) ae.getSource()).getPathForRow(row);
 481   
 
 482  7
             if ((path != null) && !path.equals(getTreePath())) {
 483  0
                 return false;
 484   
             }
 485   
         }
 486   
 
 487  11
         return true;
 488   
     }
 489   
 
 490   
     /**
 491   
      * Consume the event.
 492   
      * @param ae AWTEvent to be consumed.
 493   
      * @return boolean true if the event was consumed.
 494   
      */
 495  11
     public boolean consume(final AWTEvent ae) {
 496  11
         if (super.consume(ae)) {
 497  2
             return true;
 498   
         }
 499   
 
 500  9
         MouseEvent me     = (MouseEvent) ae;
 501  9
         JTree      source = (JTree) me.getSource();
 502  9
         int        row    = ((JTree) source).getRowForLocation(
 503   
                 me.getX(),
 504   
                 me.getY());
 505  9
         TreePath path = ((JTree) source).getPathForRow(row);
 506   
 
 507  9
         if (path == null) {
 508  0
             return true;
 509   
         }
 510   
 
 511  9
         setSource(source);
 512  9
         setModifiers(me.getModifiers());
 513  9
         setNumberOfClicks(me.getClickCount());
 514  9
         setPopupTrigger(me.isPopupTrigger());
 515  9
         setSleepTime(getDefaultSleepTime());
 516   
 
 517  9
         Point p = new Point(
 518   
                 me.getX(),
 519   
                 me.getY());
 520  9
         Point screen = source.getLocationOnScreen();
 521  9
         screen.translate(p.x, p.y);
 522  9
         setLocationOnScreen(screen);
 523  9
         setTreePath(path);
 524  9
         setNodeValue(path.getLastPathComponent().toString());
 525   
 
 526  9
         setPosition(CENTER);
 527  9
         setReferencePoint(null);
 528   
 
 529  9
         setValid(true);
 530   
 
 531  9
         return true;
 532   
     }
 533   
 
 534   
     /**
 535   
      * Compare to event datas and deterime if they are equal.
 536   
      *
 537   
      * @param o Object to be compared.
 538   
      * @return true if the events are the same.
 539   
      */
 540  11
     public boolean equals(final Object o) {
 541  11
         if (!super.equals(o)) {
 542  9
             return false;
 543   
         }
 544   
 
 545  2
         JTreeMouseEventData data = (JTreeMouseEventData) o;
 546   
 
 547  2
         TreePath path     = getTreePath();
 548  2
         TreePath dataPath = data.getTreePath();
 549   
 
 550  2
         if ((path != null) && (dataPath != null) && !data.equals(m_treePath)) {
 551  0
             return false;
 552   
         }
 553   
 
 554  2
         if ((getNodeValue() != null)
 555   
                 && (data.getNodeValue() != null)
 556   
                 && !getNodeValue().equals(data.getNodeValue())) {
 557  1
             return false;
 558   
         }
 559   
 
 560  1
         return true;
 561   
     }
 562   
 
 563   
     /**
 564   
      * Get the hashCode.
 565   
      * @return int hashCode.
 566   
      */
 567  0
     public int hashCode() {
 568  0
         int nodeHash = 0;
 569   
 
 570  0
         if (m_nodeValue != null) {
 571  0
             nodeHash = m_nodeValue.hashCode();
 572   
         }
 573   
 
 574  0
         return super.hashCode() + nodeHash;
 575   
     }
 576   
 
 577   
     /**
 578   
      * Populate the XML Element with this nodes attributes.
 579   
      * @param e element to be populated.
 580   
      */
 581  0
     public void populate(final Element e) {
 582  0
         super.populate(e);
 583  0
         e.setAttribute(JFCXMLConstants.TYPE, "JTreeMouseEventData");
 584   
 
 585  0
         e.setAttribute(
 586   
             JFCXMLConstants.NODEVALUE,
 587   
             getNodeValue());
 588   
     }
 589   
 
 590   
     /**
 591   
      * Prepare the component to receive the event.
 592   
      *
 593   
      * @return true if the component is ready to receive the event.
 594   
      */
 595  23
     public boolean prepareComponent() {
 596  23
         if (!isValidForProcessing(getSource())) {
 597  1
             return false;
 598   
         }
 599   
 
 600  22
         m_tree.updateUI();
 601   
 
 602  22
         JFCTestCase testCase = getTestCase();
 603   
 
 604  22
         if (testCase != null) {
 605   
             // try to clear the event queue
 606  22
             testCase.flushAWT();
 607   
         }
 608   
 
 609  22
         TreePath path = getTreePath();
 610   
 
 611  22
         if (path == null) {
 612  22
             path = new TreePath(buildPath(getNode(
 613   
                             m_tree,
 614   
                             getNodeValue())));
 615   
         }
 616   
 
 617  22
         if (path == null) {
 618  0
             return false;
 619   
         }
 620   
 
 621   
 //        m_tree.setSelectionPath(path);
 622   
 
 623  22
         if (testCase != null) {
 624   
             // try to clear the event queue
 625  22
             testCase.pauseAWT();
 626   
         }
 627  22
         m_tree.scrollPathToVisible(path);
 628  22
         if (testCase != null) {
 629  22
             testCase.flushAWT();
 630  22
             testCase.pauseAWT();
 631   
         }
 632   
 
 633  22
         Rectangle cellRect = m_tree.getPathBounds(path);
 634   
 
 635  22
         if (testCase != null) {
 636   
             // try to clear the event queue
 637  22
             testCase.flushAWT();
 638  22
             testCase.pauseAWT();
 639   
         }
 640   
 
 641  22
         Point p = calculatePoint(cellRect);
 642   
 
 643  22
         if (!m_tree.getVisibleRect().contains(p)) {
 644  1
             Rectangle vis     = m_tree.getVisibleRect();
 645  1
             final Rectangle newView = new Rectangle(p.x - (int) (vis.width / 2),
 646   
                     p.y - (int) (vis.height / 2), vis.width, vis.height);
 647  1
             m_tree.scrollRectToVisible(newView);
 648   
         }
 649   
 
 650  22
         Point screen = m_tree.getLocationOnScreen();
 651  22
         screen.translate(p.x, p.y);
 652  22
         setLocationOnScreen(screen);
 653   
 
 654  22
         return true;
 655   
     }
 656   
 
 657   
     /**
 658   
      * Get string description of event.
 659   
      * @return String description of event.
 660   
      */
 661  2
     public String toString() {
 662  2
         if (!isValid()) {
 663  0
             return super.toString();
 664   
         }
 665   
 
 666  2
         StringBuffer buf = new StringBuffer(1000);
 667  2
         buf.append(super.toString());
 668  2
         buf.append(" nodeValue: " + getNodeValue());
 669  2
         buf.append(" treePath: " + getTreePath());
 670   
 
 671  2
         return buf.toString();
 672   
     }
 673   
 
 674   
     /**
 675   
      * Finds the node in the specified tree by comparing
 676   
      * with the value passed in.
 677   
      *
 678   
      * @param tree    The tree containing the node
 679   
      * @param userObj The value of the node (usually the node label)
 680   
      * @return The node whose value matched the value passed in
 681   
      */
 682  22
     private TreeNode getNode(final JTree tree, final String userObj) {
 683  22
         if (userObj == null) {
 684  0
             return null;
 685   
         }
 686   
 
 687  22
         TreeModel model = tree.getModel();
 688   
 
 689   
         // if the userObj is the same as the userObject of the root, just return root
 690  22
         TreeNode root = (TreeNode) model.getRoot();
 691   
 
 692  22
         if (checkNodesUserObject(root, userObj)) {
 693  3
             return root;
 694   
         }
 695   
 
 696  19
         List nodeList = findNodeList(
 697   
                 root,
 698   
                 new ArrayList());
 699  19
         TreeNode node = null;
 700  19
         Iterator iter = nodeList.iterator();
 701   
 
 702  1356
         while (iter.hasNext()) {
 703  1356
             node = (TreeNode) iter.next();
 704   
 
 705  1356
             if (checkNodesUserObject(node, userObj)) {
 706  19
                 return node;
 707   
             }
 708   
         }
 709   
 
 710   
         // nothing matched - return null
 711  0
         return null;
 712   
     }
 713   
 
 714   
     /**
 715   
      * Builds the parents of node up to and including the root node,
 716   
      * where the original node is the last element in the returned array.
 717   
      * The length of the returned array gives the node's depth in the
 718   
      * tree.
 719   
      *
 720   
      * @param node    The TreeNode whose path has to be built.
 721   
      * @return   The array of nodes in the tree above the specified node.
 722   
      */
 723  22
     private Object[] buildPath(final TreeNode node) {
 724  22
         ArrayList retVal = new ArrayList();
 725   
 
 726  22
         if (node != null) {
 727  22
             retVal.add(0, node);
 728   
 
 729  22
             TreeNode parent = node.getParent();
 730   
 
 731  22
             while (parent != null) {
 732  30
                 retVal.add(0, parent);
 733  30
                 parent = parent.getParent();
 734   
             }
 735   
         }
 736   
 
 737  22
         retVal.trimToSize();
 738   
 
 739  22
         return retVal.toArray();
 740   
     }
 741   
 
 742   
     /**
 743   
      * Checks to see if the node is not null and its
 744   
      * userObject is equal to the value passed in.
 745   
      *
 746   
      * @param node    Node
 747   
      * @param userObj Expected value
 748   
      * @return true if the values are the same
 749   
      */
 750  1378
     private boolean checkNodesUserObject(final TreeNode node,
 751   
         final String userObj) {
 752  1378
         if (node == null) {
 753  0
             return false;
 754   
         }
 755   
 
 756  1378
         return ((node.toString() != null) && node.toString().equals(userObj));
 757   
     }
 758   
 
 759   
     /**
 760   
      * Calls itself recursively to build a list of all
 761   
      * the child nodes in the parent.
 762   
      *
 763   
      * @param parent  Node whose children have to be added to the list
 764   
      * @param outList List of all the nodes in the tree
 765   
      * @return List of all nodes
 766   
      */
 767  5935
     private List findNodeList(final TreeNode parent, final List outList) {
 768  5935
         TreeNode node;
 769   
 
 770  5935
         for (int idx = 0; idx < parent.getChildCount(); idx++) {
 771  5916
             node = (TreeNode) parent.getChildAt(idx);
 772  5916
             outList.add(node);
 773  5916
             findNodeList(node, outList);
 774   
         }
 775   
 
 776  5935
         return outList;
 777   
     }
 778   
 }
 779