JTP
Class SplashMessage

java.lang.Object
  extended by JTP.SplashMessage

public class SplashMessage
extends Object

Displays various "pop-up" messages. (e.g. level end message) Note: Only the most recently requested message will be displayed.

Author:
V.Termanis

Field Summary
static long DEFAULT
          Default display length.
static long LONG
          Long display length.
static long SHORT
          Short display length.
 
Constructor Summary
SplashMessage(Font f, Color bg, Color txt, Color bd, int lineSpacing, int borderSpacing, int curvature, float borderThickness, ScreenFrames frames, Images imgData, Graphics2D g)
          Constructs a new SplashMessage instance with the given attributes.
 
Method Summary
 void cancel()
          Cancels any currently requested messages.
 void display(Rectangle drawArea, Graphics2D g)
          Draws the requested message to the screen.
 long getDisplayLength()
          Returns lenght for which the requested message will be displayed.
 boolean hasForcedLength()
          Returns whether a particular display length has been set or not.
static boolean isValidMessage(String message)
          Checks whether the given message is valid.
 void request(boolean p2, long time)
          Requests player start message to be displayed.
 void request(int p1Score, int p2Score, long time)
          Requests player scores to be displayed.
 void request(String message)
          Requests a text message to be displayed.
 void request(String message, long time)
          Requests a text message to be displayed.
 boolean requested()
          Checks whether a message have been requested.
protected  void requestHelp()
          Request help message (horribly hardcoded)
 void setDisplayLength(long time)
          Sets display length for any currently requested message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHORT

public static final long SHORT
Short display length.

See Also:
Constant Field Values

DEFAULT

public static final long DEFAULT
Default display length.

See Also:
Constant Field Values

LONG

public static final long LONG
Long display length.

See Also:
Constant Field Values
Constructor Detail

SplashMessage

public SplashMessage(Font f,
                     Color bg,
                     Color txt,
                     Color bd,
                     int lineSpacing,
                     int borderSpacing,
                     int curvature,
                     float borderThickness,
                     ScreenFrames frames,
                     Images imgData,
                     Graphics2D g)
              throws IllegalArgumentException,
                     NullPointerException
Constructs a new SplashMessage instance with the given attributes. One instance can be used to display any number of splash messages.

Parameters:
f - the font to use for text
bg - background colour
txt - text colour
bd - border colour
lineSpacing - in pixels between lines
borderSpacing - spacing between text and border (both vertical and horizontal)
curvature - roundness of edges
borderThickness - in pixels
frames - provides access to screen information (e.g. to render in the middle of the screen)
imgData - images required by some times up splash message
g - context used to determine text size (one-off)
Throws:
IllegalArgumentException - if any of lineSpacing, borderSpacing, borderThickness or curvature are < 0.
NullPointerException - if any of f, bg or txt are null
Method Detail

display

public void display(Rectangle drawArea,
                    Graphics2D g)
Draws the requested message to the screen.

Parameters:
drawArea - used to calculate center of screen
g - graphics context for drawing

requestHelp

protected void requestHelp()
Request help message (horribly hardcoded)


request

public void request(boolean p2,
                    long time)
             throws IllegalArgumentException
Requests player start message to be displayed.

Parameters:
p2 - indicates for which player the message is
time - length in milliseconds to display message for
Throws:
IllegalArgumentException - if time < 1

request

public void request(int p1Score,
                    int p2Score,
                    long time)
             throws IllegalArgumentException
Requests player scores to be displayed.

Parameters:
p1Score - player one score
p2Score - player two score
time - length in milliseconds to display message for
Throws:
IllegalArgumentException - if time < 1

request

public void request(String message,
                    long time)
             throws IllegalArgumentException
Requests a text message to be displayed.

Parameters:
message - message to display. If this is null then any previous message request is cancelled.
time - length in milliseconds to display message for
Throws:
IllegalArgumentException - if time < 1 null.

isValidMessage

public static boolean isValidMessage(String message)
Checks whether the given message is valid.

Parameters:
message - the string to check
Returns:
false if any of the following is true:
  • message is null
  • length of message is zero
  • message only contains whitespace characters: [\t\n\x0B\f\r]

request

public void request(String message)
Requests a text message to be displayed. The message display length will depend on the length of the message. Note: If the message is too large to fit on the screen the display length will be calculated just for the part of the message which is actually shown.

Parameters:
message - message to display. If this is null then any previous message request is cancelled.

setDisplayLength

public void setDisplayLength(long time)
                      throws IllegalArgumentException
Sets display length for any currently requested message.

Parameters:
time - length in milliseconds to display message for
Throws:
IllegalArgumentException - if time < 1

hasForcedLength

public boolean hasForcedLength()
Returns whether a particular display length has been set or not.

Returns:
true if message is supposed to be displayed for a certain length or false, if this class it to determine the display length (and it is o.k. to cancel display of said message at any point).

getDisplayLength

public long getDisplayLength()
Returns lenght for which the requested message will be displayed.

Returns:
time to display in milliseconds, or zero if the display length is to be calculated by this class.

cancel

public void cancel()
Cancels any currently requested messages.


requested

public boolean requested()
Checks whether a message have been requested.

Returns:
true if a message has been requested