KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > browser > WindowEvent


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.browser;
12
13 import org.eclipse.swt.widgets.*;
14 import org.eclipse.swt.events.*;
15 import org.eclipse.swt.graphics.*;
16
17 /**
18  * A <code>WindowEvent</code> is sent by a {@link Browser} when
19  * a new window needs to be created or when an existing window needs to be
20  * closed. This notification occurs when a javascript command such as
21  * <code>window.open</code> or <code>window.close</code> gets executed by
22  * a <code>Browser</code>.
23  *
24  * <p>
25  * The following example shows how <code>WindowEvent</code>'s are typically
26  * handled.
27  *
28  * <code><pre>
29  * public static void main(String[] args) {
30  * Display display = new Display();
31  * Shell shell = new Shell(display);
32  * shell.setText("Main Window");
33  * shell.setLayout(new FillLayout());
34  * Browser browser = new Browser(shell, SWT.NONE);
35  * initialize(display, browser);
36  * shell.open();
37  * browser.setUrl("http://www.eclipse.org");
38  * while (!shell.isDisposed()) {
39  * if (!display.readAndDispatch())
40  * display.sleep();
41  * }
42  * display.dispose();
43  * }
44  *
45  * static void initialize(final Display display, Browser browser) {
46  * browser.addOpenWindowListener(new OpenWindowListener() {
47  * public void open(WindowEvent event) {
48  * // Certain platforms can provide a default full browser.
49  * // simply return in that case if the application prefers
50  * // the default full browser to the embedded one set below.
51  * if (!event.required) return;
52  *
53  * // Embed the new window
54  * Shell shell = new Shell(display);
55  * shell.setText("New Window");
56  * shell.setLayout(new FillLayout());
57  * Browser browser = new Browser(shell, SWT.NONE);
58  * initialize(display, browser);
59  * event.browser = browser;
60  * }
61  * });
62  * browser.addVisibilityWindowListener(new VisibilityWindowListener() {
63  * public void hide(WindowEvent event) {
64  * Browser browser = (Browser)event.widget;
65  * Shell shell = browser.getShell();
66  * shell.setVisible(false);
67  * }
68  * public void show(WindowEvent event) {
69  * Browser browser = (Browser)event.widget;
70  * Shell shell = browser.getShell();
71  * if (event.location != null) shell.setLocation(event.location);
72  * if (event.size != null) {
73  * Point size = event.size;
74  * shell.setSize(shell.computeSize(size.x, size.y));
75  * }
76  * if (event.addressBar || event.menuBar || event.statusBar || event.toolBar) {
77  * // Create widgets for the address bar, menu bar, status bar and/or tool bar
78  * // leave enough space in the Shell to accommodate a Browser of the size
79  * // given by event.size
80  * }
81  * shell.open();
82  * }
83  * });
84  * browser.addCloseWindowListener(new CloseWindowListener() {
85  * public void close(WindowEvent event) {
86  * Browser browser = (Browser)event.widget;
87  * Shell shell = browser.getShell();
88  * shell.close();
89  * }
90  * });
91  * }
92  * </pre></code>
93  *
94  * The following notifications are emitted when the user selects a hyperlink that targets a new window
95  * or as the result of a javascript that executes window.open.
96  *
97  * <p>Main Browser
98  * <ul>
99  * <li>User selects a link that opens in a new window or javascript requests a new window</li>
100  * <li>OpenWindowListener.open() notified</li>
101  * <ul>
102  * <li>Application creates a new Shell and a second Browser inside that Shell</li>
103  * <li>Application registers WindowListener's on that second Browser, such as VisibilityWindowListener</li>
104  * <li>Application returns the second Browser as the host for the new window content</li>
105  * </ul>
106  * </ul>
107  *
108  * <p>Second Browser
109  * <ul>
110  * <li>VisibilityWindowListener.show() notified</li>
111  * <ul>
112  * <li>Application sets navigation tool bar, status bar, menu bar and Shell size
113  * <li>Application makes the Shell hosting the second Browser visible
114  * <li>User now sees the new window
115  * </ul>
116  * </ul>
117  *
118  * @see CloseWindowListener
119  * @see OpenWindowListener
120  * @see VisibilityWindowListener
121  *
122  * @since 3.0
123  */

124 public class WindowEvent extends TypedEvent {
125
126     /**
127      * Specifies whether the platform requires the user to provide a
128      * <code>Browser</code> to handle the new window.
129      *
130      * @since 3.1
131      */

132     public boolean required;
133     
134     
135     /**
136      * <code>Browser</code> provided by the application.
137      */

138     public Browser browser;
139
140     /**
141      * Requested location for the <code>Shell</code> hosting the <code>Browser</code>.
142      * It is <code>null</code> if no location has been requested.
143      */

144     public Point location;
145
146     /**
147      * Requested <code>Browser</code> size. The client area of the <code>Shell</code>
148      * hosting the <code>Browser</code> should be large enough to accommodate that size.
149      * It is <code>null</code> if no size has been requested.
150      */

151     public Point size;
152     
153     /**
154      * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should
155      * display an address bar.
156      *
157      * @since 3.1
158      */

159     public boolean addressBar;
160
161     /**
162      * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should
163      * display a menu bar.
164      *
165      * @since 3.1
166      */

167     public boolean menuBar;
168     
169     /**
170      * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should
171      * display a status bar.
172      *
173      * @since 3.1
174      */

175     public boolean statusBar;
176     
177     /**
178      * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should
179      * display a tool bar.
180      *
181      * @since 3.1
182      */

183     public boolean toolBar;
184     
185     static final long serialVersionUID = 3617851997387174969L;
186     
187 WindowEvent(Widget w) {
188     super(w);
189 }
190 }
191
Popular Tags