ix.util
Class Util

java.lang.Object
  |
  +--ix.util.Util

public class Util
extends java.lang.Object

Class for useful static methods that don't belong anywhere else.

See Also:
Collect, Fn, Strings

Inner Class Summary
static class Util.NameGenerator
          Name generator a la gensym.
 
Constructor Summary
Util()
           
 
Method Summary
static java.lang.String askLine(java.lang.String prompt)
          Simple, text-based user interaction.
static java.lang.Object copy(java.lang.Object obj)
          Returns a top-level copy of the object.
static java.lang.Object copy(java.lang.Object obj, java.lang.Class resultClass)
          Returns a top-level copy as an instance of the specified result class.
static boolean dialogConfirms(java.awt.Component parent, java.lang.String text)
          Displays a confirmation dialog.
static void displayAndWait(java.awt.Component parentComponent, java.lang.Object message)
          Asks the GUI event-handling thread to displays a text message in a dialogue box and does not return until this has occurred.
static void displayMessage(java.awt.Component parentComponent, java.lang.Object message)
          Asks the GUI event-handling thread to displays a text message in a dialogue box.
static java.lang.String generateName(java.lang.String base)
          Generates a name unique within this VM that begins with the specified base string.
static java.lang.String getHostName()
          Returns the name of the machine that is running this JVM.
static java.lang.String getUserName()
          Returns the name of the user who started this JVM.
static java.lang.Object makeInstance(java.lang.Class c)
          Makes an instance of a class using the 0-argument constructor.
static void notImplemented(java.awt.Component parent, java.lang.String item)
          Brings up a message that the given string item is not yet supported.
static void printGreeting(java.lang.String name)
          A method to print the name of the system, the release version, and the release date.
static void printLines(java.lang.String[] lines)
          Print the elements of a String[] array to System.out as lines.
static java.lang.String quote(java.lang.String text)
          Puts double quotes around a string.
static java.lang.String readLine(java.io.InputStream is)
          Reads a line from an InputStream and returns it as a String.
static javax.swing.ImageIcon resourceImageIcon(java.lang.String name)
          Constructs an ImageIcon from the named (image) resource found on the system's class path.
static javax.swing.ImageIcon resourceImageIconFromFile(java.lang.String filename)
          Deprecated. As of April 1, 2002; try resourceImageIcon(String).
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

printGreeting

public static void printGreeting(java.lang.String name)
A method to print the name of the system, the release version, and the release date.

displayMessage

public static void displayMessage(java.awt.Component parentComponent,
                                  java.lang.Object message)
Asks the GUI event-handling thread to displays a text message in a dialogue box.

Always calls SwingUtilities.invokeLater(Runnable), which puts the request at the end of the queue even if called from the event dispatching thread.

Parameters:
parentComponent - determines the Frame in which dialogs are displayed.
message - the contents of the message.

displayAndWait

public static void displayAndWait(java.awt.Component parentComponent,
                                  java.lang.Object message)
Asks the GUI event-handling thread to displays a text message in a dialogue box and does not return until this has occurred.

If this method is called outside the event dispatching thread, it calls SwingUtilities.invokeAndWait(Runnable).

Parameters:
parentComponent - determines the Frame in which dialogs are displayed.
text - the contents of the message.

notImplemented

public static void notImplemented(java.awt.Component parent,
                                  java.lang.String item)
Brings up a message that the given string item is not yet supported. e.g. "Deleting a schema is not yet supported"

dialogConfirms

public static boolean dialogConfirms(java.awt.Component parent,
                                     java.lang.String text)
Displays a confirmation dialog.

resourceImageIcon

public static javax.swing.ImageIcon resourceImageIcon(java.lang.String name)
Constructs an ImageIcon from the named (image) resource found on the system's class path. If the name contains "/", it is used as-is; else "resources/images/" is added to the front.

resourceImageIconFromFile

public static javax.swing.ImageIcon resourceImageIconFromFile(java.lang.String filename)
Deprecated. As of April 1, 2002; try resourceImageIcon(String).

Constructs an ImageIcon from the specified file in the "images" subdirectory of the I-X "resources" directory.

getUserName

public static java.lang.String getUserName()
Returns the name of the user who started this JVM.

getHostName

public static java.lang.String getHostName()
                                    throws java.net.UnknownHostException
Returns the name of the machine that is running this JVM.

quote

public static java.lang.String quote(java.lang.String text)
Puts double quotes around a string. This is useful to indicate the boundaries of the string when it's included in other text such as in an error or warning message.

generateName

public static java.lang.String generateName(java.lang.String base)
Generates a name unique within this VM that begins with the specified base string. (Note that "unique" means unique among the names generated in this way; the same string might, of course, be constructed in some other way.)

copy

public static java.lang.Object copy(java.lang.Object obj)
                             throws java.lang.InstantiationException,
                                    java.lang.IllegalAccessException,
                                    java.lang.reflect.InvocationTargetException
Returns a top-level copy of the object.
See Also:
ObjectCopier

copy

public static java.lang.Object copy(java.lang.Object obj,
                                    java.lang.Class resultClass)
                             throws java.lang.InstantiationException,
                                    java.lang.IllegalAccessException,
                                    java.lang.reflect.InvocationTargetException
Returns a top-level copy as an instance of the specified result class.
See Also:
ObjectCopier

makeInstance

public static java.lang.Object makeInstance(java.lang.Class c)
Makes an instance of a class using the 0-argument constructor.
Throws:
java.lang.Error - if the attempt fails.

printLines

public static void printLines(java.lang.String[] lines)
Print the elements of a String[] array to System.out as lines.

askLine

public static java.lang.String askLine(java.lang.String prompt)
Simple, text-based user interaction. askLine prints a prompt to System.out and returns a String containing the next line from System.in.

If askLine blocks when reading, we'd like other threads to be able to run; but that doesn't seem to happen reliably. Presumably, this is a bug. In any case, askLine works around the problem by having a loop that checks whether input is available and sleeps for a second if it isn't.


readLine

public static java.lang.String readLine(java.io.InputStream is)
Reads a line from an InputStream and returns it as a String. In Java, we seem to have to write this ourself unless we wrap a special stream (or Reader) around whatever we want to read. Here we provide a static method, because that's easier to mix with other operations. The only InputStream method called is read().