gov.nih.nlm.mms
Class MMSToolkit

java.lang.Object
  extended bygov.nih.nlm.swing.SwingToolkit
      extended bygov.nih.nlm.mms.MMSToolkit
All Implemented Interfaces:
SwingConstants

public class MMSToolkit
extends SwingToolkit

Utility class containing methods for MetamorphoSys applications.

Author:
Brian A. Carlsen

Field Summary
 
Fields inherited from class gov.nih.nlm.swing.SwingToolkit
key_map, properties
 
Fields inherited from interface gov.nih.nlm.swing.SwingConstants
EMPTY_BORDER, EMPTY_BORDER_NO_TOP, EMPTY_INSETS, GRID_INSETS, HAS_POPUP_BORDER, IS_REQUIRED_BORDER, VIEW
 
Constructor Summary
MMSToolkit()
           
 
Method Summary
static boolean archiveContainsDir(File file, String dir)
          Returns true if the given archive File contains the given directory.
static void cancel()
          Determines whether or not a cancel operation should call System.Exit.
static File chooseFile(String title, String button_text, int selection_mode, File current_dir, File selected_file, FileFilter fileFilter, Frame owner)
          Prompts user to choose a file, specifying a file filter.
static File chooseFile(String title, String button_text, int selection_mode, File current_dir, File selected_file, FileFilter fileFilter, String fileExtension, Frame owner)
          Prompts user to choose a file to save, specifying a file filter and file extension.
static File chooseFile(String title, String button_text, int selection_mode, File current_dir, File selected_file, Frame owner)
          Prompt user to choose a file.
static boolean containsUnicode(String str)
          Indicates whether or not the given String has any extended unicode characters in it.
static void copyResourceToFile(InputStream resource_stream, String write_file, String subset_dir)
          Copies the contents of the given InputStream to a new directory with a given file name.
static void Exit(int return_value)
          Cleans up system resources, then exits.
static void exitToWelcomeGUI(JFrame frame)
          Closes given JFrame and returns to the WelcomeGUI.
static void fakeMRDOCSuppressRows()
           
static String getApplicationBuildDate()
          Returns the application timestamp from MMSYS/config/timestamp.dat.
static String getApplicationVersion()
          Returns the application version from MMSYS/config/version.dat.
static String getBuildDate()
          Returns build date of the UMLS from release.dat.
static String getExtension(File f)
          Returns the extension portion of the file's name.
static MetamorphoSysGUI getGui()
          Returns the MetamorphoSysGUI.
static String[] getInterfaceImplementations(String interface_name)
          Scans all .jar files in the CLASSPATH and returns all fully qualified class names that implement the specified interface.
static String getLvgVersion()
          Returns the lvg version from release.dat.
static String getReleaseDate()
          Returns release date of the UMLS from release.dat.
static Properties getReleaseDatProperties()
          Get a copy of the release.dat Properties with the property list filled in.
static String getReleaseDescription()
          Returns release description of the UMLS from release.dat.
static String getReleaseVersion()
          Returns release version of the UMLS from release.dat.
static JMenuItem getResourceHelpMenu(String title, String url, Frame owner)
          Returns a JMenuItem for a "Help" menu that opens a browser with the specified URL.
static JMenuItem getURLHelpMenu(String title, String url, GlassPaneListener gpl)
          Returns a JMenuItem for a "Help" menu that opens a browser with the specified URL.
static Object instantiateObject(String name)
          Instantiates an object of the specified fully qualified type.
static JPanel makeCard(JTable table, String title)
          Helper function to make panels for the MetamorphoSysGUI tabbed pane.
static void printStackTrace(Exception e, BufferedWriter b)
          Prints the stack trace from the given Exception to the given BufferedWriter.
static boolean readTar(InputStream in, String untarDir, File tgz_file, Frame owner)
           
static void setGui(MetamorphoSysGUI gui)
          Sets a reference to the MetamorphoSysGUI.
static void setReleaseDatLocation(String rd)
          Sets the location of the release.dat file.
static void setUsingView(boolean view)
          Sets the "using view" flag.
static void showLogAndExitToWelcomeGUI(String title, File log_file)
          Cleans up system resources, shows the log file, then exits.
static String[] splitString(String to_split, int line_length)
          Splits a string on word boundaries so that each element of the string array returned represents a "line" of the original string that is no longer than the specified max line length.
static long timeDifference(Date now, Date then)
          Compute the time difference between the specified parameters.
static String timeToString(long time)
          Convert a long representing a time to a string representing hours, minutes, and seconds.
static void writeReleaseDatFile(String mr_dir)
          Helper method for writing release.dat.
 
Methods inherited from class gov.nih.nlm.swing.SwingToolkit
confirmRequest, confirmRequest, confirmRequestWithOption, copy, displayTextFile, displayTextFile, displayURL, getMultiLineUserInput, getMultiLineUserInput, getPanelForHTML, getProperties, getProperty, getProperty, getUserInput, getUserInput, makeColorTransparent, md5, notifyUser, notifyUser, notifyUser, notifyUserWithOption, readScaledImage, removeProperty, reportError, reportError, reportError, setProperties, setProperty, unzip, unzip, usingView
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MMSToolkit

public MMSToolkit()
Method Detail

setUsingView

public static void setUsingView(boolean view)
Sets the "using view" flag.

Parameters:
view - a boolean flag indicating whether or not the current application is using a GUI.

chooseFile

public static File chooseFile(String title,
                              String button_text,
                              int selection_mode,
                              File current_dir,
                              File selected_file,
                              Frame owner)
Prompt user to choose a file.

Parameters:
title - the title of the dialog
button_text - the text on the button
selection_mode - the selection mode (i.e. Files/Directories/both)
current_dir - the current directory
selected_file - File
owner - parent Component
Returns:
the File selected by the user

chooseFile

public static File chooseFile(String title,
                              String button_text,
                              int selection_mode,
                              File current_dir,
                              File selected_file,
                              FileFilter fileFilter,
                              Frame owner)
Prompts user to choose a file, specifying a file filter.

Parameters:
title - the title of the dialog
button_text - the text on the button
selection_mode - the selection mode (i.e. Files/Directories/both)
current_dir - the current directory
selected_file - File
fileFilter - FileFilter on accepted file type(s)
owner - parent Component
Returns:
the File selected by the user

chooseFile

public static File chooseFile(String title,
                              String button_text,
                              int selection_mode,
                              File current_dir,
                              File selected_file,
                              FileFilter fileFilter,
                              String fileExtension,
                              Frame owner)
Prompts user to choose a file to save, specifying a file filter and file extension.

Parameters:
title - the title of the dialog
button_text - the text on the button
selection_mode - the selection mode (i.e. Files/Directories/both)
current_dir - the current directory
selected_file - File
fileFilter - FileFilter on accepted file type(s)
fileExtension - desired file extension
owner - parent Component
Returns:
the File selected by the user

getExtension

public static String getExtension(File f)
Returns the extension portion of the file's name.

Returns:
the file's extension, or an empty String if none.
See Also:
FileFilter.accept(java.io.File)

containsUnicode

public static boolean containsUnicode(String str)
                               throws UnsupportedEncodingException
Indicates whether or not the given String has any extended unicode characters in it.

Parameters:
str - given String
Returns:
boolean true extended Unicode characters are present false extended Unicode characters are not present
Throws:
UnsupportedEncodingException

archiveContainsDir

public static boolean archiveContainsDir(File file,
                                         String dir)
                                  throws Exception
Returns true if the given archive File contains the given directory.

Parameters:
file - archive File
dir - directory name
Returns:
true if archive contains the given directory false otherwise
Throws:
Exception

timeToString

public static String timeToString(long time)
Convert a long representing a time to a string representing hours, minutes, and seconds.

Parameters:
time - the time in milliseconds
Returns:
a String representation "HH:MM:SS"

timeDifference

public static long timeDifference(Date now,
                                  Date then)
Compute the time difference between the specified parameters.

Parameters:
now - the later time
then - the earlier time
Returns:
a long indicating the number of milliseconds between the specified dates

getInterfaceImplementations

public static String[] getInterfaceImplementations(String interface_name)
                                            throws ClassNotFoundException,
                                                   IOException
Scans all .jar files in the CLASSPATH and returns all fully qualified class names that implement the specified interface.

Parameters:
interface_name - the fully qualified interface name
Returns:
a String[] of all fully qualified class names implementing that interface
Throws:
ClassNotFoundException
IOException

Exit

public static void Exit(int return_value)
Cleans up system resources, then exits.

Parameters:
return_value - the System.exit(int) status code

exitToWelcomeGUI

public static void exitToWelcomeGUI(JFrame frame)
Closes given JFrame and returns to the WelcomeGUI.

Parameters:
frame - {JFrame} of sub-application to exit

showLogAndExitToWelcomeGUI

public static void showLogAndExitToWelcomeGUI(String title,
                                              File log_file)
Cleans up system resources, shows the log file, then exits.

Parameters:
title - for the log
log_file - File for log

makeCard

public static JPanel makeCard(JTable table,
                              String title)
Helper function to make panels for the MetamorphoSysGUI tabbed pane. Each panel displays the configuration GUI for one filter.

Parameters:
table - a JTable to be displayed
title - title for the panel
Returns:
a JPanel with the table and title on it

instantiateObject

public static Object instantiateObject(String name)
Instantiates an object of the specified fully qualified type.

Parameters:
name - a fully qualified class name
Returns:
Object that was instantiated

getResourceHelpMenu

public static JMenuItem getResourceHelpMenu(String title,
                                            String url,
                                            Frame owner)
Returns a JMenuItem for a "Help" menu that opens a browser with the specified URL. The title is used for the help menu item label.

Parameters:
title - for help menu
url - for help menu display
owner - parent Component
Returns:
JMenuItem for a "Help" menu item

getURLHelpMenu

public static JMenuItem getURLHelpMenu(String title,
                                       String url,
                                       GlassPaneListener gpl)
Returns a JMenuItem for a "Help" menu that opens a browser with the specified URL. The title is used for the help menu item label.

Parameters:
title - for help menu
url - to be displayed
gpl - GlassPaneListener
Returns:
JMenuItem for a "Help" menu item

getApplicationBuildDate

public static String getApplicationBuildDate()
Returns the application timestamp from MMSYS/config/timestamp.dat.

Returns:
the application timestamp from MMSYS/config/timestamp.dat.

getApplicationVersion

public static String getApplicationVersion()
Returns the application version from MMSYS/config/version.dat.

Returns:
the application version from MMSYS/config/version.dat.

getReleaseVersion

public static String getReleaseVersion()
Returns release version of the UMLS from release.dat.

Returns:
release version of the UMLS from release.dat

getReleaseDescription

public static String getReleaseDescription()
Returns release description of the UMLS from release.dat.

Returns:
release description of the UMLS from release.dat

getReleaseDate

public static String getReleaseDate()
Returns release date of the UMLS from release.dat.

Returns:
release date of the UMLS from release.dat

getBuildDate

public static String getBuildDate()
Returns build date of the UMLS from release.dat.

Returns:
build date of the UMLS from release.dat

getLvgVersion

public static String getLvgVersion()
Returns the lvg version from release.dat.

Returns:
lvg version from release.dat

writeReleaseDatFile

public static void writeReleaseDatFile(String mr_dir)
                                throws IOException
Helper method for writing release.dat.

Parameters:
mr_dir - directory location for release.dat
Throws:
IOException - if the file cannot be written

getReleaseDatProperties

public static Properties getReleaseDatProperties()
Get a copy of the release.dat Properties with the property list filled in.

Returns:
a copy of the release.dat Properties.

setReleaseDatLocation

public static void setReleaseDatLocation(String rd)
                                  throws IOException
Sets the location of the release.dat file. Opens the release.dat file and load the properties.

Parameters:
rd - the location of the release.dat file
Throws:
IOException

copyResourceToFile

public static void copyResourceToFile(InputStream resource_stream,
                                      String write_file,
                                      String subset_dir)
                               throws IOException
Copies the contents of the given InputStream to a new directory with a given file name. It treats the stream as a character stream by wrapping it with

Parameters:
resource_stream - InputStream of resource to be copied
write_file - String name of subset file
subset_dir - String subset directory
Throws:
IOException - if anything goes wrong

setGui

public static void setGui(MetamorphoSysGUI gui)
Sets a reference to the MetamorphoSysGUI.

Parameters:
gui - the MetamorphoSysGUI

getGui

public static MetamorphoSysGUI getGui()
Returns the MetamorphoSysGUI.

Returns:
the MetamorphoSysGUI

cancel

public static void cancel()
Determines whether or not a cancel operation should call System.Exit.


splitString

public static String[] splitString(String to_split,
                                   int line_length)
Splits a string on word boundaries so that each element of the string array returned represents a "line" of the original string that is no longer than the specified max line length. This is very useful for breaking up long strings into 80 character chunks for displaying in a " terminal.

Parameters:
to_split - the String to split up
line_length - the maximum line length, or -1 to accept the default setting.
Returns:
a String[] of the lines

fakeMRDOCSuppressRows

public static void fakeMRDOCSuppressRows()

printStackTrace

public static void printStackTrace(Exception e,
                                   BufferedWriter b)
Prints the stack trace from the given Exception to the given BufferedWriter.

Parameters:
e - Exception
b - BufferedWriter

readTar

public static boolean readTar(InputStream in,
                              String untarDir,
                              File tgz_file,
                              Frame owner)
                       throws IOException
Throws:
IOException


Copyright ©2005