jsky.html
Class HTMLViewer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by jsky.html.HTMLViewer
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, GenericToolBarTarget

public class HTMLViewer
extends JPanel
implements GenericToolBarTarget

Used to associate handler classes with file suffixes and mime-types. This information is used to determine which class to use to display a file or URL returned from a catalog query.

Version:
$Revision: 1.10 $
Author:
Allan Brighton
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  AbstractAction backAction
          Action to use for the "Back" menu and toolbar items
protected  Stack backStack
          Stack of HTMLViewerHistoryItem, used to go back to a previous page
protected static JFileChooser fileChooser
          Reuse file chooser widget
protected  AbstractAction forwAction
          Action to use for the "Forward" menu and toolbar items
protected  Stack forwStack
          Stack of HTMLViewerHistoryItem, used to go forward to the next page
protected static String HISTORY_LIST_NAME
          Base filename for serialization of the history list
protected  LinkedList historyList
          List of HTMLViewerHistoryItem, for previously viewed catalogs or query results.
protected  JEditorPane html
          Used to display HTML
protected  EventListenerList listenerList
          list of listeners for change events
protected  int maxHistoryItems
          Max number of items in the history list
protected  boolean noStack
          Set when the back or forward actions are active to avoid the normal history stack handling
protected  AbstractAction openAction
          Action to use for the "Open..." menu and toolbar items
protected  Component parent
          The top level parent frame (or internal frame) used to close the window
protected  AbstractAction printAction
          Action to use for the "Print..." menu and toolbar items
protected  AbstractAction saveAsAction
          Action to use for the "Save as..." menu and toolbar items
protected  URL url
          The URL of the currently displayed page
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
HTMLViewer()
          Create a window for displaying HTML.
HTMLViewer(Component parent)
          Create a window for displaying HTML.
HTMLViewer(Component parent, URL url)
          Create a window for displaying the given HTML URL.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Register to receive change events from this object whenever a new HTML page is displayed.
 void addHistoryMenuItems(JMenu menu)
          Add history items (for previously displayed components) to the given menu
protected  void addToHistory()
          Add the current URL to the history stack, removing duplicates.
protected  void addToHistory(HTMLViewerHistoryItem historyItem)
          Add the given item to the history stack, removing duplicates.
 void back()
          Go back to the previous component in the history list
protected  void cleanupHistoryList()
          This method is called after the history list is deserialized to remove any items in the list that can't be accessed.
protected  void clearHistory()
          Add the current URL to the history list
 void close()
          Close the window
protected  HyperlinkListener createHyperLinkListener()
          Create and return a listener for HTML links.
protected  void fireChange(ChangeEvent e)
          Notify any listeners that a new HTML page is being displayed.
 void forward()
          Go forward to the next component in the history list
 AbstractAction getBackAction()
          Return the action for "Back"
 JEditorPane getEditorPane()
          Used to display HTML
 AbstractAction getForwAction()
          Return the action for "Forward"
 int getMaxHistoryItems()
          Return the max number of items in the history list.
 AbstractAction getOpenAction()
          Return the action for "Open"
 AbstractAction getPrintAction()
           
 AbstractAction getSaveAsAction()
           
protected  void loadHistory()
          Try to load the history list from a file, and create an empty list if that fails.
protected  JFileChooser makeFileChooser()
          Create and return a new file chooser to be used to select a file to open.
protected  HTMLViewerHistoryItem makeHTMLViewerHistoryItem()
          Return a new HTMLViewerHistoryItem for the currently displayed catalog.
protected  LinkedList mergeHistoryList()
          Merge the historyList with current serialized version (another instance may have written it since we read it last).
 void open()
          Display a file chooser to select a local catalog file to open
 void open(String fileOrUrl)
          Open and display the given file or URL
 void openURL()
          Display a dialog to enter a URL to display
 void print()
          Pop up a dialog for printing the current page.
 void removeChangeListener(ChangeListener l)
          Stop receiving change events from this object.
 void saveAs()
          Pop up a dialog to ask the user for a file name, and then save the current page to the selected file.
protected  void saveHistory(boolean merge)
          Save the current history list to a file.
 void setMaxHistoryItems(int n)
          Set the max number of items in the history list.
 void setPage(URL url)
          Display the given URL, which should have the content type text/html.
 void setText(String text)
          Display the given HTML text.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, doLayout, 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, addInputMethodListener, 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, getInputMethodRequests, 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, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, 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

parent

protected Component parent
The top level parent frame (or internal frame) used to close the window


html

protected JEditorPane html
Used to display HTML


url

protected URL url
The URL of the currently displayed page


fileChooser

protected static JFileChooser fileChooser
Reuse file chooser widget


listenerList

protected EventListenerList listenerList
list of listeners for change events


backStack

protected Stack backStack
Stack of HTMLViewerHistoryItem, used to go back to a previous page


forwStack

protected Stack forwStack
Stack of HTMLViewerHistoryItem, used to go forward to the next page


noStack

protected boolean noStack
Set when the back or forward actions are active to avoid the normal history stack handling


historyList

protected LinkedList historyList
List of HTMLViewerHistoryItem, for previously viewed catalogs or query results.


HISTORY_LIST_NAME

protected static final String HISTORY_LIST_NAME
Base filename for serialization of the history list

See Also:
Constant Field Values

maxHistoryItems

protected int maxHistoryItems
Max number of items in the history list


openAction

protected AbstractAction openAction
Action to use for the "Open..." menu and toolbar items


backAction

protected AbstractAction backAction
Action to use for the "Back" menu and toolbar items


forwAction

protected AbstractAction forwAction
Action to use for the "Forward" menu and toolbar items


saveAsAction

protected AbstractAction saveAsAction
Action to use for the "Save as..." menu and toolbar items


printAction

protected AbstractAction printAction
Action to use for the "Print..." menu and toolbar items

Constructor Detail

HTMLViewer

public HTMLViewer()
Create a window for displaying HTML.


HTMLViewer

public HTMLViewer(Component parent)
Create a window for displaying HTML.

Parameters:
parent - the top level parent frame (or internal frame) used to close the window

HTMLViewer

public HTMLViewer(Component parent,
                  URL url)
Create a window for displaying the given HTML URL.

Parameters:
parent - The top level parent frame (or internal frame) used to close the window
url - A URL to display
Method Detail

getEditorPane

public JEditorPane getEditorPane()
Used to display HTML


setPage

public void setPage(URL url)
Display the given URL, which should have the content type text/html.

Parameters:
url - A URL to display

setText

public void setText(String text)
Display the given HTML text.


createHyperLinkListener

protected HyperlinkListener createHyperLinkListener()
Create and return a listener for HTML links.


open

public void open()
Display a file chooser to select a local catalog file to open


makeFileChooser

protected JFileChooser makeFileChooser()
Create and return a new file chooser to be used to select a file to open.


open

public void open(String fileOrUrl)
Open and display the given file or URL


openURL

public void openURL()
Display a dialog to enter a URL to display


close

public void close()
Close the window


back

public void back()
Go back to the previous component in the history list


forward

public void forward()
Go forward to the next component in the history list


addChangeListener

public void addChangeListener(ChangeListener l)
Register to receive change events from this object whenever a new HTML page is displayed.


removeChangeListener

public void removeChangeListener(ChangeListener l)
Stop receiving change events from this object.


fireChange

protected void fireChange(ChangeEvent e)
Notify any listeners that a new HTML page is being displayed.


addToHistory

protected void addToHistory()
Add the current URL to the history stack, removing duplicates.


addToHistory

protected void addToHistory(HTMLViewerHistoryItem historyItem)
Add the given item to the history stack, removing duplicates.


makeHTMLViewerHistoryItem

protected HTMLViewerHistoryItem makeHTMLViewerHistoryItem()
Return a new HTMLViewerHistoryItem for the currently displayed catalog.


getMaxHistoryItems

public int getMaxHistoryItems()
Return the max number of items in the history list.


setMaxHistoryItems

public void setMaxHistoryItems(int n)
Set the max number of items in the history list.


addHistoryMenuItems

public void addHistoryMenuItems(JMenu menu)
Add history items (for previously displayed components) to the given menu


cleanupHistoryList

protected void cleanupHistoryList()
This method is called after the history list is deserialized to remove any items in the list that can't be accessed.


mergeHistoryList

protected LinkedList mergeHistoryList()
Merge the historyList with current serialized version (another instance may have written it since we read it last).


clearHistory

protected void clearHistory()
Add the current URL to the history list


saveHistory

protected void saveHistory(boolean merge)
Save the current history list to a file.

Parameters:
merge - if true, merge the list with the existing list on disk.

loadHistory

protected void loadHistory()
Try to load the history list from a file, and create an empty list if that fails.


saveAs

public void saveAs()
Pop up a dialog to ask the user for a file name, and then save the current page to the selected file.


print

public void print()
Pop up a dialog for printing the current page.


getOpenAction

public AbstractAction getOpenAction()
Description copied from interface: GenericToolBarTarget
Return the action for "Open"

Specified by:
getOpenAction in interface GenericToolBarTarget

getSaveAsAction

public AbstractAction getSaveAsAction()

getPrintAction

public AbstractAction getPrintAction()

getBackAction

public AbstractAction getBackAction()
Description copied from interface: GenericToolBarTarget
Return the action for "Back"

Specified by:
getBackAction in interface GenericToolBarTarget

getForwAction

public AbstractAction getForwAction()
Description copied from interface: GenericToolBarTarget
Return the action for "Forward"

Specified by:
getForwAction in interface GenericToolBarTarget