source.ucregents.playground
Class Utility

java.lang.Object
  extended by source.ucregents.playground.Utility

public final class Utility
extends java.lang.Object

A class of commonly used, misc, helper methods.


Field Summary
static java.lang.String ResourcePath
           
static java.lang.String SoundPath
           
 
Constructor Summary
Utility()
           
 
Method Summary
static java.awt.Color ApplyAlpha(java.awt.Color c, int alpha)
          Creates and returns a new Color identical in all ways except that it's alpha value is set to the one specified
static boolean areParallel(javax.vecmath.Vector2d firstVector, javax.vecmath.Vector2d secondVector)
          Checks to see if 2 vectors are Approximately parallel
static java.applet.AudioClip cacheSound(java.lang.String filename)
          Gets a Sound and caches it if not yet cached.
static java.lang.String Capitalize(java.lang.String s)
          Capitalizes the beginning of a string.
static java.lang.Object CreateInstanceOf(java.lang.Class<?> c, java.lang.Class<?> assignableFrom)
          Creates an instance of the specified class.
static void FocusOn(javax.swing.JInternalFrame comp)
          Focuses on a JInternalFrame
static java.awt.image.BufferedImage GetBufferedImage(java.lang.String filename)
           
static java.lang.String getDefaultImageName()
          Return the filename of the default image.
static java.awt.Color getRandomColor()
          Gets a Random color with values between 25 and 225 for each RGB Value
static javax.vecmath.Vector2d getUnitVectorX()
          Gets the Unit vector in the X direction
static javax.vecmath.Vector2d getUnitVectorY()
          Gets the Unit vector in the Y direction
static javax.vecmath.Vector2d getZeroVector()
          Gets the Zero vector
static void HandleEvent(int type, int subtype, BaseEntity b)
          Execute all UserEvents associated with a given Base Entity.
static void HandleEvents(int type, int subtype, java.util.Vector<BaseEntity> ents)
          Loop through all entities and execute any events bound to a certain type and subtype.
static java.awt.geom.Point2D.Double parsePoint2D_Double(java.lang.String stringToParse)
          Parses a Point2D.Double from a string
static void PlaySound(java.lang.String filename)
          Plays a sound in a new thread.
static boolean RandomBoolean()
          Gets a Random Boolean value
static double RandomDouble()
           
static double RandomDouble(double min, double max)
           
static int RandomInt(int max)
           
static int RandomInt(int min, int max)
           
static javax.vecmath.Vector2d VectorDivision(javax.vecmath.Vector2d v1, double scalar)
          Divides a vector by a scalar
static javax.vecmath.Vector2d VectorMultiplication(javax.vecmath.Vector2d v1, double scalar)
          Multiplies a vector by a scalar
static javax.vecmath.Vector2d VectorScale(javax.vecmath.Vector2d v1, double scalar)
          Scales a vector by a scalar
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ResourcePath

public static final java.lang.String ResourcePath
See Also:
Constant Field Values

SoundPath

public static final java.lang.String SoundPath
See Also:
Constant Field Values
Constructor Detail

Utility

public Utility()
Method Detail

ApplyAlpha

public static java.awt.Color ApplyAlpha(java.awt.Color c,
                                        int alpha)
Creates and returns a new Color identical in all ways except that it's alpha value is set to the one specified

Parameters:
c - The color to apply the alpha to.
alpha - The alpha value to apply to the Color. Normal values from 0 - 255
Returns:
Returns the new color with the aplha applied to it

areParallel

public static boolean areParallel(javax.vecmath.Vector2d firstVector,
                                  javax.vecmath.Vector2d secondVector)
Checks to see if 2 vectors are Approximately parallel

Parameters:
firstVector - The first Vector2D
secondVector - The second Vector2D
Returns:
Returns a boolean stating wether or not the Vectors are close to parallel

cacheSound

public static java.applet.AudioClip cacheSound(java.lang.String filename)
Gets a Sound and caches it if not yet cached.

Parameters:
filename - The sound to cache
Returns:
The sound

Capitalize

public static java.lang.String Capitalize(java.lang.String s)
Capitalizes the beginning of a string.

Parameters:
s - The string to capitalize
Returns:
Returns the Capitalized string

CreateInstanceOf

public static java.lang.Object CreateInstanceOf(java.lang.Class<?> c,
                                                java.lang.Class<?> assignableFrom)
Creates an instance of the specified class.

Parameters:
c - The class to instantiate
assignableFrom - An optional class that will do check to ensure that the class to instantiate is or extends this parameter
Returns:
Returns the instance of the specified class if there are no errors. Otherwise, it returns null.

FocusOn

public static void FocusOn(javax.swing.JInternalFrame comp)
Focuses on a JInternalFrame

Parameters:
comp - The frame to focus on

GetBufferedImage

public static java.awt.image.BufferedImage GetBufferedImage(java.lang.String filename)
Parameters:
filename - The filename of the image
Returns:
The BufferedImage from the image. If the file wasn't found, returns the DefaultImage. If any other errors, returns null

getDefaultImageName

public static java.lang.String getDefaultImageName()
Return the filename of the default image. Usually an error image.

Returns:
Returns a default or 'error.png'

getRandomColor

public static java.awt.Color getRandomColor()
Gets a Random color with values between 25 and 225 for each RGB Value

Returns:
A random color

getUnitVectorX

public static javax.vecmath.Vector2d getUnitVectorX()
Gets the Unit vector in the X direction

Returns:
Returns a Unit vector in the X direction

getUnitVectorY

public static javax.vecmath.Vector2d getUnitVectorY()
Gets the Unit vector in the Y direction

Returns:
Returns a Unit vector in the Y direction

getZeroVector

public static javax.vecmath.Vector2d getZeroVector()
Gets the Zero vector

Returns:
Returns a Zero Vector

HandleEvent

public static void HandleEvent(int type,
                               int subtype,
                               BaseEntity b)
Execute all UserEvents associated with a given Base Entity.

Parameters:
type - Corresponds to the event id (e.g. MouseEvent.BUTTON_PRESSED)
subtype - Corresponds to the specific key or button associated with the event (e.g. MouseEvent.BUTTON1)
b - The object on which to execute the events

HandleEvents

public static void HandleEvents(int type,
                                int subtype,
                                java.util.Vector<BaseEntity> ents)
Loop through all entities and execute any events bound to a certain type and subtype.

Parameters:
type - Corresponds to the event id (e.g. MouseEvent.BUTTON_PRESSED)
subtype - Corresponds to the specific key or button associated with the event (e.g. MouseEvent.BUTTON1)
ents - Execute appropriate events with each entity in this vector

parsePoint2D_Double

public static java.awt.geom.Point2D.Double parsePoint2D_Double(java.lang.String stringToParse)
Parses a Point2D.Double from a string

Parameters:
stringToParse - The string to parse
Returns:
Returns the parsed Point2D.Double, or, returns null if there was a parsing error

PlaySound

public static void PlaySound(java.lang.String filename)
Plays a sound in a new thread. Gets the sound if it exists in the cache, or, caches it if needbe.

Parameters:
filename - The filename of the sound.

RandomBoolean

public static boolean RandomBoolean()
Gets a Random Boolean value

Returns:
Returns either true or false with equal probability

RandomDouble

public static double RandomDouble()
Returns:
Returns a random double between 0 & 1

RandomDouble

public static double RandomDouble(double min,
                                  double max)
Parameters:
min - The minimum double value to return. The value is the minimum and included in the result
max - The maximum double value to return. The value is the maximum and excluded from the result
Returns:
Returns a double from min Inclusive to max Exclusive

RandomInt

public static int RandomInt(int max)
Parameters:
max - The maximum int value to return. The value is the maximum and excluded from the result
Returns:
Returns a value from 0 Inclusive to max Exclusive

RandomInt

public static int RandomInt(int min,
                            int max)
Parameters:
min - The minimum int value to return. The value is the minimum and included in the result
max - The maximum int value to return. The value is the maximum and excluded from the result
Returns:
Returns an integer from min Inclusive to max Exclusive

VectorDivision

public static javax.vecmath.Vector2d VectorDivision(javax.vecmath.Vector2d v1,
                                                    double scalar)
Divides a vector by a scalar

Parameters:
v1 - The vector
scalar - The scalar
Returns:
The Divided vector

VectorMultiplication

public static javax.vecmath.Vector2d VectorMultiplication(javax.vecmath.Vector2d v1,
                                                          double scalar)
Multiplies a vector by a scalar

Parameters:
v1 - The vector
scalar - The scalar
Returns:
The Multiplied vector

VectorScale

public static javax.vecmath.Vector2d VectorScale(javax.vecmath.Vector2d v1,
                                                 double scalar)
Scales a vector by a scalar

Parameters:
v1 - The vector
scalar - The scalar
Returns:
The Scaled vector