public class Browser extends Composite
Note that although this class is a subclass of Composite
,
it does not make sense to set a layout on it.
IMPORTANT: This class is not intended to be subclassed.
Currently implemented
The enabled property in not (yet) evaluated.
Focus events are not yet implemented
Constructor and Description |
---|
Browser(Composite parent,
int style)
Constructs a new instance of this class given its parent
and a style value describing its behavior and appearance.
|
Modifier and Type | Method and Description |
---|---|
void |
addLocationListener(LocationListener listener)
Adds the listener to the collection of listeners who will be
notified when the current location has changed or is about to change.
|
void |
addProgressListener(ProgressListener listener)
Adds the listener to the collection of listeners who will be
notified when a progress is made during the loading of the current
URL or when the loading of the current URL has been completed.
|
protected void |
checkWidget()
Throws an
SWTException if the receiver can not
be accessed by the caller. |
java.lang.Object |
evaluate(java.lang.String script)
Returns the result, if any, of executing the specified script.
|
void |
evaluate(java.lang.String script,
BrowserCallback browserCallback)
Executes the given script in a non-blocking way.
|
boolean |
execute(java.lang.String script)
Execute the specified script.
|
<T> T |
getAdapter(java.lang.Class<T> adapter)
Implementation of the
Adaptable interface. |
java.lang.String |
getUrl()
Returns the current URL.
|
java.lang.Object |
getWebBrowser()
Returns the JavaXPCOM
nsIWebBrowser for the receiver, or null
if it is not available. |
void |
removeLocationListener(LocationListener listener)
Removes the listener from the collection of listeners who will
be notified when the current location is changed or about to be changed.
|
void |
removeProgressListener(ProgressListener listener)
Removes the listener from the collection of listeners who will
be notified when a progress is made during the loading of the current
URL or when the loading of the current URL has been completed.
|
boolean |
setText(java.lang.String html)
Renders HTML.
|
boolean |
setUrl(java.lang.String url)
Loads a URL.
|
changed, computeSize, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addTouchListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getShell, getSize, getToolTipText, getTouchEnabled, getVisible, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCursor, setData, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setSize, setSize, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, update
addDisposeListener, addListener, checkSubclass, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, toString
public Browser(Composite parent, int style)
The style value is either one of the style constants defined in
class SWT
which is applicable to instances of this
class, or must be built by bitwise OR'ing together
(that is, using the int
"|" operator) two or more
of those SWT
style constants. The class description
lists the style constants that are applicable to the class.
Style bits are also inherited from superclasses.
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to constructjava.lang.IllegalArgumentException
- SWTException
- SWTError
- Widget.getStyle()
public boolean setUrl(java.lang.String url)
url
- the URL to be loadedjava.lang.IllegalArgumentException
- SWTException
- getUrl()
public java.lang.String getUrl()
String
if there is no current URLSWTException
- setUrl(java.lang.String)
public boolean setText(java.lang.String html)
The html parameter is Unicode encoded since it is a java String
.
As a result, the HTML meta tag charset should not be set. The charset is implied
by the String
itself.
html
- the HTML content to be renderedjava.lang.IllegalArgumentException
- SWTException
- setUrl(java.lang.String)
public boolean execute(java.lang.String script)
Execute a script containing javascript commands in the context of the current document.
RAP Note: Care should be taken when using this method.
The given script
is executed in an IFRAME
inside the document that represents the client-side application.
Since the execution context of an IFRAME
is not fully
isolated from the surrounding document it may break the client-side
application.
This method is not supported when running the application in JEE_COMPATIBILITY mode.
Use evaluate(String, BrowserCallBack)
instead.
This method will throw an IllegalStateException if called while another script is still pending or executed. This can happen if called within a BrowserFunction, or if an SWT event is pending to be executed. (E.g. clicking a Button twice very fast.)
script
- the script with javascript commandstrue
if the operation was successful and
false
otherwisejava.lang.IllegalArgumentException
- SWTException
- java.lang.UnsupportedOperationException
- when running the application in JEE_COMPATIBILITY modejava.lang.IllegalStateException
- when another script is already being executed.Application.OperationMode
public java.lang.Object evaluate(java.lang.String script) throws SWTException
Evaluates a script containing javascript commands in the context of
the current document. If document-defined functions or properties
are accessed by the script then this method should not be invoked
until the document has finished loading (ProgressListener.completed()
gives notification of this).
If the script returns a value with a supported type then a java representation of the value is returned. The supported javascript -> java mappings are:
null
java.lang.Double
java.lang.String
java.lang.Boolean
java.lang.Object[]
SWTException
is thrown if the return value has an
unsupported type, or if evaluating the script causes a javascript
error to be thrown.
RAP Note: Care should be taken when using this method.
The given script
is executed in an IFRAME
inside the document that represents the client-side application.
Since the execution context of an IFRAME
is not fully
isolated from the surrounding document it may break the client-side
application.
This method is not supported when running the application in JEE_COMPATIBILITY mode.
Use evaluate(String, BrowserCallback)
instead.
This method will throw an IllegalStateException if called while another script is still pending or executed. This can happen if called within a BrowserFunction, or if an SWT event is pending to be executed. (E.g. clicking a Button twice very fast.)
script
- the script with javascript commandsjava.lang.IllegalArgumentException
- SWTException
- java.lang.UnsupportedOperationException
- when running the application in JEE_COMPATIBILITY modejava.lang.IllegalStateException
- when another script is already being executed.ProgressListener.completed(ProgressEvent)
,
Application.OperationMode
public void evaluate(java.lang.String script, BrowserCallback browserCallback)
browserCallback
is notified
when the result from the operation is available.
Use this method instead of the execute()
or evaluate()
methods when
running in JEE_COMPATIBILITY mode.
This method will throw an IllegalStateException if called while another script is still pending to be executed.
script
- the script to execute, must not be null
.browserCallback
- the callback to be notified when the result from the script execution is
available, must not be null
.java.lang.IllegalStateException
- when another script is already being executed.BrowserCallback
,
Application.OperationMode
public void addLocationListener(LocationListener listener)
This notification typically occurs when the application navigates
to a new location with setUrl(String)
or when the user
activates a hyperlink.
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeLocationListener(LocationListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void addProgressListener(ProgressListener listener)
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeProgressListener(ProgressListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public <T> T getAdapter(java.lang.Class<T> adapter)
Widget
Adaptable
interface.
IMPORTANT: This method is not part of the RWT public API. It is marked public only so that it can be shared within the packages provided by RWT. It should never be accessed from application code.
getAdapter
in interface Adaptable
getAdapter
in class Composite
adapter
- the lookup classnull
if
there is no adapter associated with the given class.public java.lang.Object getWebBrowser()
nsIWebBrowser
for the receiver, or null
if it is not available. In order for an nsIWebBrowser
to be returned all
of the following must be true: SWT.MOZILLA
nsIWebBrowser
or null
protected void checkWidget()
Widget
SWTException
if the receiver can not
be accessed by the caller. This may include both checks on
the state of the receiver and more generally on the entire
execution context. This method should be called by
widget implementors to enforce the standard SWT invariants.
Currently, it is an error to invoke any method (other than
isDisposed()
) on a widget that has had its
dispose()
method called. It is also an error
to call widget methods from any thread that is different
from the thread that created the widget.
In future releases of SWT, there may be more or fewer error checks and exceptions may be thrown for different reasons.
checkWidget
in class Widget
Copyright (c) EclipseSource and others 2002, 2017.
All rights reserved. This program and the accompanying materials
are made available under the terms of the
Eclipse Public License v1.0