001: package org.netbeans.jemmy.testing;
002:
003: import org.netbeans.jemmy.*;
004:
005: import org.netbeans.jemmy.demo.Demonstrator;
006:
007: import org.netbeans.jemmy.operators.JComboBoxOperator;
008: import org.netbeans.jemmy.operators.*;
009: import org.netbeans.jemmy.util.*;
010:
011: import java.awt.Adjustable;
012: import java.awt.Button;
013: import java.awt.ScrollPane;
014: import java.awt.Component;
015:
016: import java.io.PrintWriter;
017:
018: import javax.swing.JFrame;
019:
020: import java.lang.reflect.InvocationTargetException;
021:
022: public class jemmy_035 extends JemmyTest {
023:
024: private boolean checkInside(Component comp, ComponentOperator area,
025: int x, int y, int width, int height) {
026: double compLeft = comp.getLocationOnScreen().getX() + x;
027: double compTop = comp.getLocationOnScreen().getY() + y;
028: double compRight = compLeft + width;
029: double compBottom = compTop + height;
030: double areaLeft = area.getSource().getLocationOnScreen().getX();
031: double areaTop = area.getSource().getLocationOnScreen().getY();
032: double areaRight = areaLeft + area.getSource().getWidth();
033: double areaBottom = areaTop + area.getSource().getHeight();
034: return (compLeft >= areaLeft && compRight <= areaRight
035: && compTop >= areaTop && compBottom <= areaBottom);
036: }
037:
038: private boolean checkInside(Component comp, ComponentOperator area) {
039: return (checkInside(comp, area, 0, 0, comp.getWidth(), comp
040: .getHeight()));
041: }
042:
043: public int runIt(Object obj) {
044:
045: try {
046:
047: try {
048: (new ClassReference(
049: "org.netbeans.jemmy.testing.Application_035"))
050: .startApplication();
051: } catch (ClassNotFoundException e) {
052: getOutput().printStackTrace(e);
053: } catch (InvocationTargetException e) {
054: getOutput().printStackTrace(e);
055: } catch (NoSuchMethodException e) {
056: getOutput().printStackTrace(e);
057: }
058:
059: ComponentOperator
060: .setDefaultComponentVisualizer(new EmptyVisualizer());
061:
062: JFrame win = JFrameOperator.waitJFrame("Application_035",
063: true, true);
064:
065: Button butt00 = ButtonOperator.findButton(win, "00", true,
066: true);
067: Button butt04 = ButtonOperator.findButton(win, "04", true,
068: true);
069: Button butt11 = ButtonOperator.findButton(win, "11", true,
070: true);
071: Button butt22 = ButtonOperator.findButton(win, "22", true,
072: true);
073: Button butt24 = ButtonOperator.findButton(win, "24", true,
074: true);
075: Button butt33 = ButtonOperator.findButton(win, "33", true,
076: true);
077: Button butt44 = ButtonOperator.findButton(win, "44", true,
078: true);
079: Button butt42 = ButtonOperator.findButton(win, "42", true,
080: true);
081: Button butt40 = ButtonOperator.findButton(win, "40", true,
082: true);
083:
084: ScrollPaneOperator scroller = new ScrollPaneOperator(
085: new JFrameOperator(win));
086:
087: if (scroller.getSource() != ScrollPaneOperator
088: .findScrollPaneUnder(butt00)) {
089: getOutput()
090: .printErrLine(
091: "One of two methods: findScrollPane or findUnder does not work correcly");
092: return (1);
093: }
094:
095: Demonstrator.setTitle("jemmy_035 test");
096:
097: Demonstrator.nextStep("Set scroller values to maximum");
098:
099: scroller.setValues(scroller.getHAdjustable().getMaximum(),
100: scroller.getVAdjustable().getMaximum());
101:
102: if (!checkInside(butt44, scroller)) {
103: getOutput().printErrLine(
104: "44 button is not inside scroll area!");
105: return (1);
106: }
107:
108: Demonstrator.nextStep("Set scroller values to (0, 0)");
109:
110: scroller.setValues(0, 0);
111:
112: if (!checkInside(butt00, scroller)) {
113: getOutput().printErrLine(
114: "00 button is not inside scroll area!");
115: return (1);
116: }
117:
118: Demonstrator
119: .nextStep("Scroll to the center of \"22\" button");
120:
121: scroller.scrollToComponentPoint(butt22,
122: butt22.getWidth() / 2, butt22.getHeight() / 2);
123:
124: if (!checkInside(butt22, scroller,
125: butt22.getWidth() / 2 - 1,
126: butt22.getHeight() / 2 - 1, 2, 2)) {
127: getOutput().printErrLine(
128: "22 button center is not inside scroll area!");
129: return (1);
130: }
131:
132: Demonstrator.nextStep("Scroll to right");
133:
134: scroller.scrollToRight();
135:
136: if (!checkInside(butt24, scroller,
137: butt24.getWidth() / 2 - 1,
138: butt24.getHeight() / 2 - 1, 2, 2)) {
139: getOutput().printErrLine(
140: "24 button center is not inside scroll area!");
141: return (1);
142: }
143:
144: int x22 = 10;
145: int y22 = 10;
146: int w22 = butt22.getWidth() - 20;
147: int h22 = butt22.getHeight() - 20;
148: Demonstrator.nextStep("Scroll to (" + Integer.toString(x22)
149: + "," + Integer.toString(y22) + ","
150: + Integer.toString(w22) + ","
151: + Integer.toString(h22) + ")"
152: + " rectangle in \"22\" button");
153:
154: scroller.scrollToComponentRectangle(butt22, x22, y22, w22,
155: h22);
156:
157: if (!checkInside(butt22, scroller, x22, y22, w22, h22)) {
158: getOutput().printErrLine(
159: "22 button is not inside scroll area!");
160: return (1);
161: }
162:
163: Demonstrator.nextStep("Scroll to bottom");
164:
165: scroller.scrollToBottom();
166:
167: int x42 = 10;
168: int y42 = 10;
169: int w42 = butt42.getWidth() - 20;
170: int h42 = butt42.getHeight() - 20;
171: if (!checkInside(butt42, scroller, x42, y42, w42, h42)) {
172: getOutput().printErrLine(
173: "42 button is not inside scroll area!");
174: return (1);
175: }
176:
177: Demonstrator.nextStep("Scroll to left");
178:
179: scroller.scrollToLeft();
180:
181: if (!checkInside(butt40, scroller)) {
182: getOutput().printErrLine(
183: "40 button is not inside scroll area!");
184: return (1);
185: }
186:
187: Demonstrator.nextStep("Scroll to top");
188:
189: scroller.scrollToTop();
190:
191: if (!checkInside(butt00, scroller)) {
192: getOutput().printErrLine(
193: "00 button is not inside scroll area!");
194: return (1);
195: }
196:
197: Demonstrator.nextStep("Scroll to center");
198:
199: scroller.scrollToValues(0.5, 0.5);
200:
201: if (!checkInside(butt22, scroller,
202: butt22.getWidth() / 2 - 1,
203: butt22.getHeight() / 2 - 1, 1, 1)) {
204:
205: getOutput().printErrLine(
206: "22 button is not inside scroll area!");
207: return (1);
208: }
209:
210: Demonstrator.nextStep("Scroll to \"11\" button");
211:
212: scroller.scrollToComponent(butt11);
213:
214: if (!checkInside(butt11, scroller)) {
215: getOutput().printErrLine(
216: "11 button is not inside scroll area!");
217: return (1);
218: }
219:
220: Demonstrator.nextStep("Scroll to \"33\" button");
221:
222: scroller.scrollToComponent(butt33);
223:
224: if (!checkInside(butt33, scroller)) {
225: getOutput().printErrLine(
226: "33 button is not inside scroll area!");
227: return (1);
228: }
229:
230: Demonstrator.nextStep("Scroll to horizontal center");
231:
232: scroller.scrollToHorizontalValue(0.5);
233:
234: Demonstrator.nextStep("Scroll to vertical center");
235:
236: scroller.scrollToVerticalValue(0.5);
237:
238: if (!checkInside(butt22, scroller)) {
239: getOutput().printErrLine(
240: "22 button is not inside scroll area!");
241: return (1);
242: }
243:
244: Demonstrator.showFinalComment("Test passed");
245:
246: } catch (Exception e) {
247: finalize();
248: throw (new TestCompletedException(1, e));
249: }
250:
251: finalize();
252:
253: return (0);
254: }
255:
256: }
|