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 javax
.microedition
.lcdui
;
12 import cc
.squirreljme
.jvm
.mle
.scritchui
.brackets
.ScritchMenuKindBracket
;
13 import cc
.squirreljme
.jvm
.mle
.scritchui
.brackets
.ScritchWindowBracket
;
14 import cc
.squirreljme
.jvm
.mle
.scritchui
.callbacks
.ScritchMenuItemActivateListener
;
15 import cc
.squirreljme
.runtime
.lcdui
.scritchui
.DisplayState
;
16 import cc
.squirreljme
.runtime
.lcdui
.scritchui
.DisplayableState
;
17 import cc
.squirreljme
.runtime
.lcdui
.scritchui
.MenuActionApplicable
;
18 import cc
.squirreljme
.runtime
.lcdui
.scritchui
.MenuActionNodeOnly
;
19 import cc
.squirreljme
.runtime
.lcdui
.scritchui
.MenuActionTree
;
20 import cc
.squirreljme
.runtime
.lcdui
.scritchui
.MenuActionTreeLeaf
;
23 * Handles activation of menu items.
27 class __ExecDisplayMenuItemActivate__
28 implements ScritchMenuItemActivateListener
30 /** The display state. */
31 private final DisplayState _state
;
34 * Initializes the handler.
36 * @param __state The display state.
37 * @throws NullPointerException On null arguments.
40 __ExecDisplayMenuItemActivate__(DisplayState __state
)
41 throws NullPointerException
44 throw new NullPointerException("NARG");
46 this._state
= __state
;
54 public void menuItemActivate(ScritchWindowBracket __window
,
55 ScritchMenuKindBracket __menuItem
)
57 if (__window
== null || __menuItem
== null)
58 throw new NullPointerException("NARG");
60 // Get the current displayable, we will be looking in its menu!
61 Display display
= this._state
.display();
62 DisplayableState displayableState
= this._state
.current();
63 if (displayableState
== null)
66 // Get actual displayable
67 Displayable current
= displayableState
.displayable();
71 // Find the leaf that belongs to this item
72 MenuActionTree tree
= MenuActionNodeOnly
.rootTree(current
);
73 MenuActionTreeLeaf leaf
= tree
.find(__menuItem
);
75 // Not found? Just ignore then
79 // Get the MIDP for this
80 MenuActionApplicable node
= leaf
.owner();
82 // If not a command, ignore
83 if (!(node
instanceof Command
))
86 // If there is no command listener, then do not bother
87 CommandListener listener
= current
.__getCommandListener();
92 listener
.commandAction((Command
)node
, current
);