JDIC API V0.9 Release 0

org.jdesktop.jdic.browser
Class WebBrowser

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by org.jdesktop.jdic.browser.WebBrowser
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class WebBrowser
extends java.awt.Canvas

A WebBrowser component represents a blank rectangular area of the screen onto which the application can display webpages or from which the application can trap events from the browser window. In order to show WebBrowser component in GUI, users need to add WebBrowser to a top-level container, such as Frame.

The class that is interested in processing a WebBrowser event should implement interface WebBrowserListener, and the object created with that class should use WebBrowser's addWebBrowserListener method to register as a listener.

As an AWT component, a WebBrowser component must be hosted by a native container somewhere higher up in the component tree (for example, by a JPanel object).

See Also:
WebBrowserEvent, WebBrowserListener, Serialized Form

Nested Class Summary
static class WebBrowser.Status
          Deprecated. As of release 0.9 of JDIC. Its APIs have been moved to org.jdesktop.jdic.browser.WebBrowser class. Will be removed in a future release.
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
WebBrowser()
          Constructs a new WebBrowser object with no URL specified.
WebBrowser(java.net.URL url)
          Constructs a new WebBrowser with an URL specified.
 
Method Summary
 void addNotify()
          Creates the peer for this WebBrowser component.
 void addWebBrowserListener(WebBrowserListener listener)
          Adds a WebBrowserEvent listener to the listener list.
 void back()
          Navigates backward one item in the history list.
 java.lang.String executeScript(java.lang.String javaScript)
          Executes specified JavaScript code in a currently opened document.
 void forward()
          Navigates forward one item in the history list.
static java.lang.String getBrowserBinary()
          Deprecated. As of release 0.9 of JDIC. This method was unnecessarily exposed and will be removed in a future release.
 java.lang.String getContent()
          Returns the HTML content of a document, opened in a browser.
 WebBrowser.Status getStatus()
          Deprecated. The WebBrowser.Status inner class is deprecated as of release 0.9 of JDIC. Its APIs have been moved to this Browser class. This API is no longer used, and will be removed in a future release.
 java.net.URL getURL()
          Returns the URL of the resource that is currently being displayed.
 WebBrowserListener[] getWebBrowserListeners()
          Returns an array of all the registered WebBrowser listeners.
 boolean isBackEnabled()
          Checks whether this WebBrowser object's back command is enabled.
 boolean isForwardEnabled()
          Checks whether this WebBrowser object's forward command is enabled.
 boolean isInitialized()
          Checks whether this WebBrowser object is initialized successfully.
 void refresh()
          Reloads the URL that is currently displayed in the WebBrowser component.
 void removeWebBrowserListener(WebBrowserListener listener)
          Removes a WebBrowserEvent listener from the listener list.
 void setBounds(int x, int y, int width, int height)
          Moves and resizes this component.
 void setContent(java.lang.String htmlContent)
          Sets new HTML content.
static void setDebug(boolean b)
          Enables or disables debug message output.
 void setURL()
          Sets the loaded page to be a blank page.
 void setURL(java.net.URL url)
          Navigates to a resource identified by an URL using HTTP GET method.
 void setURL(java.net.URL url, java.lang.String postData)
          Navigates to a resource identified by an URL using HTTP POST method.
 void stop()
          Stops any page loading and rendering activities.
protected  boolean willOpenURL(java.net.URL url)
          Called before every navigation operation occurs.
protected  boolean willOpenWindow()
          Called before every new window is to be created.
 
Methods inherited from class java.awt.Canvas
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, paint, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WebBrowser

public WebBrowser()
Constructs a new WebBrowser object with no URL specified.


WebBrowser

public WebBrowser(java.net.URL url)
Constructs a new WebBrowser with an URL specified.

Method Detail

addNotify

public void addNotify()
Creates the peer for this WebBrowser component. The peer allows us to modify the appearance of the WebBrowser component without changing its functionality.

Overrides:
addNotify in class java.awt.Canvas

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

Overrides:
setBounds in class java.awt.Component
Parameters:
x - - the new x-coordinate of this component
y - - the new y-coordinate of this component
width - - the new width of this component
height - - the new height of this component

addWebBrowserListener

public void addWebBrowserListener(WebBrowserListener listener)
Adds a WebBrowserEvent listener to the listener list. If listener is null, no exception is thrown and no action is performed.

Parameters:
listener - the WebBrowser event listener.

removeWebBrowserListener

public void removeWebBrowserListener(WebBrowserListener listener)
Removes a WebBrowserEvent listener from the listener list. If listener is null, no exception is thrown and no action is performed. If the listener is not in the listener list, no listener is removed.

Parameters:
listener - the WebBrowser event listener.

getWebBrowserListeners

public WebBrowserListener[] getWebBrowserListeners()
Returns an array of all the registered WebBrowser listeners.

Returns:
all of this component's WebBrowserListeners or an empty array if no component listeners are currently registered.
Since:
0.9

getURL

public java.net.URL getURL()
Returns the URL of the resource that is currently being displayed.

Returns:
the current URL being display, or null if no URL is currently displayed or the WebBrowser is not yet initialized.

setURL

public void setURL()
Sets the loaded page to be a blank page.


setURL

public void setURL(java.net.URL url)
Navigates to a resource identified by an URL using HTTP GET method.

Parameters:
url - the URL to navigate.

setURL

public void setURL(java.net.URL url,
                   java.lang.String postData)
Navigates to a resource identified by an URL using HTTP POST method.

Parameters:
url - the URL to navigate.
postData - data to send to the server during the HTTP POST transaction.

back

public void back()
Navigates backward one item in the history list.


forward

public void forward()
Navigates forward one item in the history list.


refresh

public void refresh()
Reloads the URL that is currently displayed in the WebBrowser component.


stop

public void stop()
Stops any page loading and rendering activities.


setContent

public void setContent(java.lang.String htmlContent)
Sets new HTML content.

Parameters:
htmlContent - the HTML content to set.
Since:
0.9

getContent

public java.lang.String getContent()
Returns the HTML content of a document, opened in a browser.

Returns:
the HTML content of a document, opened in a browser.
Since:
0.9

executeScript

public java.lang.String executeScript(java.lang.String javaScript)
Executes specified JavaScript code in a currently opened document. This should not be called until after a documentComplete event is fired in WebBrowserListener.

Returns:
the result of JavaScript execution, if there is any.
Since:
0.9

setDebug

public static void setDebug(boolean b)
Enables or disables debug message output. Debug message out is disabled initially by default. Calls it via reflection when necessary.

Parameters:
b - if true, debug message output is enabled; otherwise debug message output is disabled.

getStatus

public WebBrowser.Status getStatus()
Deprecated. The WebBrowser.Status inner class is deprecated as of release 0.9 of JDIC. Its APIs have been moved to this Browser class. This API is no longer used, and will be removed in a future release.

Returns a Status object, which indicates the status of this WebBrowser object.

See Also:
WebBrowser.Status

getBrowserBinary

public static java.lang.String getBrowserBinary()
Deprecated. As of release 0.9 of JDIC. This method was unnecessarily exposed and will be removed in a future release.

Returns the name of the embedded browser's native binary, which runs as a standalone native process.


isInitialized

public boolean isInitialized()
Checks whether this WebBrowser object is initialized successfully.

Returns:
true if the WebBrowser object is initialized successfully; otherwise, false.

isBackEnabled

public boolean isBackEnabled()
Checks whether this WebBrowser object's back command is enabled.

Returns:
true if the WebBrowser can navigate to the previous session history item, and false otherwise.
See Also:
back()

isForwardEnabled

public boolean isForwardEnabled()
Checks whether this WebBrowser object's forward command is enabled.

Returns:
true if the WebBrowser can navigate to the next session history item, and false otherwise.
See Also:
forward()

willOpenURL

protected boolean willOpenURL(java.net.URL url)
Called before every navigation operation occurs. A subclass could override this method to change or block URL loading.

Returns:
false will prevent the the navigation from starting; otherwise true.

willOpenWindow

protected boolean willOpenWindow()
Called before every new window is to be created. A subclass could override this method to prevent new window from popping up.

Returns:
false will prevent the new window from popping up; otherwise true.

JDIC API V0.9 Release 0

For more information and documentation on JDIC, see JDIC website.

That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, working code examples, license terms and bug report information.

Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.