buoy.widget

Class BDocumentViewer


public class BDocumentViewer
extends Widget

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:

Author:
Peter Eastman

Constructor Summary

BDocumentViewer()
Create an empty BDocumentViewer.
BDocumentViewer(URL document)
Create a new BDocumentViewer displaying the document referenced by a URL.

Method Summary

String
getContentType()
Get the MIME type of the document currently being displayed.
URL
getDocument()
Get the URL for the document currently being displayed.
void
processLinkEvent(DocumentLinkEvent event)
Process a DocumentLinkEvent generated by this viewer, and handle it appropriately.
void
setDocument(String text, String type)
Set the document to display in this BDocumentViewer.
void
setDocument(URL document)
Set the document to display in this BDocumentViewer.

Methods inherited from class buoy.widget.Widget

addEventLink, dispatchEvent, getBackground, getBounds, getComponent, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible

Methods inherited from class buoy.event.EventSource

addEventLink, addEventLink, addEventLink, dispatchEvent, removeEventLink

Constructor Details

BDocumentViewer

public BDocumentViewer()
Create an empty BDocumentViewer.

BDocumentViewer

public BDocumentViewer(URL document)
            throws IOException
Create a new BDocumentViewer displaying the document referenced by a URL. 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).
Parameters:
document - a URL pointing to the document to display

Method Details

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".
Parameters:
text - the text of the document to display
type - 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).
Parameters:
document - a URL pointing to the document to display

Written by Peter Eastman.