Merge heads; mark more APIs.
[SquirrelJME.git] / modules / midp-lcdui / src / main / java / javax / microedition / lcdui / __ExecDisplayMenuItemActivate__.java
blob0a7914fcf9efae550d82f4bbbb81de75fa89a9b1
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;
22 /**
23 * Handles activation of menu items.
25 * @since 2024/07/30
27 class __ExecDisplayMenuItemActivate__
28 implements ScritchMenuItemActivateListener
30 /** The display state. */
31 private final DisplayState _state;
33 /**
34 * Initializes the handler.
36 * @param __state The display state.
37 * @throws NullPointerException On null arguments.
38 * @since 2024/07/30
40 __ExecDisplayMenuItemActivate__(DisplayState __state)
41 throws NullPointerException
43 if (__state == null)
44 throw new NullPointerException("NARG");
46 this._state = __state;
49 /**
50 * {@inheritDoc}
51 * @since 2024/07/30
53 @Override
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)
64 return;
66 // Get actual displayable
67 Displayable current = displayableState.displayable();
68 if (current == null)
69 return;
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
76 if (leaf == null)
77 return;
79 // Get the MIDP for this
80 MenuActionApplicable node = leaf.owner();
82 // If not a command, ignore
83 if (!(node instanceof Command))
84 return;
86 // If there is no command listener, then do not bother
87 CommandListener listener = current.__getCommandListener();
88 if (listener == null)
89 return;
91 // Execute
92 listener.commandAction((Command)node, current);