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
.ScritchMenuBarBracket
;
14 import cc
.squirreljme
.runtime
.cldc
.annotation
.SquirrelJMEVendorApi
;
15 import javax
.microedition
.lcdui
.Displayable
;
16 import javax
.microedition
.lcdui
.Menu
;
17 import org
.jetbrains
.annotations
.Async
;
20 * Represents the layout state for a menu bar.
22 * It might be awkward that menu bars are bound to {@link Displayable}s,
23 * however {@link Displayable}s always have just a single menu bar.
25 * There is a single pinned menu which is used as the default menu for
26 * commands that are added, since they need to go somewhere.
28 * @see ScritchMenuBarBracket
32 public final class MenuLayoutBar
33 extends MenuLayoutBindableSub
<Displayable
>
35 /** Root node which represents the menu bar. */
36 private volatile MenuLayoutBarNode _rootNode
;
38 /** The pinned menu. */
39 private volatile Menu _pinned
;
42 * Initializes the bindable.
44 * @param __scritch The ScritchUI interface.
45 * @param __item The item to bind to.
46 * @throws NullPointerException On null arguments.
49 public MenuLayoutBar(ScritchInterface __scritch
, Displayable __item
)
50 throws NullPointerException
52 super(__scritch
, __item
);
56 * Returns the pinned menu, which generally is the default item.
58 * @return The pinned menu, or {@code null} if there is nothing pinned.
71 * Pins the given menu as the default menu, or clears it.
73 * @param __menu The menu to pin as the default, {@code null} will clear
78 public void pin(Menu __menu
)
82 this._pinned
= __menu
;
87 * Performs recursive refreshing of this bindable.
89 * @throws IllegalStateException If this is called outside the event
95 protected void refreshInLoop()
96 throws IllegalStateException
98 ScritchInterface scritchApi
= this.scritchApi
;
101 // Do we need to make the root node?
102 MenuLayoutBarNode rootNode
= this._rootNode
;
103 if (rootNode
== null)
105 // Create native menu bar first
106 ScritchMenuBarBracket bar
= scritchApi
.menu().menuBarNew();
109 rootNode
= new MenuLayoutBarNode(this.getMidp(), bar
);
110 this._rootNode
= rootNode
;
113 // Clear out entire tree, so we rebuild the menu
114 rootNode
.__clear(scritchApi
, false);
116 // Then rebuild in loop
117 rootNode
.__build(scritchApi
);