gov.nasa.pds.ltdt.gui.util
Class Utility

java.lang.Object
  extended by gov.nasa.pds.ltdt.gui.util.Utility

public class Utility
extends java.lang.Object


Constructor Summary
Utility()
           
 
Method Summary
static java.lang.String addCRLF(java.lang.String s)
          Add carriage-return (\) followed by linefeed (\) at the end of a string.
static java.lang.String addLeadingWhiteSpace(java.lang.String string, int length)
          Adds leading whitespaces to a given string
static java.lang.String addQuotes(java.lang.String string)
          Add surrounding quotes
static java.lang.String addTrailingWhiteSpace(java.lang.String string, int length)
           
static javax.swing.JPanel createVerticalBoxPanel()
          Create a panel to hold components vertically
static boolean dirRWAllowed(java.lang.String dir)
          Examine if a directory is read/write permitted
static java.lang.String formatInt(int in, int targetLength)
           
static java.util.ArrayList getKeyList(java.lang.String inFile)
          Get a list of key fields in a keyword=value type of file, for example LTDT tool profile, LTDT project property file, etc.
static java.lang.String getNewProjectLogFileName(java.lang.String newProjectLocation)
          Get fully qualified name for a project log file located at non-default path
static java.lang.String getNewProjectPropertyFileName(java.lang.String newProjectLocation)
          Get fully qualified name for a project property file located at non-default path
static java.lang.String getNewProjectTemplateFileName(java.lang.String newProjectLocation)
          Get fully qualified name for a project templae file located at non-default path
static java.lang.String getNewProjectWDDFileName(java.lang.String newProjectLocation)
          Get fully qualified name for a project WDD file located at non-default path
static java.lang.String getProjectLocation(java.lang.String projectName)
          Given a proejct name, retrive the path of the project from LTDT property file HOME/.ltdt
static java.lang.String getProjectLogFileName(java.util.Properties props)
          Get full path name for a project log file
static java.lang.String getProjectName(java.lang.String projectLocation)
          Given a project location, search the LTDT tool property and find out the project registered with the location
static java.lang.String getProjectPropertyFileName(java.util.Properties props)
          Get fully qualified name for a project property file
static java.lang.String getProjectTemplateFileName(java.util.Properties props)
          Get fully qualified name for a project template file
static java.lang.String getProjectWDDFileName(java.util.Properties props)
          Get fully qualified name for a project WDD file
static java.util.Properties getProperties(java.net.URL propFile)
          Bases on URL, load and return properties info
static java.util.ArrayList getSortedProjectList(java.lang.String propFile)
          Return a sorted list of LTDT project names available on the system.
static void initializeEmptyProject(java.util.Properties props, MainWindow window)
          Clear windows and properties to get ready for the next project
static java.lang.String list2quotedSet(java.util.List dlist)
          Given a list object, this method constructs and returns a string contains element from the original list, with "," as delimiter and " around each element value.
static java.lang.String list2stringLF(java.util.List dlist)
          Given a List object and return it as a String with a ',' and a line feed as delimiters ** with a leading line feed
static java.lang.String list2stringNLF(java.util.List dlist)
          Given a List object and return it as a String with a ',' and a line feed as delimiters, ** without leading line feed
static java.lang.String makeTestString(int size)
          Makes a string.
static java.lang.String reformatDescription(java.lang.String origDescription)
           
static java.util.List rowstring2list(java.lang.String instring)
          Given a string, tokenize it, and create an ArrayList as result.
static java.util.List rowstring2listNotQuoted(java.lang.String instring)
          Given a string, tokenize it, and create an ArrayList as result.
static java.util.List rowstring2urllist(java.lang.String instring)
          Given a string with ; as delimeter, convert each elements into URL and stored in a list
static void startWait(MainWindow window)
           
static void stopWait(MainWindow window)
           
static java.net.URL toURL(java.lang.String s)
          Convert a string to a URL.
static java.lang.String trimLeadingWhiteSpace(java.lang.String string)
          Removes leading whitespaces in a string
static java.lang.String trimLeadingWhiteSpace(java.lang.String string, int length)
          Removes leading whitespaces in a string
static void writeLogEntry(java.lang.String logfile, java.lang.String message)
          Append a timestamp and a message to a log file
static void writeTemplate(MainWindow window, java.lang.String filename)
          Writes content in template editor to a file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utility

public Utility()
Method Detail

createVerticalBoxPanel

public static javax.swing.JPanel createVerticalBoxPanel()
Create a panel to hold components vertically

Returns:
A panel with vertical box layout and opaque background

formatInt

public static java.lang.String formatInt(int in,
                                         int targetLength)
Parameters:
in - An integer to be formatted to right justified string
targetLength - The length of string after formatting
Returns:
formatted string wih input integer padded with blanks on lefthand-side (right justified)

toURL

public static java.net.URL toURL(java.lang.String s)
                          throws java.net.MalformedURLException
Convert a string to a URL.

Parameters:
s - The string to convert
Returns:
A URL of the input string
Throws:
java.net.MalformedURLException

addCRLF

public static java.lang.String addCRLF(java.lang.String s)
Add carriage-return (\) followed by linefeed (\) at the end of a string.

Parameters:
s -
Returns:
The string appended with \\.

addLeadingWhiteSpace

public static java.lang.String addLeadingWhiteSpace(java.lang.String string,
                                                    int length)
Adds leading whitespaces to a given string

Parameters:
string - The string to add whitespaces to.
length - The number of whitespaces to add to the line.
Returns:
The string with leading whitespaces added.

addTrailingWhiteSpace

public static java.lang.String addTrailingWhiteSpace(java.lang.String string,
                                                     int length)

trimLeadingWhiteSpace

public static java.lang.String trimLeadingWhiteSpace(java.lang.String string,
                                                     int length)
Removes leading whitespaces in a string

Parameters:
string - The string
length - The number of whitespaces to delete
Returns:
The trimmed string

trimLeadingWhiteSpace

public static java.lang.String trimLeadingWhiteSpace(java.lang.String string)
Removes leading whitespaces in a string

Parameters:
string - The string
Returns:
The given string without the leading whitespaces

addQuotes

public static java.lang.String addQuotes(java.lang.String string)
Add surrounding quotes

Parameters:
string -
Returns:
The string surrounded with quotes

makeTestString

public static java.lang.String makeTestString(int size)
Makes a string. For instance, if the given size is '3', the string returned will be 'ABC'.

Parameters:
size - The size of the string
Returns:
a string based on the given size

getKeyList

public static java.util.ArrayList getKeyList(java.lang.String inFile)
                                      throws java.io.IOException
Get a list of key fields in a keyword=value type of file, for example LTDT tool profile, LTDT project property file, etc. The existence of input file should be checked prior to calling this method. Lines starts with # and lines does not have K=V pairs are ignored.

Parameters:
inFile - Input filename.
Returns:
An ArrayList containing valid project names.
Throws:
java.io.IOException

getSortedProjectList

public static java.util.ArrayList getSortedProjectList(java.lang.String propFile)
                                                throws java.io.IOException
Return a sorted list of LTDT project names available on the system. The project names are included in this list only if their associating project property files exist.

Parameters:
propFile - The LTDT tool property file with project=path entries
Returns:
List of sorted project names
Throws:
java.io.IOException - , FileNotFoundException

getProjectLocation

public static java.lang.String getProjectLocation(java.lang.String projectName)
                                           throws java.io.IOException,
                                                  java.io.FileNotFoundException
Given a proejct name, retrive the path of the project from LTDT property file HOME/.ltdt

Parameters:
projectName -
Returns:
Path where a project workarea is located
Throws:
java.io.IOException
java.io.FileNotFoundException

getProjectName

public static java.lang.String getProjectName(java.lang.String projectLocation)
                                       throws java.io.IOException,
                                              java.io.FileNotFoundException
Given a project location, search the LTDT tool property and find out the project registered with the location

Parameters:
projectLocation -
Returns:
Project Name
Throws:
java.io.IOException
java.io.FileNotFoundException

dirRWAllowed

public static boolean dirRWAllowed(java.lang.String dir)
Examine if a directory is read/write permitted

Parameters:
dir - Directory
Returns:
true or false

writeLogEntry

public static void writeLogEntry(java.lang.String logfile,
                                 java.lang.String message)
                          throws java.io.IOException
Append a timestamp and a message to a log file

Parameters:
logfile -
message -
Throws:
java.io.IOException

getProjectPropertyFileName

public static java.lang.String getProjectPropertyFileName(java.util.Properties props)
Get fully qualified name for a project property file

Parameters:
props -
Returns:
Project Property File Name

getNewProjectPropertyFileName

public static java.lang.String getNewProjectPropertyFileName(java.lang.String newProjectLocation)
Get fully qualified name for a project property file located at non-default path

Parameters:
newProjectLocation -
Returns:
Project property file name

getProjectTemplateFileName

public static java.lang.String getProjectTemplateFileName(java.util.Properties props)
Get fully qualified name for a project template file

Parameters:
props -
Returns:
Template file name

getNewProjectTemplateFileName

public static java.lang.String getNewProjectTemplateFileName(java.lang.String newProjectLocation)
Get fully qualified name for a project templae file located at non-default path

Parameters:
newProjectLocation -
Returns:
Template file name

getProjectWDDFileName

public static java.lang.String getProjectWDDFileName(java.util.Properties props)
Get fully qualified name for a project WDD file

Parameters:
props -
Returns:
Project WDD file name in project path

getNewProjectWDDFileName

public static java.lang.String getNewProjectWDDFileName(java.lang.String newProjectLocation)
Get fully qualified name for a project WDD file located at non-default path

Parameters:
newProjectLocation -
Returns:
Project WDD file name at a non-default path

getProjectLogFileName

public static java.lang.String getProjectLogFileName(java.util.Properties props)
Get full path name for a project log file

Parameters:
props -
Returns:
Project log file name

getNewProjectLogFileName

public static java.lang.String getNewProjectLogFileName(java.lang.String newProjectLocation)
Get fully qualified name for a project log file located at non-default path

Parameters:
newProjectLocation -
Returns:
Project log file name

initializeEmptyProject

public static void initializeEmptyProject(java.util.Properties props,
                                          MainWindow window)
Clear windows and properties to get ready for the next project

Parameters:
props -
window -

list2stringLF

public static java.lang.String list2stringLF(java.util.List dlist)
Given a List object and return it as a String with a ',' and a line feed as delimiters ** with a leading line feed

Parameters:
dlist -
Returns:
concatenated string with elements from a list plus a leading line feed

list2stringNLF

public static java.lang.String list2stringNLF(java.util.List dlist)
Given a List object and return it as a String with a ',' and a line feed as delimiters, ** without leading line feed

Parameters:
dlist -
Returns:
concatenated string with elements from a list not including a leading line feed

list2quotedSet

public static java.lang.String list2quotedSet(java.util.List dlist)
Given a list object, this method constructs and returns a string contains element from the original list, with "," as delimiter and " around each element value.

Parameters:
dlist -
Returns:
string with concatenated list element values

rowstring2list

public static java.util.List rowstring2list(java.lang.String instring)
Given a string, tokenize it, and create an ArrayList as result. The delimiters are blank space, carriage return (\r), line feed (\n), semicolon(;) or comma (,)

Parameters:
instring -
Returns:
list of string tokens

rowstring2urllist

public static java.util.List rowstring2urllist(java.lang.String instring)
                                        throws java.net.MalformedURLException
Given a string with ; as delimeter, convert each elements into URL and stored in a list

Parameters:
instring -
Returns:
list of urls
Throws:
java.net.MalformedURLException

rowstring2listNotQuoted

public static java.util.List rowstring2listNotQuoted(java.lang.String instring)
Given a string, tokenize it, and create an ArrayList as result. The delimiters are blank space, carriage return (\r), line feed (\n), semicolon(;) or comma (,) The process explicitly removes surrounding quotes on every value in the result list.

Parameters:
instring -
Returns:
list of string tokens

writeTemplate

public static void writeTemplate(MainWindow window,
                                 java.lang.String filename)
                          throws java.io.IOException
Writes content in template editor to a file

Parameters:
window -
filename -
Throws:
java.io.IOException

startWait

public static void startWait(MainWindow window)

stopWait

public static void stopWait(MainWindow window)

reformatDescription

public static java.lang.String reformatDescription(java.lang.String origDescription)

getProperties

public static java.util.Properties getProperties(java.net.URL propFile)
                                          throws java.io.IOException
Bases on URL, load and return properties info

Returns:
Loaded properties
Throws:
java.io.IOException


Copyright © 2005-2008 NASA Jet Propulsion Laboratory, California Institute of Technology. All Rights Reserved.