X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWidget.java;h=ce22330576309206861b8246be3423a248499180;hb=505be508ae7d3fb48122be548b310a238cfb91eb;hp=32b55983613a67914aec832d2d0ac7c6ab323287;hpb=713de2aab8afa1556d987897a9f28b85f5c0f8a2;p=fanfix.git diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 32b5598..ce22330 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import jexer.backend.Screen; import jexer.bits.Cell; import jexer.bits.CellAttributes; +import jexer.bits.Clipboard; import jexer.bits.ColorTheme; import jexer.event.TCommandEvent; import jexer.event.TInputEvent; @@ -208,20 +209,9 @@ public abstract class TWidget implements Comparable { } this.enabled = enabled; + this.parent = parent; children = new ArrayList(); - // Allow parentless widgets - if (parent != null) { - // Do not add TStatusBars, they are drawn by TApplication. - if (this instanceof TStatusBar) { - // We don't add the child to the children list here - this.parent = parent; - this.window = parent.window; - } else { - parent.addChild(this); - } - } - this.x = x; this.y = y; this.width = width; @@ -602,9 +592,8 @@ public abstract class TWidget implements Comparable { * @param command command event */ public void onCommand(final TCommandEvent command) { - // Default: do nothing, pass to children instead - for (TWidget widget: children) { - widget.onCommand(command); + if (activeChild != null) { + activeChild.onCommand(command); } } @@ -1137,6 +1126,18 @@ public abstract class TWidget implements Comparable { return null; } + /** + * Get the Clipboard. + * + * @return the Clipboard, or null if not assigned + */ + public Clipboard getClipboard() { + if (window != null) { + return window.getApplication().getClipboard(); + } + return null; + } + /** * Comparison operator. For various subclasses it sorts on: *
    @@ -1150,7 +1151,7 @@ public abstract class TWidget implements Comparable { * difference between this.z and that.z, or String.compareTo(text) */ @Override - public final int compareTo(final TWidget that) { + public int compareTo(final TWidget that) { if ((this instanceof TWindow) && (that instanceof TWindow) ) { @@ -1373,10 +1374,8 @@ public abstract class TWidget implements Comparable { * * @param child TWidget to add */ - private void addChild(final TWidget child) { + public void addChild(final TWidget child) { children.add(child); - child.parent = this; - child.window = this.window; if ((child.enabled) && !(child instanceof THScroller) @@ -1416,6 +1415,19 @@ public abstract class TWidget implements Comparable { * @return TRUE if the child was removed, FALSE if it was not found */ public boolean removeChild(final TWidget child) { +<<<<<<< HEAD:TWidget.java + if (children.remove(child)) { + child.close(); + child.parent = null; + child.window = null; + + resetTabOrder(); + + return true; + } + + return false; +======= if (children.remove(child)) { child.close(); child.parent = null; @@ -1427,6 +1439,7 @@ public abstract class TWidget implements Comparable { } return false; +>>>>>>> upstream-sep2019-tcombo:src/jexer/TWidget.java } /** @@ -1452,9 +1465,9 @@ public abstract class TWidget implements Comparable { if (activeChild != null) { activeChild.active = false; } - child.active = true; - activeChild = child; } + child.active = true; + activeChild = child; } } @@ -2181,6 +2194,21 @@ public abstract class TWidget implements Comparable { return new TRadioGroup(this, x, y, label); } + /** + * Convenience function to add a radio button group to this + * container/window. + * + * @param x column relative to parent + * @param y row relative to parent + * @param width width of group + * @param label label to display on the group box + */ + public final TRadioGroup addRadioGroup(final int x, final int y, + final int width, final String label) { + + return new TRadioGroup(this, x, y, width, label); + } + /** * Convenience function to add a text field to this container/window. *