Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/nokia/mid/ui/FullCanvas.java


1   /*
2    *  Nokia API for MicroEmulator
3    *  Copyright (C) 2003 Markus Heberling <markus@heberling.net>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19   
20  package com.nokia.mid.ui;
21   
22  import javax.microedition.lcdui.Canvas;
23  import javax.microedition.lcdui.Command;
24  import javax.microedition.lcdui.CommandListener;
25  import javax.microedition.lcdui.Displayable;
26  
27  import com.barteo.emulator.device.DeviceFactory;
28  
29  /** The Softkey Codes are not generated by normal devices. In this class they are
30   * emulated with commands. SOFTKEY1 is mapped to Command.OK and SOFTKEY2 to
31   * Command.BACK. You should edit your device config file, so that OK is on the
32   * left and Back on the right.
33   */
34  public abstract class FullCanvas extends Canvas
35  {
36    public static final int KEY_SOFTKEY1 = -6;
37    public static final int KEY_SOFTKEY2 = -7;
38    public static final int KEY_SEND = -10;
39    public static final int KEY_END = -11;
40    public static final int KEY_SOFTKEY3 = -5;
41    public static final int KEY_UP_ARROW = -1;
42    public static final int KEY_DOWN_ARROW = -2;
43    public static final int KEY_LEFT_ARROW = -3;
44    public static final int KEY_RIGHT_ARROW = -4;
45  
46    /** Creates a new FullCanvas.
47     * Adds two empty commands to emulate softkey functions.
48     */    
49    protected FullCanvas()
50    {
51      super();
52      super.addCommand(new NokiaCommand(KEY_SOFTKEY1,Command.OK));
53      super.addCommand(new NokiaCommand(KEY_SOFTKEY2,Command.BACK));
54      super.setCommandListener(new NokiaCommandListener(this));
55    }
56      
57    /** Commands are not supported by FullCanvas
58     * @param cmd
59     */    
60    public void addCommand(Command cmd)
61    {
62      throw new IllegalStateException();
63    }
64      
65      
66    public int getWidth()
67    {
68      return DeviceFactory.getDevice().getDeviceDisplay().getFullWidth();
69    }
70  
71  
72    public int getHeight()
73    {
74      return DeviceFactory.getDevice().getDeviceDisplay().getFullHeight();
75    }
76  
77    /** Commands are not supported by FullCanvas
78     * @param l
79     */    
80    public void setCommandListener(CommandListener l)
81    {
82      throw new IllegalStateException();
83    }
84      
85    //used to simulate softbutton key events
86    void press(int i)
87    {
88      keyPressed(i);
89      keyRepeated(i);
90    }
91                    
92  }
93  
94  class NokiaCommandListener implements CommandListener
95  {
96    FullCanvas fc;
97      
98      
99    NokiaCommandListener(FullCanvas f)
100   {
101     fc=f;
102   }
103     
104     
105   public void commandAction(Command c, Displayable d)
106   {
107     fc.press(((NokiaCommand)c).getKey());
108     //this.keyReleased(((NokiaCommand)c).getKey());
109   }
110   
111 }
112 
113 
114 class NokiaCommand extends Command
115 {
116   int key;
117   
118   
119   NokiaCommand(int key, int type)
120   {
121     super("", type, 1);
122     this.key=key;
123   }
124     
125     
126   int getKey()
127   {
128     return key;
129   }
130   
131 }