KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > gargoylesoftware > htmlunit > TopLevelWindow


1 /*
2  * Copyright (c) 2002, 2005 Gargoyle Software Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. The end-user documentation included with the redistribution, if any, must
13  * include the following acknowledgment:
14  *
15  * "This product includes software developed by Gargoyle Software Inc.
16  * (http://www.GargoyleSoftware.com/)."
17  *
18  * Alternately, this acknowledgment may appear in the software itself, if
19  * and wherever such third-party acknowledgments normally appear.
20  * 4. The name "Gargoyle Software" must not be used to endorse or promote
21  * products derived from this software without prior written permission.
22  * For written permission, please contact info@GargoyleSoftware.com.
23  * 5. Products derived from this software may not be called "HtmlUnit", nor may
24  * "HtmlUnit" appear in their name, without prior written permission of
25  * Gargoyle Software Inc.
26  *
27  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
30  * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
33  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */

38 package com.gargoylesoftware.htmlunit;
39
40
41 /**
42  * A window representing a top level browser window.
43  *
44  * @version $Revision: 100 $
45  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
46  * @author David K. Taylor
47  * @author David D. Kilzer
48  */

49 public class TopLevelWindow implements WebWindow {
50
51     private String JavaDoc name_;
52     private Page enclosedPage_;
53     private WebClient webClient_;
54     private WebWindow opener_;
55
56     private Object JavaDoc scriptObject_;
57
58
59     /**
60      * Create an instance.
61      * @param name The name of the new window
62      * @param webClient The web client that "owns" this window.
63      */

64     public TopLevelWindow( final String JavaDoc name, final WebClient webClient ) {
65         Assert.notNull("name", name);
66         Assert.notNull("webClient", webClient);
67
68         name_ = name;
69         webClient_ = webClient;
70
71         webClient_.registerWebWindow(this);
72     }
73
74
75     /**
76      * Return the name of this window.
77      *
78      * @return The name of this window.
79      */

80     public String JavaDoc getName() {
81         return name_;
82     }
83
84
85     /**
86      * Set the name of this window.
87      *
88      * @param name The new name of this window.
89      */

90     public void setName(String JavaDoc name) {
91         name_ = name;
92     }
93
94
95     /**
96      * Return the currently loaded page or null if no page has been loaded.
97      *
98      * @return The currently loaded page or null if no page has been loaded.
99      */

100     public Page getEnclosedPage() {
101         return enclosedPage_;
102     }
103
104
105     /**
106      * Set the currently loaded page.
107      *
108      * @param page The new page or null if there is no page (ie empty window)
109      */

110     public void setEnclosedPage( final Page page ) {
111         enclosedPage_ = page;
112     }
113
114
115     /**
116      * Return the window that contains this window. Since this is a top
117      * level window, return this window.
118      *
119      * @return This window since there is no parent.
120      */

121     public WebWindow getParentWindow() {
122         return this;
123     }
124
125
126     /**
127      * Return the top level window that contains this window. Since this
128      * is a top level window, return this window.
129      *
130      * @return This window since it is top level.
131      */

132     public WebWindow getTopWindow() {
133         return this;
134     }
135
136
137     /**
138      * Return the web client that owns this window
139      * @return The web client
140      */

141     public WebClient getWebClient() {
142         return webClient_;
143     }
144
145
146     /**
147      * Return a string representation of this object
148      * @return A string representation of this object
149      */

150     public String JavaDoc toString() {
151         return "TopLevelWindow[name=\""+getName()+"\"]";
152     }
153
154
155     /**
156      * Internal use only - subject to change without notice.<p>
157      * Set the javascript object that corresponds to this element. This is not guarenteed
158      * to be set even if there is a javascript object for this html element.
159      * @param scriptObject The javascript object.
160      */

161     public void setScriptObject( final Object JavaDoc scriptObject ) {
162         scriptObject_ = scriptObject;
163     }
164
165
166     /**
167      * Internal use only - subject to change without notice.<p>
168      * Return the javascript object that corresponds to this element.
169      * @return The javascript object that corresponsd to this element.
170      */

171     public Object JavaDoc getScriptObject() {
172         return scriptObject_;
173     }
174
175
176     /**
177      * Set the opener property. This is the WebWindow that caused this new window to be opened.
178      * @param opener The new opener
179      */

180     public void setOpener( final WebWindow opener ) {
181         opener_ = opener;
182     }
183
184
185     /**
186      * Return the opener property. This is the WebWindow that caused this new window to be opened.
187      * @return The opener
188      */

189     public WebWindow getOpener() {
190         return opener_;
191     }
192
193     /**
194      * Close this window.
195      */

196     public void close() {
197         getWebClient().deregisterWebWindow(this);
198     }
199 }
200
Popular Tags