13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.netbeans.jemmy.operators;
24
25 import java.awt.Component;
26 import java.awt.Frame;
27 import java.awt.Image;
28 import java.awt.MenuBar;
29 import java.util.Hashtable;
30
31 import org.netbeans.jemmy.ComponentChooser;
32 import org.netbeans.jemmy.FrameWaiter;
33 import org.netbeans.jemmy.JemmyException;
34 import org.netbeans.jemmy.JemmyProperties;
35 import org.netbeans.jemmy.Outputable;
36 import org.netbeans.jemmy.TestOut;
37 import org.netbeans.jemmy.TimeoutExpiredException;
38 import org.netbeans.jemmy.Timeouts;
39 import org.netbeans.jemmy.drivers.DriverManager;
40 import org.netbeans.jemmy.drivers.FrameDriver;
41
42 /**
43 * <BR><BR>Timeouts used: <BR>
44 * FrameWaiter.WaitFrameTimeout - time to wait frame displayed <BR>
45 * FrameWaiter.AfterFrameTimeout - time to sleep after frame has been dispayed
46 * <BR>
47 * ComponentOperator.WaitStateTimeout - time to wait for text <BR>.
48 *
49 * @see org.netbeans.jemmy.Timeouts
50 *
51 * @author Alexandre Iline (alexandre.iline@oracle.com)
52 *
53 */
258 /**
259 * Deiconifies the frame.
260 */
261 public void deiconify() {
262 output.printLine("Deiconifying frame\n " + toStringSource());
263 output.printGolden("Deiconifying frame");
264 driver.deiconify(this);
265 if (getVerification()) {
266 waitState(Frame.NORMAL);
267 }
268 }
269
270 /**
271 * Maximizes the frame.
272 */
273 public void maximize() {
274 output.printLine("Maximizing frame\n " + toStringSource());
275 output.printGolden("Maximizing frame");
276 driver.maximize(this);
277 if (getVerification()) {
278 waitState(Frame.NORMAL);
279 }
280 }
281
282 /**
283 * Demaximizes the frame.
284 */
285 public void demaximize() {
286 output.printLine("Demaximizing frame\n " + toStringSource());
287 output.printGolden("Demaximizing frame");
288 driver.demaximize(this);
289 if (getVerification()) {
290 waitState(Frame.NORMAL);
291 }
292 }
293
294 /**
295 * Waits for the frame to have a specified state.
296 *
297 * @param state a state for the frame to have.
298 */
299 public void waitState(final int state) {
300 getOutput().printLine("Wait frame to have "
301 + Integer.toString(state)
302 + " state \n : "
303 + toStringSource());
304 getOutput().printGolden("Wait frame to have "
305 + Integer.toString(state)
306 + " state");
307 waitState(new ComponentChooser() {
308 @Override
309 public boolean checkComponent(Component comp) {
310 return ((Frame) comp).getState() == state;
311 }
312
313 @Override
314 public String getDescription() {
315 return Integer.toString(state) + " state";
316 }
317
318 @Override
319 public String toString() {
320 return "FrameOperator.waitState.ComponentChooser{description = " + getDescription() + '}';
321 }
322 });
323 }
324
325 /**
326 * Returns information about component.
327 */
328 @Override
329 public Hashtable<String, Object> getDump() {
330 Hashtable<String, Object> result = super.getDump();
360 @Override
361 public MenuBar map() {
362 return ((Frame) getSource()).getMenuBar();
363 }
364 }));
365 }
366
367 /**
368 * Maps {@code Frame.getState()} through queue
369 */
370 public int getState() {
371 return (runMapping(new MapIntegerAction("getState") {
372 @Override
373 public int map() {
374 return ((Frame) getSource()).getState();
375 }
376 }));
377 }
378
379 /**
380 * Maps {@code Frame.getTitle()} through queue
381 */
382 public String getTitle() {
383 return (runMapping(new MapAction<String>("getTitle") {
384 @Override
385 public String map() {
386 return ((Frame) getSource()).getTitle();
387 }
388 }));
389 }
390
391 /**
392 * Maps {@code Frame.isResizable()} through queue
393 */
394 public boolean isResizable() {
395 return (runMapping(new MapBooleanAction("isResizable") {
396 @Override
397 public boolean map() {
398 return ((Frame) getSource()).isResizable();
399 }
432 @Override
433 public void map() {
434 ((Frame) getSource()).setResizable(b);
435 }
436 });
437 }
438
439 /**
440 * Maps {@code Frame.setState(int)} through queue
441 */
442 public void setState(final int i) {
443 runMapping(new MapVoidAction("setState") {
444 @Override
445 public void map() {
446 ((Frame) getSource()).setState(i);
447 }
448 });
449 }
450
451 /**
452 * Maps {@code Frame.setTitle(String)} through queue
453 */
454 public void setTitle(final String string) {
455 runMapping(new MapVoidAction("setTitle") {
456 @Override
457 public void map() {
458 ((Frame) getSource()).setTitle(string);
459 }
460 });
461 }
462
463 //End of mapping //
464 ////////////////////////////////////////////////////////
465 /**
466 * A method to be used from subclasses. Uses timeouts and output passed as
467 * parameters during the waiting.
468 *
469 * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
470 * @param index Ordinal component index.
471 * @param timeouts timeouts to be used during the waiting.
472 * @param output an output to be used during the waiting.
473 * @return Component instance or null if component was not found.
474 * @throws TimeoutExpiredException
475 */
476 protected static Frame waitFrame(ComponentChooser chooser, int index,
477 Timeouts timeouts, TestOut output) {
478 try {
479 FrameWaiter waiter = new FrameWaiter();
480 waiter.setTimeouts(timeouts);
481 waiter.setOutput(output);
482 return waiter.waitFrame(new FrameFinder(chooser), index);
483 } catch (InterruptedException e) {
484 throw new JemmyException("Interrupted while waiting for a frame with " + chooser + " and index = " + index, e);
485 }
486 }
487
488 /**
489 * Checks component type.
490 */
491 public static class FrameFinder extends Finder {
492
493 /**
494 * Constructs FrameFinder.
495 *
496 * @param sf other searching criteria.
497 */
498 public FrameFinder(ComponentChooser sf) {
499 super(Frame.class, sf);
500 }
501
502 /**
503 * Constructs FrameFinder.
504 */
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.netbeans.jemmy.operators;
24
25 import java.awt.Component;
26 import java.awt.Frame;
27 import java.awt.Image;
28 import java.awt.MenuBar;
29 import java.util.Hashtable;
30
31 import org.netbeans.jemmy.ComponentChooser;
32 import org.netbeans.jemmy.FrameWaiter;
33 import org.netbeans.jemmy.JemmyProperties;
34 import org.netbeans.jemmy.Outputable;
35 import org.netbeans.jemmy.TestOut;
36 import org.netbeans.jemmy.TimeoutExpiredException;
37 import org.netbeans.jemmy.Timeouts;
38 import org.netbeans.jemmy.drivers.DriverManager;
39 import org.netbeans.jemmy.drivers.FrameDriver;
40
41 /**
42 * <BR><BR>Timeouts used: <BR>
43 * FrameWaiter.WaitFrameTimeout - time to wait frame displayed <BR>
44 * FrameWaiter.AfterFrameTimeout - time to sleep after frame has been dispayed
45 * <BR>
46 * ComponentOperator.WaitStateTimeout - time to wait for text <BR>.
47 *
48 * @see org.netbeans.jemmy.Timeouts
49 *
50 * @author Alexandre Iline (alexandre.iline@oracle.com)
51 *
52 */
257 /**
258 * Deiconifies the frame.
259 */
260 public void deiconify() {
261 output.printLine("Deiconifying frame\n " + toStringSource());
262 output.printGolden("Deiconifying frame");
263 driver.deiconify(this);
264 if (getVerification()) {
265 waitState(Frame.NORMAL);
266 }
267 }
268
269 /**
270 * Maximizes the frame.
271 */
272 public void maximize() {
273 output.printLine("Maximizing frame\n " + toStringSource());
274 output.printGolden("Maximizing frame");
275 driver.maximize(this);
276 if (getVerification()) {
277 waitState(Frame.MAXIMIZED_BOTH);
278 }
279 }
280
281 /**
282 * Demaximizes the frame.
283 */
284 public void demaximize() {
285 output.printLine("Demaximizing frame\n " + toStringSource());
286 output.printGolden("Demaximizing frame");
287 driver.demaximize(this);
288 if (getVerification()) {
289 waitState(Frame.NORMAL);
290 }
291 }
292
293 /**
294 * Waits for the frame to have a specified state.
295 *
296 * @param state a state for the frame to have.
297 */
298 public void waitState(final int state) {
299 getOutput().printLine("Wait frame to have "
300 + Integer.toString(state)
301 + " state \n : "
302 + toStringSource());
303 getOutput().printGolden("Wait frame to have "
304 + Integer.toString(state)
305 + " state");
306 waitState(new ComponentChooser() {
307 @Override
308 public boolean checkComponent(Component comp) {
309 return ((Frame) comp).getExtendedState() == state;
310 }
311
312 @Override
313 public String getDescription() {
314 return Integer.toString(state) + " state";
315 }
316
317 @Override
318 public String toString() {
319 return "FrameOperator.waitState.ComponentChooser{description = " + getDescription() + '}';
320 }
321 });
322 }
323
324 /**
325 * Returns information about component.
326 */
327 @Override
328 public Hashtable<String, Object> getDump() {
329 Hashtable<String, Object> result = super.getDump();
359 @Override
360 public MenuBar map() {
361 return ((Frame) getSource()).getMenuBar();
362 }
363 }));
364 }
365
366 /**
367 * Maps {@code Frame.getState()} through queue
368 */
369 public int getState() {
370 return (runMapping(new MapIntegerAction("getState") {
371 @Override
372 public int map() {
373 return ((Frame) getSource()).getState();
374 }
375 }));
376 }
377
378 /**
379 * Maps {@code Frame.getExtendedState()} through queue
380 * @return the state of the frame
381 */
382 public int getExtendedState() {
383 return (runMapping(new MapAction<Integer>("getExtendedState") {
384 @Override
385 public Integer map() {
386 return ((Frame) getSource()).getExtendedState();
387 }
388 }));
389 }
390
391 /**
392 * Maps {@code Frame.getTitle()} through queue
393 */
394 public String getTitle() {
395 return (runMapping(new MapAction<String>("getTitle") {
396 @Override
397 public String map() {
398 return ((Frame) getSource()).getTitle();
399 }
400 }));
401 }
402
403 /**
404 * Maps {@code Frame.isResizable()} through queue
405 */
406 public boolean isResizable() {
407 return (runMapping(new MapBooleanAction("isResizable") {
408 @Override
409 public boolean map() {
410 return ((Frame) getSource()).isResizable();
411 }
444 @Override
445 public void map() {
446 ((Frame) getSource()).setResizable(b);
447 }
448 });
449 }
450
451 /**
452 * Maps {@code Frame.setState(int)} through queue
453 */
454 public void setState(final int i) {
455 runMapping(new MapVoidAction("setState") {
456 @Override
457 public void map() {
458 ((Frame) getSource()).setState(i);
459 }
460 });
461 }
462
463 /**
464 * Maps {@code Frame.setExtendedState(int)} through queue
465 * @param state of the frame
466 */
467 public void setExtendedState(final int state) {
468 runMapping(new MapAction<Void>("setExtendedState") {
469 @Override
470 public Void map() {
471 ((Frame) getSource()).setExtendedState(state);
472 return null;
473 }
474 });
475
476 }
477
478 /**
479 * Maps {@code Frame.setTitle(String)} through queue
480 */
481 public void setTitle(final String string) {
482 runMapping(new MapVoidAction("setTitle") {
483 @Override
484 public void map() {
485 ((Frame) getSource()).setTitle(string);
486 }
487 });
488 }
489
490 //End of mapping //
491 ////////////////////////////////////////////////////////
492 /**
493 * A method to be used from subclasses. Uses timeouts and output passed as
494 * parameters during the waiting.
495 *
496 * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
497 * @param index Ordinal component index.
498 * @param timeouts timeouts to be used during the waiting.
499 * @param output an output to be used during the waiting.
500 * @return Component instance or null if component was not found.
501 * @throws TimeoutExpiredException
502 */
503 protected static Frame waitFrame(ComponentChooser chooser, int index,
504 Timeouts timeouts, TestOut output) {
505 try {
506 FrameWaiter waiter = new FrameWaiter();
507 waiter.setTimeouts(timeouts);
508 waiter.setOutput(output);
509 return waiter.waitFrame(new FrameFinder(chooser), index);
510 } catch (InterruptedException e) {
511 throw new JemmyException("Interrupted while waiting for a frame with " +
512 chooser + " and index = " + index, e);
513 }
514 }
515
516 /**
517 * Checks component type.
518 */
519 public static class FrameFinder extends Finder {
520
521 /**
522 * Constructs FrameFinder.
523 *
524 * @param sf other searching criteria.
525 */
526 public FrameFinder(ComponentChooser sf) {
527 super(Frame.class, sf);
528 }
529
530 /**
531 * Constructs FrameFinder.
532 */
|