X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=TWidget.java;fp=src%2Fjexer%2FTWidget.java;h=32ed80656882ec6f6267d042d8c52febbb3fd4dc;hp=5c93712084a9b6f90bd9728ed17d368de82dfaa4;hb=e6bb1700749980e69b5e913acbfd276f129c24dc;hpb=1e8647a978ba3c3966dbf8ae90eeae6612f403be diff --git a/src/jexer/TWidget.java b/TWidget.java similarity index 99% rename from src/jexer/TWidget.java rename to TWidget.java index 5c93712..32ed806 100644 --- a/src/jexer/TWidget.java +++ b/TWidget.java @@ -185,14 +185,7 @@ public abstract class TWidget implements Comparable { * @param enabled if true assume enabled */ protected TWidget(final TWidget parent, final boolean enabled) { - this.enabled = enabled; - this.parent = parent; - children = new ArrayList(); - - if (parent != null) { - this.window = parent.window; - parent.addChild(this); - } + this(parent, enabled, 0, 0, 0, 0); } /** @@ -1157,6 +1150,7 @@ public abstract class TWidget implements Comparable { * @return difference between this.tabOrder and that.tabOrder, or * difference between this.z and that.z, or String.compareTo(text) */ + @Override public int compareTo(final TWidget that) { if ((this instanceof TWindow) && (that instanceof TWindow) @@ -1410,6 +1404,29 @@ public abstract class TWidget implements Comparable { children.get(i).tabOrder = i; } } + + /** + * Remove and {@link TWidget#close()} the given child from this {@link TWidget}. + *

+ * Will also reorder the tab values of the remaining children. + * + * @param child the child to remove + * + * @return TRUE if the child was removed, FALSE if it was not found + */ + public boolean removeChild(final TWidget child) { + if (children.remove(child)) { + child.close(); + child.parent = null; + child.window = null; + + resetTabOrder(); + + return true; + } + + return false; + } /** * Switch the active child.