public class Help_Viewer
extends javax.swing.JFrame
implements javax.swing.event.HyperlinkListener
The viewer operates as a standalone application, a JFrame
dialog, or
a modal JDialog
. In each case, the viewer is supplied at initial
construction with a URL for the index pane and for the content pane. If the
index pane URL is null, the index pane is removed from the viewer.
If the content pane URL is null, the content pane is retained but
is blank. The URLs can also be derived from a reference class and a set of
constants: Constants.RESOURCES_DIRECTORY
, DEFAULT_INDEX_URL
,
and DEFAULT_CONTENT_URL
.
To use the help viewer as a standalone application, invoke it on the command line as with any Java application:
java [-cp classpath] HiRISE.HiPlan.Help.Help_Viewer [--class className] [--index indexUrl] [--content contentUrl] [--title title]
Without any of the command-line options, the help viewer is invoked with no index pane and a blank content pane; it has the title "HiPlan Help."
The --class option loads the viewer's index and content panes from
URLs generated by the class loader. The default path to the index file is
resources/help/index.html, rooted at className's location.
The default path to the content file is
resources/help/main.html, also rooted at className's
location. The --class option also sets the viewer's title based on
the simple name
of the indicated class.
Example: With the option --class HiRISE.HiPlan.HOGG.HOGG, the index file is loaded from HiRISE/HiPlan/HOGG/resources/help/index.html, wherever the HiRISE.HiPlan.HOGG package is found in the classpath. The viewer's title is "HOGG Help."
The --index option loads the index pane from indexUrl. If combined with the --class option, the URL is assumed to be relative to the className's class path as determined by the class loader.
The --content option loads the content pane from contentUrl. If combined with the --class option, the URL is assumed to be relative to the className's class path as determined by the class loader.
Examples: The options --class HiRISE.HiPlan.HOGG.HOGG --index foo.html will cause the help viewer to load the index pane from HiRISE/HiPlan/HOGG/foo.html. The options --class HiRISE.HiPlan.HOGG.HOGG --content bar.html will cause the help viewer to load the content pane from HiRISE/HiPlan/HOGG/bar.html.
The --title option overrides the application's default window title. The default title is either "HiPlan Help" or the simple name of the className if supplied.
To use the help viewer as a modeless JFrame dialog, intantiate it with a
reference class from which the help viewer's title and index and content
URLs will be derived. The title is derived from the reference class's simple name
. The URLs are generated by the class
loader from the reference class's path, to which is appended resources
and either help/index.html
or help/main.html
. Set the viewer to visible
to
display.
Example:
final Help_Viewer viewer = new Help_Viewer(HiRISE.HiPlan.HOGG.HOGG.class); Action showHelp = new AbstractAction("Help") { public void actionPerformed(ActionEvent e) { viewer.setVisible(true); } }; JMenuItem item = new JMenuItem(showHelp);
Alternatively, instantiate it with a custom title, index URL, and content URL.
Example:
Class hogg = HiRISE.HiPlan.HOGG.HOGG.class; URL indexUrl = hogg.getResource( Constants.RESOURCES_DIRECTORY + "/" + Help_Viewer.DEFAULT_INDEX_URL ); URL contentUrl = hogg.getResource( Constants.RESOURCES_DIRECTORY + "/" + Help_Viewer.DEFAULT_CONTENT_URL ); final Help_Viewer viewer = new Help_Viewer( hogg.getSimpleName(), indexUrl, contentUrl ); Action showHelp = new AbstractAction("Help") { public void actionPerformed(ActionEvent e) { viewer.setVisible(true); } }; JMenuItem item = new JMenuItem(showHelp);
To use the help viewer as a modal JDialog instead of as a modeless JFrame, a
showDialog(Dialog)
method is provided. This method embeds the help
viewer in a JDialog. To use, instantiate the help viewer with a reference
class as above and invoke the showDialog method.
Example:
final HOGG_Dialog hogg = new HOGG_Dialog(); final Help_Viewer viewer = new Help_Viewer(HiRISE.HiPlan.HOGG.HOGG.class); Action showHelp = new AbstractAction("Help") { public void actionPerformed(ActionEvent e) { viewer.showDialog(hogg); } }; JMenuItem item = new JMenuItem(showHelp);
The help viewer handles file protocol URLs itself; their contents are displayed in its content pane.
http protocol URLs are passed off to an external web browser if possible; if not, the operator is presented with a dialog indicating this fact that includes the target URL. The operator can copy this URL and paste it into a browser manually.
Other protocol URLs are not handled at all. An error dialog indicates this fact and presents the operator with the target URL. The operator can copy and paste this URL into an appropriate browser if desired.
JEditorPane
,
Serialized Formjavax.swing.JFrame.AccessibleJFrame
java.awt.Window.AccessibleAWTWindow, java.awt.Window.Type
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_CONTENT_URL
The default content URL.
|
static java.lang.String |
DEFAULT_INDEX_URL
The default index URL.
|
static java.lang.String |
DEFAULT_TITLE
The default title for the dialog window.
|
static int |
FAILURE
Exit status when the application fails.
|
static java.lang.String |
FILE_PROTOCOL_PREFIX
The starting text for a URL file protocol.
|
static java.lang.String |
HTTP_PROTOCOL_PREFIX
The starting text for a URL HTTP protocol.
|
static java.lang.String |
ID
Class identification name with source code version and date.
|
static java.lang.String |
STANDALONE_PROPERTY
The system property whose value is "true" if the help viewer should be
started up in standalone mode.
|
static int |
SUCCESS
Exit status when the application succeeds.
|
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
Help_Viewer()
Creates a new help viewer frame with a default title.
|
Help_Viewer(java.lang.Class referenceClass)
Creates a new help viewer based on the input reference class.
|
Help_Viewer(java.lang.String title)
Creates a new help viewer frame with the indicated title.
|
Help_Viewer(java.lang.String title,
java.net.URL indexUrl,
java.net.URL contentUrl)
Creates a new help viewer frame with the indicated title.
|
Help_Viewer(java.net.URL indexUrl,
java.net.URL contentUrl)
Creates a new help viewer frame with a default title.
|
Modifier and Type | Method and Description |
---|---|
java.net.URL |
getContentUrl()
Gets the URL for the contents of the content pane.
|
java.net.URL |
getIndexUrl()
Gets the URL for the contents of the index pane.
|
void |
handleAbout()
Handles a request to display the application About dialog.
|
boolean |
handleMacQuit()
Handles a request to quit as generated by the Mac-supplied Quit menu item.
|
void |
hyperlinkUpdate(javax.swing.event.HyperlinkEvent e)
Receives hyperlink events and handles them appropriately.
|
static void |
main(java.lang.String[] args)
Invokes a standalone application version of the help viewer in its own
thread.
|
void |
setContentUrl(java.net.URL contentUrl)
Sets the URL for the contents of the content pane and loads the content
pane with that content.
|
void |
setIndexUrl(java.net.URL indexUrl)
Sets the URL for the contents of the index pane and loads the index pane
with that content.
|
void |
showDialog(java.awt.Dialog owner)
Displays the help viewer in a modeless dialog instead of in its default
window.
|
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final java.lang.String ID
public static final java.lang.String DEFAULT_INDEX_URL
public static final java.lang.String DEFAULT_CONTENT_URL
public static final java.lang.String HTTP_PROTOCOL_PREFIX
public static final java.lang.String FILE_PROTOCOL_PREFIX
public static final java.lang.String DEFAULT_TITLE
public static final java.lang.String STANDALONE_PROPERTY
public static final int SUCCESS
public static final int FAILURE
public Help_Viewer(java.lang.Class referenceClass)
The viewer's title is set to the class's simple
name
plus Help. For example, with a referenceClass of
HiRISE.HiPlan.HOGG.HOGG, the title is "HOGG Help."
The viewer's index URL and initial content URL are generated by the class loader. The path to the index file is resources/help/index.html. The path to the content file is resources/help/main.html. Both are rooted at referenceClass's location.
referenceClass
- The reference class from which the help viewer's
title and URLs are derived. May not be null.Constants.RESOURCES_DIRECTORY
,
DEFAULT_INDEX_URL
,
DEFAULT_CONTENT_URL
public Help_Viewer(java.lang.String title, java.net.URL indexUrl, java.net.URL contentUrl)
If the title is null, the DEFAULT_TITLE
will be used
instead. If the index URL is null, the index pane will not be
displayed. If the content URL is null, the content pane will be
displayed with a blank document.
title
- the frame title.indexUrl
- the URL from which the index pane's contents are loaded.contentUrl
- the URL from which the content pane's contents are
loaded.public Help_Viewer(java.net.URL indexUrl, java.net.URL contentUrl)
indexUrl
- the URL from which the index pane's contents are loaded.contentUrl
- the URL from which the content pane's contents are
loaded.Help_Viewer(String,URL,URL)
public Help_Viewer(java.lang.String title)
title
- the frame title.Help_Viewer(String,URL,URL)
public Help_Viewer()
Help_Viewer(String,URL,URL)
public java.net.URL getIndexUrl()
public void setIndexUrl(java.net.URL indexUrl)
indexUrl
- the new index URL to set.public java.net.URL getContentUrl()
public void setContentUrl(java.net.URL contentUrl)
contentUrl
- the new content URL to set.public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent e)
Events of type ENTERED
trigger a status bar
update that reports the URL's target in the help viewer's status bar.
Events of type EXITED
clear the status bar.
Events of type ACTIVATED
are handled in one
of three ways. If the URL is a file URL, the indicated resource is
loaded into the content panel, regardless of the event's source. If the
URL is an HTTP protocol URL (or HTTPS), an attempt is made to load it
into an external browser; if the attempt fails, a message with the URL
is presented to the operator. If the URL is of some other protocol, a
message with the URL is presented to the operator.
The third-party BrowserLauncher utility is used for handing URLs off to external browsers. It is invoked via reflection as either edu.asu.jmars.util.BrowserLauncher or edu.stanford.ejalbert.BrowserLauncher. If the launcher is not found in the classpath, a message with the URL is presented to the operator. (The launcher is included in the JMARS distribution, so it is likely able to be found.)
hyperlinkUpdate
in interface javax.swing.event.HyperlinkListener
e
- the hyperlink event.public void handleAbout()
On a Mac, an About menu item is also supplied in the application menu. A
Mac_Adapter
registers this method as the handler for the Apple event
generated by this menu item.
This method is exposed for access by the Mac Adapter.
public boolean handleMacQuit()
This method is exposed for access by the Mac Adapter
.
public void showDialog(java.awt.Dialog owner)
owner
- the non-null dialog owner for the help viewer dialog.public static void main(java.lang.String[] args)
java [-cp classpath] HiRISE.HiPlan.Help.Help_Viewer [--class className] [--index indexUrl] [--content contentUrl] [--title title]
Options are not case-sensitive and may be reduced to their shortest unique form. One or two dashes may be used.
DEFAULT_TITLE
.
The indexUrl and contentUrl are straightforward on their own: they set the contents of the index and content panes, respectively.
If className is used on its own, the viewer's index and content panes
are loaded from URLs generated by the class loader. The path to the index
file is the class name plus Constants.RESOURCES_DIRECTORY
plus
DEFAULT_INDEX_URL
. The content file is likewise constructed from
DEFAULT_CONTENT_URL
.
If className is used in conjunction with indexUrl or contentUrl, the index or content URL will be appended to the class name's URL from the class loader. If only one such URL is provided, the other pane will be loaded as above.
If title is not specified, DEFAULT_TITLE
will be used unless
className is used. If the class name is provided, it will be
incorporated into the title in this case.
args
- the command-line arguments.Copyright \ (C) Arizona Board of Regents on behalf of the \ Planetary Image Research Laboratory, Lunar and \ Planetary Laboratory at the University of Arizona