package gui;

import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * An abstract "screen" in a MIDlet
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public abstract class AbstractScreen
{
    protected  ApplicationContext          context;
    

    public static final String  CANCEL         = new String("Cancel");
    public static final String  EXIT           = new String("Exit");
    public static final String  INFORMATION    = new String("Information");
    public static final String  OK             = new String("OK");
    public static final String  SELECT         = new String("Select");
    
    protected static final Command CANCEL_COMMAND = new Command(CANCEL, Command.CANCEL, 1);
    protected static final Command EXIT_COMMAND   = new Command(EXIT,   Command.EXIT,   1);
    protected static final Command OK_COMMAND     = new Command(OK,     Command.OK,     1);
    protected static final Command SELECT_COMMAND = new Command(SELECT, Command.SCREEN, 1);
    
    /**
     * Explicit Value Constructor
     *
     * @param context   The application context
     */
    public AbstractScreen(ApplicationContext context)
    {
        this.context = context;
    }
    

    /**
     * Enter this instance of an AbstractScreen
     */
    public void enter()
    {
        Display      display;
        Displayable  displayable;
        
        context.setState(this);
        
        displayable = getDisplayable();
        displayable.setCommandListener(context);

        display     = context.getDisplay();
        display.setCurrent(displayable);
    }
        
    
    /**
     * Get the ApplicationContext for this "screen"
     */
    protected ApplicationContext getContext()
    {
        return context;
    }
    
    
    
    /**
     * Get the Displayable associated with this AbstractScreen
     *
     * @returns   The Displayable
     */
    protected abstract Displayable getDisplayable();
    
}
