Merge branch 'upstream-sep2019-sfix' into subtree
authorNiki Roo <niki@nikiroo.be>
Thu, 2 Jan 2020 17:19:24 +0000 (18:19 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 2 Jan 2020 17:19:24 +0000 (18:19 +0100)
1  2 
TButton.java
TWidget.java

diff --combined TButton.java
index d86fa4400d16b51dc3be15dbaa38f5421ffdc7b5,d1d7b390cca0170e0c33f9cde044e968c64fc947..d1d7b390cca0170e0c33f9cde044e968c64fc947
@@@ -129,6 -129,20 +129,20 @@@ public class TButton extends TWidget 
          this(parent, text, x, y);
          this.action = action;
      }
+     
+     /**
+      * The action to call when the button is pressed.
+      **/
+     public TAction getAction() {
+               return action;
+       }
+     
+     /**
+      * The action to call when the button is pressed.
+      **/
+     public void setAction(TAction action) {
+               this.action = action;
+       }
  
      // ------------------------------------------------------------------------
      // Event handlers ---------------------------------------------------------
diff --combined TWidget.java
index 32ed80656882ec6f6267d042d8c52febbb3fd4dc,e11a947687027b4da7de59b10d51f1542ea54342..d60efd8d3a321236e2069199c6db2fb364505d69
@@@ -36,7 -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;
@@@ -185,7 -184,14 +185,7 @@@ public abstract class TWidget implement
       * @param enabled if true assume enabled
       */
      protected TWidget(final TWidget parent, final boolean enabled) {
 -        this.enabled = enabled;
 -        this.parent = parent;
 -        children = new ArrayList<TWidget>();
 -
 -        if (parent != null) {
 -            this.window = parent.window;
 -            parent.addChild(this);
 -        }
 +        this(parent, enabled, 0, 0, 0, 0);
      }
  
      /**
       * @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);
          }
      }
  
          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:
       * <ul>
       * @return difference between this.tabOrder and that.tabOrder, or
       * difference between this.z and that.z, or String.compareTo(text)
       */
 -    public final int compareTo(final TWidget that) {
 +    @Override
 +    public int compareTo(final TWidget that) {
          if ((this instanceof TWindow)
              && (that instanceof TWindow)
          ) {
       *
       * @param child TWidget to add
       */
-     private void addChild(final TWidget child) {
+     public void addChild(final TWidget child) {
          children.add(child);
  
          if ((child.enabled)
              children.get(i).tabOrder = i;
          }
      }
 +    
 +    /**
 +     * Remove and {@link TWidget#close()} the given child from this {@link TWidget}.
 +     * <p>
 +     * 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.
                  if (activeChild != null) {
                      activeChild.active = false;
                  }
 -                child.active = true;
 -                activeChild = child;
              }
 +            child.active = true;
 +            activeChild = child;
          }
      }
  
          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.
       *