|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JEditorPane
net.sourceforge.sillyview.HTMLPane
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.
| Nested Class Summary |
|---|
| Nested classes inherited from class javax.swing.JEditorPane |
|---|
javax.swing.JEditorPane.AccessibleJEditorPane, javax.swing.JEditorPane.AccessibleJEditorPaneHTML, javax.swing.JEditorPane.JEditorPaneAccessibleHypertextSupport |
| Nested classes inherited from class javax.swing.text.JTextComponent |
|---|
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding |
| Nested classes inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
|---|
java.awt.Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
|---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
private boolean |
autodump
|
private Category |
cat
|
private LookAndFeelToCSS |
converter
|
private java.lang.String |
dString
|
private boolean |
initialized
|
private javax.swing.LookAndFeel |
lastLookAndFeel
|
private javax.swing.plaf.TextUI |
lastUI
|
| 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(java.lang.String text)
Creates a new HTMLPane instance with the given text. |
|
HTMLPane(java.lang.String text,
javax.swing.text.html.StyleSheet theme)
Creates a new HTMLPane instance with the given
text and stylesheet. |
|
HTMLPane(javax.swing.text.html.StyleSheet theme)
Creates a new HTMLPane instance with the given
stylesheet. |
|
HTMLPane(java.net.URL initialPage)
Creates a new HTMLPane instance showing the HTML
page at the given URL and with no accessory stylesheet. |
|
HTMLPane(java.net.URL initialPage,
javax.swing.text.html.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(javax.swing.event.HyperlinkListener l)
Add a HyperlinkListener to this pane. |
private void |
bugFixSetText(java.lang.String text)
Sets the text to the given value, tearing down the JEditorPane's backing model, which prevents peculiarities. |
void |
doLayout()
Tries to do super.doLayout() and warns if this causes an exception. |
void |
dump()
Dumps the current stylesheet for debugging. |
void |
dump(javax.swing.text.html.StyleSheet styles)
Sends all style rules to be printed out to System.out. |
LookAndFeelToCSS |
getConverter()
Describe getConverter method here. |
private static java.lang.String |
getDocument(java.lang.String documentURL)
Returns the HTML document at the given URL as a String. |
protected static java.lang.String |
getDocument(java.net.URL u)
Returns the HTML document at the given URL as a String. |
protected javax.swing.text.html.StyleSheet |
getDocumentStyleSheet()
Returns the stylesheet for the current document. |
private javax.swing.text.html.HTMLEditorKit |
getHTMLEditorKit()
Returns the editorkit if it is a HTMLEditorKit, or null otherwise. |
private javax.swing.text.html.StyleSheet |
getStyleSheet(javax.swing.LookAndFeel mlf)
|
private void |
init()
Sets the pane to non-editable, the content type to "text/html; UTF-8" and deactivates "autoformsubmission" so that HyperlinkListeners can handle form submission events. |
void |
setAutoDump(boolean b)
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(java.lang.String text)
Sets the text and clears and clears any applied "theme" stylesheets. |
private void |
setText(java.net.URL textURL)
Sets the text to the HTML document at the given URL. |
private void |
setTextUrl(java.lang.String textUrl)
Sets the text to the HTML document at the given URL. |
protected void |
setTheme(java.lang.String styleSheetUrl)
Adds the stylesheet at the given url as a "theme," i.e. |
private void |
setTheme(javax.swing.text.html.StyleSheet s2)
Adds the stylesheet at the given url as a "theme," i.e. |
private void |
setTheme(java.net.URL styleSheetUrl)
Adds the stylesheet at the given url as a "theme," i.e. |
void |
setUI(javax.swing.plaf.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 |
| Field Detail |
|---|
private java.lang.String dString
private LookAndFeelToCSS converter
private volatile boolean initialized
private Category cat
private boolean autodump
private volatile javax.swing.LookAndFeel lastLookAndFeel
private volatile javax.swing.plaf.TextUI lastUI
| Constructor Detail |
|---|
public HTMLPane()
HTMLPane instance with no text.
public HTMLPane(java.lang.String text)
HTMLPane instance with the given text.
Default text encoding is "text/html; UTF-8".
text - a String valuepublic HTMLPane(javax.swing.text.html.StyleSheet theme)
HTMLPane instance with the given
stylesheet. Default text encoding is "text/html; UTF-8".
theme - a StyleSheet value
public HTMLPane(java.lang.String text,
javax.swing.text.html.StyleSheet theme)
HTMLPane instance with the given
text and stylesheet. Default text encoding is "text/html; UTF-8".
text - a String valuetheme - a StyleSheet value
public HTMLPane(java.net.URL initialPage)
throws java.io.IOException
HTMLPane instance showing the HTML
page at the given URL and with no accessory stylesheet.
Default text encoding is "text/html; UTF-8".
initialPage - an URL value
java.io.IOException - if an error occurs
public HTMLPane(java.net.URL initialPage,
javax.swing.text.html.StyleSheet theme)
throws java.io.IOException
HTMLPane instance showing the HTML page
at the given URL and with the given accesory stylesheet.
Default text encoding is "text/html; UTF-8".
initialPage - an URL valuetheme - a StyleSheet value
java.io.IOException - if an error occurs| Method Detail |
|---|
private final void init()
protected javax.swing.text.html.StyleSheet getDocumentStyleSheet()
StyleSheet value
private static java.lang.String getDocument(java.lang.String documentURL)
throws java.net.MalformedURLException,
java.io.IOException
documentURL - a String value
String value
java.net.MalformedURLException - if an error occurs
java.io.IOException - if an error occurs
protected static java.lang.String getDocument(java.net.URL u)
throws java.io.IOException
u - an URL value
String value
java.io.IOException - if an error occurs
protected void setTheme(java.lang.String styleSheetUrl)
throws java.net.MalformedURLException
styleSheetUrl - a String value
java.net.MalformedURLException - if an error occursprivate void setTheme(java.net.URL styleSheetUrl)
styleSheetUrl - an URL valueprivate void setTheme(javax.swing.text.html.StyleSheet s2)
s2 - a StyleSheet valueprivate javax.swing.text.html.HTMLEditorKit getHTMLEditorKit()
private final void bugFixSetText(java.lang.String text)
public final void setText(java.lang.String text)
setText in class javax.swing.JEditorPanetext - a String value
private void setTextUrl(java.lang.String textUrl)
throws java.net.MalformedURLException,
java.io.IOException
textUrl - a String value
java.net.MalformedURLException - if an error occurs
java.io.IOException - if an error occurs
private void setText(java.net.URL textURL)
throws java.io.IOException
textURL - an URL value
java.io.IOException - if an error occurspublic final void dump()
public void setAutoDump(boolean b)
b - a boolean valuepublic final void dump(javax.swing.text.html.StyleSheet styles)
styles - a StyleSheet valuepublic void setUI(javax.swing.plaf.TextUI newui)
setUI method here.
setUI in class javax.swing.text.JTextComponentnewui - a javax.swing.plaf.TextUI valuepublic final LookAndFeelToCSS getConverter()
getConverter method here.
LookAndFeelToCSS valuepublic final void setConverter(LookAndFeelToCSS conv)
conv - a LookAndFeelToCSS valueprivate javax.swing.text.html.StyleSheet getStyleSheet(javax.swing.LookAndFeel mlf)
public void addHyperlinkListener(javax.swing.event.HyperlinkListener l)
addHyperlinkListener in class javax.swing.JEditorPanel - a HyperlinkListener valuepublic void doLayout()
doLayout in class java.awt.Container
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||