1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package com
.nokia
.mid
.ui
;
12 import cc
.squirreljme
.runtime
.cldc
.annotation
.Api
;
13 import cc
.squirreljme
.runtime
.cldc
.annotation
.ApiDefinedDeprecated
;
14 import javax
.microedition
.lcdui
.Canvas
;
15 import javax
.microedition
.lcdui
.Command
;
16 import javax
.microedition
.lcdui
.CommandListener
;
17 import javax
.microedition
.lcdui
.Displayable
;
20 * This the Nokia canvas, command buttons are forwarded to the key pressed
21 * and released commands for the canvas.
26 public abstract class FullCanvas
29 /** Virtual soft key 1. */
30 static final Command _SOFT1
= new Command("Soft1", Command
.SCREEN
, 0);
32 /** Virtual soft key 2. */
33 static final Command _SOFT2
= new Command("Soft2", Command
.SCREEN
, 1);
35 /** Virtual soft key 3. */
36 static final Command _SOFT3
= new Command("Soft3", Command
.SCREEN
, 2);
40 public static final int KEY_DOWN_ARROW
= -2;
44 public static final int KEY_END
= -11;
48 public static final int KEY_LEFT_ARROW
= -3;
52 public static final int KEY_RIGHT_ARROW
= -4;
56 public static final int KEY_SEND
= -10;
60 public static final int KEY_SOFTKEY1
= -6;
64 public static final int KEY_SOFTKEY2
= -7;
68 public static final int KEY_SOFTKEY3
= -5;
72 public static final int KEY_UP_ARROW
= -1;
75 * Initializes the base canvas and sets as full-screen.
83 // Nokia API just says to call this instead, so this is done
84 this.setFullScreenMode(true);
86 // Since we need to simulate soft commands in the game, we have to
87 // add our own commands and such to this.
88 this.addCommand(FullCanvas
._SOFT1
);
89 this.addCommand(FullCanvas
._SOFT2
);
90 this.addCommand(FullCanvas
._SOFT3
);
92 // Then use virtual command listener to forward
93 this.setCommandListener(new __VirtualListener__());
97 * Always throws {@link IllegalStateException} as commands are not
98 * supported in Nokia canvases.
100 * @param __c The command to add.
101 * @throws IllegalStateException Always.
105 public void addCommand(Command __c
)
107 // Since we are providing this special functionality we need to wrap
108 // but still access these internal commands
109 if (__c
== FullCanvas
._SOFT1
|| __c
== FullCanvas
._SOFT2
|| __c
== FullCanvas
._SOFT3
)
111 super.addCommand(__c
);
115 // {@squirreljme.error EB2x Commands are not supported.}
116 throw new IllegalStateException("EB2x");
120 * Always throws {@link IllegalStateException} as commands are not
121 * supported in Nokia canvases.
123 * @param __l The command to add.
124 * @throws IllegalStateException Always.
128 public void setCommandListener(CommandListener __l
)
130 // Since this is virtualized, we do want to handle this one!
131 if (__l
instanceof __VirtualListener__
)
133 super.setCommandListener(__l
);
137 // {@squirreljme.error EB2y Commands are not supported.}
138 throw new IllegalStateException("EB2y");
142 * Command listener to forward keys to the canvas.
146 private static final class __VirtualListener__
147 implements CommandListener
155 public final void commandAction(Command __c
, Displayable __d
)
157 // Do nothing if this is some other thing
158 if (!(__d
instanceof FullCanvas
))
161 // Determine code to use
163 if (__c
== FullCanvas
._SOFT1
)
164 code
= FullCanvas
.KEY_SOFTKEY1
;
165 else if (__c
== FullCanvas
._SOFT2
)
166 code
= FullCanvas
.KEY_SOFTKEY2
;
167 else if (__c
== FullCanvas
._SOFT3
)
168 code
= FullCanvas
.KEY_SOFTKEY3
;
174 // Press and release, since that is all we can do really!
175 FullCanvas fc
= (FullCanvas
)__d
;
177 fc
.keyReleased(code
);