Class WindowEvent
- java.lang.Object
-
- java.util.EventObject
-
- org.eclipse.swt.internal.SWTEventObject
-
- org.eclipse.swt.events.TypedEvent
-
- com.equo.chromium.swt.WindowEvent
-
- All Implemented Interfaces:
- Serializable
public class WindowEvent extends org.eclipse.swt.events.TypedEvent
AWindowEvent
is sent by aBrowser
when a new window needs to be created or when an existing window needs to be closed. This notification occurs when a javascript command such aswindow.open
orwindow.close
gets executed by aBrowser
.The following example shows how
WindowEvent
's are typically handled.
The following notifications are emitted when the user selects a hyperlink that targets a new window or as the result of a javascript that executes window.open.public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Main Window"); shell.setLayout(new FillLayout()); Browser browser = new Browser(shell, SWT.NONE); initialize(display, browser); shell.open(); browser.setUrl("http://www.eclipse.org"); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } static void initialize(final Display display, Browser browser) { browser.addOpenWindowListener(new OpenWindowListener() { public void open(WindowEvent event) { // Certain platforms can provide a default full browser. // simply return in that case if the application prefers // the default full browser to the embedded one set below. if (!event.required) return; // Embed the new window Shell shell = new Shell(display); shell.setText("New Window"); shell.setLayout(new FillLayout()); Browser browser = new Browser(shell, SWT.NONE); initialize(display, browser); event.browser = browser; } }); browser.addVisibilityWindowListener(new VisibilityWindowListener() { public void hide(WindowEvent event) { Browser browser = (Browser)event.widget; Shell shell = browser.getShell(); shell.setVisible(false); } public void show(WindowEvent event) { Browser browser = (Browser)event.widget; Shell shell = browser.getShell(); if (event.location != null) shell.setLocation(event.location); if (event.size != null) { Point size = event.size; shell.setSize(shell.computeSize(size.x, size.y)); } if (event.addressBar || event.menuBar || event.statusBar || event.toolBar) { // Create widgets for the address bar, menu bar, status bar and/or tool bar // leave enough space in the Shell to accommodate a Browser of the size // given by event.size } shell.open(); } }); browser.addCloseWindowListener(new CloseWindowListener() { public void close(WindowEvent event) { Browser browser = (Browser)event.widget; Shell shell = browser.getShell(); shell.close(); } }); }
Main Browser
- User selects a link that opens in a new window or javascript requests a new window
- OpenWindowListener.open() notified
- Application creates a new Shell and a second Browser inside that Shell
- Application registers WindowListener's on that second Browser, such as VisibilityWindowListener
- Application returns the second Browser as the host for the new window content
Second Browser
- VisibilityWindowListener.show() notified
- Application sets navigation tool bar, status bar, menu bar and Shell size
- Application makes the Shell hosting the second Browser visible
- User now sees the new window
- Since:
- 3.0
- See Also:
CloseWindowListener
,OpenWindowListener
,VisibilityWindowListener
, Sample code and further information, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description boolean
addressBar
Specifies whether theShell
hosting theBrowser
should display an address bar.Browser
browser
Browser
provided by the application.org.eclipse.swt.graphics.Point
location
Requested location for theShell
hosting theBrowser
.boolean
menuBar
Specifies whether theShell
hosting theBrowser
should display a menu bar.boolean
required
Specifies whether the platform requires the user to provide aBrowser
to handle the new window.org.eclipse.swt.graphics.Point
size
RequestedBrowser
size.boolean
statusBar
Specifies whether theShell
hosting theBrowser
should display a status bar.boolean
toolBar
Specifies whether theShell
hosting theBrowser
should display a tool bar.
-
Constructor Summary
Constructors Constructor and Description WindowEvent(org.eclipse.swt.widgets.Widget widget)
Constructs a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description String
toString()
Returns a string containing a concise, human-readable description of the receiver.-
Methods inherited from class java.util.EventObject
getSource
-
-
-
-
Field Detail
-
required
public boolean required
Specifies whether the platform requires the user to provide aBrowser
to handle the new window.- Since:
- 3.1
-
browser
public Browser browser
Browser
provided by the application.
-
location
public org.eclipse.swt.graphics.Point location
Requested location for theShell
hosting theBrowser
. It isnull
if no location has been requested.
-
size
public org.eclipse.swt.graphics.Point size
RequestedBrowser
size. The client area of theShell
hosting theBrowser
should be large enough to accommodate that size. It isnull
if no size has been requested.
-
addressBar
public boolean addressBar
Specifies whether theShell
hosting theBrowser
should display an address bar.- Since:
- 3.1
-
menuBar
public boolean menuBar
Specifies whether theShell
hosting theBrowser
should display a menu bar. Note that this is alwaystrue
on OS X.- Since:
- 3.1
-
statusBar
public boolean statusBar
Specifies whether theShell
hosting theBrowser
should display a status bar.- Since:
- 3.1
-
toolBar
public boolean toolBar
Specifies whether theShell
hosting theBrowser
should display a tool bar.- Since:
- 3.1
-
-
Constructor Detail
-
WindowEvent
public WindowEvent(org.eclipse.swt.widgets.Widget widget)
Constructs a new instance of this class.- Parameters:
widget
- the widget that fired the event- Since:
- 3.5
-
-
Method Detail
-
toString
public String toString()
Returns a string containing a concise, human-readable description of the receiver.- Overrides:
toString
in classorg.eclipse.swt.events.TypedEvent
- Returns:
- a string representation of the event
-
-
Copyright © 2024. All rights reserved.