Commit ed1dcdec authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Update the display if a command is added/removed; Add remove to volatile lists.

parent a8567487
......@@ -45,15 +45,16 @@ More detailed changes:
to launched tasks.
* `java.util.Vector`, was missing.
* 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()`.
* Moved the graphics drawing operations to another class.
* Update the `Display` when a command is added or removed.
* 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.
* 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()`.
* Removals
* `net.multiphasicapps.classfile.ExecutableCode` was not used.
* Programs and Libraries
......
......@@ -99,7 +99,12 @@ public abstract class Displayable
if ((cd.getCapabilities() & Display.SUPPORTS_COMMANDS) == 0)
throw new DisplayCapabilityException("EB27");
// Add the command
this._commands.addUniqueObjRef(__c);
// Update the display if attached
if (cd != null)
cd.__updateUIStack();
}
public Command getCommand(int __p)
......@@ -178,9 +183,27 @@ public abstract class Displayable
return this._isshown && this._parent != null;
}
public void removeCommand(Command __a)
/**
* Removes the specified command. If the command is {@code null} or it
* has never been added, this does nothing. If a command is removed then
* the display will be updated.
*
* @param __c The command to remove.
* @since 2019/04/15
*/
public void removeCommand(Command __c)
{
throw new todo.TODO();
if (__c == null)
return;
// If the command was removed, then do an update
if (this._commands.remove(__c))
{
// Update if the display is attached
Display cd = this.__currentDisplay();
if (cd != null)
cd.__updateUIStack();
}
}
public void removeCommandOrMenu(int __p)
......
......@@ -13,6 +13,7 @@ package javax.microedition.lcdui;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
/**
* This is a list which is volatile but not synchronized but is backed by an
......@@ -119,6 +120,50 @@ final class __VolatileList__<T>
((Object)(Arrays.<Object>asList(this._values).iterator()));
}
/**
* Removes the specified item from the list.
*
* @param __v The item to remove.
* @return {@code true} if it was removed.
* @since 2019/04/15
*/
@SuppressWarnings({"unchecked"})
public final boolean remove(T __v)
{
Object[] values = this._values;
// Check if we have this item first
int dx = 0, n = values.length;
for (; dx < n; dx++)
{
Object t = values[dx];
// No match
if ((__v == null) != (t == null) || !Objects.equals(t, __v))
continue;
// Stop
break;
}
// No match
if (dx >= n)
return false;
// Setup new array and copy all elements before and after
Object[] newvalues = new Object[n - 1];
for (int i = 0; i < dx; i++)
newvalues[i] = values[i];
for (int i = dx + 1, o = dx; i < n; i++, o++)
newvalues[o] = values[i];
// Use this new array
this._values = newvalues;
// Was changed
return true;
}
/**
* Returns the number of values.
*
......
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