javauis/lcdui_qt/src/javax/microedition/lcdui/KeyTable.java
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 package javax.microedition.lcdui;
       
    18 
       
    19 import org.eclipse.swt.SWT;
       
    20 
       
    21 /**
       
    22  * Key table.
       
    23  */
       
    24 final class KeyTable {
       
    25 
       
    26     static final int[][] KEY_TO_GAME_TABLE = {
       
    27         {-1,  Canvas.UP},
       
    28         {50,  Canvas.UP},
       
    29         {SWT.ARROW_UP,  Canvas.UP},
       
    30 
       
    31         {-2,  Canvas.DOWN},
       
    32         {56,  Canvas.DOWN},
       
    33         {SWT.ARROW_DOWN,  Canvas.DOWN},
       
    34 
       
    35         {-3,  Canvas.LEFT},
       
    36         {52,  Canvas.LEFT},
       
    37         {SWT.ARROW_LEFT,  Canvas.LEFT},
       
    38 
       
    39         {-4,  Canvas.RIGHT},
       
    40         {54,  Canvas.RIGHT},
       
    41         {SWT.ARROW_RIGHT,  Canvas.RIGHT},
       
    42 
       
    43         {-5,  Canvas.FIRE},
       
    44         {53,  Canvas.FIRE},
       
    45         {-10, Canvas.FIRE},
       
    46 
       
    47         {55,  Canvas.GAME_A},
       
    48         {57,  Canvas.GAME_B},
       
    49         {42,  Canvas.GAME_C},
       
    50         {35,  Canvas.GAME_D},
       
    51     };
       
    52 
       
    53     /**
       
    54      * Private constructor.
       
    55      */
       
    56     private KeyTable() {
       
    57     }
       
    58 
       
    59     static int getGameAction(int keyCode) {
       
    60         for (int i = 0; i < KEY_TO_GAME_TABLE.length; i++) {
       
    61             if (KEY_TO_GAME_TABLE[i][0] == keyCode) {
       
    62                 return KEY_TO_GAME_TABLE[i][1];
       
    63             }
       
    64         }
       
    65         throw new IllegalArgumentException(
       
    66                 MsgRepository.CANVAS_EXCEPTION_INVALID_KEY_CODE);
       
    67     }
       
    68 
       
    69     static int getKeyCode(int gameAction) {
       
    70         for (int i = 0; i < KEY_TO_GAME_TABLE.length; i++) {
       
    71             if (KEY_TO_GAME_TABLE[i][1] == gameAction) {
       
    72                 return KEY_TO_GAME_TABLE[i][0];
       
    73             }
       
    74         }
       
    75         throw new IllegalArgumentException(
       
    76                 MsgRepository.CANVAS_EXCEPTION_INVALID_GAME_ACTION);
       
    77     }
       
    78 
       
    79 
       
    80     static String getKeyName(int keyCode) {
       
    81 
       
    82         switch(keyCode) {
       
    83             /*case Canvas.KEY_NUM0:
       
    84                 return "0";
       
    85 
       
    86             case Canvas.KEY_NUM1:
       
    87                 return "1";
       
    88 
       
    89             case Canvas.KEY_NUM2:
       
    90                 return "2";
       
    91 
       
    92             case Canvas.KEY_NUM3:
       
    93                 return "3";
       
    94 
       
    95             case Canvas.KEY_NUM4:
       
    96                 return "4";
       
    97 
       
    98             case Canvas.KEY_NUM5:
       
    99                 return "5";
       
   100 
       
   101             case Canvas.KEY_NUM6:
       
   102                 return "6";
       
   103 
       
   104             case Canvas.KEY_NUM7:
       
   105                 return "7";
       
   106 
       
   107             case Canvas.KEY_NUM8:
       
   108                 return "8";
       
   109 
       
   110             case Canvas.KEY_NUM9:
       
   111                 return "9";
       
   112 
       
   113 
       
   114             case Canvas.KEY_STAR:
       
   115                 return "*";
       
   116 
       
   117             case Canvas.KEY_POUND:
       
   118                 return "#";
       
   119                 */
       
   120             case -1:
       
   121                 return OpenLcduiLocalization.getMessage("key_up");
       
   122 
       
   123             case -2:
       
   124                 return OpenLcduiLocalization.getMessage("key_down");
       
   125                 
       
   126             case -3:
       
   127                 return OpenLcduiLocalization.getMessage("key_left");
       
   128 
       
   129             case -4:
       
   130                 return OpenLcduiLocalization.getMessage("key_right");
       
   131 
       
   132             case -5:
       
   133                 return OpenLcduiLocalization.getMessage("key_select");
       
   134 
       
   135             default:
       
   136                 return "";
       
   137         }
       
   138     }
       
   139 
       
   140 }