|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.common.util.Util
A bunch of utility functions that address omissions in the Java language and class libraries, plus some extra game-specific stuff.
Constructor Summary | |
Util()
|
Method Summary | |
static boolean |
appendToFile(java.lang.String path,
java.lang.String text)
Appends a string to the end of a text file. |
static void |
copyFile(java.io.File src,
java.io.File dest)
Copies a file. |
static void |
copyFile(java.lang.String src,
java.lang.String dest)
Copies a file. |
static boolean |
derivedFrom(java.lang.Class subClass,
java.lang.String superName)
Figure out whether one class is derived from another, where the superclass is specified by a string, so you don't have to know about it statically. |
static java.awt.Image |
filterImage(java.awt.Image src,
java.awt.image.ImageFilter filter)
Takes the specified image and creates a grayscale version. |
static java.lang.String |
formatColor(java.awt.Color c)
prints out a color as a 3-item list |
static java.lang.String |
formatPoint(java.awt.Dimension d)
Formats a Dimension object as (x, y). |
static java.lang.String |
formatPoint(int x,
int y)
Use this for error-checking and diagnostics. |
static java.lang.String |
formatPoint(int x,
int y,
int z)
|
static java.lang.String |
formatPoint(java.awt.Point p)
|
static java.lang.String |
formatTime(long sec)
Turns a number of seconds into a string showing the days, hours, minutes and seconds for that interval. |
static java.lang.String |
formatTimeShort(long sec)
Formats a time (in seconds) as hrs:min, e.g. 12:34 |
static java.awt.Frame |
getFrame(java.awt.Component c)
Gets the top-level Frame object by searching up the tree. |
static java.awt.Image |
loadImage(java.awt.Component c,
java.lang.String name)
|
static java.awt.Image |
loadImage(java.lang.String name)
Loads an image from disk. |
static void |
main(java.lang.String[] args)
Tests everything. |
static void |
markBusy(java.awt.Component c)
Mark the app as busy. |
static void |
markNotBusy(java.awt.Component c)
Mark the app as not busy. |
static byte[] |
pack3DIntArray(int[][][] data)
Packs a 3D int array into an array of bytes, such that it can be read back in by a DataInputStream wrapping a ByteArrayInputStream. |
static byte[] |
packShortArray(short[] data)
Packs an array of shorts into an array of bytes such that it can be read back in by a DataInputStream wrapping a ByteArrayInputStream. |
static byte[] |
packStringArray(java.lang.String[] data)
Turns an array of strings into an array of bytes, using a DataOutputStream wrapping a ByteArrayOutputStream. |
static void |
print(java.lang.Object[] objs)
Prints an object array out by calling toString() on all the elements. |
static void |
print2DIntArray(int[][] array)
Prints a 2D array for debugging. |
static void |
print3DIntArray(int[][][] array)
Prints a 3D array for debugging. |
static java.lang.String |
printByteArray(byte[] data)
Used for debugging - produces really ugly output. |
static java.lang.String |
printException(java.lang.Throwable t)
Captures an Exception backtrace into a string. |
static void |
printIntArray(int[] array)
Prints out an array's values. |
static void |
printObjectArray(java.lang.Object[] array)
Prints out an array of arbitrary objects. |
static void |
printProperties(java.util.Properties p)
Prints a java.util.Properties list. |
static void |
printStringArray(java.lang.String[] array)
Prints an array's values. |
static byte[] |
readFile(java.lang.String path)
Reads a file as an array of bytes. |
static java.lang.String |
readFileCache(java.lang.String path)
Reads the contents of a file, caching the results. |
void |
showImageSize(java.awt.Image i)
Used for debugging only. |
static int[][][] |
unpack3DIntArray(byte[] data)
Unpacks a 3D int[][][] that was written to a byte array using a DataOutputStream and a ByteArrayOutputStream. |
static short[] |
unpackShortArray(byte[] data)
Unpacks an array of shorts that was packaged up by writing the values onto a DataOutputStream wrapping a ByteArrayOutputStream. |
static java.lang.String[] |
unpackStringArray(byte[] data)
Unpacks an array of Strings that was packaged up by writing the values onto a DataOutputStream wrapping a ByteArrayOutputStream. |
static void |
waitForImage(java.awt.Component component,
java.awt.Image image)
|
static void |
waitForImage(java.awt.Image image)
Waits for an image to finish being loaded or rendered (e.g. from getScaledInstance()), by creating a component to do the waiting. |
static boolean |
writeFile(java.lang.String path,
byte[] bytes)
Writes the contents of a file. |
static boolean |
writeFile(java.lang.String path,
java.lang.String body)
Writes the contents of a file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Util()
Method Detail |
public static boolean derivedFrom(java.lang.Class subClass, java.lang.String superName)
subClass
- a Class you want to verify derived from superName.superName
- the String name of the class you're deriving from.
Needs to be the full package name (e.g. java.util.Vector).
public void showImageSize(java.awt.Image i)
public static java.awt.Image loadImage(java.lang.String name)
name
- the absolute path to the imagepublic static java.awt.Image loadImage(java.awt.Component c, java.lang.String name)
public static void waitForImage(java.awt.Component component, java.awt.Image image)
public static void waitForImage(java.awt.Image image)
public static java.lang.String formatPoint(java.awt.Dimension d)
public static java.lang.String formatPoint(int x, int y)
public static java.lang.String formatPoint(java.awt.Point p)
public static java.lang.String formatPoint(int x, int y, int z)
public static java.lang.String formatColor(java.awt.Color c)
public static java.awt.Frame getFrame(java.awt.Component c)
public static void markBusy(java.awt.Component c)
public static void markNotBusy(java.awt.Component c)
public static void printIntArray(int[] array)
public static void print2DIntArray(int[][] array)
array
- any 2D int arraypublic static void print3DIntArray(int[][][] array)
array
- any 3D int arraypublic static void printStringArray(java.lang.String[] array)
public static void printObjectArray(java.lang.Object[] array)
public static void copyFile(java.lang.String src, java.lang.String dest) throws java.io.IOException
java.io.IOException
public static void copyFile(java.io.File src, java.io.File dest) throws java.io.IOException
java.io.IOException
public static byte[] readFile(java.lang.String path)
path
- the absolute path to the file
public static boolean writeFile(java.lang.String path, java.lang.String body)
path
- the absolute path to the file to write,
including the filename.body
- the contents of the file
public static boolean writeFile(java.lang.String path, byte[] bytes)
path
- the absolute path to the file to write,
including the filename.bytes
- the contents of the file
public static boolean appendToFile(java.lang.String path, java.lang.String text)
path
- the full path to the file to append to.
Should be a text file.text
- the text to append. If you're appending
multiple lines to the file, you shouldn't use this
method, since it opens and writes the file on every call.
public static java.lang.String readFileCache(java.lang.String path)
path
- the absolute path to the file
public static java.lang.String printException(java.lang.Throwable t)
t
- any Throwable or Exception subclass
public static java.lang.String formatTime(long sec)
sec
- number of seconds in the interval
public static java.lang.String formatTimeShort(long sec)
sec
- the interval to formatpublic static byte[] pack3DIntArray(int[][][] data)
data
- the input data
public static int[][][] unpack3DIntArray(byte[] data)
data
- the packed arraypublic static byte[] packShortArray(short[] data)
data
- an array of short values
public static short[] unpackShortArray(byte[] data)
data
- the byte array
public static byte[] packStringArray(java.lang.String[] data)
data
- the string array
public static java.lang.String[] unpackStringArray(byte[] data)
data
- the byte array
public static java.lang.String printByteArray(byte[] data)
public static void print(java.lang.Object[] objs)
public static void printProperties(java.util.Properties p)
public static java.awt.Image filterImage(java.awt.Image src, java.awt.image.ImageFilter filter)
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |