#51 wip
[fanfix.git] / src / jexer / TWidget.java
index bcf798ae36e9f40336d40fcd18d11e3a58b0de6c..729a5f5d0c3a1b43056087e43c39fae1b7f39527 100644 (file)
@@ -619,6 +619,9 @@ public abstract class TWidget implements Comparable<TWidget> {
         List<TWidget> widgets = null;
         switch (menu.getId()) {
         case TMenu.MID_SPLIT_VERTICAL:
+            if (children.size() == 0) {
+                break;
+            }
             panel = new TPanel(null, x, y, width, height);
             pane = new TSplitPane(null, x, y, width, height, true);
             widgets = new ArrayList<TWidget>(children);
@@ -641,6 +644,9 @@ public abstract class TWidget implements Comparable<TWidget> {
             assert (panel.isActive() == true);
             return;
         case TMenu.MID_SPLIT_HORIZONTAL:
+            if (children.size() == 0) {
+                break;
+            }
             panel = new TPanel(null, x, y, width, height);
             pane = new TSplitPane(null, x, y, width, height, false);
             widgets = new ArrayList<TWidget>(children);
@@ -1109,6 +1115,11 @@ public abstract class TWidget implements Comparable<TWidget> {
 
         assert (window != null);
 
+        if (window instanceof TDesktop) {
+            // Desktop doesn't have a window border.
+            return cursorVisible;
+        }
+
         // If cursor is out of my window's bounds, it is not visible.
         if ((getCursorAbsoluteX() >= window.getAbsoluteX()
                 + window.getWidth() - 1)
@@ -1161,19 +1172,25 @@ public abstract class TWidget implements Comparable<TWidget> {
     /**
      * Get this TWidget's parent TApplication.
      *
-     * @return the parent TApplication
+     * @return the parent TApplication, or null if not assigned
      */
     public TApplication getApplication() {
-        return window.getApplication();
+        if (window != null) {
+            return window.getApplication();
+        }
+        return null;
     }
 
     /**
      * Get the Screen.
      *
-     * @return the Screen
+     * @return the Screen, or null if not assigned
      */
     public Screen getScreen() {
-        return window.getScreen();
+        if (window != null) {
+            return window.getScreen();
+        }
+        return null;
     }
 
     /**
@@ -1299,6 +1316,10 @@ public abstract class TWidget implements Comparable<TWidget> {
      * Called by parent to render to TWindow.  Note package private access.
      */
     final void drawChildren() {
+        if (window == null) {
+            return;
+        }
+
         // Set my clipping rectangle
         assert (window != null);
         assert (getScreen() != null);
@@ -1315,10 +1336,16 @@ public abstract class TWidget implements Comparable<TWidget> {
 
         int absoluteRightEdge = window.getAbsoluteX() + window.getWidth();
         int absoluteBottomEdge = window.getAbsoluteY() + window.getHeight();
-        if (!(this instanceof TWindow) && !(this instanceof TVScroller)) {
+        if (!(this instanceof TWindow)
+            && !(this instanceof TVScroller)
+            && !(parent instanceof TDesktop)
+        ) {
             absoluteRightEdge -= 1;
         }
-        if (!(this instanceof TWindow) && !(this instanceof THScroller)) {
+        if (!(this instanceof TWindow)
+            && !(this instanceof THScroller)
+            && !(parent instanceof TDesktop)
+        ) {
             absoluteBottomEdge -= 1;
         }
         int myRightEdge = getAbsoluteX() + width;