1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.runtime
.lcdui
.scritchui
;
12 import cc
.squirreljme
.jvm
.mle
.scritchui
.ScritchInterface
;
13 import cc
.squirreljme
.jvm
.mle
.scritchui
.brackets
.ScritchMenuKindBracket
;
14 import cc
.squirreljme
.runtime
.cldc
.annotation
.SquirrelJMEVendorApi
;
15 import javax
.microedition
.lcdui
.Displayable
;
16 import javax
.microedition
.lcdui
.Menu
;
19 * A single leaf within the tree.
24 public final class MenuActionTreeLeaf
26 /** The node this maps to. */
28 final MenuActionNode _node
;
30 /** The ScritchUI bracket used. */
32 final ScritchMenuKindBracket _scritch
;
35 * Initializes the leaf from the node.
37 * @param __node The node to map to.
38 * @throws NullPointerException On null arguments.
42 MenuActionTreeLeaf(MenuActionNode __node
)
43 throws NullPointerException
46 throw new NullPointerException("NARG");
48 MenuActionApplicable owner
= __node
.owner();
49 ScritchInterface api
= DisplayManager
.instance().scritch();
51 // Determine the item that should be created
52 ScritchMenuKindBracket scritch
;
53 if (owner
instanceof Displayable
)
54 scritch
= api
.menu().menuBarNew();
55 else if (owner
instanceof Menu
)
56 scritch
= api
.menu().menuNew();
58 scritch
= api
.menu().menuItemNew();
62 this._scritch
= scritch
;
66 * Returns the leaf's owner.
68 * @return The leaf's owner.
72 public final MenuActionApplicable
owner()
74 return this._node
.owner();
78 * Returns the native widget.
80 * @param <K> The widget type.
81 * @param __cl The widget type.
82 * @return The resultant widget.
83 * @throws NullPointerException On null arguments.
87 public <K
extends ScritchMenuKindBracket
> K
scritchWidget(
88 Class
<?
extends K
> __cl
)
89 throws NullPointerException
92 throw new NullPointerException("NARG");
94 return __cl
.cast(this._scritch
);