|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| JTreeMouseEventDataTagHandler.java | 25% | 53.3% | 80% | 54.2% |
|
||||||||||||||
| 1 |
package junit.extensions.jfcunit.eventdata;
|
|
| 2 |
|
|
| 3 |
import junit.extensions.xml.IXMLTestCase;
|
|
| 4 |
import junit.extensions.xml.XMLException;
|
|
| 5 |
|
|
| 6 |
import org.w3c.dom.Element;
|
|
| 7 |
|
|
| 8 |
import javax.swing.JTree;
|
|
| 9 |
import javax.swing.tree.TreePath;
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
/**
|
|
| 13 |
* This is a extension of the click and drag elements. Where the
|
|
| 14 |
* type specified is MouseEventData.
|
|
| 15 |
*
|
|
| 16 |
* <h3>Description</h3>
|
|
| 17 |
* <p>
|
|
| 18 |
* Nothing is invoked directly by this tag handler. The click and drag elements
|
|
| 19 |
* use this tag handler to customize the data specificly for the JTree.
|
|
| 20 |
* </p>
|
|
| 21 |
*
|
|
| 22 |
* <h3>Parameters</h3>
|
|
| 23 |
* <table border="1" cellpadding="2" cellspacing="0">
|
|
| 24 |
* <tr>
|
|
| 25 |
* <td valign="top"><b>Attribute</b></td>
|
|
| 26 |
* <td valign="top"><b>Description</b></td>
|
|
| 27 |
* <td align="center" valign="top"><b>Required</b></td>
|
|
| 28 |
* <td valign="top"><b>Default</b></td>
|
|
| 29 |
* <td valign="top"><b>Values</b></td>
|
|
| 30 |
* </tr>
|
|
| 31 |
* <tr>
|
|
| 32 |
* <td valign="top">type</td>
|
|
| 33 |
* <td valign="top">For this element the type must be set to JTreeMouseEventData</td>
|
|
| 34 |
* <td valign="top" align="center">Yes</td>
|
|
| 35 |
* <td valign="top">N/A</td>
|
|
| 36 |
* <td valign="top">N/A</td>
|
|
| 37 |
* </tr>
|
|
| 38 |
* <tr>
|
|
| 39 |
* <td valign="top">refid</td>
|
|
| 40 |
* <td valign="top">Id of a object reference which has been previously found.</td>
|
|
| 41 |
* <td valign="top" align="center">Yes</td>
|
|
| 42 |
* <td valign="top">N/A</td>
|
|
| 43 |
* <td valign="top">N/A</td>
|
|
| 44 |
* </tr>
|
|
| 45 |
* <tr>
|
|
| 46 |
* <td valign="top">node</td>
|
|
| 47 |
* <td valign="top">Text of the node to select</td>
|
|
| 48 |
* <td valign="top" align="center">node or pathrefid</td>
|
|
| 49 |
* <td valign="top">N/A</td>
|
|
| 50 |
* <td valign="top">Must be string specifying the value of the node.</td>
|
|
| 51 |
* </tr>
|
|
| 52 |
* <tr>
|
|
| 53 |
* <td valign="top">pathrefid</td>
|
|
| 54 |
* <td valign="top">reference to a path of the node to select.</td>
|
|
| 55 |
* <td valign="top" align="center">node or pathrefid</td>
|
|
| 56 |
* <td valign="top">N/A</td>
|
|
| 57 |
* <td valign="top">reference to a existing property refered by the refid.</td>
|
|
| 58 |
* </tr>
|
|
| 59 |
* <tr>
|
|
| 60 |
* <td valign="top">clicks</td>
|
|
| 61 |
* <td valign="top">The number of clicks to be executed.</td>
|
|
| 62 |
* <td valign="top" align="center">No</td>
|
|
| 63 |
* <td valign="top">1</td>
|
|
| 64 |
* <td valign="top">Positive Integer</td>
|
|
| 65 |
* </tr>
|
|
| 66 |
* <tr>
|
|
| 67 |
* <td valign="top">modifiers</td>
|
|
| 68 |
* <td valign="top">The modifiers to be used for this event.</td>
|
|
| 69 |
* <td valign="top" align="center">No</td>
|
|
| 70 |
* <td valign="top">Button1 if popup is false otherwise Button3</td>
|
|
| 71 |
* <td valign="top">alt altgr control meta shift button1 button2 button3</td>
|
|
| 72 |
* </tr>
|
|
| 73 |
* <tr>
|
|
| 74 |
* <td valign="top">popup</td>
|
|
| 75 |
* <td valign="top">True if this is event is using the popup button.</td>
|
|
| 76 |
* <td valign="top" align="center">No</td>
|
|
| 77 |
* <td valign="top">false</td>
|
|
| 78 |
* <td valign="top">true false</td>
|
|
| 79 |
* </tr>
|
|
| 80 |
* <tr>
|
|
| 81 |
* <td valign="top">sleeptime</td>
|
|
| 82 |
* <td valign="top">Maximum sleep time</td>
|
|
| 83 |
* <td valign="top" align="center">No</td>
|
|
| 84 |
* <td valign="top">500</td>
|
|
| 85 |
* <td valign="top">Positive Integer representing the milli-seconds</td>
|
|
| 86 |
* </tr>
|
|
| 87 |
* <tr>
|
|
| 88 |
* <td valign="top">position</td>
|
|
| 89 |
* <td valign="top">Positioning of the mouse within the bounds of the component.</td>
|
|
| 90 |
* <td valign="top" align="center">No</td>
|
|
| 91 |
* <td valign="top">center</td>
|
|
| 92 |
* <td valign="top">center north northeast east southeast south southwest west northwest custom percentage</td>
|
|
| 93 |
* </tr>
|
|
| 94 |
* <tr>
|
|
| 95 |
* <td valign="top">reference</td>
|
|
| 96 |
* <td valign="top">Reference point or number for position calculation.</td>
|
|
| 97 |
* <td valign="top" align="center">No</td>
|
|
| 98 |
* <td valign="top">null</td>
|
|
| 99 |
* <td valign="top">integers "x,y"</td>
|
|
| 100 |
* </tr>
|
|
| 101 |
*
|
|
| 102 |
* </table>
|
|
| 103 |
* <h3>Example</h3>
|
|
| 104 |
* <blockquote><pre>
|
|
| 105 |
* <click
|
|
| 106 |
* type="JTreeMouseEventData"
|
|
| 107 |
* refid="Tree"
|
|
| 108 |
* node="Music"
|
|
| 109 |
* />
|
|
| 110 |
* </pre></blockquote>
|
|
| 111 |
* <p>
|
|
| 112 |
* The above clicks once on the center of the component identified by
|
|
| 113 |
* Tree.
|
|
| 114 |
* </p>
|
|
| 115 |
* @see junit.extensions.jfcunit.eventdata.JTreeMouseEventData
|
|
| 116 |
* @author Kevin Wilson
|
|
| 117 |
*/
|
|
| 118 |
public class JTreeMouseEventDataTagHandler extends BaseEventDataTagHandler { |
|
| 119 |
/**
|
|
| 120 |
* Constructor for JTreeMouseEventDataTagHandler.
|
|
| 121 |
*
|
|
| 122 |
* @param element The element to be processed
|
|
| 123 |
* @param testCase The IXMLTestCase that uses this element
|
|
| 124 |
*/
|
|
| 125 | 14 |
public JTreeMouseEventDataTagHandler(final Element element,
|
| 126 |
final IXMLTestCase testCase) {
|
|
| 127 | 14 |
super(element, testCase);
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
/**
|
|
| 131 |
* @see junit.extensions.xml.elements.AbstractTagHandler#processElement()
|
|
| 132 |
*/
|
|
| 133 | 14 |
public void processElement() throws XMLException { |
| 134 | 14 |
validateElement(); |
| 135 |
|
|
| 136 | 14 |
JTree tree = (JTree) getComponent(); |
| 137 |
|
|
| 138 | 14 |
if (getNodeValue() != null) { |
| 139 | 14 |
setEventData( |
| 140 |
new JTreeMouseEventData(
|
|
| 141 |
getJFCTestCase(), |
|
| 142 |
tree, |
|
| 143 |
getNodeValue(), |
|
| 144 |
getClicks(), |
|
| 145 |
getModifiers(), |
|
| 146 |
getPopupTrigger(), |
|
| 147 |
getSleepTime(), |
|
| 148 |
getPosition(), |
|
| 149 |
getReference())); |
|
| 150 |
} else {
|
|
| 151 | 0 |
String id = getPathRefid(); |
| 152 | 0 |
Object pathdata = getTest().getProperty(id); |
| 153 |
|
|
| 154 | 0 |
if (pathdata instanceof PathData) { |
| 155 | 0 |
TreePath path = ((PathData) pathdata).getTreePath(tree); |
| 156 | 0 |
setEventData( |
| 157 |
new JTreeMouseEventData(
|
|
| 158 |
getJFCTestCase(), |
|
| 159 |
tree, |
|
| 160 |
path, |
|
| 161 |
getClicks(), |
|
| 162 |
getModifiers(), |
|
| 163 |
getPopupTrigger(), |
|
| 164 |
getSleepTime(), |
|
| 165 |
getPosition(), |
|
| 166 |
getReference())); |
|
| 167 |
} else {
|
|
| 168 | 0 |
throw new XMLException("pathrefid point to object which is not a PathData", |
| 169 |
getElement()); |
|
| 170 |
} |
|
| 171 |
} |
|
| 172 |
} |
|
| 173 |
|
|
| 174 |
/**
|
|
| 175 |
* @see junit.extensions.xml.elements.AbstractTagHandler#validateElement()
|
|
| 176 |
*/
|
|
| 177 | 14 |
public void validateElement() throws XMLException { |
| 178 |
// do the default validations from the super class
|
|
| 179 | 14 |
super.validateElement();
|
| 180 | 14 |
this.checkOneRequiredAttribute(new String[] {NODEVALUE, PATHREFID}); |
| 181 |
} |
|
| 182 |
|
|
| 183 |
/**
|
|
| 184 |
* Returns the value of the NODEVALUE attribute for this element.
|
|
| 185 |
* @return int The value of the NODEVALUE attribute.
|
|
| 186 |
*/
|
|
| 187 | 28 |
private String getNodeValue() {
|
| 188 | 28 |
return getString(NODEVALUE);
|
| 189 |
} |
|
| 190 |
|
|
| 191 |
/**
|
|
| 192 |
* Get the reference id for the path data.
|
|
| 193 |
* @return String reference id.
|
|
| 194 |
*/
|
|
| 195 | 0 |
private String getPathRefid() {
|
| 196 | 0 |
return getString(PATHREFID);
|
| 197 |
} |
|
| 198 |
} |
|
| 199 |
|
|
||||||||||