Class Util

java.lang.Object
  extended by Util

public class Util
extends java.lang.Object

Class Util contains utility methods used by Flicker.

This work was produced by Peter Lemkin of the National Cancer Institute, an agency of the United States Government. As a work of the United States Government there is no associated copyright. It is offered as open source software under the Mozilla Public License (version 1.1) subject to the limitations noted in the accompanying LEGAL file. This notice must be included with the code. The Flicker Mozilla and Legal files are available on http://open2dprot.sourceforge.net/Flicker

Version:
$Date$ $Revision$
Author:
P. Lemkin (LECB/NCI), G. Thornwall (SAIC), Frederick, MD
See Also:
Flicker Home

Field Summary
private static boolean doingAlertFlag
          flag to enforce an atomic alerts
private static Flicker flk
          Instance of Flicker
 java.util.Hashtable flkStateHT
          Hash table of .flk values read
private  java.awt.Color lastMsgColor
           
private  java.lang.String lastMsgStr
           
 int nEntries
          # of hash table entries after call readNameValuesHashTableFromFile()
 int nStateEntries
          # of .flk hash table entries
 
Constructor Summary
Util(Flicker flkS)
          Util() - constructor for Class Util
 
Method Summary
 boolean addUserDemoFilesDBbyURL(java.lang.String userDemoDBurl)
          addUserDemoFilesDBbyURL() - Add user's demo images to DB by userURL.
static void appendReportMsg(java.lang.String sMsg)
          appendReportMsg() - append a report message to the report popup window
static void appendReportMsg(java.lang.String sMsg, java.awt.Color color)
          appendReportMsg() - append a report message to the report popup window
(package private) static java.lang.String[] bubbleSort(java.lang.String[] data, int len)
          bubbleSort() - Sort String array via bubble sort w/len
(package private) static int[] bubbleSortIndex(float[] data, int len, boolean ascending)
          bubbleSortIndex() - sort copy of float[0:len-1] data with bubble sort, return index[].
(package private) static int[] bubbleSortIndex(java.lang.String[] data, int len, boolean ascending)
          bubbleSortIndex() - sort copy of String[0:len-1] data with bubble sort, return index[].
(package private)  void clearReportMsg()
          clearReportMsg() - clear text in report popup window
 boolean[][] computeCircularMaskList(int r)
          computeCircularMaskList() - create a list of (x,y) point offsets for use later in convolution types of operations.
 boolean copyFile(java.lang.String srcName, java.lang.String dstName, java.lang.String optUpdateMsg, int optEstInputFileLth)
          copyFile() - binary copy of one file or URL toa local file
private  char cvByteToChar(byte b)
          cvByteToChar() - convert signed byte [-128:+127] to unsigned char in range [0:255]
private  int cvByteToInt(byte b)
          cvByteToInt() - convert signed byte [-128:+127] to unsigned int in range [0:255]
 int cvColor2ColorValue(java.awt.Color color)
          cvColor2ColorValue() - convert Color.xxx to color code
 java.awt.Color cvColorValue2Color(int colorCode)
          cvColorValue2Color() - convert color code to Color.xxx
(package private) static java.lang.String cvd2s(double v, int precision)
          cvd2s() - convert double to string with precision # of digits If precision > 0 then limit # of digits in fraction
(package private) static java.lang.String cvf2s(float v, int precision)
          cvf2s() - convert float to string with exact precision # of digits.
(package private) static java.lang.String cvf2sVariable(float v, int precision)
          cvf2sVariable() - convert float to string with precision # of digits.
static java.lang.String cvi2hexs(int iVal)
          cvi2hexs() - convert integer number to hex string
static java.lang.String cvi2os(int iVal)
          cvi2os() - convert integer number to octal string with leading 0.
private  byte cvIntToByte(int i)
          cvIntToByte() - convert int in range [0:255] to signed byte in range of [-128:+127].
(package private) static java.lang.String[] cvs2Array(java.lang.String str, int maxExpected, java.lang.String delimiterChr)
          cvs2Array() - cvt arg list "1,4,3,6,..." to "," - delim String[].
(package private) static float cvs2f(java.lang.String str, float defaultValue)
          cvs2f() - convert String to float with default value
(package private) static int cvs2i(java.lang.String str, int defaultValue)
          cvs2i() - convert String to int with default value
(package private) static java.lang.String dateStr()
          dateStr() - return a new Date string of the current day and time
 boolean deleteLocalFile(java.lang.String fileName)
          deleteLocalFile() - delete local file.
 void fatalReportMsg(java.lang.String sMsg, int timeoutMsec)
          fatalReportMsg() - display a fatal report message to the report popup window, then wait for before return.
static void forceReportWindowPopup()
          forceReportWindowPopup() - force the append Report Window to popup
 void gcAndMemoryStats(java.lang.String msg)
          gcAndMemoryStats() - String garbage collect & print memory statistics.
 boolean getAnnotationFromServer(ImageData iData, Spot s)
          getAnnotationFromServer() - get the gel iData spot s data from proteomic web server
 void getBaseFlkPropertiesStr(java.lang.StringBuffer sBuf)
          getBaseFlkPropertiesStr() - add generate tab-delim base Flicker properties State string to the string buffer The format is tab-delimited (name \t value \n) with one entry/line.
(package private) static java.lang.String getCurDateStr()
          getCurDateStr() - return date string in the format of YYMMDDHHMMSS.
 java.lang.String getFileName(java.lang.String file)
          getFileName() - get the file name after last '/' if any
 java.lang.String getFileNameFromPath(java.lang.String path)
          getFileNameFromPath() - extract the filename from the path
 java.lang.String getFullCalFilePath(ImageData iData)
          getFullCalFilePath() - compute the .cal file from the qualified imageFile If there is a subdirectory before the baseFile, then strip out the directory name and add it before the actual base file.
 java.awt.Color getLastMsgColor()
          getLastMsgColor() - get the last message color
 java.lang.String getLastMsgStr()
          getLastMsgStr() - get the last message string
 java.lang.String[] getProteinIDdataByXYurl(java.lang.String clickCGIbaseURL, int x, int y, java.lang.String msg)
          getProteinIDdataByXYurl() - read data from protein web site and parse {Swiss-Prot-id, protein-name} if found.
 java.lang.String getScrollerValuesStateStr()
          getScrollerValuesStateStr() - "Report scroller values" button
 java.lang.String getStateStr()
          getStateStr() - generate a tab-delim Flicker State string for when we write out the .flk state.
 boolean getStateValue(java.lang.String key, boolean def)
          getStateValue() - get boolean PARAM and use default if not found.
 float getStateValue(java.lang.String key, float def)
          getStateValue() - get float PARAM and use default if not found.
 int getStateValue(java.lang.String key, int def)
          getStateValue() - get int PARAM and use default if not found.
 long getStateValue(java.lang.String key, long def)
          getStateValue() - get float PARAM and use default if not found.
 java.lang.String getStateValue(java.lang.String key, java.lang.String def)
          getStateValue() - get PARAM and use default if not found.
static java.lang.String leftFillWithSpaces(java.lang.String str, int n)
          leftFillWithSpaces() - left fill the string with spaces to size n.
 boolean parseBaseFlkProperties()
          parseBaseFlkProperties() - parse the base Flicker State properties in the current hash table.
static void popupAlertMsg(java.lang.String msg)
          popupAlertMsg() - display the msg in msg1 and popup up an Alert message.
static void popupAlertMsg(java.lang.String msg, java.awt.Color bgColor)
          popupAlertMsg() - display the msg in msg1 and popup up an Alert message
(package private) static java.lang.String prettyPrintDateStr(java.lang.String ds)
          prettyPrintDateStr() - pretty-print date string.
static void printCurrentMemoryUsage(java.lang.String msg)
          printCurrentMemoryUsage() - print: %free, total memory usage and time of day to stdout.
(package private) static void quickSort(int[] a, int lo0, int hi0)
          quickSort() - sort the int[] array.
 boolean readBaseFlkPropertiesFile(java.lang.String fileName)
          readBaseFlkPropertiesFile() - read the base "Flicker.properties" file if it exists.
 byte[] readBytesFromURL(java.lang.String srcName, java.lang.String optUpdateMsg)
          readBytesFromURL() - read binary data from URL
 boolean readCalibrationFile(ImageData iData)
          readCalibrationFile() - read the image calibration from the "cal/{image file base}.cal" file or "cal/{image subdirectory}-DIR-{image file base}.cal" file.
 java.util.Hashtable readFlkState(java.lang.String stateFile, boolean readSpotListFilesFlag)
          readFlkState() - read the Flicker State file stateFile with a .flk file extension.
 boolean readFlkStateFile(java.lang.String flkStateFile, boolean reportErrorMsgsFlag)
          readFlkStateFile() - read a .flk state file and change the state
 java.util.Hashtable readNameValuesHashTableFromFile(java.lang.String fileName, java.lang.String sMsg, int hashTableSize)
          readNameValuesHashTableFromFile() - read a hashtable of tab-delimited name-value pairs from a file.
 java.util.Hashtable readNameValuesHashTableFromFile(java.lang.String fileName, java.lang.String sMsg, int hashTableSize, boolean usePopupAlertsFlag)
          readNameValuesHashTableFromFile() - read a hashtable of tab-delimited name-value pairs from a file.
(package private)  int resizeLAXfileData()
          resizeLAXfileData() - resize Flicker.lax file data for Flicker.
 java.lang.String rmvFileExtension(java.lang.String fileName)
          rmvFileExtension() - remove ".tif", ".jpg", ".gif", ".ppx" from file name and ignore the case.
(package private) static java.lang.String rmvRtnChars(java.lang.String str)
          rmvRtnChars() - remove return chars.
static java.lang.String rmvSpecifiedChar(java.lang.String str, char rmvChar)
          rmvSpecifiedChar() - remove specified chararcter
 void setFlickerGUI(boolean flkFlag)
          setFlickerGUI() - set the Flicker GUI state
 void setFlickerState(boolean enableFlag)
          setFlickerState() - enable/disable flicker and the checkbox and save the flickerFlag while doing Xform.
 void setLastMsgColor(java.awt.Color c)
          setLastMsgColor() - set the last message color
 void setReportMsg(java.lang.String sMsg)
          setReportMsg() - set a report message to the report popup window
 void setStateHashtableForGetValue(java.util.Hashtable ht)
          setStateHashtableForGetValue() - set working hash table for next getStateValue calls
 void setStateHashtableForGetValue(java.util.Hashtable ht, int nEntriesVal)
          setStateHashtableForGetValue() - set working hash table for next getStateValue calls
 void showMsg(java.lang.String msg, java.awt.Color c)
          showMsg() - show msg in GUI area 1, set the status-line & set color.
 void showMsg1(java.lang.String msg, java.awt.Color c)
          showMsg1() - show msg in GUI area 1, set the status-line & set color.
 void showMsg2(java.lang.String msg, java.awt.Color c)
          showMsg2() - show msg in GUI text area 2, status line and set color.
 void showStatus(java.lang.String msg, java.awt.Color c)
          showStatus() - show msg in GUI area 1, set the status-line & set color.
static void sleepMsec(int mSec)
          sleepMsec() - sleep for mSec.
(package private) static java.lang.String timeStr()
          timeStr() - return a new daytime HH:MM:SS string of the current time.
(package private)  boolean updateDemoDBfiles()
          updateDemoDBfiles() - update DB/FlkDemoDB.txt into program install area.
(package private)  boolean updateFlickerJarFile()
          updateFlickerJarFile() - update Flicker.jar into program install area.
(package private)  boolean updateFlkDBfiles(java.lang.String[] dbFile)
          updateFlkDBfiles() - update DB/ files into program install area.
 void updateLMSvaluesInImages()
          updateLMSvaluesInImages() - redraw landmarks in images if needed.
(package private) static java.lang.String useFileSeparatorChar(java.lang.String str, java.lang.String newSeparatorStr)
          useFileSeparatorChar() - use specified file separator chararcter Eg.
 boolean writeBaseFlkPropertiesFile(java.lang.String fileName)
          writeBaseFlkPropertiesFile() - write out "Flicker.properties" file to save user preferences.
 boolean writeCalibrationFile(ImageData iData)
          writeCalibrationFile() - write the image calibration into the "cal/{{demo image file base}.cal" file.
(package private)  boolean writeFlkState(java.lang.String flkStateFile)
          writeFlkState() - write a .flk state file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

flk

private static Flicker flk
Instance of Flicker


lastMsgStr

private java.lang.String lastMsgStr

lastMsgColor

private java.awt.Color lastMsgColor

doingAlertFlag

private static boolean doingAlertFlag
flag to enforce an atomic alerts


flkStateHT

public java.util.Hashtable flkStateHT
Hash table of .flk values read


nStateEntries

public int nStateEntries
# of .flk hash table entries


nEntries

public int nEntries
# of hash table entries after call readNameValuesHashTableFromFile()

Constructor Detail

Util

public Util(Flicker flkS)
Util() - constructor for Class Util

Parameters:
flk - instance of Flicker
Method Detail

updateLMSvaluesInImages

public final void updateLMSvaluesInImages()
updateLMSvaluesInImages() - redraw landmarks in images if needed.


setFlickerGUI

public void setFlickerGUI(boolean flkFlag)
setFlickerGUI() - set the Flicker GUI state


setFlickerState

public void setFlickerState(boolean enableFlag)
setFlickerState() - enable/disable flicker and the checkbox and save the flickerFlag while doing Xform. On turning back on, then restore the flicker state.

Parameters:
enableFlag - to enable or disable flicker

sleepMsec

public static void sleepMsec(int mSec)
sleepMsec() - sleep for mSec.


leftFillWithSpaces

public static final java.lang.String leftFillWithSpaces(java.lang.String str,
                                                        int n)
leftFillWithSpaces() - left fill the string with spaces to size n. If n < str.length(), then just return str.

Parameters:
str - to fill
n - max width
Returns:
adjusted string

cvi2os

public static final java.lang.String cvi2os(int iVal)
cvi2os() - convert integer number to octal string with leading 0.

Parameters:
iVal - to convert
Returns:
octal string [TODO]

cvi2hexs

public static final java.lang.String cvi2hexs(int iVal)
cvi2hexs() - convert integer number to hex string

Parameters:
iVal - to convert
Returns:
hex string [TODO]

cvf2s

static java.lang.String cvf2s(float v,
                              int precision)
cvf2s() - convert float to string with exact precision # of digits. If precision > 0 then limit # of digits in fraction

Parameters:
v - is value to convert
i - is the # of digits precision in the mantissa
Returns:
string approximating "%0.pd" If abs(v) < pow(10.0,-p) then return "+0" or "-0"

cvf2sVariable

static java.lang.String cvf2sVariable(float v,
                                      int precision)
cvf2sVariable() - convert float to string with precision # of digits. If precision > 0 then limit # of digits in fraction

Parameters:
v - is value to convert
i - is the # of digits precision in the mantissa
Returns:
string approximating "%0.pd" If abs(v) < pow(10.0,-p) then return "+0" or "-0"

cvd2s

static java.lang.String cvd2s(double v,
                              int precision)
cvd2s() - convert double to string with precision # of digits If precision > 0 then limit # of digits in fraction

Parameters:
v - is value to convert
i - is the # of digits precision in the mantissa
Returns:
string approximating "%0.pd" If abs(v) < pow(10.0,-p) then return "+0" or "-0"

getFileName

public java.lang.String getFileName(java.lang.String file)
getFileName() - get the file name after last '/' if any


getLastMsgStr

public java.lang.String getLastMsgStr()
getLastMsgStr() - get the last message string

Returns:
last message

getLastMsgColor

public java.awt.Color getLastMsgColor()
getLastMsgColor() - get the last message color

Returns:
last message color

setLastMsgColor

public void setLastMsgColor(java.awt.Color c)
setLastMsgColor() - set the last message color

Parameters:
c - is color to set

showMsg

public void showMsg(java.lang.String msg,
                    java.awt.Color c)
showMsg() - show msg in GUI area 1, set the status-line & set color. Also append to the report window.
 Default colors are:
   ERROR    = Color.red,
   OK       = Color.black
   evt debug= Color.blue.
   info     = Color.yellow
   % done   = Color.magenta

Parameters:
msg - is status message to display
c - is color to display it

showMsg1

public void showMsg1(java.lang.String msg,
                     java.awt.Color c)
showMsg1() - show msg in GUI area 1, set the status-line & set color. Also append to the report window if GUI exists.
 Default colors are:
   ERROR    = Color.red,
   OK       = Color.black
   evt debug= Color.blue.
   info     = Color.yellow
   % done   = Color.magenta

Parameters:
msg - is status message to display
c - is color to display it

showStatus

public void showStatus(java.lang.String msg,
                       java.awt.Color c)
showStatus() - show msg in GUI area 1, set the status-line & set color. Do NOT append to the report window.
 Default colors are:
   ERROR    = Color.red,
   OK       = Color.black
   evt debug= Color.blue.
   info     = Color.yellow
   % done   = Color.magenta

Parameters:
msg - is status message to display
c - is color to display it

showMsg2

public void showMsg2(java.lang.String msg,
                     java.awt.Color c)
showMsg2() - show msg in GUI text area 2, status line and set color. Also append to the report window.
 Default colors are:
   ERROR    = Color.red,
   OK       = Color.black
   evt debug= Color.blue.
   info     = Color.yellow
   % done   = Color.magenta

Parameters:
msg - is status message to display
c - is color to display it

clearReportMsg

void clearReportMsg()
clearReportMsg() - clear text in report popup window


setReportMsg

public void setReportMsg(java.lang.String sMsg)
setReportMsg() - set a report message to the report popup window

Parameters:
sMsg - to assign

popupAlertMsg

public static void popupAlertMsg(java.lang.String msg)
popupAlertMsg() - display the msg in msg1 and popup up an Alert message. Default the background to red.

Parameters:
msg - to display

popupAlertMsg

public static void popupAlertMsg(java.lang.String msg,
                                 java.awt.Color bgColor)
popupAlertMsg() - display the msg in msg1 and popup up an Alert message

Parameters:
msg - to display
bgColor - is the background color to use

fatalReportMsg

public void fatalReportMsg(java.lang.String sMsg,
                           int timeoutMsec)
fatalReportMsg() - display a fatal report message to the report popup window, then wait for before return. Clear the window first. Bring the message to the front.

Parameters:
sMsg - to display
timeoutMsec - if != 0 then wait that time. If it is <0 then exit the program after the timeout.

appendReportMsg

public static void appendReportMsg(java.lang.String sMsg)
appendReportMsg() - append a report message to the report popup window

Parameters:
sMsg - to append

appendReportMsg

public static void appendReportMsg(java.lang.String sMsg,
                                   java.awt.Color color)
appendReportMsg() - append a report message to the report popup window

Parameters:
sMsg - to append
color - if the color is Color.red, then force it to pop up if it is not visible.

forceReportWindowPopup

public static void forceReportWindowPopup()
forceReportWindowPopup() - force the append Report Window to popup


getScrollerValuesStateStr

public java.lang.String getScrollerValuesStateStr()
getScrollerValuesStateStr() - "Report scroller values" button


readFlkStateFile

public boolean readFlkStateFile(java.lang.String flkStateFile,
                                boolean reportErrorMsgsFlag)
readFlkStateFile() - read a .flk state file and change the state

Parameters:
flkStateFile - to read
reportErrorMsgsFlag - to report error messages when loads.
Returns:
true if read the file and changed the state [TODO] restore the oImg .gif files if they exist...

getFullCalFilePath

public java.lang.String getFullCalFilePath(ImageData iData)
getFullCalFilePath() - compute the .cal file from the qualified imageFile If there is a subdirectory before the baseFile, then strip out the directory name and add it before the actual base file. "cal/{image file base}.cal" file or "cal/{image subdirectory}-DIR-{image file base}.cal" file.

Parameters:
iData - to use in computing the .cal file path
Returns:
.cal file path

readCalibrationFile

public boolean readCalibrationFile(ImageData iData)
readCalibrationFile() - read the image calibration from the "cal/{image file base}.cal" file or "cal/{image subdirectory}-DIR-{image file base}.cal" file.

Parameters:
iData - is the Image Data to read the calibration
Returns:
true if succeed

cvColorValue2Color

public java.awt.Color cvColorValue2Color(int colorCode)
cvColorValue2Color() - convert color code to Color.xxx

Parameters:
colorCode -
Returns:
Color.xxx value

cvColor2ColorValue

public int cvColor2ColorValue(java.awt.Color color)
cvColor2ColorValue() - convert Color.xxx to color code

Parameters:
color -
Returns:
color code

readNameValuesHashTableFromFile

public java.util.Hashtable readNameValuesHashTableFromFile(java.lang.String fileName,
                                                           java.lang.String sMsg,
                                                           int hashTableSize)
readNameValuesHashTableFromFile() - read a hashtable of tab-delimited name-value pairs from a file. Convert the (name\tvalue\n) data to a hashtable. Allow popup error messages.

Parameters:
fileName - is the name of the file to read
sMsg - to print when reading the file.
Returns:
hashtable else null if not found. The global variable nEntries contains the number of entries.

readNameValuesHashTableFromFile

public java.util.Hashtable readNameValuesHashTableFromFile(java.lang.String fileName,
                                                           java.lang.String sMsg,
                                                           int hashTableSize,
                                                           boolean usePopupAlertsFlag)
readNameValuesHashTableFromFile() - read a hashtable of tab-delimited name-value pairs from a file. Convert the (name\tvalue\n) data to a hashtable.

Parameters:
fileName - is the name of the file to read
sMsg - to print when reading the file.
usePopupAlertsFlag - if allow popup error messages
Returns:
hashtable else null if not found. The global variable nEntries contains the number of entries.

setStateHashtableForGetValue

public void setStateHashtableForGetValue(java.util.Hashtable ht,
                                         int nEntriesVal)
setStateHashtableForGetValue() - set working hash table for next getStateValue calls

Parameters:
ht - is hashtable to use
nEntriesVal - is the number of elements used in the hash table.

setStateHashtableForGetValue

public void setStateHashtableForGetValue(java.util.Hashtable ht)
setStateHashtableForGetValue() - set working hash table for next getStateValue calls

Parameters:
ht - is hashtable to use

readBaseFlkPropertiesFile

public boolean readBaseFlkPropertiesFile(java.lang.String fileName)
readBaseFlkPropertiesFile() - read the base "Flicker.properties" file if it exists. This sets the user's default properties. If they do a (File | Reset) it overides this.

Parameters:
fileName - to read (e.g., "Flicker.properties")
Returns:
true if succeed

writeBaseFlkPropertiesFile

public boolean writeBaseFlkPropertiesFile(java.lang.String fileName)
writeBaseFlkPropertiesFile() - write out "Flicker.properties" file to save user preferences.

Parameters:
fileName - to read (e.g., "Flicker.properties")
Returns:
true if succeed

getAnnotationFromServer

public boolean getAnnotationFromServer(ImageData iData,
                                       Spot s)
getAnnotationFromServer() - get the gel iData spot s data from proteomic web server

Parameters:
iData - is the gel image
s - is the spot (it contains the x,y) coordinates
Returns:
true if succeed

getProteinIDdataByXYurl

public java.lang.String[] getProteinIDdataByXYurl(java.lang.String clickCGIbaseURL,
                                                  int x,
                                                  int y,
                                                  java.lang.String msg)
getProteinIDdataByXYurl() - read data from protein web site and parse {Swiss-Prot-id, protein-name} if found.

Parameters:
clickCGIbaseURL - is web site to get protein data
x - is x coordinate in active gel image
y - is y coordinate in active gel image
msg - is msg coordinate in active gel image
Returns:
{Swiss-Prot-id, protein-name} if succeed, null if fail

readFlkState

public java.util.Hashtable readFlkState(java.lang.String stateFile,
                                        boolean readSpotListFilesFlag)
readFlkState() - read the Flicker State file stateFile with a .flk file extension.

Parameters:
stateFile - is the name of the Flicker state file
readSpotListFilesFlag - read the spt/*.spt files
Returns:
hashtable of the state else null if not found or the associated images are not found.

parseBaseFlkProperties

public boolean parseBaseFlkProperties()
parseBaseFlkProperties() - parse the base Flicker State properties in the current hash table.

Returns:
true if ok

writeFlkState

boolean writeFlkState(java.lang.String flkStateFile)
writeFlkState() - write a .flk state file

Parameters:
flkStateFile - to write
Returns:
true if wrote the file

writeCalibrationFile

public boolean writeCalibrationFile(ImageData iData)
writeCalibrationFile() - write the image calibration into the "cal/{{demo image file base}.cal" file. "cal/{subdirectory}-DIR-{image file base}.cal" file.

Parameters:
iData - is the Image Data to write the calibration
Returns:
true if succeed

getStateStr

public java.lang.String getStateStr()
getStateStr() - generate a tab-delim Flicker State string for when we write out the .flk state. The format is tab-delimted (name \t value \n) with one entry/line.

Returns:
the state string

getBaseFlkPropertiesStr

public void getBaseFlkPropertiesStr(java.lang.StringBuffer sBuf)
getBaseFlkPropertiesStr() - add generate tab-delim base Flicker properties State string to the string buffer The format is tab-delimited (name \t value \n) with one entry/line.

Parameters:
sBuf - is the string buffer to add data to

getStateValue

public java.lang.String getStateValue(java.lang.String key,
                                      java.lang.String def)
getStateValue() - get PARAM and use default if not found.


getStateValue

public int getStateValue(java.lang.String key,
                         int def)
getStateValue() - get int PARAM and use default if not found.


getStateValue

public long getStateValue(java.lang.String key,
                          long def)
getStateValue() - get float PARAM and use default if not found.


getStateValue

public float getStateValue(java.lang.String key,
                           float def)
getStateValue() - get float PARAM and use default if not found.


getStateValue

public boolean getStateValue(java.lang.String key,
                             boolean def)
getStateValue() - get boolean PARAM and use default if not found.


copyFile

public boolean copyFile(java.lang.String srcName,
                        java.lang.String dstName,
                        java.lang.String optUpdateMsg,
                        int optEstInputFileLth)
copyFile() - binary copy of one file or URL toa local file

Parameters:
srcName - is either a full path local file name or a http:// prefixed URL string of the source file.
dstName - is the full path of the local destination file name
optUpdateMsg - (opt) will display message in showMsg() and increasing ... in showMsg2(). One '.' for every 10K bytes read. This only is used when reading a URL. Set to null if not used.
optEstInputFileLth - is the estimate size of the input file if known else 0. Used in progress bar.
Returns:
true if succeed.

readBytesFromURL

public byte[] readBytesFromURL(java.lang.String srcName,
                               java.lang.String optUpdateMsg)
readBytesFromURL() - read binary data from URL

Parameters:
srcName - is either a full path local file name or a http:// prefixed URL string of the source file.
optUpdateMsg - (opt) will display message in showMsg() and increasing ... in showMsg2(). One '.' for every 10K bytes read. This only is used when reading a URL. Set to null if not used.
Returns:
a byte[] if succeed, else null.

deleteLocalFile

public boolean deleteLocalFile(java.lang.String fileName)
deleteLocalFile() - delete local file.

Returns:
false if failed..

updateFlickerJarFile

final boolean updateFlickerJarFile()
updateFlickerJarFile() - update Flicker.jar into program install area.
 [1] Define directory for Flicker.jar path and other file and URL names.
 [2] Backup the old Flicker.jar as Flicker.jar.bkup
 [3] Open the url: from flkJarURL. This is hardwired to be
         "http://www.lecb.ncifcrf.gov/Flicker/Flicker.jar"
     and read the file from the Web into local file "Flicker.jar.tmp"
 [4] Move the "Flicker.jar.tmp" file into "Flicker.jar" in the
     program directory

 Since changing the Flicker.jar file is a potential security risk,
 we make this procedure final and hardwire the flkJarURL!

Returns:
true if succeed
See Also:
copyFile(java.lang.String, java.lang.String, java.lang.String, int), deleteLocalFile(java.lang.String)

updateFlkDBfiles

final boolean updateFlkDBfiles(java.lang.String[] dbFile)
updateFlkDBfiles() - update DB/ files into program install area.
 [1] Define directory for DB/Flk*DB.txt path and other file and URL 
     names.
 [2] Backup the old DB/ as FlkMapDB.txt.bkup
 [3] Open the url: from flkMapDBURL. This is hardwired to be
         "http://www.lecb.ncifcrf.gov/Flicker/DB/< dbList>"
     and read the file from the Web into local file "< dbList >.tmp"
 [4] Move the "< dbList >.tmp" file into "DB/.txt" in the 
    program directory

 Since changing the DB/ file is a potential security risk,
 we make this procedure final and hardwire the flk*DBURL!

Parameters:
dbFile - is a list of DB/ to read
Returns:
true if succeed
See Also:
copyFile(java.lang.String, java.lang.String, java.lang.String, int), deleteLocalFile(java.lang.String)

updateDemoDBfiles

final boolean updateDemoDBfiles()
updateDemoDBfiles() - update DB/FlkDemoDB.txt into program install area. Also read the DB/FlkDemoDB.dir to get the list of files in the Images/ directory to read.
 [1] Get the list of files in DB/FlkDemoDB.dir into < imgList >
 [2] For each iFile in imgList[1:nFiles],
  [2.1] Backup the old Image/imgList[i] as imgList[i].bkup
   [2.2] Open the url: from flkDemoDBURL. This is hardwired to be
         "http://www.lecb.ncifcrf.gov/Flicker/Image/"+imgList[i]
         and read the file from the Web into local file 
          imgList[i]+".tmp"
   [2.3] Move the imgList[i]+".tmp" file into "Images/"+imgList[i] in the
    program directory
 [3] Copy the "http://www.lecb.ncifcrf.gov/Flicker/Images/*" files
   to "/Images".

 Since changing the DB/FlkDemoDB.txt file is a potential security risk,
 we make this procedure final and hardwire the flkDemoDBURL!

Returns:
true if succeed
See Also:
copyFile(java.lang.String, java.lang.String, java.lang.String, int), deleteLocalFile(java.lang.String)

addUserDemoFilesDBbyURL

public boolean addUserDemoFilesDBbyURL(java.lang.String userDemoDBurl)
addUserDemoFilesDBbyURL() - Add user's demo images to DB by userURL. This will append a user's DB/FlkDemoDB.txt data with the current Flicker DB/FlkDemoDB.txt file in the installation area. Also read the user's DB/FlkDemoDB.dir to get the list of demo files to read and add from the user's server to the installation Images/ directory.
 [1] This assumes that the DB/FlkDemoDB.txt has been read into the
    FlkDemo database in memory on when Flicker was started.
   [1.1] Copy DB/FlkDemo.txt to DB/FlkDemo.txt.bkup
 [2] Read the URL file < userURL >/DB/FlkDemoDB.dir into < userImgList >
 [3] Read the URL file < userURL >/DB/FlkDemoDB.txt into another instance
     of FlkDemo.
 [4] Using < userImgList >, read each iFile in userImgList[1:nFiles],
   [4.1] Open the url: from userDemoDBurl. This URL compute as
           ( userDemoDBurl + "Images/" + userImgList[i] )
         and read the file from the Web into local file 
            ( "Images/" + ( userImgList[i])
   [4.2] Append an the entry for userImgList[i] into the in-core FlkDemo
         data structure.
 [5] If successful, write out the DB/FlkDemo.txt file with the new data.
 [6] Give user message that they need to restart Flicker to see the changes.

 Since changing the DB/FlkDemoDB.txt file is a potential security risk,
 we make this procedure final and hardwire the flkDemoDBURL!

Parameters:
userDemoDBurl - is the base address for the user's demo data this Web directory will contain subdirectories Images/ and DB/ and DB/ contains FlkDemoDB.dir and FlkDemoDB.txt with the entries for the corresponding images.
Returns:
true if succeed
See Also:
copyFile(java.lang.String, java.lang.String, java.lang.String, int), deleteLocalFile(java.lang.String)

dateStr

static java.lang.String dateStr()
dateStr() - return a new Date string of the current day and time

Returns:
a new Date string of the current day and time

getCurDateStr

static java.lang.String getCurDateStr()
getCurDateStr() - return date string in the format of YYMMDDHHMMSS. This date string is sortable by date. Note: Adds "0" to first single digit if value is 1-9.


prettyPrintDateStr

static java.lang.String prettyPrintDateStr(java.lang.String ds)
prettyPrintDateStr() - pretty-print date string.

Parameters:
ds - is the date string in the format of YYMMDDHHMMSS.
Returns:
pretty print string DD/MM/YY HH:MM:SS

cvs2Array

static java.lang.String[] cvs2Array(java.lang.String str,
                                    int maxExpected,
                                    java.lang.String delimiterChr)
cvs2Array() - cvt arg list "1,4,3,6,..." to "," - delim String[]. If there are more than maxExpected number of args in string, ignore them and just return what has been parsed so far.

Parameters:
str - string containt a list of Strings
maxExpected - # of numbers to be parsed [DEPRICATED and ignored]
delimChr - delimiter to be used with "," the default
Returns:
array of Strings else null if problem

cvs2f

static float cvs2f(java.lang.String str,
                   float defaultValue)
cvs2f() - convert String to float with default value

Parameters:
str - to convert
defaultValue - if bad numeric string
Returns:
numeric value

cvs2i

static int cvs2i(java.lang.String str,
                 int defaultValue)
cvs2i() - convert String to int with default value

Parameters:
str - to convert
defaultValue - if bad numeric string
Returns:
numeric value

cvByteToInt

private final int cvByteToInt(byte b)
cvByteToInt() - convert signed byte [-128:+127] to unsigned int in range [0:255]

Parameters:
b - is byte to convert
Returns:

cvByteToChar

private final char cvByteToChar(byte b)
cvByteToChar() - convert signed byte [-128:+127] to unsigned char in range [0:255]

Parameters:
b - is byte to convert
Returns:
unsigned char

cvIntToByte

private final byte cvIntToByte(int i)
cvIntToByte() - convert int in range [0:255] to signed byte in range of [-128:+127].

Parameters:
i - is integer to convert
Returns:
usigned byte

quickSort

static void quickSort(int[] a,
                      int lo0,
                      int hi0)
quickSort() - sort the int[] array. Based on QuickSort method by James Gosling from Sun's SortDemo applet

Parameters:
a - array of data to sort
lo0 - lower bound of array
hi0 - uppper bound of array

bubbleSort

static java.lang.String[] bubbleSort(java.lang.String[] data,
                                     int len)
bubbleSort() - Sort String array via bubble sort w/len

Parameters:
data - array of data to be sorted
len - size of subarray array of data to be sorted [0:len-1]
Returns:
the new sorted string[] array

bubbleSortIndex

static int[] bubbleSortIndex(java.lang.String[] data,
                             int len,
                             boolean ascending)
bubbleSortIndex() - sort copy of String[0:len-1] data with bubble sort, return index[]. Do NOT actually sort the original data[].

Parameters:
data - array of data to be sorted
len - size of subarray array of data to be sorted [0:len-1]
ascending - sort if true
Returns:
the index[] of the sorted data

bubbleSortIndex

static int[] bubbleSortIndex(float[] data,
                             int len,
                             boolean ascending)
bubbleSortIndex() - sort copy of float[0:len-1] data with bubble sort, return index[]. Do NOT actually sort the original data[].

Parameters:
data - array of data to be sorted
len - size of subarray array of data to be sorted [0:len-1]
ascending - sort if true
Returns:
the index[] of the sorted data

getFileNameFromPath

public java.lang.String getFileNameFromPath(java.lang.String path)
getFileNameFromPath() - extract the filename from the path

Parameters:
path -
Returns:
filename

rmvFileExtension

public java.lang.String rmvFileExtension(java.lang.String fileName)
rmvFileExtension() - remove ".tif", ".jpg", ".gif", ".ppx" from file name and ignore the case.

Parameters:
fileName -
Returns:
filename without file extension

rmvRtnChars

static java.lang.String rmvRtnChars(java.lang.String str)
rmvRtnChars() - remove return chars. Map '\r' or "\r\n" to '\n' chars.

Parameters:
String - str to process
Returns:
String with '\r' removed.

rmvSpecifiedChar

public static java.lang.String rmvSpecifiedChar(java.lang.String str,
                                                char rmvChar)
rmvSpecifiedChar() - remove specified chararcter

Parameters:
str - to process
rmvChar - to remove
Returns:
String with all instances of the specified charater removed.

useFileSeparatorChar

static java.lang.String useFileSeparatorChar(java.lang.String str,
                                             java.lang.String newSeparatorStr)
useFileSeparatorChar() - use specified file separator chararcter Eg. if it is '\' then switch '/' to '\', Eg. if it is '/' then switch '\' to '/',

Parameters:
str - to process
newSeparatorStr - to use
Returns:
String with all instances of the specified character changed.

timeStr

static java.lang.String timeStr()
timeStr() - return a new daytime HH:MM:SS string of the current time.

Returns:
a new daytime HH:MM:SS string of the current time

printCurrentMemoryUsage

public static void printCurrentMemoryUsage(java.lang.String msg)
printCurrentMemoryUsage() - print: %free, total memory usage and time of day to stdout. A sample value is
   **** Memory[ BCF:setBrCt() end]:
   28% free, tot=24.36Mb [9:30:0] ****
,/PRE>

Parameters:
msg - to display with this memory snapshot
See Also:
FileIO#logMsgln, cvd2s(double, int), timeStr()

gcAndMemoryStats

public void gcAndMemoryStats(java.lang.String msg)
gcAndMemoryStats() - String garbage collect & print memory statistics. Note that the free memory number is only an estimate. It may be more accurate if you run the garbage collector before calling 'freeMemory()'. Note: freeMemory is not always accurate. Print the accompanying message.


computeCircularMaskList

public boolean[][] computeCircularMaskList(int r)
computeCircularMaskList() - create a list of (x,y) point offsets for use later in convolution types of operations. [TODO] code is not complete....

Parameters:
r - - radius of circle inside the region
Returns:
region[0:2*r][0:2*r] (i.e., x,y) with 1

resizeLAXfileData

int resizeLAXfileData()
resizeLAXfileData() - resize Flicker.lax file data for Flicker. This file is read by the InstallAnywhere runtime when you start Flicker and is used to set the initial heap and stack process size. The LAX file (e.g., C:/Program Files/Flicker/Flicker.lax) specifies the startup sizes for both the heap and stack. It determines the current size, asks the user for a new size then creates a new file if it succeeds in the Q and A. The memory size specified must be > 128Mbytes and less than the swap space. However, it is not clear how to get access to that value across all systems.

Returns:
-1 if fail, else the new memory size