us.asciiroth.client
Class Util

java.lang.Object
  extended by us.asciiroth.client.Util

public class Util
extends java.lang.Object

Static utility methods for the game.


Field Summary
static com.google.gwt.core.client.GWT.UncaughtExceptionHandler UNCAUGHT_EXCEPTION_HANDLER
          A generic uncaught exception handler that defers to the minimal logging implementation.
 
Constructor Summary
Util()
           
 
Method Summary
static java.lang.String format(java.lang.String format, int... values)
          Format a string of the format "This is a {0} format string {1}" by substituting the int values provided (there must be one for each braced substitution marker in the string).
static java.lang.String format(java.lang.String format, java.lang.String... values)
          Format a string of the format "This is a {0} format string {1}" by substituting the string values provided (there must be one for each braced substitution marker in the string).
static Item getItemOtherColor(Item item, Color color)
          Get an item of a similar type, but change it to the specified color.
static
<T> java.lang.String
getType(java.lang.Class<T> c)
          Get the simple name for this class (the class name without the package), which is used for serializing and serializing pieces.
static java.lang.String getType(java.lang.Object obj)
          Get the simple name of this object's class, which is used for serializing and deserializing pieces in the game.
static int inRange(int value, int lower, int upper)
          Return a value or the lower/upper bound of a range within which the value should fall.
static boolean isBlank(java.lang.String str)
           
static boolean isNotBlank(java.lang.String str)
           
static Color oscillate(Color from, Color to, int rate, int frame)
          Given a base color and an alternate, oscillate between them.
static java.lang.String renderSymbolAndLabel(boolean outside, Piece piece, int count)
          Render the symbol with a label and a count of items, in both the cell info panel and the inventory palette.
static java.lang.String renderSymbolAndLabel2(boolean outside, Bag.Entry<Item> entry)
           
static void setOpacity(com.google.gwt.user.client.Element el, double opacity)
          Set the opacity on this element.
static void showError(java.lang.String error)
          Show an error to the user.
static void showError(java.lang.String error, java.lang.String... args)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNCAUGHT_EXCEPTION_HANDLER

public static final com.google.gwt.core.client.GWT.UncaughtExceptionHandler UNCAUGHT_EXCEPTION_HANDLER
A generic uncaught exception handler that defers to the minimal logging implementation. Registered for both the game and the editor, currently.

Constructor Detail

Util

public Util()
Method Detail

format

public static java.lang.String format(java.lang.String format,
                                      int... values)
Format a string of the format "This is a {0} format string {1}" by substituting the int values provided (there must be one for each braced substitution marker in the string).

Parameters:
format - a string to format
values - one or more values to substitute into the string.
Returns:
the formatted string

format

public static java.lang.String format(java.lang.String format,
                                      java.lang.String... values)
Format a string of the format "This is a {0} format string {1}" by substituting the string values provided (there must be one for each braced substitution marker in the string).

Parameters:
format - a string to format
values - one or more values to substitute into the string.
Returns:
the formatted string

getItemOtherColor

public static Item getItemOtherColor(Item item,
                                     Color color)
Get an item of a similar type, but change it to the specified color.

Parameters:
item - the item serving as a prototype
color - the new color for the new item created
Returns:
the item with a new color.

getType

public static <T> java.lang.String getType(java.lang.Class<T> c)
Get the simple name for this class (the class name without the package), which is used for serializing and serializing pieces. GWT doesn't support the Java library methods for this such as Class.class.getSimpleName().

Parameters:
c - the class of the piece
Returns:
the string simple name of the class

getType

public static java.lang.String getType(java.lang.Object obj)
Get the simple name of this object's class, which is used for serializing and deserializing pieces in the game. GWT doesn't support the Java library methods for this such as obj.getClass().getSimpleName().

Parameters:
obj - a piece
Returns:
the string simple name of the class

inRange

public static int inRange(int value,
                          int lower,
                          int upper)
Return a value or the lower/upper bound of a range within which the value should fall.

Parameters:
value - the value being tested
lower - the lowest number that can be returned
upper - the highest number that can be returned
Returns:
the value, or the lower/upper value if the provided value falls outside of the range

isBlank

public static boolean isBlank(java.lang.String str)

isNotBlank

public static boolean isNotBlank(java.lang.String str)

oscillate

public static Color oscillate(Color from,
                              Color to,
                              int rate,
                              int frame)
Given a base color and an alternate, oscillate between them. I'm sure there's better ways to do this, but this works (== looks cool).

Parameters:
from -
to -
rate -
frame -
Returns:
new color

renderSymbolAndLabel

public static java.lang.String renderSymbolAndLabel(boolean outside,
                                                    Piece piece,
                                                    int count)
Render the symbol with a label and a count of items, in both the cell info panel and the inventory palette.

Parameters:
outside -
piece -
count -
Returns:
a string to render

renderSymbolAndLabel2

public static java.lang.String renderSymbolAndLabel2(boolean outside,
                                                     Bag.Entry<Item> entry)

setOpacity

public static void setOpacity(com.google.gwt.user.client.Element el,
                              double opacity)
Set the opacity on this element. Does not account for opacity in Internet Explorer. I feel this is likely to be fixed by IE8, least I hope.

Parameters:
el -
opacity - a double value for opacity (from 0.0 to 1.0)

showError

public static void showError(java.lang.String error)
Show an error to the user. This could just as well be a Window.alert() dialog...

Parameters:
error -

showError

public static void showError(java.lang.String error,
                             java.lang.String... args)

0.7

2009 Alx Dark