001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id: Demonstrator.java,v 1.3 2007/10/05 11:37:29 jskrivanek Exp $ $Revision: 1.3 $ $Date: 2007/10/05 11:37:29 $
044: *
045: */
046:
047: package org.netbeans.jemmy.demo;
048:
049: import org.netbeans.jemmy.EventDispatcher;
050: import org.netbeans.jemmy.JemmyProperties;
051: import org.netbeans.jemmy.TestOut;
052: import org.netbeans.jemmy.TimeoutExpiredException;
053:
054: /**
055: *
056: * Class to display step comments.
057: *
058: * @author Alexandre Iline (alexandre.iline@sun.com)
059: *
060: */
061:
062: public class Demonstrator {
063:
064: private static CommentWindow displayer;
065: private static CommentWindow nonDisplayer;
066:
067: /**
068: * Notifies current CommentWindow implementation to change title.
069: * @param title new CommentWindow's title
070: */
071: public static void setTitle(String title) {
072: displayer.setTitle(title);
073: }
074:
075: /**
076: * Changes current CommentWindow.
077: * @param cw CommentWindow instance.
078: */
079: public static void setCommentWindow(CommentWindow cw) {
080: displayer = cw;
081: }
082:
083: /**
084: * Notifies current CommentWindow implementation to display comments for a new step.
085: * @param stepComment New step comments
086: */
087: public static void nextStep(String stepComment) {
088: getDisplayer().nextStep(stepComment);
089: while (getDisplayer().isStopped()) {
090: try {
091: Thread.currentThread().sleep(100);
092: } catch (InterruptedException e) {
093: }
094: }
095: if (getDisplayer() != nonDisplayer) {
096: try {
097: EventDispatcher.waitQueueEmpty(TestOut.getNullOutput(),
098: JemmyProperties.getCurrentTimeouts());
099: } catch (TimeoutExpiredException e) {
100: e.printStackTrace();
101: }
102: }
103: if (getDisplayer().isInterrupted()) {
104: getDisplayer().close();
105: throw (new DemoInterruptedException(getDisplayer()
106: .getInterruptMessage()));
107: }
108: }
109:
110: /**
111: * Notifies current CommentWindow implementation to display final comments.
112: * @param stepComment New step comments
113: */
114: public static void showFinalComment(String stepComment) {
115: getDisplayer().showFinalComment(stepComment);
116: while (getDisplayer().isStopped()) {
117: try {
118: Thread.currentThread().sleep(100);
119: } catch (InterruptedException e) {
120: }
121: }
122: getDisplayer().close();
123: if (getDisplayer() != nonDisplayer) {
124: try {
125: EventDispatcher.waitQueueEmpty(TestOut.getNullOutput(),
126: JemmyProperties.getCurrentTimeouts());
127: } catch (TimeoutExpiredException e) {
128: e.printStackTrace();
129: }
130: }
131: }
132:
133: static {
134: setCommentWindow(new DefaultCommentWindow());
135: setTitle("Step comments");
136: nonDisplayer = new NonWindow();
137: }
138:
139: private static class NonWindow implements CommentWindow {
140: public void setTitle(String title) {
141: }
142:
143: public boolean isStopped() {
144: return (false);
145: }
146:
147: public void nextStep(String stepComment) {
148: JemmyProperties.getCurrentOutput().printLine(
149: "Step comments:\n" + stepComment);
150: }
151:
152: public void showFinalComment(String stepComment) {
153: JemmyProperties.getCurrentOutput().printLine(
154: "Final comments:\n" + stepComment);
155: }
156:
157: public boolean isInterrupted() {
158: return (false);
159: }
160:
161: public String getInterruptMessage() {
162: return ("");
163: }
164:
165: public void close() {
166: }
167: }
168:
169: private static CommentWindow getDisplayer() {
170: if (System.getProperty("jemmy.demo") != null
171: && System.getProperty("jemmy.demo").equals("on")) {
172: return (displayer);
173: } else {
174: return (nonDisplayer);
175: }
176: }
177: }
|