net.sourceforge.sillyview
Class HTMLPane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JEditorPane
                      extended by net.sourceforge.sillyview.HTMLPane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
Direct Known Subclasses:
HTMLPaneView

public class HTMLPane
extends JEditorPane

This class is a convenience class for JEditorPanes used to show HTML content that are un-editable (so as to enable listening for hyperlink events) and handle UTF-8 characters gracefully. It wouldn't be strictly necessary were it not for some bugs in the Java 1.4.2 StyledDocument api (getlength()=0). This class keeps its own copy of the EditorPane's text to work around the getLength, and subsequent getText problems. Important to note is that a HTMLPane is aware of and responsive to Swing Pluggable LookAndFeel colors. JEditorPanes are ignorant of changes to LookAndFeel. You can plug in your own LookAndFeel to StyleSheet converter by subclassing LookAndFeelToCSS and using HTMLPane's setConverter() method. The default BasicLookAndFeelToCSS converter may well not handle your favorite LookAndFeel (Swing's default Metal LookAndFeel is supported) , and you may be forced to write a LookAndFeelToCSS converter for it. A "theme" stylesheet (the result of a conversion) does not override styles implemented directly in the HTML document or included in the HTML document. It does override all other styles.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JEditorPane
JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupport
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
HTMLPane()
          Creates a new HTMLPane instance with no text.
HTMLPane(String text)
          Creates a new HTMLPane instance with the given text.
HTMLPane(String text, StyleSheet theme)
          Creates a new HTMLPane instance with the given text and stylesheet.
HTMLPane(StyleSheet theme)
          Creates a new HTMLPane instance with the given stylesheet.
HTMLPane(URL initialPage)
          Creates a new HTMLPane instance showing the HTML page at the given URL and with no accessory stylesheet.
HTMLPane(URL initialPage, StyleSheet theme)
          Creates a new HTMLPane instance showing the HTML page at the given URL and with the given accesory stylesheet.
 
Method Summary
 void addHyperlinkListener(HyperlinkListener listener)
          Add a HyperlinkListener to this pane.
 void doLayout()
          Tries to do super.doLayout() and warns if this causes an exception.
 void dump()
          Dumps the current stylesheet for debugging.
 void dump(StyleSheet styles)
          Sends all style rules to be printed out to System.out.
 void forceValidate()
           
 LookAndFeelToCSS getConverter()
          Describe getConverter method here.
protected static String getDocument(URL u)
          Returns the HTML document at the given URL as a String.
protected  StyleSheet getDocumentStyleSheet()
          Returns the stylesheet for the current document.
 void setAutoDump(boolean newAutoDump)
          Setting autoDump to true causes the stylesheet to be printed every time it is changed.
 void setConverter(LookAndFeelToCSS conv)
          Allows you to plug in a LookAndFeel to CSS converter of your choice.
 void setText(String text)
          Sets the text and clears and clears any applied "theme" stylesheets.
protected  void setTheme(String styleSheetUrl)
          Adds the stylesheet at the given url as a "theme," i.e.
 void setUI(TextUI newui)
          Describe setUI method here.
 
Methods inherited from class javax.swing.JEditorPane
createDefaultEditorKit, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, getUIClassID, paramString, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, replaceSelection, scrollToReference, setContentType, setEditorKit, setEditorKitForContentType, setPage, setPage
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, updateUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HTMLPane

public HTMLPane()
Creates a new HTMLPane instance with no text.


HTMLPane

public HTMLPane(String text)
Creates a new HTMLPane instance with the given text. Default text encoding is "text/html; UTF-8".

Parameters:
text - a String value

HTMLPane

public HTMLPane(StyleSheet theme)
Creates a new HTMLPane instance with the given stylesheet. Default text encoding is "text/html; UTF-8".

Parameters:
theme - a StyleSheet value

HTMLPane

public HTMLPane(String text,
                StyleSheet theme)
Creates a new HTMLPane instance with the given text and stylesheet. Default text encoding is "text/html; UTF-8".

Parameters:
text - a String value
theme - a StyleSheet value

HTMLPane

public HTMLPane(URL initialPage)
         throws IOException
Creates a new HTMLPane instance showing the HTML page at the given URL and with no accessory stylesheet. Default text encoding is "text/html; UTF-8".

Parameters:
initialPage - an URL value
Throws:
IOException - if an error occurs

HTMLPane

public HTMLPane(URL initialPage,
                StyleSheet theme)
         throws IOException
Creates a new HTMLPane instance showing the HTML page at the given URL and with the given accesory stylesheet. Default text encoding is "text/html; UTF-8".

Parameters:
initialPage - an URL value
theme - a StyleSheet value
Throws:
IOException - if an error occurs
Method Detail

getDocumentStyleSheet

protected StyleSheet getDocumentStyleSheet()
Returns the stylesheet for the current document.

Returns:
a StyleSheet value

getDocument

protected static String getDocument(URL u)
                             throws IOException
Returns the HTML document at the given URL as a String.

Parameters:
u - an URL value
Returns:
a String value
Throws:
IOException - if an error occurs

setTheme

protected void setTheme(String styleSheetUrl)
                 throws MalformedURLException
Adds the stylesheet at the given url as a "theme," i.e. it will not override rules in the document's own stylesheet.

Parameters:
styleSheetUrl - a String value
Throws:
MalformedURLException - if an error occurs

setText

public final void setText(String text)
Sets the text and clears and clears any applied "theme" stylesheets.

Overrides:
setText in class JEditorPane
Parameters:
text - a String value

dump

public final void dump()
Dumps the current stylesheet for debugging.


setAutoDump

public void setAutoDump(boolean newAutoDump)
Setting autoDump to true causes the stylesheet to be printed every time it is changed.

Parameters:
b - a boolean value

dump

public final void dump(StyleSheet styles)
Sends all style rules to be printed out to System.out.

Parameters:
styles - a StyleSheet value

setUI

public void setUI(TextUI newui)
Describe setUI method here.

Overrides:
setUI in class JTextComponent
Parameters:
newui - a javax.swing.plaf.TextUI value

getConverter

public final LookAndFeelToCSS getConverter()
Describe getConverter method here.

Returns:
a LookAndFeelToCSS value

setConverter

public final void setConverter(LookAndFeelToCSS conv)
Allows you to plug in a LookAndFeel to CSS converter of your choice.

Parameters:
conv - a LookAndFeelToCSS value

addHyperlinkListener

public void addHyperlinkListener(HyperlinkListener listener)
Add a HyperlinkListener to this pane. This allows you to handle hyperlink events as well as form submission events.

Overrides:
addHyperlinkListener in class JEditorPane
Parameters:
l - a HyperlinkListener value

doLayout

public void doLayout()
Tries to do super.doLayout() and warns if this causes an exception.

Overrides:
doLayout in class Container

forceValidate

public void forceValidate()