Class Browser
- java.lang.Object
-
- org.eclipse.swt.widgets.Widget
-
- org.eclipse.swt.widgets.Control
-
- org.eclipse.swt.widgets.Scrollable
-
- org.eclipse.swt.widgets.Composite
-
- org.eclipse.swt.browser.Browser
-
public class Browser extends Composite
Instances of this class implement the browser user interface metaphor. It allows the user to visualize and navigate through HTML documents.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.
- Since:
- 1.0
Currently implemented
- text and url property
The enabled property in not (yet) evaluated.
Focus events are not yet implemented
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLocationListener(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.voidaddProgressListener(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 voidcheckWidget()Throws anSWTExceptionif the receiver can not be accessed by the caller.java.lang.Objectevaluate(java.lang.String script)Returns the result, if any, of executing the specified script.voidevaluate(java.lang.String script, BrowserCallback browserCallback)Executes the given script in a non-blocking way.booleanexecute(java.lang.String script)Execute the specified script.<T> TgetAdapter(java.lang.Class<T> adapter)Implementation of theAdaptableinterface.java.lang.StringgetBrowserType()Returns the type of native browser being used by this instance.java.lang.StringgetUrl()Returns the current URL.java.lang.ObjectgetWebBrowser()Returns the JavaXPCOMnsIWebBrowserfor the receiver, ornullif it is not available.voidremoveLocationListener(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.voidremoveProgressListener(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.booleansetText(java.lang.String html)Renders HTML.booleansetUrl(java.lang.String url)Loads a URL.-
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, computeSize, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
-
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
-
Methods inherited from class org.eclipse.swt.widgets.Control
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
-
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, toString
-
-
-
-
Constructor Detail
-
Browser
public Browser(Composite parent, int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.The style value is either one of the style constants defined in class
SWTwhich is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint"|" operator) two or more of thoseSWTstyle constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent- a widget which will be the parent of the new instance (cannot be null)style- the style of widget to construct- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError-- ERROR_NO_HANDLES if a handle could not be obtained for browser creation
- See Also:
Widget.getStyle()
-
-
Method Detail
-
setUrl
public boolean setUrl(java.lang.String url)
Loads a URL.- Parameters:
url- the URL to be loaded- Returns:
- true if the operation was successful and false otherwise.
- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the url is null
SWTException-- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
- See Also:
getUrl()
-
getUrl
public java.lang.String getUrl()
Returns the current URL.- Returns:
- the current URL or an empty
Stringif there is no current URL - Throws:
SWTException-- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
- See Also:
setUrl(java.lang.String)
-
setText
public boolean setText(java.lang.String html)
Renders 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 theStringitself.- Parameters:
html- the HTML content to be rendered- Returns:
- true if the operation was successful and false otherwise.
- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the html is null
SWTException-- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
- See Also:
setUrl(java.lang.String)
-
execute
public boolean execute(java.lang.String script)
Execute the specified 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
scriptis executed in anIFRAMEinside the document that represents the client-side application. Since the execution context of anIFRAMEis 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.)
- Parameters:
script- the script with javascript commands- Returns:
trueif the operation was successful andfalseotherwise- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the script is null
SWTException-- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
java.lang.UnsupportedOperationException- when running the application in JEE_COMPATIBILITY modejava.lang.IllegalStateException- when another script is already being executed.- Since:
- 1.1
- See Also:
Application.OperationMode
-
evaluate
public java.lang.Object evaluate(java.lang.String script) throws SWTExceptionReturns the result, if any, of executing the specified script.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:
- javascript null or undefined ->
null - javascript number ->
java.lang.Double - javascript string ->
java.lang.String - javascript boolean ->
java.lang.Boolean - javascript array whose elements are all of supported types ->
java.lang.Object[]
SWTExceptionis 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
scriptis executed in anIFRAMEinside the document that represents the client-side application. Since the execution context of anIFRAMEis 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.)
- Parameters:
script- the script with javascript commands- Returns:
- the return value, if any, of executing the script
- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the script is null
SWTException-- ERROR_FAILED_EVALUATE when the script evaluation causes a javascript error to be thrown
- ERROR_INVALID_RETURN_VALUE when the script returns a value of unsupported type
- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
java.lang.UnsupportedOperationException- when running the application in JEE_COMPATIBILITY modejava.lang.IllegalStateException- when another script is already being executed.- Since:
- 1.4
- See Also:
ProgressListener.completed(ProgressEvent),Application.OperationMode
- javascript null or undefined ->
-
evaluate
public void evaluate(java.lang.String script, BrowserCallback browserCallback)Executes the given script in a non-blocking way. ThebrowserCallbackis notified when the result from the operation is available.Use this method instead of the
execute()orevaluate()methods when running in JEE_COMPATIBILITY mode.This method will throw an IllegalStateException if called while another script is still pending to be executed.
- Parameters:
script- the script to execute, must not benull.browserCallback- the callback to be notified when the result from the script execution is available, must not benull.- Throws:
java.lang.IllegalStateException- when another script is already being executed.- Since:
- 3.1
- See Also:
BrowserCallback,Application.OperationMode
-
addLocationListener
public 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.This notification typically occurs when the application navigates to a new location with
setUrl(String)or when the user activates a hyperlink.- Parameters:
listener- the listener which should be notified- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException-- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
-
removeLocationListener
public 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.- Parameters:
listener- the listener which should no longer be notified- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException-- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
-
addProgressListener
public 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.- Parameters:
listener- the listener which should be notified- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException-- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
- Since:
- 1.4
-
removeProgressListener
public 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.- Parameters:
listener- the listener which should no longer be notified- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException-- ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- ERROR_WIDGET_DISPOSED when the widget has been disposed
- Since:
- 1.4
-
getAdapter
public <T> T getAdapter(java.lang.Class<T> adapter)
Description copied from class:WidgetImplementation of theAdaptableinterface.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.
- Specified by:
getAdapterin interfaceAdaptable- Overrides:
getAdapterin classComposite- Parameters:
adapter- the lookup class- Returns:
- an object that can be cast to the given class or
nullif there is no adapter associated with the given class.
-
getWebBrowser
public java.lang.Object getWebBrowser()
Returns the JavaXPCOMnsIWebBrowserfor the receiver, ornullif it is not available. In order for annsIWebBrowserto be returned all of the following must be true:- the receiver's style must be
SWT.MOZILLA - the classes from JavaXPCOM >= 1.8.1.2 must be resolvable at runtime
- the version of the underlying XULRunner must be >= 1.8.1.2
- Returns:
- the receiver's JavaXPCOM
nsIWebBrowserornull - Since:
- 1.4
- the receiver's style must be
-
getBrowserType
public java.lang.String getBrowserType()
Returns the type of native browser being used by this instance.- Returns:
- the type of the native browser
- Since:
- 3.13
-
checkWidget
protected void checkWidget()
Description copied from class:WidgetThrows anSWTExceptionif 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 itsdispose()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.
- Overrides:
checkWidgetin classWidget
-
-