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
.ScritchEventLoopInterface
;
13 import cc
.squirreljme
.runtime
.cldc
.annotation
.SquirrelJMEVendorApi
;
16 * This keeps track of an object string, if it changes then an update to
17 * a signal end is emitted.
19 * The listener that is called is always in the event loop.
21 * @param <T> The object type.
22 * @param <L> The listener type to use.
26 public abstract class ObjectTracker
<T
, L
>
28 /** The event loop used. */
30 protected final ScritchEventLoopInterface loop
;
32 /** The current value. */
36 /** The currently attached listener. */
41 * Initializes the object tracker with the given initial text.
43 * @param __loop The event loop interface.
44 * @param __init The initial value to use.
45 * @throws NullPointerException On null arguments.
49 public ObjectTracker(ScritchEventLoopInterface __loop
, T __init
)
50 throws NullPointerException
53 throw new NullPointerException("NARG");
60 * Executes the given listener.
62 * @param __listener The listener to execute.
63 * @param __value The value being set.
64 * @throws NullPointerException If no listener was specified.
68 protected abstract void exec(L __listener
, T __value
)
69 throws NullPointerException
;
72 * Connects to the given listener.
74 * @param __listener The listener to connect to.
75 * @throws NullPointerException On null arguments.
79 public final void connect(L __listener
)
80 throws NullPointerException
82 if (__listener
== null)
83 throw new NullPointerException("NARG");
87 this._listener
= __listener
;
90 // Since we connected a listener, we want to make sure it has the
91 // most up-to-date information
92 this.loop
.loopExecute(new __ExecObjectTracker__
<T
, L
>(this));
96 * Gets the current text.
98 * @return The current text.
101 @SquirrelJMEVendorApi
111 * Sets the given text.
113 * @param __t The text to set.
116 @SquirrelJMEVendorApi
117 public final void set(T __t
)
123 listener
= this._listener
;
126 // Inform listener of the change?
127 if (listener
!= null)
128 this.loop
.loopExecute(new __ExecObjectTracker__
<T
, L
>(