net.grelf
Class Util

java.lang.Object
  extended by net.grelf.Util

public class Util
extends java.lang.Object

Miscellaneous useful static methods. This class cannot be instantiated.


Field Summary
static boolean DEBUG
           
 
Method Summary
static double askDouble(java.awt.Component parentComponent, java.lang.String prompt, double initialValue, double min, double max)
          Ask the user for a double value.
static double askDouble(java.lang.String prompt, double initialValue, double min, double max)
          Ask the user for a double value.
static int askInteger(java.awt.Component parentComponent, java.lang.String prompt, int initialValue, int min, int max)
          Ask the user for an int value.
static int askInteger(java.lang.String prompt, int initialValue, int min, int max)
          Ask the user for an int value.
static java.lang.String askString(java.awt.Component parentComponent, java.lang.String prompt, java.lang.String initialValue)
          Ask the user for a String of free text.
static java.lang.String askString(java.lang.String prompt, java.lang.String initialValue)
          Ask the user for a String of free text.
static boolean confirm(java.awt.Component parent, java.lang.String title, java.lang.Object question)
          Convenience method for displaying a yes/no confirmation dialogue.
static boolean confirm(java.lang.String title, java.lang.Object question)
          Convenience method for displaying a yes/no confirmation dialogue.
static java.lang.String format_yyyyMMddTHHmmss(java.util.Date when)
           
static java.lang.String format(double d)
          Format a measurement of type double for display (not using HTML).
static java.lang.String formatHTML(double d)
          Format a measurement of type double for display.
static long getMilliseconds(java.lang.String dateTime)
          Convert a date-time string in format 2006:11:16 21:05:10 into milliseconds since 1970.0.
static boolean isRoomForTemporaryTiffImages(java.io.File path, int nFiles, long imWidth, long imHeight, int imBands, int imBits)
          Check whether there is enough disc space for the estimated size of temporary TIFF files, prompting the user to do something about it if there is not.
static void logInfo(java.lang.String msg)
           
static void logInfo(java.lang.String msg, java.lang.Object... params)
           
static void logWarning(java.lang.String msg)
           
static void logWarning(java.lang.String msg, java.lang.Object... params)
           
static javax.swing.JMenuItem menuItem(java.awt.event.ActionListener listener, java.lang.String label, java.lang.String command, int mnemonic, int acceleratorKey)
          Convenience method for creating a menu item.
static javax.swing.JMenuItem menuItem(java.awt.event.ActionListener listener, java.lang.String label, java.lang.String command, int mnemonic, int acceleratorKey, boolean withCtrl)
          Convenience method for creating a menu item.
static void message(java.awt.Component parent, java.lang.String title, java.lang.Object text)
          Convenience method for displaying a message dialogue.
static void message(java.lang.String title, java.lang.Object text)
          Convenience method for displaying a message dialogue.
static int nOccurs(java.lang.String s, char ch)
          Find the number of occurences of a character in a String.
static void notYet()
          Display a message dialogue apologising that an operation is not yet available.
static void notYet(java.awt.Component parent)
          Display a message dialogue apologising that an operation is not yet available.
static java.lang.String rational(java.lang.String s)
          If a String comprises numbers separated by a '/' do the implied division and return the result as a new String.
static float rationalFloat(java.lang.String s)
          If a String comprises numbers separated by a '/' do the implied division and return the result as a new float.
static java.lang.String removeSubString(java.lang.String s, java.lang.String subString)
          If subString occurs in String s remove it, otherwise return unmodified s.
static double rootSumOfSquares(double[] x)
           
static long rootSumOfSquares(long[] x)
           
static void saveJTableAsCSV(java.lang.String[] columnHeadings, javax.swing.JTable table, java.lang.String pathToFile)
          Removes any HTML (swing formatting) elements embedded in cells.
static void setOwningApp(java.awt.Component parent, javax.swing.ImageIcon icon)
           
static void setShowErrors(boolean show)
          Set false if you want Util.warning () only to write to the log, not to show a message to the user.
static void showMemory(java.lang.String message)
          Show some JVM memory information in the console window.
static java.lang.String[] splitPath(java.lang.String path)
          Split a path (may be using forward slashes or backslashes).
static void warning(java.awt.Component parent, java.lang.String title, java.lang.Object text)
          Convenience method for displaying a message dialogue with a warning icon and also logging the warning.
static void warning(java.awt.Component parent, java.lang.String title, java.lang.String text, java.lang.Object... params)
          Convenience method for displaying a message dialogue with a warning icon and also logging the warning.
static void warning(java.lang.String title, java.lang.Object text)
          Convenience method for displaying a message dialogue with a warning icon and also logging the warning.
static void warning(java.lang.String title, java.lang.String text, java.lang.Object... params)
          Convenience method for displaying a message dialogue with a warning icon and also logging the warning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values
Method Detail

setOwningApp

public static void setOwningApp(java.awt.Component parent,
                                javax.swing.ImageIcon icon)

askDouble

public static double askDouble(java.lang.String prompt,
                               double initialValue,
                               double min,
                               double max)
Ask the user for a double value. Returns Double.NaN if user cancelled input.


askDouble

public static double askDouble(java.awt.Component parentComponent,
                               java.lang.String prompt,
                               double initialValue,
                               double min,
                               double max)
Ask the user for a double value. Returns Double.NaN if user cancelled input.


askInteger

public static int askInteger(java.lang.String prompt,
                             int initialValue,
                             int min,
                             int max)
Ask the user for an int value. Returns Integer.MIN_VALUE if user cancelled input.


askInteger

public static int askInteger(java.awt.Component parentComponent,
                             java.lang.String prompt,
                             int initialValue,
                             int min,
                             int max)
Ask the user for an int value. Returns Integer.MIN_VALUE if user cancelled input.


askString

public static java.lang.String askString(java.lang.String prompt,
                                         java.lang.String initialValue)
Ask the user for a String of free text. Returns null if user cancelled input.


askString

public static java.lang.String askString(java.awt.Component parentComponent,
                                         java.lang.String prompt,
                                         java.lang.String initialValue)
Ask the user for a String of free text. Returns null if user cancelled input.


confirm

public static boolean confirm(java.lang.String title,
                              java.lang.Object question)
Convenience method for displaying a yes/no confirmation dialogue.


confirm

public static boolean confirm(java.awt.Component parent,
                              java.lang.String title,
                              java.lang.Object question)
Convenience method for displaying a yes/no confirmation dialogue.


format_yyyyMMddTHHmmss

public static java.lang.String format_yyyyMMddTHHmmss(java.util.Date when)

format

public static java.lang.String format(double d)
Format a measurement of type double for display (not using HTML).


formatHTML

public static java.lang.String formatHTML(double d)
Format a measurement of type double for display. Uses HTML so powers of ten are displayed in mathematical style using superscripts rather than computerese E-notation.


getMilliseconds

public static long getMilliseconds(java.lang.String dateTime)
Convert a date-time string in format 2006:11:16 21:05:10 into milliseconds since 1970.0. Returns 0 if the date cannot be parsed.


isRoomForTemporaryTiffImages

public static boolean isRoomForTemporaryTiffImages(java.io.File path,
                                                   int nFiles,
                                                   long imWidth,
                                                   long imHeight,
                                                   int imBands,
                                                   int imBits)
Check whether there is enough disc space for the estimated size of temporary TIFF files, prompting the user to do something about it if there is not. The path parameter can refer to any object in the partition to be checked. Requires Java 6 or later.


logInfo

public static void logInfo(java.lang.String msg,
                           java.lang.Object... params)

logInfo

public static void logInfo(java.lang.String msg)

logWarning

public static void logWarning(java.lang.String msg,
                              java.lang.Object... params)

logWarning

public static void logWarning(java.lang.String msg)

menuItem

public static javax.swing.JMenuItem menuItem(java.awt.event.ActionListener listener,
                                             java.lang.String label,
                                             java.lang.String command,
                                             int mnemonic,
                                             int acceleratorKey)
Convenience method for creating a menu item. This is the usual version to call, which adds Ctrl+ to the accelerator key.


menuItem

public static javax.swing.JMenuItem menuItem(java.awt.event.ActionListener listener,
                                             java.lang.String label,
                                             java.lang.String command,
                                             int mnemonic,
                                             int acceleratorKey,
                                             boolean withCtrl)
Convenience method for creating a menu item. Call this version if you don't want Ctrl+ added to the accelerator key, using withCtrl = false.


message

public static void message(java.lang.String title,
                           java.lang.Object text)
Convenience method for displaying a message dialogue.


message

public static void message(java.awt.Component parent,
                           java.lang.String title,
                           java.lang.Object text)
Convenience method for displaying a message dialogue.


nOccurs

public static int nOccurs(java.lang.String s,
                          char ch)
Find the number of occurences of a character in a String.


notYet

public static void notYet()
Display a message dialogue apologising that an operation is not yet available. The parent is assumed to be GRIP.


notYet

public static void notYet(java.awt.Component parent)
Display a message dialogue apologising that an operation is not yet available.


rational

public static java.lang.String rational(java.lang.String s)
If a String comprises numbers separated by a '/' do the implied division and return the result as a new String. Otherwise return the original String.


rationalFloat

public static float rationalFloat(java.lang.String s)
If a String comprises numbers separated by a '/' do the implied division and return the result as a new float. Otherwise return the original String parsed as a float. Return -1.0F if parsing fails.


removeSubString

public static java.lang.String removeSubString(java.lang.String s,
                                               java.lang.String subString)
If subString occurs in String s remove it, otherwise return unmodified s. Only checks for a single occurence of the sub-string.


rootSumOfSquares

public static double rootSumOfSquares(double[] x)

rootSumOfSquares

public static long rootSumOfSquares(long[] x)

saveJTableAsCSV

public static void saveJTableAsCSV(java.lang.String[] columnHeadings,
                                   javax.swing.JTable table,
                                   java.lang.String pathToFile)
Removes any HTML (swing formatting) elements embedded in cells. The array columnHeadings may be null, in which case there is simply no headings row in the output.
10.4.29: Added pathToFile parameter, to remove dependency on net.grelf.grip.FileIO


showMemory

public static void showMemory(java.lang.String message)
Show some JVM memory information in the console window.


splitPath

public static java.lang.String[] splitPath(java.lang.String path)
Split a path (may be using forward slashes or backslashes).


warning

public static void warning(java.lang.String title,
                           java.lang.Object text)
Convenience method for displaying a message dialogue with a warning icon and also logging the warning.


warning

public static void warning(java.awt.Component parent,
                           java.lang.String title,
                           java.lang.Object text)
Convenience method for displaying a message dialogue with a warning icon and also logging the warning.


warning

public static void warning(java.lang.String title,
                           java.lang.String text,
                           java.lang.Object... params)
Convenience method for displaying a message dialogue with a warning icon and also logging the warning.


warning

public static void warning(java.awt.Component parent,
                           java.lang.String title,
                           java.lang.String text,
                           java.lang.Object... params)
Convenience method for displaying a message dialogue with a warning icon and also logging the warning.


setShowErrors

public static void setShowErrors(boolean show)
Set false if you want Util.warning () only to write to the log, not to show a message to the user.