bluegammon.gui.popup
Class Popup

java.lang.Object
  extended bybluegammon.gui.popup.Popup
All Implemented Interfaces:
java.lang.Runnable

public class Popup
extends java.lang.Object
implements java.lang.Runnable

The Popup represents a popup with text and zero or many alternatives that user can select among. A popup can be shown for a specific amount of time or forever, the latter case requiring a user to close the popup. The choice of the alternatives can be reported by implementing a PopupListener

This class contains all functionality of a popup, i.e. interaction, graphics and callback.

Author:
Peter Andersson

Field Summary
static char[][] ALT_CANCEL
          Preset alternative containing CANCEL
static char[][] ALT_OK
          Preset alternative containing OK
static char[][] ALT_OK_CANCEL
          Preset alternatives containing OK and CANCEL
static char[][] ALT_YES_NO
          Preset alternatives containing YES and NO
static char[][] ALT_YES_NO_CANCEL
          Preset alternatives containing YES, NO, and CANCEL
 
Constructor Summary
Popup()
          Creates an uninitialized popup.
 
Method Summary
 void dispose()
          Disposes all resources held by this popup and closes it.
 int findNextBreak(char[] text, int offset, int len, int w, javax.microedition.lcdui.Font f)
          Returns next break when breaking a string.
 byte getTimeOutChoice()
          Returns alternative index on timeout
 void init(char[] text, char[][] altTexts, byte timeOut, byte defaultAlt, byte timeOutAlt, PopupListener listener, int width, int height)
          Initializes this popup.
 boolean isActive()
          Returns whether this popup is active or not.
 void keyPressed(int keyCode, int gameCode)
          Handles user interaction when pressing a key.
 void paint(javax.microedition.lcdui.Graphics g)
          Paints the popup.
 void run()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALT_OK

public static final char[][] ALT_OK
Preset alternative containing OK


ALT_CANCEL

public static final char[][] ALT_CANCEL
Preset alternative containing CANCEL


ALT_YES_NO

public static final char[][] ALT_YES_NO
Preset alternatives containing YES and NO


ALT_OK_CANCEL

public static final char[][] ALT_OK_CANCEL
Preset alternatives containing OK and CANCEL


ALT_YES_NO_CANCEL

public static final char[][] ALT_YES_NO_CANCEL
Preset alternatives containing YES, NO, and CANCEL

Constructor Detail

Popup

public Popup()
Creates an uninitialized popup. Call init to setup this popup instance. This constructor is used for instance cache functionality.

Method Detail

init

public void init(char[] text,
                 char[][] altTexts,
                 byte timeOut,
                 byte defaultAlt,
                 byte timeOutAlt,
                 PopupListener listener,
                 int width,
                 int height)
Initializes this popup.

Parameters:
text - The text to show in popup.
altTexts - The alternatives to select among or null if no choices.
timeOut - Time out for this popup in seconds (0 means no timeout).
defaultAlt - Index of default alternative.
timeOutAlt - Alternative index reported on time out.
listener - The popuplistener being reported on selection or timeout or null if no listener.
width - Canvas width.
height - Canvas height.

findNextBreak

public int findNextBreak(char[] text,
                         int offset,
                         int len,
                         int w,
                         javax.microedition.lcdui.Font f)
Returns next break when breaking a string.

Parameters:
text - The chars to calculate on
offset - From what offset to read in chars
len - How many characters to read
w - Width
f - Font
Returns:
Offset of next break or length of text if no more breaks

paint

public void paint(javax.microedition.lcdui.Graphics g)
Paints the popup. Call this from your Displayable's paint method.

Parameters:
g - Graphics context to paint on.

keyPressed

public void keyPressed(int keyCode,
                       int gameCode)
Handles user interaction when pressing a key. Call this from your Displayable's keyPressed keyRepeated method.

Parameters:
keyCode - The keycode.
gameCode - The gamecode.

dispose

public void dispose()
Disposes all resources held by this popup and closes it.


isActive

public boolean isActive()
Returns whether this popup is active or not.

Returns:
true if active, false otherwise.

getTimeOutChoice

public byte getTimeOutChoice()
Returns alternative index on timeout

Returns:
timeout alternative

run

public void run()
Specified by:
run in interface java.lang.Runnable