kiwi.util
Class KiwiUtils

java.lang.Object
  extended bykiwi.util.KiwiUtils

public final class KiwiUtils
extends java.lang.Object

This class consists of several convenience routines and constants, all of which are static.

Author:
Mark Lindner

Field Summary
private static AboutFrame aboutFrame
           
static int blockSize
          The data transfer block size.
static java.awt.Font boldFont
          A default bold font.
private static java.awt.datatransfer.Clipboard clipboard
           
static javax.swing.border.EmptyBorder defaultBorder
          A default Kiwi border (empty, 5 pixels on all sides).
static javax.swing.border.EmptyBorder emptyBorder
          A default Kiwi border (empty, 0 pixels on all sides).
static java.awt.Insets emptyInsets
          Empty insets (zero pixels on all sides).
static java.io.File filesystemRoot
          The root of the filesystem.
static java.awt.Insets firstBottomInsets
          Predefined insets for first component on last line.
static java.awt.Insets firstInsets
          Predefined insets for first component on first or subsequent lines.
static java.awt.Font italicFont
          A default italic font.
static java.awt.Insets lastBottomInsets
          Predefined insets for last component on last line.
private static java.awt.Cursor lastCursor
           
static java.awt.Insets lastInsets
          Predefined insets for last component on first or subsequent lines.
static java.awt.Point origin
          An origin point: (0,0)
private static java.awt.Frame phantomFrame
          A phantom Frame.
static java.awt.Font plainFont
          A default plain font.
private static ResourceManager resmgr
           
 
Constructor Summary
private KiwiUtils()
           
 
Method Summary
private static void _cascadeWindow(java.awt.Window parent, java.awt.Window w, int offsetx, int offsety)
           
private static void _positionWindow(java.awt.Window w, int x, int y)
           
static void busyOff(java.awt.Component c)
          Turn off the busy cursor.
static void busyOn(java.awt.Component c)
          Turn on a busy cursor.
static void cascadeWindow(java.awt.Component c, java.awt.Window w)
          Cascade a window off of a component's parent window.
static void cascadeWindow(java.awt.Window parent, java.awt.Window w)
          Cascade a window off of a parent window.
static void cascadeWindow(java.awt.Window parent, java.awt.Window w, int offset)
          Cascade a window off of a parent window.
static void cascadeWindow(java.awt.Window parent, java.awt.Window w, int offsetx, int offsety)
          Cascade a window off of a parent window.
static void centerWindow(java.awt.Component c, java.awt.Window w)
          Center a window within the bounds of a component's parent window.
static void centerWindow(java.awt.Window w)
          Center a window on the screen.
static void centerWindow(java.awt.Window parent, java.awt.Window w)
          Center a window within the bounds of another window.
static int deleteTree(java.io.File parent)
          Recursively delete files in a directory.
static java.awt.datatransfer.Clipboard getClipboard()
          Get a reference to the system clipboard.
static java.lang.String getClipboardText()
          Copy text from the system clipboard.
static java.awt.Frame getFrameForComponent(java.awt.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 java.awt.Frame getPhantomFrame()
          Get a reference to a phantom frame.
static ResourceManager getResourceManager()
          Get a reference to the internal resource manager singleton.
static void paintImmediately(java.awt.Component c)
          Paint a component immediately.
static boolean printWindow(java.awt.Window window, java.lang.String title)
          Print a hardcopy of the contents of a window.
static byte[] readStreamToByteArray(java.io.InputStream input)
          Deprecated. This method has been moved to the StreamUtils class.
static java.io.OutputStream readStreamToStream(java.io.InputStream input, java.io.OutputStream output)
          Deprecated. This method has been moved to the StreamUtils class.
static java.lang.String readStreamToString(java.io.InputStream input)
          Deprecated. This method has been moved to the StreamUtils class.
static void setClipboardText(java.lang.String text)
          Copy text to the system clipboard.
static void setDefaultLookAndFeel()
          Set the default cross-platform Look and Feel
static void setFonts(java.awt.Container container, java.awt.Font font)
          Recursively set the font on a container and all of its descendant components.
static void setNativeLookAndFeel()
          Set the native (system) Look and Feel
static void sleep(int sec)
          Suspend the calling thread.
static void writeStringToStream(java.lang.String s, java.io.OutputStream output)
          Deprecated. This method has been moved to the StreamUtils class.
 
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.

See Also:
Constant Field Values

phantomFrame

private static java.awt.Frame phantomFrame
A phantom Frame.


emptyInsets

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


defaultBorder

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


emptyBorder

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


firstInsets

public static final java.awt.Insets firstInsets
Predefined insets for first component on first or subsequent lines. Defines 5 pixels of space to the right and below.


lastInsets

public static final java.awt.Insets lastInsets
Predefined insets for last component on first or subsequent lines. Defines 5 pixels of space below.


firstBottomInsets

public static final java.awt.Insets firstBottomInsets
Predefined insets for first component on last line. Defines 5 pixels of space to the right.


lastBottomInsets

public static final java.awt.Insets lastBottomInsets
Predefined insets for last component on last line. Defines no pixels of space.


filesystemRoot

public static final java.io.File filesystemRoot
The root of the filesystem.


boldFont

public static final java.awt.Font boldFont
A default bold font.


plainFont

public static final java.awt.Font plainFont
A default plain font.


italicFont

public static final java.awt.Font italicFont
A default italic font.


origin

public static final java.awt.Point origin
An origin point: (0,0)


lastCursor

private static java.awt.Cursor lastCursor

clipboard

private static java.awt.datatransfer.Clipboard clipboard

resmgr

private static ResourceManager resmgr

aboutFrame

private static AboutFrame aboutFrame
Constructor Detail

KiwiUtils

private KiwiUtils()
Method Detail

paintImmediately

public static final void paintImmediately(java.awt.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(java.awt.Window parent,
                                       java.awt.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(java.awt.Window parent,
                                       java.awt.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(java.awt.Window parent,
                                       java.awt.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.

cascadeWindow

public static final void cascadeWindow(java.awt.Component c,
                                       java.awt.Window w)
Cascade a window off of a component's parent window.

Parameters:
w - The window to cascade.
c - The component off whose parent window this window should be cascaded. If a window cannot be found in the component hierarchy above c, the window is centered on the screen.

_cascadeWindow

private static void _cascadeWindow(java.awt.Window parent,
                                   java.awt.Window w,
                                   int offsetx,
                                   int offsety)

centerWindow

public static final void centerWindow(java.awt.Window w)
Center a window on the screen.

Parameters:
w - The window to center.

_positionWindow

private static final void _positionWindow(java.awt.Window w,
                                          int x,
                                          int y)

centerWindow

public static final void centerWindow(java.awt.Window parent,
                                      java.awt.Window w)
Center a window within the bounds of another window.

Parameters:
w - The window to center.
parent - The window to center within.

centerWindow

public static final void centerWindow(java.awt.Component c,
                                      java.awt.Window w)
Center a window within the bounds of a component's parent window.

Parameters:
w - The window to center.
c - The component within whose parent window this window should be centered. If a window cannot be found in the component hierarchy above c, the window is centered on the screen.

busyOn

public static final void busyOn(java.awt.Component c)
Turn on a busy cursor.

Parameters:
c - The component whose cursor will be changed.

busyOff

public static final void busyOff(java.awt.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 java.awt.Frame getFrameForComponent(java.awt.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.


printWindow

public static final boolean printWindow(java.awt.Window window,
                                        java.lang.String title)
Print a hardcopy of the contents of a window.

Parameters:
window - The window to print.
title - A title for the print job.
Returns:
true if the print job was started, or false if the user cancelled the print dialog.

getClipboard

public static final java.awt.datatransfer.Clipboard getClipboard()
Get a reference to the system clipboard.

Returns:
The clipboard.

setClipboardText

public static final void setClipboardText(java.lang.String text)
Copy text to the system clipboard.

Parameters:
text - The text to copy to the clipboard.

getClipboardText

public static final java.lang.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 java.io.OutputStream readStreamToStream(java.io.InputStream input,
                                                            java.io.OutputStream output)
                                                     throws java.io.IOException
Deprecated. This method has been moved to the StreamUtils class.

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:
java.io.IOException - If an error occurred while reading from the stream.

readStreamToString

public static final java.lang.String readStreamToString(java.io.InputStream input)
                                                 throws java.io.IOException
Deprecated. This method has been moved to the StreamUtils class.

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:
java.io.IOException - If an error occurred while reading from the stream.

writeStringToStream

public static final void writeStringToStream(java.lang.String s,
                                             java.io.OutputStream output)
                                      throws java.io.IOException
Deprecated. This method has been moved to the StreamUtils class.

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:
java.io.IOException - If an error occurred while writing to the stream.

readStreamToByteArray

public static final byte[] readStreamToByteArray(java.io.InputStream input)
                                          throws java.io.IOException
Deprecated. This method has been moved to the StreamUtils class.

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:
java.io.IOException - If an error occurred while reading from the stream.

getPhantomFrame

public static final java.awt.Frame getPhantomFrame()
Get a reference to a phantom frame.

Returns:
The phantom frame.

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(java.io.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.

setFonts

public static void setFonts(java.awt.Container container,
                            java.awt.Font font)
Recursively set the font on a container and all of its descendant components.

Parameters:
container - The container.
font - The new font.
Since:
Kiwi 1.4.3

setDefaultLookAndFeel

public static void setDefaultLookAndFeel()
Set the default cross-platform Look and Feel

Since:
Kiwi 1.4.3

setNativeLookAndFeel

public static void setNativeLookAndFeel()
Set the native (system) Look and Feel

Since:
Kiwi 1.4.3