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
.nttdocomo
.ui
;
12 import cc
.squirreljme
.jvm
.mle
.constants
.UIMetricType
;
13 import cc
.squirreljme
.runtime
.cldc
.annotation
.Api
;
14 import cc
.squirreljme
.runtime
.cldc
.debug
.Debugging
;
15 import cc
.squirreljme
.runtime
.lcdui
.mle
.UIBackend
;
16 import cc
.squirreljme
.runtime
.lcdui
.mle
.UIBackendFactory
;
17 import java
.lang
.ref
.WeakReference
;
18 import javax
.microedition
.lcdui
.Command
;
19 import javax
.microedition
.lcdui
.Displayable
;
22 * This is the main frame within an i-mode application, it is equivalent to
23 * MIDP's {@link Displayable}.
29 public abstract class Frame
31 /** The left soft key. */
33 public static final int SOFT_KEY_1
= 0;
35 /** The right soft key. */
37 public static final int SOFT_KEY_2
= 1;
39 /** The number of soft keys which are valid. */
40 static final int _NUM_SOFT_KEYS
= 2;
42 /** The actual soft key commands. */
43 final Command
[] _softKeys
;
45 /** The background color of the display. */
46 final __BGColor__ _bgColor
;
56 Command
[] softKeys
= new Command
[Frame
._NUM_SOFT_KEYS
];
57 this._softKeys
= softKeys
;
60 for (int i
= 0; i
< Frame
._NUM_SOFT_KEYS
; i
++)
61 softKeys
[i
] = new Command("", Command
.ITEM
, i
);
63 // Use default background color
64 UIBackend backend
= UIBackendFactory
.getInstance(true);
65 int defaultBgColor
= backend
.metric(backend
.displays()[0],
66 UIMetricType
.COLOR_CANVAS_BACKGROUND
) | 0xFF_
000000;
67 this._bgColor
= new __BGColor__(defaultBgColor
);
71 * Returns the {@link Displayable} this wraps.
73 * @return The MIDP {@link Displayable} used.
76 abstract Displayable
__displayable();
79 * Returns the height of the current frame.
81 * @return The height of the current frame.
85 public int getHeight()
87 return this.__displayable().getHeight();
91 * Returns the width of the current frame.
93 * @return The width of the current frame.
99 return this.__displayable().getWidth();
103 public void setBackground(int __c
)
105 throw Debugging
.todo();
109 * Sets the label for a soft key.
111 * @param __key The key to set.
112 * @param __label The label for the key.
116 public void setSoftLabel(int __key
, String __label
)
118 if (__key
< 0 || __key
>= Frame
._NUM_SOFT_KEYS
)
119 throw Debugging
.todo("Handle soft key %d?", __key
);
121 Displayable displayable
= this.__displayable();
122 Command softKey
= this._softKeys
[__key
];
124 // If a layout policy for the soft keys has not been set, set it now
125 if (displayable
.getCommandLayoutPolicy() == null)
126 displayable
.setCommandLayoutPolicy(new __SoftKeyLayout__());
128 // Setup command and show it
129 if (__label
!= null && !__label
.isEmpty())
132 softKey
.setLabel(__label
);
135 displayable
.addCommand(softKey
);
140 displayable
.removeCommand(softKey
);
144 * Must be called after construction so SquirrelJME can implement more
149 final void __postConstruct()
151 // Add the listener for commands
152 this.__displayable().setCommandListener(
153 new __ShoulderButtonEmitter__(new WeakReference
<>(this)));