org.lobobrowser.html.gui

Class HtmlPanel

Implemented Interfaces:
FrameContext
Known Direct Subclasses:
SimpleBrowserFrame

public class HtmlPanel
extends JComponent
implements FrameContext

The HtmlPanel class is a Swing component that can render a HTML DOM.
Author:
J. H. S.

Constructor Summary

HtmlPanel()
Constructs an HtmlPanel.

Method Summary

void
addSelectionChangeListener(SelectionChangeListener listener)
Adds listener of selection changes.
void
clearDocument()
Clears the current document if any.
boolean
copy()
Copies the current selection, if any, into the clipboard.
protected FrameSetPanel
createFrameSetPanel()
Method invoked internally to create a FrameSetPanel.
protected HtmlBlockPanel
createHtmlBlockPanel(UserAgentContext ucontext, HtmlRendererContext rcontext)
Method invoked internally to create a HtmlBlockPanel.
void
delayedRelayout(NodeImpl node)
Invalidates the layout of the given node and schedules it to be layed out later.
void
expandSelection(RenderableSpot rpoint)
Internal method used to expand the selection to the given point.
BoundableRenderable
getBlockRenderable()
Gets the root Renderable of the HTML block.
FrameSetPanel
getFrameSetPanel()
Gets an instance of FrameSetPanel in case the currently rendered page is a FRAMESET.
NodeImpl
getRootNode()
Gets the HTML DOM node currently rendered if any.
org.w3c.dom.Node
getSelectionNode()
Gets a DOM node enclosing the selection.
String
getSelectionText()
Gets the selection text.
boolean
hasSelection()
Returns true only if the current block has a selection.
void
removeSelectionChangeListener(SelectionChangeListener listener)
Removes a listener of selection changes that was previously added.
void
resetSelection(RenderableSpot rpoint)
Internal method used to reset the selection so that it is empty at the given point.
void
scroll(int x, int y)
Scrolls the document such that x and y coordinates are placed in the upper-left corner of the panel.
void
setDocument(Document node, HtmlRendererContext rcontext)
Sets an HTML DOM node and invalidates the component so it is rendered as soon as possible in the GUI thread.
void
setDocument(Document node, HtmlRendererContext rcontext, HtmlParserContext pcontext)
Deprecated. HtmlParserContext is no longer used here.
void
setHtml(String htmlSource, String uri, HtmlRendererContext rcontext)
Renders HTML given as a string.
void
setPreferredWidth(int width)
Sets a preferred width that serves as a hint in calculating the preferred size of the HtmlPanel.

Constructor Details

HtmlPanel

public HtmlPanel()
Constructs an HtmlPanel.

Method Details

addSelectionChangeListener

public void addSelectionChangeListener(SelectionChangeListener listener)
Adds listener of selection changes. Note that it does not have any effect on FRAMESETs.
Parameters:
listener - An instance of SelectionChangeListener.

clearDocument

public void clearDocument()
Clears the current document if any. If called outside the GUI thread, the operation will be scheduled to be performed in the GUI thread.

copy

public boolean copy()
Copies the current selection, if any, into the clipboard. This method has no effect in FRAMESETs at the moment.

createFrameSetPanel

protected FrameSetPanel createFrameSetPanel()
Method invoked internally to create a FrameSetPanel. It is made available so it can be overridden.

createHtmlBlockPanel

protected HtmlBlockPanel createHtmlBlockPanel(UserAgentContext ucontext,
                                              HtmlRendererContext rcontext)
Method invoked internally to create a HtmlBlockPanel. It is made available so it can be overridden.

delayedRelayout

public void delayedRelayout(NodeImpl node)
Invalidates the layout of the given node and schedules it to be layed out later. Multiple invalidations may be processed in a single document layout.
Specified by:
delayedRelayout in interface FrameContext

expandSelection

public void expandSelection(RenderableSpot rpoint)
Internal method used to expand the selection to the given point.

Note: This method should be invoked in the GUI thread.

Specified by:
expandSelection in interface FrameContext

getBlockRenderable

public BoundableRenderable getBlockRenderable()
Gets the root Renderable of the HTML block. It returns null for FRAMESETs.

getFrameSetPanel

public FrameSetPanel getFrameSetPanel()
Gets an instance of FrameSetPanel in case the currently rendered page is a FRAMESET.

Note: This method should be invoked in the GUI thread.

Returns:
A FrameSetPanel instance or null if the document currently rendered is not a FRAMESET.

getRootNode

public NodeImpl getRootNode()
Gets the HTML DOM node currently rendered if any.

getSelectionNode

public org.w3c.dom.Node getSelectionNode()
Gets a DOM node enclosing the selection. The node returned should be the inner-most node that encloses both selection start and end points. Note that the selection end point may be just outside of the selection.

Note: This method should be invoked in the GUI thread.


getSelectionText

public String getSelectionText()
Gets the selection text.

Note: This method should be invoked in the GUI thread.


hasSelection

public boolean hasSelection()
Returns true only if the current block has a selection. This method has no effect in FRAMESETs at the moment.

removeSelectionChangeListener

public void removeSelectionChangeListener(SelectionChangeListener listener)
Removes a listener of selection changes that was previously added.

resetSelection

public void resetSelection(RenderableSpot rpoint)
Internal method used to reset the selection so that it is empty at the given point. This is what is called when the user clicks on a point in the document.

Note: This method should be invoked in the GUI thread.

Specified by:
resetSelection in interface FrameContext

scroll

public void scroll(int x,
                   int y)
Scrolls the document such that x and y coordinates are placed in the upper-left corner of the panel.
Parameters:
x - The x coordinate.
y - The y coordinate.

setDocument

public void setDocument(Document node,
                        HtmlRendererContext rcontext)
Sets an HTML DOM node and invalidates the component so it is rendered as soon as possible in the GUI thread.

If this method is called from a thread that is not the GUI dispatch thread, the document is scheduled to be set later. Note that preferred size calculations should be done in the GUI dispatch thread for this reason.

Parameters:
node - This should normally be a Document instance obtained with DocumentBuilderImpl.

rcontext - A renderer context.

setDocument

public void setDocument(Document node,
                        HtmlRendererContext rcontext,
                        HtmlParserContext pcontext)

Deprecated. HtmlParserContext is no longer used here.

Sets an HTML DOM node and invalidates the component so it is rendered immediately in the GUI thread.
Parameters:
node - This should normally be a Document instance obtained with DocumentBuilderImpl.

Note: It is safe to call this method outside of the GUI thread.

rcontext - A renderer context.
pcontext - A parser context.

setHtml

public void setHtml(String htmlSource,
                    String uri,
                    HtmlRendererContext rcontext)
Renders HTML given as a string.

setPreferredWidth

public void setPreferredWidth(int width)
Sets a preferred width that serves as a hint in calculating the preferred size of the HtmlPanel. Note that the preferred size can only be calculated when a document is available, and it will vary during incremental rendering.

This method currently does not have any effect when the document is a FRAMESET.

Note also that setting the preferred width to a value other than -1 (the default) will have an effect in renderer performance.

Parameters:
width - The preferred width, or -1 to unset.