kiwi.util
Class KiwiUtils

java.lang.Object
  |
  +--kiwi.util.KiwiUtils

public final class KiwiUtils
extends Object

This class consists of several convenience routines. These methods are all static.

Version:
2.0 (10/98)
Author:
Mark Lindner, PING Software Group

Field Summary
static int blockSize
          The data transfer block size.
static EmptyBorder defaultBorder
          A default Kiwi border (empty, 5 pixels on all sides).
static EmptyBorder emptyBorder
          A default Kiwi border (empty, 0 pixels on all sides).
static Insets emptyInsets
          Empty insets (zero pixels on all sides).
static File filesystemRoot
          The root of the filesystem.
static Frame phantomFrame
          A phantom Frame.
 
Method Summary
static void busyOff(Component c)
          Turn off the busy cursor.
static void busyOn(Component c)
          Turn on a busy cursor.
static void cascadeWindow(Window parent, Window w)
          Cascade a window off of a parent window.
static void cascadeWindow(Window parent, Window w, int offset)
          Cascade a window off of a parent window.
static void cascadeWindow(Window parent, Window w, int offsetx, int offsety)
          Cascade a window off of a parent window.
static void centerWindow(Window w)
          Center a window on the screen.
static void centerWindow(Window parent, Window w)
          Center a window within the bounds of another window.
static int deleteTree(File parent)
          Recursively delete files in a directory.
static String getClipboardText()
          Copy text from the system clipboard.
static Frame getFrameForComponent(Component c)
          Get the Frame parent of a component.
static AboutFrame getKiwiAboutFrame()
          Get an instance to a prebuilt about window that describes the Kiwi Toolkit itself.
static ResourceManager getResourceManager()
          Get a reference to the internal resource manager singleton.
static void paintImmediately(Component c)
          Paint a component immediately.
static byte[] readStreamToByteArray(InputStream input)
          Read all of the data from a stream, returning the contents as a byte array.
static OutputStream readStreamToStream(InputStream input, OutputStream output)
          Read all of the data from a stream, writing it to another stream.
static String readStreamToString(InputStream input)
          Read all of the data from a stream, returning the contents as a String.
static void setClipboardText(String text)
          Copy text to the system clipboard.
static void sleep(int sec)
          Suspend the calling thread.
static void writeStringToStream(String s, OutputStream output)
          Write a string to a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blockSize

public static final int blockSize
The data transfer block size.

phantomFrame

public static final Frame phantomFrame
A phantom Frame.

emptyInsets

public static final Insets emptyInsets
Empty insets (zero pixels on all sides).

defaultBorder

public static final EmptyBorder defaultBorder
A default Kiwi border (empty, 5 pixels on all sides).

emptyBorder

public static final EmptyBorder emptyBorder
A default Kiwi border (empty, 0 pixels on all sides).

filesystemRoot

public static final File filesystemRoot
The root of the filesystem.
Method Detail

paintImmediately

public static final void paintImmediately(Component c)
Paint a component immediately. Paints a component immediately (as opposed to queueing a repaint request in the event queue.)
Parameters:
c - The component to repaint.

cascadeWindow

public static final void cascadeWindow(Window parent,
                                       Window w,
                                       int offset)
Cascade a window off of a parent window. Moves a window a specified number of pixels below and to the right of another window.
Parameters:
parent - The parent window.
w - The window to cascade.
offset - The number of pixels to offset the window by vertically and horizontally.

cascadeWindow

public static final void cascadeWindow(Window parent,
                                       Window w,
                                       int offsetx,
                                       int offsety)
Cascade a window off of a parent window. Moves a window a specified number of pixels below and to the right of another window.
Parameters:
parent - The parent window.
w - The window to cascade.
offsetx - The number of pixels to offset the window by horizontally.
offsety - The number of pixels to offset the window by vertically.

cascadeWindow

public static final void cascadeWindow(Window parent,
                                       Window w)
Cascade a window off of a parent window. Moves a window 40 pixels below and to the right of another window.
Parameters:
parent - The parent window.
w - The window to cascade.

centerWindow

public static final void centerWindow(Window w)
Center a window on the screen.
Parameters:
w - The window to center.

centerWindow

public static final void centerWindow(Window parent,
                                      Window w)
Center a window within the bounds of another window.
Parameters:
w - The window to center.
parent - The window to center within.

busyOn

public static final void busyOn(Component c)
Turn on a busy cursor.
Parameters:
c - The component whose cursor will be changed.

busyOff

public static final void busyOff(Component c)
Turn off the busy cursor. The last cursor saved will be restored.
Parameters:
c - The component whose cursor will be changed.

getFrameForComponent

public static final Frame getFrameForComponent(Component c)
Get the Frame parent of a component. This method searches upward in the component hierarchy, searching for an ancestor that is a Frame.

setClipboardText

public static final void setClipboardText(String text)
Copy text to the system clipboard.
Parameters:
text - The text to copy to the clipboard.

getClipboardText

public static final String getClipboardText()
Copy text from the system clipboard.
Returns:
The text that is in the clipboard, or null if the clipboard is empty or does not contain plain text.

getResourceManager

public static final ResourceManager getResourceManager()
Get a reference to the internal resource manager singleton. The Kiwi Toolkit has a small built-in collection of textures, icons, audio clips, and HTML files.

sleep

public static final void sleep(int sec)
Suspend the calling thread. Suspends the calling thread, returning immediately if an exception occurs.
Parameters:
sec - The number of seconds to sleep.

readStreamToStream

public static final OutputStream readStreamToStream(InputStream input,
                                                    OutputStream output)
                                             throws IOException
Read all of the data from a stream, writing it to another stream. Reads data from the input stream and writes it to the output stream, until no more data is available.
Parameters:
input - The input stream.
output - The output stream.
Throws:
IOException - If an error occurred while reading from the stream.

readStreamToString

public static final String readStreamToString(InputStream input)
                                       throws IOException
Read all of the data from a stream, returning the contents as a String. Note that this method is not unicode-aware.
Parameters:
input - The stream to read from.
Returns:
The contents of the stream, as a String.
Throws:
IOException - If an error occurred while reading from the stream.

writeStringToStream

public static final void writeStringToStream(String s,
                                             OutputStream output)
                                      throws IOException
Write a string to a stream. Note that this method is not unicode-aware.
Parameters:
s - The string to write.
output - The stream to write it to.
Throws:
IOException - If an error occurred while writing to the stream.

readStreamToByteArray

public static final byte[] readStreamToByteArray(InputStream input)
                                          throws IOException
Read all of the data from a stream, returning the contents as a byte array.
Parameters:
input - The stream to read from.
Returns:
The contents of the stream, as a byte array.
Throws:
IOException - If an error occurred while reading from the stream.

getKiwiAboutFrame

public static final AboutFrame getKiwiAboutFrame()
Get an instance to a prebuilt about window that describes the Kiwi Toolkit itself.

deleteTree

public static final int deleteTree(File parent)
Recursively delete files in a directory. Deletes all files and subdirectories in the given directory.
Parameters:
parent - The parent (presumed to be a directory) of the files to be deleted. The parent is not deleted.
Returns:
The number of files and directories deleted.