HiRISE

HiRISE.HiPlan.Utilities
Class GuiUtilities

java.lang.Object
  extended by HiRISE.HiPlan.Utilities.GuiUtilities

public class GuiUtilities
extends Object

A collection of GUI-related utilities for HiPlan and other applications.

These utility methods should not be used in a headless environment, i.e., when the jawa.awt.headless system property is true.

Version:
1.19
Author:
Christian Schaller - UA/PIRL

Field Summary
static int DEFAULT_ALPHA
          Default alpha.
static String DEFAULT_POD_TOOL
          The default POD conversion tool.
static String HICOMMAND_OUTPUT_DIRECTORY
          The directory containing output HiRISE command files generated by HiCommand.
static Class HIPLAN_REFERENCE_CLASS
          The HiPlan reference class: The HOGG.
static String ID
          Class identification name with source code version and date.
static String POD_TOOL_PROPERTY
          The system property for setting the POD conversion tool.
static String RELEASE_NOTES_FILENAME
          The name of the HiPlan release notes file.
static float SMALL_FONT_FACTOR
          The scaling factor for the small label font.
 
Method Summary
static File getFileChooserDirectory()
          Gets the current directory for the file chooser.
static File getFileToOpen(Component parent, FileFilter... filters)
           
static File getFileToOpen(Component parent, String title, String approveButtonText, File selectedFile, boolean fileHidingEnabled, FileFilter... filters)
           
static File getFileToSave(Component parent, FileFilter... filters)
           
static File getFileToSave(Component parent, String title, String approveButtonText, File selectedFile, boolean fileHidingEnabled, boolean confirmOverwrite, String extension, JComponent accessory, FileFilter... filters)
           
static Action getLoggingEnableAction()
          Creates an action that enables or disables HiPlan logging.
static BufferedImage loadImage(Class refClass, String filename)
           
static ImageIcon loadImageIcon(Class refClass, String filename)
           
static KeyStroke makeAccelerator(int k, int... m)
          Creates an accelerator key stroke using the default menu shortcut key mask.
static Color makeAlphaColor(Color c)
           
static Color makeAlphaColor(Color c, int alpha)
           
static JFileChooser makeFileChooser()
          Creates a new file chooser.
static Action makePodViewerAction(Class refClass, Component viewerParent)
           
static Action makePodViewerAction(Class refClass, String filename, String title, Component viewerParent)
           
static Action makeReleaseNotesAction(Component viewerParent)
          Creates an action that displays the HiPlan release notes in a simple viewing window.
static Font makeSmallFont(Font font)
          Creates a smaller version of an input font by scaling its size by a factor of SMALL_FONT_FACTOR.
static JLabel makeSmallLabel(double value)
          Creates a numeric label with a small, plain font.
static JLabel makeSmallLabel(int value)
          Creates a numeric label with a small, plain font.
static JLabel makeSmallLabel(String text)
          Creates a label with a small, plain font.
static JComponent makeTextComponent(String text)
          Creates a reasonably sized text dialog text component.
static Action makeTextFileAction(String label, Class refClass, String filename, String viewerTitle, Component viewerParent)
          Creates an action that displays a text file in a simple viewing window.
static Action makeTextFileAction(String label, URL url, String viewerTitle, Component viewerParent)
          Creates an action that displays a text file in a simple viewing window.
static void setFileChooserDirectory(File fileChooserDirectory)
          Sets the current directory for the file chooser.
static void showReleaseNotes(Component parent)
          Displays the HiPlan release notes in a simple viewing window.
static void showTextFile(Class refClass, String filename, String title, Component parent)
          Displays a text file in a simple viewing window.
static void showTextFile(URL url, String title, Component parent)
          Displays a text file in a simple viewing window.
static void viewParameter(Component parent, String title, Parameter parameter)
          Displays a PVL parameter in a modal dialog viewer with a given parent component and title.
static void viewParameter(Component parent, String title, Parameter parameter, String message)
          Displays a PVL parameter in a modal dialog viewer with a given parent component, title, and explanatory message.
static void viewParameter(String title, Parameter parameter)
          Displays a PVL parameter in a modal dialog viewer with a gien title.
static void viewParameter(String title, Parameter parameter, String message)
          Displays a PVL parameter in a modal dialog viewer with a given title and explanatory message.
static void viewPod(File perlFile, String title, Component parent)
           
static void viewText(String text, String title, boolean isError, Component parent)
           
static void viewText(String text, String title, boolean isError, int width, int height, Component parent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
Class identification name with source code version and date.

See Also:
Constant Field Values

RELEASE_NOTES_FILENAME

public static final String RELEASE_NOTES_FILENAME
The name of the HiPlan release notes file. This file is found one directory up from the HOGG's location as determined by the class loader.

See Also:
Constant Field Values

HIPLAN_REFERENCE_CLASS

public static final Class HIPLAN_REFERENCE_CLASS
The HiPlan reference class: The HOGG.


POD_TOOL_PROPERTY

public static final String POD_TOOL_PROPERTY
The system property for setting the POD conversion tool. The default value is "pod2text -l." Note that the POD viewer expects plain text, so the POD conversion tool should be one that generates plain text instead of styled.

See Also:
Constant Field Values

DEFAULT_POD_TOOL

public static final String DEFAULT_POD_TOOL
The default POD conversion tool.

See Also:
Constant Field Values

SMALL_FONT_FACTOR

public static final float SMALL_FONT_FACTOR
The scaling factor for the small label font.

See Also:
Constant Field Values

HICOMMAND_OUTPUT_DIRECTORY

public static final String HICOMMAND_OUTPUT_DIRECTORY
The directory containing output HiRISE command files generated by HiCommand.

See Also:
Constant Field Values

DEFAULT_ALPHA

public static final int DEFAULT_ALPHA
Default alpha. Roughly 15%.

See Also:
Constant Field Values
Method Detail

makeAccelerator

public static KeyStroke makeAccelerator(int k,
                                        int... m)
Creates an accelerator key stroke using the default menu shortcut key mask. Optional key masks may further modify the default mask. To add the shift key to the mask, invoke this method with SHIFT_MASK, for example. The default key mask is system-dependent.

Parameters:
k - the base key, modified by the default shortcut key mask.
m - the additional, optional modifiers.
See Also:
InputEvent, Toolkit.getMenuShortcutKeyMask()

showTextFile

public static void showTextFile(URL url,
                                String title,
                                Component parent)
Displays a text file in a simple viewing window. The viewer, a JEditorPane is set non-editable and uses a monospaced font. It is embedded in a JScrollPane and displayed as a modal dialog via a JOptionPane.

If the text file's URL cannot be resolved for any reason, "Unable to load file" is displayed instead.

Parameters:
url - the text file's URL.
title - the viewer's title.
parent - the parent component for the viewer.

showTextFile

public static void showTextFile(Class refClass,
                                String filename,
                                String title,
                                Component parent)
Displays a text file in a simple viewing window.

The named file is expected to be found by the class loader in a location relative to the reference class.

Parameters:
refClass - the reference class used by the class loader to find filename.
filename - the text file, located relative to refClass.
title - the viewer's title.
parent - the parent component for the viewer.
See Also:
showTextFile(URL,String,Component)

showReleaseNotes

public static void showReleaseNotes(Component parent)
Displays the HiPlan release notes in a simple viewing window. The release notes, in a file called Release_Notes.txt, are expected to be found one directory up from the location of the HiPlan reference class, the HOGG.

Parameters:
parent - the parent component for the viewer.
See Also:
showTextFile(URL,String,Component)

makeTextFileAction

public static Action makeTextFileAction(String label,
                                        URL url,
                                        String viewerTitle,
                                        Component viewerParent)
Creates an action that displays a text file in a simple viewing window.

Parameters:
label - the action's label.
url - the text file's URL.
viewerTitle - the viewer's title.
viewerParent - the viewer's parent component.
See Also:
showTextFile(URL,String,Component)

makeTextFileAction

public static Action makeTextFileAction(String label,
                                        Class refClass,
                                        String filename,
                                        String viewerTitle,
                                        Component viewerParent)
Creates an action that displays a text file in a simple viewing window.

The named file is expected to be found by the class loader in a location relative to the reference class.

Parameters:
label - the action's label.
refClass - the reference class used by the class loader to find filename.
filename - the text file, located relative to refClass.
viewerTitle - the viewer's title.
viewerParent - the viewer's parent component.
See Also:
showTextFile(Class,String,String,Component), showTextFile(URL,String,Component)

makeReleaseNotesAction

public static Action makeReleaseNotesAction(Component viewerParent)
Creates an action that displays the HiPlan release notes in a simple viewing window. The release notes, in a file called Release_Notes.txt, are expected to be found one directory up from the location of the HiPlan reference class, the HOGG.

Parameters:
viewerParent - the viewer's parent component.
See Also:
showReleaseNotes(Component), showTextFile(URL,String,Component)

viewPod

public static void viewPod(File perlFile,
                           String title,
                           Component parent)

makePodViewerAction

public static Action makePodViewerAction(Class refClass,
                                         String filename,
                                         String title,
                                         Component viewerParent)

makePodViewerAction

public static Action makePodViewerAction(Class refClass,
                                         Component viewerParent)

getLoggingEnableAction

public static Action getLoggingEnableAction()
Creates an action that enables or disables HiPlan logging. The action's function and name is determined by the LoggingUtilities.isLoggingEnabled() value.

If logging is enabled, then the action's name is "Disable Logging," and activating it fires the LoggingUtilities.disableLogging() method.

If logging is not enabled, the action's name is "Enable Logging," and activating it fires the LoggingUtilities.enableLogging() method.

The action is stored for later use by repeated invocations of this method.

Returns:
a logging enable/disable action.

makeTextComponent

public static JComponent makeTextComponent(String text)
Creates a reasonably sized text dialog text component. The type of component is determined by the length of the text parameter. If it is 32 characters or less in length, a JLabel is returned. If it is 33 to 64 characters in length, a JTextArea is returned. If it is longer, a JTextArea in a JScrollPane is returned.

The number of visible rows in the scroll pane is determined by the length of the text. If fewer than 512 characters, five rows will be visible. Otherwise ten will be visible.

Parameters:
text - the text to be displayed by the component.
Returns:
a component that displays the text.

loadImageIcon

public static ImageIcon loadImageIcon(Class refClass,
                                      String filename)

loadImage

public static BufferedImage loadImage(Class refClass,
                                      String filename)

makeSmallFont

public static Font makeSmallFont(Font font)
Creates a smaller version of an input font by scaling its size by a factor of SMALL_FONT_FACTOR.

Parameters:
font - the input font.
Returns:
a smaller version of the input font.

makeSmallLabel

public static JLabel makeSmallLabel(String text)
Creates a label with a small, plain font. The font is scaled from the default label font size by a factor of SMALL_FONT_FACTOR.

Parameters:
text - the text for the label.
Returns:
a label with a small, plain font.

makeSmallLabel

public static JLabel makeSmallLabel(int value)
Creates a numeric label with a small, plain font. The font is scaled from the default label font size by a factor of SMALL_FONT_FACTOR.

Parameters:
value - the integer value of the label.
Returns:
a label with a small, plain font.

makeSmallLabel

public static JLabel makeSmallLabel(double value)
Creates a numeric label with a small, plain font. The font is scaled from the default label font size by a factor of SMALL_FONT_FACTOR. The label is formatted with one decimal place.

Parameters:
value - the double value of the label.
Returns:
a label with a small, plain font.

viewParameter

public static void viewParameter(Component parent,
                                 String title,
                                 Parameter parameter,
                                 String message)
Displays a PVL parameter in a modal dialog viewer with a given parent component, title, and explanatory message. If the parent component is null, or if it has no enclosing frame, a shared frame is used, centering the dialog on the primary monitor. If the title is null, a default title is used. If the explanatory message is null, no such message is shown and the dialog shows only the Parameter.

If the input parameter appears to be derived from a HiCat planned observation record, the viewer includes a button to view the observation's HiCommand-generated command file. A check for an enclosed parameter named COMMAND_FILE_PATHNAME determines whether to display the button. Note that if there is no local access to the production HiRISE command file directory (HICOMMAND_OUTPUT_DIRECTORY), the button is not displayed even if the parameter is determined to be from an observation record.

Parameters:
parent - a parent component for the dialog.
title - the dialog's title.
parameter - the PVL parameter to display.
message - an optional explanatory message to include with the dialog.
See Also:
Parameter_Pane

viewParameter

public static void viewParameter(Component parent,
                                 String title,
                                 Parameter parameter)
Displays a PVL parameter in a modal dialog viewer with a given parent component and title. If the parent component is null, or if it has no enclosing frame, a shared frame is used, centering the dialog on the primary monitor. If the title is null, a default title is used.

Parameters:
parent - a parent component for the dialog.
title - the dialog's title.
parameter - the PVL parameter to display.
See Also:
Parameter_Pane

viewParameter

public static void viewParameter(String title,
                                 Parameter parameter,
                                 String message)
Displays a PVL parameter in a modal dialog viewer with a given title and explanatory message. If the title is null, a default title is used. If the explanatory message is null, no such message is shown and the dialog shows only the Parameter. A shared frame is used for the dialog, displaying it in the center of the primary monitor.

Parameters:
title - the dialog's title.
parameter - the PVL parameter to display.
message - an optional explanatory message to include with the dialog.
See Also:
Parameter_Pane

viewParameter

public static void viewParameter(String title,
                                 Parameter parameter)
Displays a PVL parameter in a modal dialog viewer with a gien title. If the title is null, a default title is used. A shared frame is used for the dialog, displaying it in the center of the primary monitor.

Parameters:
title - the dialog's title.
parameter - the PVL parameter to display.
See Also:
Parameter_Pane

viewText

public static void viewText(String text,
                            String title,
                            boolean isError,
                            int width,
                            int height,
                            Component parent)

viewText

public static void viewText(String text,
                            String title,
                            boolean isError,
                            Component parent)

makeFileChooser

public static JFileChooser makeFileChooser()
Creates a new file chooser. The chooser's current directory is set to the value returned by getFileChooserDirectory(); if null, the current directory is set to the operator's current working directory (the value of System.getProperty("user.dir")).

For Mac-like file chooser behavior, setFileChooserDirectory(File) should be invoked with the chooser's new current directory if the file chooser is approved.

Returns:
a file chooser.

getFileChooserDirectory

public static File getFileChooserDirectory()
Gets the current directory for the file chooser. If this value is null, the directory will be the working directory from which this application was launched.

Returns:
the file chooser directory; may be null.
See Also:
makeFileChooser()

setFileChooserDirectory

public static void setFileChooserDirectory(File fileChooserDirectory)
Sets the current directory for the file chooser. If the new fileChooserDirectory value is not a directory, this method silently does nothing.

Parameters:
fileChooserDirectory - the new current directory for the file chooser.
See Also:
makeFileChooser()

getFileToOpen

public static File getFileToOpen(Component parent,
                                 String title,
                                 String approveButtonText,
                                 File selectedFile,
                                 boolean fileHidingEnabled,
                                 FileFilter... filters)

getFileToOpen

public static File getFileToOpen(Component parent,
                                 FileFilter... filters)

getFileToSave

public static File getFileToSave(Component parent,
                                 String title,
                                 String approveButtonText,
                                 File selectedFile,
                                 boolean fileHidingEnabled,
                                 boolean confirmOverwrite,
                                 String extension,
                                 JComponent accessory,
                                 FileFilter... filters)

getFileToSave

public static File getFileToSave(Component parent,
                                 FileFilter... filters)

makeAlphaColor

public static Color makeAlphaColor(Color c,
                                   int alpha)

makeAlphaColor

public static Color makeAlphaColor(Color c)

HiRISE

Copyright (C) Arizona Board of Regents on behalf of the Planetary Image Research Laboratory, Lunar and Planetary Laboratory at the University of Arizona