Commit 9d58c0bd authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

If there is no title set for a Displayable, instead of saying "SquirrelJME"...

If there is no title set for a Displayable, instead of saying "SquirrelJME" try to derive the name of the program; Set the title if a Displayable is made current and it was already the current one (if it lost focus).
parent 544ea65e
......@@ -47,6 +47,12 @@ More detailed changes:
* Moved the graphics drawing operations to another class.
* Made all the graphics operations not throw a `TODO`, instead they will
just draw a placeholder graphic.
* When a `Displayable` is made current and it is already the current
displayed item, always set the title since it may have been placed in
the background by another application calling `setCurrent()`.
* Use a default title for a `Displayable` if one has not been set, this
will be in the order of the suite name, the main class, and if those
are not valid then "SquirrelJME" will be used instead.
* Removals
* `net.multiphasicapps.classfile.ExecutableCode` was not used.
* Programs and Libraries
......
......@@ -45,16 +45,29 @@ public final class ActiveMidlet
*/
public static MIDlet get()
throws IllegalStateException
{
MIDlet rv = ActiveMidlet.optional();
// {@squirreljme.error AD01 No MIDlet is currently active.}
if (rv == null)
throw new IllegalStateException("AD01");
return rv;
}
/**
* Returns the currently active midlet.
*
* @return The active midlet or {@code null} if none is active.
* @since 2019/04/14
*/
public static MIDlet optional()
throws IllegalStateException
{
// Lock
synchronized (_ACTIVE_LOCK)
{
// {@squirreljme.error AD01 No MIDlet is currently active.}
MIDlet rv = _ACTIVE_MIDLET;
if (rv == null)
throw new IllegalStateException("AD01");
return rv;
return _ACTIVE_MIDLET;
}
}
......
......@@ -776,6 +776,10 @@ public class Display
{
__EventCallback__._CALLBACK.__register();
// Use the title of this thing
NativeDisplayAccess.setDisplayTitle(this._state.nativeid,
__show._dtitle);
// Since we took over, we should recalculate the entire display
// because we would have missed resize events and other such
// things
......@@ -825,7 +829,7 @@ public class Display
// Use the title of this thing
NativeDisplayAccess.setDisplayTitle(this._state.nativeid,
__show.getTitle());
__show._dtitle);
// Update the UI stack
this.__updateUIStack(this._uipersist, null);
......
......@@ -12,8 +12,10 @@ package javax.microedition.lcdui;
import cc.squirreljme.runtime.cldc.asm.NativeDisplayAccess;
import cc.squirreljme.runtime.lcdui.SerializedEvent;
import cc.squirreljme.runtime.midlet.ActiveMidlet;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import javax.microedition.midlet.MIDlet;
/**
* A displayable is a primary container such as a form or a canvas that can be
......@@ -35,6 +37,9 @@ public abstract class Displayable
/** The title of the displayable. */
volatile String _title;
/** Display title to use. */
volatile String _dtitle;
/** The ticker of the displayable. */
volatile Ticker _ticker;
......@@ -48,6 +53,8 @@ public abstract class Displayable
*/
Displayable()
{
// Use a default title for now
this.__setTitle(null);
}
/**
......@@ -237,19 +244,8 @@ public abstract class Displayable
*/
public void setTitle(String __t)
{
// Cache it for later return
this._title = __t;
// Set the title of the display
Display d = this.__currentDisplay();
if (d != null)
{
// Set title there
d._state.setTitle(__t);
// Set as needing repaint
d._uipersist.repaint = true;
}
// Call internal title set
this.__setTitle(__t);
}
/**
......@@ -274,6 +270,54 @@ public abstract class Displayable
{
this._isshown = __shown;
}
/**
* Sets the title of this displayable, internal logic to.
*
* @param __t The title to use, {@code null} clears it.
* @since 2019/04/14
*/
private void __setTitle(String __t)
{
// Cache it for later return
this._title = __t;
// If no title is being set, fallback to a default one (derived from
// the suite)
if (__t == null)
{
// Try getting a sensible name from a system property
MIDlet amid = ActiveMidlet.optional();
if (amid != null)
{
// MIDlet Name
__t = amid.getAppProperty("midlet-name");
// Otherwise this might not be a MIDlet, so just use the main
// class instead
if (__t == null)
__t = amid.getAppProperty("main-class");
}
// Fallback to just using SquirrelJME
if (__t == null)
__t = "SquirrelJME";
}
// Store this
this._dtitle = __t;
// Set the title of the display
Display d = this.__currentDisplay();
if (d != null)
{
// Set title there
d._state.setTitle(__t);
// Set as needing repaint
d._uipersist.repaint = true;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment