/*
 * Copyright (c) 2006-2008 MiniMe. Code released under The MIT/X Window System
 * License. Full license text can be found in license.txt
 */
package minime;

import javax.microedition.lcdui.*;

/**
 * The Portability class stores mobile device information: key code, font face,
 * style and size, and color.
 * 
 * @author aaa
 * 
 */
public class Portability
{
    //
    // keys
    //
    public static int KEY_NUM0 = Canvas.KEY_NUM0;
    public static int KEY_NUM1 = Canvas.KEY_NUM1;
    public static int KEY_NUM2 = Canvas.KEY_NUM2;
    public static int KEY_NUM3 = Canvas.KEY_NUM3;
    public static int KEY_NUM4 = Canvas.KEY_NUM4;
    public static int KEY_NUM5 = Canvas.KEY_NUM5;
    public static int KEY_NUM6 = Canvas.KEY_NUM6;
    public static int KEY_NUM7 = Canvas.KEY_NUM7;
    public static int KEY_NUM8 = Canvas.KEY_NUM8;
    public static int KEY_NUM9 = Canvas.KEY_NUM9;
    public static int KEY_STAR = Canvas.KEY_STAR;
    public static int KEY_POUND = Canvas.KEY_POUND;
    
    public static int KEY_UP = ${device.key.KEY_UP} ;
    public static int KEY_DOWN = ${device.key.KEY_DOWN} ;
    public static int KEY_LEFT = ${device.key.KEY_LEFT} ;
    public static int KEY_RIGHT = ${device.key.KEY_RIGHT} ;
    public static int KEY_FIRE = ${device.key.KEY_FIRE} ;
    
    public static int KEY_GAME_A = Canvas.GAME_A;
    public static int KEY_GAME_B = Canvas.GAME_B;
    public static int KEY_GAME_C = Canvas.GAME_C;
    public static int KEY_GAME_D = Canvas.GAME_D;

    public static int KEY_SOFT_LEFT = ${device.softKey.KEY_LEFT} ;
    public static int KEY_SOFT_RIGHT = ${device.softKey.KEY_RIGHT};
    public static int KEY_SOFT_CLEAR = ${device.softKey.KEY_CLEAR};
    //
    // fonts
    //
    public static int SYSTEM_FONT = javax.microedition.lcdui.Font.FACE_SYSTEM;
    public static int MONOSPACE_FONT = javax.microedition.lcdui.Font.FACE_MONOSPACE;
    public static int PROPORTIONAL_FONT = javax.microedition.lcdui.Font.FACE_PROPORTIONAL;
    public static int SMALL_FONT = javax.microedition.lcdui.Font.SIZE_SMALL;
    public static int MEDIUM_FONT = javax.microedition.lcdui.Font.SIZE_MEDIUM;
    public static int LARGE_FONT = javax.microedition.lcdui.Font.SIZE_LARGE;
    public static int BOLD_STYLE = javax.microedition.lcdui.Font.STYLE_BOLD;
    public static int ITALIC_STYLE = javax.microedition.lcdui.Font.STYLE_ITALIC;
    public static int PLAIN_STYLE = javax.microedition.lcdui.Font.STYLE_PLAIN ;
    public static int UNDERLINED_STYLE = javax.microedition.lcdui.Font.STYLE_UNDERLINED;

    //
    // colors
    //
    public static int TRANSPARENT = 	0xff000000 ;    // transparent color
    public static int C_BLACK = 			0x00000000 ;
	public static int NAVYBLUE = 		0x000000A0 ; 
    public static int BLUE = 			0x000000ff ;
    public static int GREEN = 			0x0000ff00 ;
    public static int AQUA = 			0x0000FFFF ;
	public static int OLIVEDRAB = 		0x006B8E23 ;
    public static int AQUAMARINE = 		0x007FFFD4 ;
    public static int PURPLE =			0x00800080 ;
    public static int BLUEVIOLET = 		0x008A2BE2 ;
    public static int C_GREY = 			0x00C0C0C0 ;
    public static int PLUM =			0x00DDA0DD ;
    public static int VIOLET =			0x00EE82EE ;
    public static int ALICEBLUE = 		0x00F0F8FF ;
	public static int AZURE =			0x00F0FFFF ;
    public static int ANTIQUEWHITE = 	0x00FAEBD7 ;
    public static int RED = 			0x00FF0000;
	public static int ORANGERED = 		0x00FF4500 ;
	public static int C_ORANGE = 			0x00FFA500 ;
    public static int PINK =			0x00FFC8CB ;
    public static int YELLOW = 			0x00FFFF00 ;
    public static int LIGHTYELLOW = 	0x00FFFFE0 ;
    public static int IVORY = 			0x00FFFFF0 ;
    public static int C_WHITE = 			0x00FFFFFF ;
    
    

    // ... fell free to add more color
    
	
	public static int POPUP_TEXT_COLOR = 0x00D03060;

    static public int defaultFontTextColor = C_BLACK ;
    static public int defaultBaseViewBgColor = C_WHITE ;
    
    // default Menu related
    static public int defaultMenuItemFrameThickness = 3 ;
    static public int defaultMenuItemTextColor = C_BLACK ;
    static public int defaultMenuSelectionFrameColor = C_ORANGE ;
    static public int defaultDisableMenuItemTextColor = C_GREY ;
    static public int defaultPopUpMessageColor=C_GREY;
    
    private static Canvas canvas;

    /**
     * Sets the canvas as Portability canvas
     * @param canvas
     *              the canvas instance
     */
    static public void setCanvas(Canvas canvas)
    {
        Portability.canvas = canvas;
    }

    /**
     * Translates the keyCode to corresponding key code on the device.
     * @param keyCode
     *              the key code being requested 
     * @return corresponding key code on the device.
     * @throws RuntimeException if not set Portability canvas
     */
    static public int translateKeyCode(int keyCode)
    {
        if ( null == canvas )
        {
            throw new RuntimeException( "[Portability] Canvs not set for translateKeyCode" );
        }
        if ( keyCode == KEY_SOFT_LEFT )
        {
            return KEY_SOFT_LEFT;
        }
        else if ( keyCode == KEY_SOFT_RIGHT )
        {
            return KEY_SOFT_RIGHT;
        }
        else if ( keyCode == KEY_SOFT_CLEAR )
        {
            return KEY_SOFT_CLEAR;
        }
        else
        {
            return canvas.getGameAction( keyCode );
        }
    }
    
    
    
}
