A BDocumentViewer is used for displaying formatted text documents. The supported document types include HTML,
Rich Text Format (RTF), and plain text. This class is most often used for displaying help screens or
documentation within a program.
When the user clicks on a hyperlink inside an HTML document, the BDocumentViewer generates a
DocumentLinkEvent
. You can then pass that event to
processLinkEvent()
, which will load the
new document pointed to by the hyperlink. This can be done most easily by having the BDocumentViewer
listen for its own events directly:
viewer.addEventLink(DocumentLinkEvent.class, viewer, "processLinkEvent");
Alternatively, you can have another object listen for the events and then pass them on to the
BDocumentViewer. This would be useful, for example, if you wanted to filter the events and only
allow certain hyperlinks to be followed.
When you tell the BDocumentViewer to load a new document, either by calling
setDocument()
or
processLinkEvent()
, the loading is usually
done asynchronously. When loading is complete, it generates a
ValueChangedEvent
. If you want to show a
progress bar while the document is being loaded, for example, you can listen for the event to
know when to stop animating the progress bar.
In addition to the event types generated by all Widgets, BDocumentViewers generate the following event types:
getContentType
public String getContentType()
Get the MIME type of the document currently being displayed.
getDocument
public URL getDocument()
Get the URL for the document currently being displayed. If the document was not specified
by a URL, this returns null.
processLinkEvent
public void processLinkEvent(DocumentLinkEvent event)
throws IOException
Process a DocumentLinkEvent generated by this viewer, and handle it appropriately. Depending
on the event, this causes either the entire document, or the contents of one frame, to be
replaced with the link target.
setDocument
public void setDocument(String text,
String type)
Set the document to display in this BDocumentViewer. So that the viewer can know how to
interpret the document contents, you must specify its MIME type. Currently supported types
include "text/plain", "text/html", and "text/rtf".
text
- the text of the document to displaytype
- the MIME type of the document
setDocument
public void setDocument(URL document)
throws IOException
Set the document to display in this BDocumentViewer. Depending on the
location and type of document, it may be loaded either synchronously or ansynchronously. For
this reason, no assumptions should be made about whether the document has been loaded when this
method returns. This method may throw an IOException if an error occurs while loading the
document, but the lack of an exception cannot be taken to mean that the document was loaded
successfully (in the case of asynchronous loading).
document
- a URL pointing to the document to display