From 77dc800caee530b6d993706a5b4db4b858546f97 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 24 Oct 2019 08:42:21 +0200 Subject: [PATCH] TWidget: removeChild (req. for TComboBox fixes) --- src/jexer/TWidget.java | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index e94fed25..eb061750 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -184,14 +184,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); } /** @@ -1145,6 +1138,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 final int compareTo(final TWidget that) { if ((this instanceof TWindow) && (that instanceof TWindow) @@ -1398,6 +1392,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. -- 2.27.0