Commit 544ea65e authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Put title of the program in the launch list; Add system property to...

Put title of the program in the launch list; Add system property to automatically launch a program when the list is refreshed.
parent 2ef49fa1
......@@ -45,11 +45,18 @@ More detailed changes:
to launched tasks.
* 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.
* Removals
* `net.multiphasicapps.classfile.ExecutableCode`, not used.
* `net.multiphasicapps.classfile.ExecutableCode` was not used.
* Programs and Libraries
* `demo-hello`
* Made the system properties array `final`.
* `launcher`
* Added the system property `cc.squirreljme.autolaunch` to automatically
launch a program once the program list is read.
* When a program is launched, instead of saying just "Loading..." instead
allow show the program which is being loaded in the title.
* `tac`
* Override standard output and forward to standard error while a test is
running, so things are not kludged.
......
......@@ -39,6 +39,14 @@ import javax.microedition.swm.TaskStatus;
public class MidletMain
extends MIDlet
{
/**
* {@squirreljme.property cc.squirreljme.autolaunch=program This specifies
* the program that should be auto-launched once the program list has been
* processed.}
*/
public static final String AUTOLAUNCH_PROPERTY =
"cc.squirreljme.autolaunch";
/** Timer used to reschedule things. */
static final Timer _TIMER =
new Timer("LauncherRecoverThread");
......@@ -65,6 +73,28 @@ public class MidletMain
/** The programs which are mapped to the list. */
private volatile __Program__[] _programs;
/** Automatic launch program. */
private volatile String _autolaunch;
/**
* Initializes the launcher.
*
* @since 2019/04/14
*/
{
// Do not crash if we cannot read properties
String al = null;
try
{
al = System.getProperty(AUTOLAUNCH_PROPERTY);
}
catch (SecurityException e)
{
}
this._autolaunch = al;
}
/**
* {@inheritDoc}
* @since 2016/10/11
......@@ -180,6 +210,17 @@ public class MidletMain
// Re-flip on this display
if (_MAIN_DISPLAY.getCurrent() == programlist)
_MAIN_DISPLAY.setCurrent(programlist);
// Automatically launch a program?
String autolaunch = this._autolaunch;
if (autolaunch != null)
{
this._autolaunch = null;
// Launch it
System.err.println("Auto-launching " + autolaunch + "...");
this.__launch(autolaunch);
}
}
/**
......@@ -218,6 +259,99 @@ public class MidletMain
this.refresh();
}
/**
* Launches the specified program.
*
* @param __p The program to launch.
* @throws NullPointerException On null arguments.
* @since 2019/04/14
*/
private void __launch(__Program__ __p)
throws NullPointerException
{
if (__p == null)
throw new NullPointerException("NARG");
// Indication that something is happening
this.programlist.setTitle("Launching " + __p.displayname + "...");
// Launch this program
__p.__launch();
// All done so, return the title back
this.programlist.setTitle("SquirrelJME Launcher");
}
/**
* Launches the specified program.
*
* @param __p The program to launch.
* @since 2019/04/14
*/
private void __launch(int __p)
{
__Program__[] programs = this._programs;
// Do nothing if out of bounds
if (__p < 0 || __p >= programs.length)
return;
// Launch
this.__launch(programs[__p]);
}
/**
* Launches the specified program.
*
* @param __p The program to launch.
* @throws NullPointerException On null arguments.
* @since 2019/04/14
*/
private void __launch(String __p)
throws NullPointerException
{
if (__p == null)
throw new NullPointerException("NARG");
// This will use multiple matches, with less priority following
__Program__ bysj = null,
bydn = null,
bysn = null,
bymc = null;
// Find all the possible matches for a program
for (__Program__ p : this._programs)
if (bysj == null && __p.equalsIgnoreCase(p.squirreljmename))
bysj = p;
else if (bydn == null && __p.equalsIgnoreCase(p.displayname))
bydn = p;
else if (bysn == null && __p.equalsIgnoreCase(p.suitename))
bysn = p;
else if (bymc == null && __p.equalsIgnoreCase(p.main))
bymc = p;
// Use a priority based order
__Program__ p = (bysj != null ? bysj :
(bydn != null ? bydn :
(bysn != null ? bysn :
(bymc != null ? bymc : null))));
if (p != null)
{
this.__launch(p);
return;
}
// If everything fails, just assume it is an index to a program on the
// program list
try
{
this.__launch(Integer.parseInt(__p));
}
catch (NumberFormatException e)
{
}
}
/**
* This is the handler for commands.
*
......@@ -236,23 +370,15 @@ public class MidletMain
// Launching a program?
if (__c == MidletMain.this.launchcommand)
{
__Program__[] programs = MidletMain.this._programs;
// If the list is empty then do nothing because it will NPE
// or out of bounds if the selection is off
List list = (List)__d;
int seldx = list.getSelectedIndex();
if (list.size() <= 0 || seldx < 0 || seldx >= programs.length)
if (list.size() <= 0 || seldx < 0)
return;
// Indication that something is happening
MidletMain.this.programlist.setTitle("Launching...");
// Launch this program
programs[seldx].__launch();
// All done so, return the title back
programlist.setTitle("SquirrelJME Launcher");
// Call other launcher
MidletMain.this.__launch(seldx);
}
// Exiting the VM?
......
......@@ -28,12 +28,18 @@ final class __Program__
/** The suite that is used. */
protected final Suite suite;
/** The name of the suite. */
protected final String suitename;
/** The main entry point. */
protected final String main;
/** The display name of this suite. */
protected final String displayname;
/** The SquirrelJME name. */
protected final String squirreljmename;
/** The active task. */
final __ActiveTask__ _activetask;
......@@ -56,9 +62,35 @@ final class __Program__
this.suite = __suite;
this.main = __main;
this.displayname = (__dn != null ? __dn :
__suite.getName() + " " + __main);
String suitename = __suite.getName();
this.suitename = suitename;
String displayname;
this.displayname = (displayname = (__dn != null ? __dn :
suitename + " " + __main));
this._activetask = __at;
// Try to get the internal project name for SquirrelJME, this is used
// for quick launching
String sjn = __suite.getAttributeValue(
"X-SquirrelJME-InternalProjectName");
if (sjn == null)
{
// Only add normal characters
StringBuilder sb = new StringBuilder();
for (int i = 0, n = displayname.length(); i < n; i++)
{
char c = displayname.charAt(i);
if (Character.isDigit(c) || Character.isLowerCase(c) ||
Character.isUpperCase(c))
sb.append(c);
}
sjn = sb.toString();
}
this.squirreljmename = sjn.toLowerCase();
}
/**
......
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