Refactoring - boolean getters and miscellaneous
[fanfix.git] / src / jexer / TWidget.java
index d6864db746316659ef5d3ed4fed3cc76b0934d6a..7ea1a427cbb78227e40c9b4935139631a66b3919 100644 (file)
@@ -86,13 +86,6 @@ public abstract class TWidget implements Comparable<TWidget> {
         this.height = height;
     }
 
-    /**
-     * Request full repaint on next screen refresh.
-     */
-    protected final void setRepaint() {
-        window.getApplication().setRepaint();
-    }
-
     /**
      * Get this TWidget's parent TApplication.
      *
@@ -140,7 +133,7 @@ public abstract class TWidget implements Comparable<TWidget> {
      *
      * @return if true, this widget will receive events
      */
-    public final boolean getActive() {
+    public final boolean isActive() {
         return active;
     }
 
@@ -274,7 +267,7 @@ public abstract class TWidget implements Comparable<TWidget> {
      *
      * @return if true, this widget can be tabbed to or receive events
      */
-    public final boolean getEnabled() {
+    public final boolean isEnabled() {
         return enabled;
     }
 
@@ -310,15 +303,15 @@ public abstract class TWidget implements Comparable<TWidget> {
     /**
      * If true, this widget has a cursor.
      */
-    private boolean hasCursor = false;
+    private boolean cursorVisible = false;
 
     /**
      * Set visible cursor flag.
      *
-     * @param hasCursor if true, this widget has a cursor
+     * @param cursorVisible if true, this widget has a cursor
      */
-    public final void setHasCursor(final boolean hasCursor) {
-        this.hasCursor = hasCursor;
+    public final void setCursorVisible(final boolean cursorVisible) {
+        this.cursorVisible = cursorVisible;
     }
 
     /**
@@ -326,8 +319,8 @@ public abstract class TWidget implements Comparable<TWidget> {
      *
      * @return if true, this widget has a visible cursor
      */
-    public final boolean visibleCursor() {
-        return hasCursor;
+    public final boolean isCursorVisible() {
+        return cursorVisible;
     }
 
     /**
@@ -399,11 +392,11 @@ public abstract class TWidget implements Comparable<TWidget> {
      * @return true if this widget is active and all of its parents are
      * active.
      */
-    public final boolean getAbsoluteActive() {
+    public final boolean isAbsoluteActive() {
         if (parent == this) {
             return active;
         }
-        return (active && parent.getAbsoluteActive());
+        return (active && parent.isAbsoluteActive());
     }
 
     /**
@@ -412,7 +405,7 @@ public abstract class TWidget implements Comparable<TWidget> {
      * @return absolute screen column number for the cursor's X position
      */
     public final int getCursorAbsoluteX() {
-        assert (hasCursor);
+        assert (cursorVisible);
         return getAbsoluteX() + cursorX;
     }
 
@@ -422,7 +415,7 @@ public abstract class TWidget implements Comparable<TWidget> {
      * @return absolute screen row number for the cursor's Y position
      */
     public final int getCursorAbsoluteY() {
-        assert (hasCursor);
+        assert (cursorVisible);
         return getAbsoluteY() + cursorY;
     }
 
@@ -487,14 +480,14 @@ public abstract class TWidget implements Comparable<TWidget> {
     public final void drawChildren() {
         // Set my clipping rectangle
         assert (window != null);
-        assert (window.getScreen() != null);
-        Screen screen = window.getScreen();
+        assert (getScreen() != null);
+        Screen screen = getScreen();
 
         screen.setClipRight(width);
         screen.setClipBottom(height);
 
-        int absoluteRightEdge = window.getAbsoluteX() + screen.getWidth();
-        int absoluteBottomEdge = window.getAbsoluteY() + screen.getHeight();
+        int absoluteRightEdge = window.getAbsoluteX() + window.getWidth();
+        int absoluteBottomEdge = window.getAbsoluteY() + window.getHeight();
         if (!(this instanceof TWindow) && !(this instanceof TVScroller)) {
             absoluteRightEdge -= 1;
         }
@@ -508,14 +501,14 @@ public abstract class TWidget implements Comparable<TWidget> {
             screen.setClipRight(0);
         } else if (myRightEdge > absoluteRightEdge) {
             screen.setClipRight(screen.getClipRight()
-                - myRightEdge - absoluteRightEdge);
+                - (myRightEdge - absoluteRightEdge));
         }
         if (getAbsoluteY() > absoluteBottomEdge) {
             // I am offscreen
             screen.setClipBottom(0);
         } else if (myBottomEdge > absoluteBottomEdge) {
             screen.setClipBottom(screen.getClipBottom()
-                - myBottomEdge - absoluteBottomEdge);
+                - (myBottomEdge - absoluteBottomEdge));
         }
 
         // Set my offset
@@ -727,9 +720,6 @@ public abstract class TWidget implements Comparable<TWidget> {
         activeChild.active = false;
         children.get(tabOrder).active = true;
         activeChild = children.get(tabOrder);
-
-        // Refresh
-        window.getApplication().setRepaint();
     }
 
     /**
@@ -789,27 +779,25 @@ public abstract class TWidget implements Comparable<TWidget> {
         // If I have any buttons on me AND this is an Alt-key that matches
         // its mnemonic, send it an Enter keystroke
         for (TWidget widget: children) {
-            /*
-            TODO
-
-            if (TButton button = cast(TButton)w) {
-                if (button.enabled &&
-                    !keypress.key.isKey &&
-                    keypress.key.alt &&
-                    !keypress.key.ctrl &&
-                    (toLowercase(button.mnemonic.shortcut) == toLowercase(keypress.key.ch))) {
-
-                    w.handleEvent(new TKeypressEvent(kbEnter));
+            if (widget instanceof TButton) {
+                TButton button = (TButton) widget;
+                if (button.isEnabled()
+                    && !keypress.getKey().isFnKey()
+                    && keypress.getKey().isAlt()
+                    && !keypress.getKey().isCtrl()
+                    && (Character.toLowerCase(button.getMnemonic().getShortcut())
+                        == Character.toLowerCase(keypress.getKey().getChar()))
+                ) {
+
+                    widget.handleEvent(new TKeypressEvent(kbEnter));
                     return;
                 }
             }
-             */
         }
 
         // Dispatch the keypress to an active widget
         for (TWidget widget: children) {
             if (widget.active) {
-                window.getApplication().setRepaint();
                 widget.handleEvent(keypress);
                 return;
             }