Rename ntt-docomo-star-api to vendor-api-ntt-docomo-star.
[SquirrelJME.git] / modules / ntt-docomo-doja-api / src / main / java / com / nttdocomo / ui / Frame.java
blob1ab3cabd8b6ca461c7daceacd4d99ffde05b6500
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.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;
21 /**
22 * This is the main frame within an i-mode application, it is equivalent to
23 * MIDP's {@link Displayable}.
25 * @see Displayable
26 * @since 2021/11/30
28 @Api
29 public abstract class Frame
31 /** The left soft key. */
32 @Api
33 public static final int SOFT_KEY_1 = 0;
35 /** The right soft key. */
36 @Api
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;
48 /**
49 * Base constructor.
51 * @since 2021/11/30
53 Frame()
55 // Setup soft keys
56 Command[] softKeys = new Command[Frame._NUM_SOFT_KEYS];
57 this._softKeys = softKeys;
59 // Add them now
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);
70 /**
71 * Returns the {@link Displayable} this wraps.
73 * @return The MIDP {@link Displayable} used.
74 * @since 2021/11/30
76 abstract Displayable __displayable();
78 /**
79 * Returns the height of the current frame.
81 * @return The height of the current frame.
82 * @since 2021/11/30
84 @Api
85 public int getHeight()
87 return this.__displayable().getHeight();
90 /**
91 * Returns the width of the current frame.
93 * @return The width of the current frame.
94 * @since 2021/11/30
96 @Api
97 public int getWidth()
99 return this.__displayable().getWidth();
102 @Api
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.
113 * @since 2021/11/30
115 @Api
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())
131 // Change label
132 softKey.setLabel(__label);
134 // Show it
135 displayable.addCommand(softKey);
138 // It goes away
139 else
140 displayable.removeCommand(softKey);
144 * Must be called after construction so SquirrelJME can implement more
145 * operations.
147 * @since 2022/02/14
149 final void __postConstruct()
151 // Add the listener for commands
152 this.__displayable().setCommandListener(
153 new __ShoulderButtonEmitter__(new WeakReference<>(this)));