mymobilesite.controller
Class GUI

java.lang.Object
  extended by mymobilesite.controller.GUI
All Implemented Interfaces:
java.lang.Runnable, javax.microedition.lcdui.CommandListener, javax.microedition.lcdui.ItemCommandListener

public class GUI
extends java.lang.Object
implements javax.microedition.lcdui.CommandListener, javax.microedition.lcdui.ItemCommandListener, java.lang.Runnable

The GUI class does everything that is presented to the user and handles events that are caused by user action. The class relies on several states which indicates which GUI window should be shown to the user.

Author:
Gunn Olaussen, Kirsti N. Torgersen

Field Summary
private  javax.microedition.lcdui.Command back
           
private  Controller controller
           
private  int currentState
           
private  javax.microedition.lcdui.Display display
           
static int ERROR_SCREEN
           
private  javax.microedition.lcdui.Command exit
           
private  javax.microedition.lcdui.Command help
           
static int HELP_SCREEN
           
private  javax.microedition.lcdui.ChoiceGroup lang
           
private  Language language
           
static int LOGIN_SCREEN
           
private  javax.microedition.lcdui.Form mainForm
           
private  java.lang.String message
           
private  javax.microedition.lcdui.Command ok
           
private  javax.microedition.lcdui.TextField password
           
private  int previousState
           
private  javax.microedition.lcdui.ChoiceGroup prov
           
static int PROVIDER_SCREEN
           
private  javax.microedition.lcdui.Command save
           
static int SERVICEDETAIL_SCREEN
           
private  javax.microedition.lcdui.ChoiceGroup servicel
           
private  Service[] serviceList
           
static int SERVICELIST_SCREEN
           
private  javax.microedition.lcdui.Command settings
           
static int SETTINGS_SCREEN
           
static int SPLASH_SCREEN
          These state variables are used by the class to determine what window to show.
private  javax.microedition.lcdui.Command tryagain
           
private  int userChoice
           
private  javax.microedition.lcdui.TextField username
           
static int WAITING_SCREEN
           
 
Constructor Summary
GUI(Controller cont)
          The constructor is given a reference to the controller so that it can retrieve neccessary variables.
 
Method Summary
 void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)
          Calls doCommand(c)
 void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Item item)
          Calls doCommand(c)
private  void createCommandButtons()
          Creates new command buttons either at startup or when the language is changed.
private  void doCommand(javax.microedition.lcdui.Command c)
          Performs the appropriate action according to the command it receives.
 int getPreviousState()
          This returns the privious state which is used when the user is going back to the previous screen.
 void run()
          This method is used when a window is set.
 void setLanguage(java.lang.String lan)
          This method sets the language in the Configuration class if the input is different from that currently in the RecordStore.
 void setWindow(int window)
          This method tells the application which window it should show.
 void setWindow(int window, java.lang.String msg)
          This method tells the application which window it should show.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPLASH_SCREEN

public static final int SPLASH_SCREEN
These state variables are used by the class to determine what window to show.

See Also:
Constant Field Values

LOGIN_SCREEN

public static final int LOGIN_SCREEN
See Also:
Constant Field Values

HELP_SCREEN

public static final int HELP_SCREEN
See Also:
Constant Field Values

SETTINGS_SCREEN

public static final int SETTINGS_SCREEN
See Also:
Constant Field Values

PROVIDER_SCREEN

public static final int PROVIDER_SCREEN
See Also:
Constant Field Values

SERVICELIST_SCREEN

public static final int SERVICELIST_SCREEN
See Also:
Constant Field Values

SERVICEDETAIL_SCREEN

public static final int SERVICEDETAIL_SCREEN
See Also:
Constant Field Values

WAITING_SCREEN

public static final int WAITING_SCREEN
See Also:
Constant Field Values

ERROR_SCREEN

public static final int ERROR_SCREEN
See Also:
Constant Field Values

controller

private Controller controller

currentState

private int currentState

previousState

private int previousState

userChoice

private int userChoice

language

private Language language

serviceList

private Service[] serviceList

message

private java.lang.String message

display

private javax.microedition.lcdui.Display display

mainForm

private javax.microedition.lcdui.Form mainForm

ok

private javax.microedition.lcdui.Command ok

exit

private javax.microedition.lcdui.Command exit

settings

private javax.microedition.lcdui.Command settings

help

private javax.microedition.lcdui.Command help

save

private javax.microedition.lcdui.Command save

back

private javax.microedition.lcdui.Command back

tryagain

private javax.microedition.lcdui.Command tryagain

username

private javax.microedition.lcdui.TextField username

password

private javax.microedition.lcdui.TextField password

lang

private javax.microedition.lcdui.ChoiceGroup lang

prov

private javax.microedition.lcdui.ChoiceGroup prov

servicel

private javax.microedition.lcdui.ChoiceGroup servicel
Constructor Detail

GUI

public GUI(Controller cont)
The constructor is given a reference to the controller so that it can retrieve neccessary variables. All the GUI variables which are needed throughout the application's execution are initialized here.

Parameters:
cont - Controller The program controller which is needed to retrieve some variables.
Method Detail

getPreviousState

public int getPreviousState()
This returns the privious state which is used when the user is going back to the previous screen.

Returns:
int The previous application state

setWindow

public void setWindow(int window)
This method tells the application which window it should show. This is used when there is a window which does not show a message which is expected as an input.

Parameters:
window - int The id of the window which we want displayed

setWindow

public void setWindow(int window,
                      java.lang.String msg)
This method tells the application which window it should show. This is used when the user should be shown a specific message.

Parameters:
window - int The id of the window which we want displayed
msg - String The message that should be shown in this window

setLanguage

public void setLanguage(java.lang.String lan)
This method sets the language in the Configuration class if the input is different from that currently in the RecordStore. The language used in the application is also updated.

Parameters:
lan - String The chosen language.

createCommandButtons

private void createCommandButtons()
Creates new command buttons either at startup or when the language is changed.


run

public void run()
This method is used when a window is set. It runs in its own Thread and creates the window which is determined by the current state.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

commandAction

public void commandAction(javax.microedition.lcdui.Command c,
                          javax.microedition.lcdui.Displayable d)
Calls doCommand(c)

Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener
See Also:
CommandListener.commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)

commandAction

public void commandAction(javax.microedition.lcdui.Command c,
                          javax.microedition.lcdui.Item item)
Calls doCommand(c)

Specified by:
commandAction in interface javax.microedition.lcdui.ItemCommandListener
See Also:
ItemCommandListener.commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Item)

doCommand

private void doCommand(javax.microedition.lcdui.Command c)
Performs the appropriate action according to the command it receives.