buoy.widget
Class BDocumentViewer

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.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(java.net.URL document)
          Create a new BDocumentViewer displaying the document referenced by a URL.
 
Method Summary
 javax.swing.JEditorPane getComponent()
          Get the java.awt.Component corresponding to this Widget.
 java.lang.String getContentType()
          Get the MIME type of the document currently being displayed.
 java.net.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(java.lang.String text, java.lang.String type)
          Set the document to display in this BDocumentViewer.
 void setDocument(java.net.URL document)
          Set the document to display in this BDocumentViewer.
 
Methods inherited from class buoy.widget.Widget
addEventLink, dispatchEvent, getBackground, getBounds, 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, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BDocumentViewer

public BDocumentViewer()
Create an empty BDocumentViewer.


BDocumentViewer

public BDocumentViewer(java.net.URL document)
                throws java.io.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
Throws:
java.io.IOException
Method Detail

getComponent

public javax.swing.JEditorPane getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

getDocument

public java.net.URL getDocument()
Get the URL for the document currently being displayed. If the document was not specified by a URL, this returns null.


setDocument

public void setDocument(java.net.URL document)
                 throws java.io.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
Throws:
java.io.IOException

setDocument

public void setDocument(java.lang.String text,
                        java.lang.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

getContentType

public java.lang.String getContentType()
Get the MIME type of the document currently being displayed.


processLinkEvent

public void processLinkEvent(DocumentLinkEvent event)
                      throws java.io.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.

Throws:
java.io.IOException


Written by Peter Eastman.