Marking of more classes, might get rid of in the future and optimize; Implement shrin...
[SquirrelJME.git] / modules / nokia-api / src / main / java / com / nokia / mid / ui / FullCanvas.java
blobba2cdaac4367c4867c85b999a4ca3b4782b642ef
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
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;
19 /**
20 * This the Nokia canvas, command buttons are forwarded to the key pressed
21 * and released commands for the canvas.
23 * @since 2019/09/23
25 @Api
26 public abstract class FullCanvas
27 extends Canvas
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);
38 /** Down arrow. */
39 @Api
40 public static final int KEY_DOWN_ARROW = -2;
42 /** End. */
43 @Api
44 public static final int KEY_END = -11;
46 /** Left arrow. */
47 @Api
48 public static final int KEY_LEFT_ARROW = -3;
50 /** Right arrow. */
51 @Api
52 public static final int KEY_RIGHT_ARROW = -4;
54 /** Send. */
55 @Api
56 public static final int KEY_SEND = -10;
58 /** Soft Key 1. */
59 @Api
60 public static final int KEY_SOFTKEY1 = -6;
62 /** Soft Key 2. */
63 @Api
64 public static final int KEY_SOFTKEY2 = -7;
66 /** Soft Key 3. */
67 @Api
68 public static final int KEY_SOFTKEY3 = -5;
70 /** Up Arrow. */
71 @Api
72 public static final int KEY_UP_ARROW = -1;
74 /**
75 * Initializes the base canvas and sets as full-screen.
77 * @since 2019/09/23
79 @Api
80 @ApiDefinedDeprecated
81 public FullCanvas()
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__());
96 /**
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.
102 * @since 2019/09/23
104 @Override
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);
112 return;
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.
125 * @since 2019/09/23
127 @Override
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);
134 return;
137 // {@squirreljme.error EB2y Commands are not supported.}
138 throw new IllegalStateException("EB2y");
142 * Command listener to forward keys to the canvas.
144 * @since 2019/09/23
146 private static final class __VirtualListener__
147 implements CommandListener
150 * {@inheritDoc}
152 * @since 2019/09/23
154 @Override
155 public final void commandAction(Command __c, Displayable __d)
157 // Do nothing if this is some other thing
158 if (!(__d instanceof FullCanvas))
159 return;
161 // Determine code to use
162 int code;
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;
170 // Unknown?
171 else
172 return;
174 // Press and release, since that is all we can do really!
175 FullCanvas fc = (FullCanvas)__d;
176 fc.keyPressed(code);
177 fc.keyReleased(code);