#14 TDesktop working, TWindow hide/show/max/restore working
[nikiroo-utils.git] / src / jexer / TApplication.java
index d8bec5e5d07b00dd54faca3f0660fbfcf9e4884a..6d71dc7771327d84b6135c75054b22f36d2033f4 100644 (file)
@@ -1278,9 +1278,9 @@ public class TApplication implements Runnable {
     }
 
     /**
-     * Return the number of windows that are visible.
+     * Return the number of windows that are showing.
      *
-     * @return the number of windows that are visible
+     * @return the number of windows that are showing on screen
      */
     public final int shownWindowCount() {
         int n = 0;
@@ -1292,6 +1292,21 @@ public class TApplication implements Runnable {
         return n;
     }
 
+    /**
+     * Return the number of windows that are hidden.
+     *
+     * @return the number of windows that are hidden
+     */
+    public final int hiddenWindowCount() {
+        int n = 0;
+        for (TWindow w: windows) {
+            if (w.isHidden()) {
+                n++;
+            }
+        }
+        return n;
+    }
+
     /**
      * Check if a window instance is in this application's window list.
      *
@@ -1304,6 +1319,7 @@ public class TApplication implements Runnable {
         }
         for (TWindow w: windows) {
             if (w == window) {
+                assert (window.getApplication() == this);
                 return true;
             }
         }
@@ -1496,8 +1512,8 @@ public class TApplication implements Runnable {
      * otherwise switch to the previous window in the list
      */
     public final void switchWindow(final boolean forward) {
-        // Only switch if there are multiple windows
-        if (windows.size() < 2) {
+        // Only switch if there are multiple visible windows
+        if (shownWindowCount() < 2) {
             return;
         }
         assert (activeWindow != null);
@@ -1522,18 +1538,23 @@ public class TApplication implements Runnable {
                 return;
             }
 
-            int nextWindowI;
-            if (forward) {
-                nextWindowI = (activeWindowI + 1) % windows.size();
-            } else {
-                if (activeWindowI == 0) {
-                    nextWindowI = windows.size() - 1;
+            int nextWindowI = activeWindowI;
+            for (;;) {
+                if (forward) {
+                    nextWindowI++;
+                    nextWindowI %= windows.size();
                 } else {
-                    nextWindowI = activeWindowI - 1;
+                    nextWindowI--;
+                    if (nextWindowI < 0) {
+                        nextWindowI = windows.size() - 1;
+                    }
                 }
-            }
 
-            activateWindow(windows.get(nextWindowI));
+                if (windows.get(nextWindowI).isShown()) {
+                    activateWindow(windows.get(nextWindowI));
+                    break;
+                }
+            }
         } // synchronized (windows)
 
     }
@@ -1746,11 +1767,11 @@ public class TApplication implements Runnable {
                 continue;
             }
             for (int x = w.getX(); x < w.getX() + w.getWidth(); x++) {
-                if (x == width) {
+                if (x >= width) {
                     continue;
                 }
                 for (int y = w.getY(); y < w.getY() + w.getHeight(); y++) {
-                    if (y == height) {
+                    if (y >= height) {
                         continue;
                     }
                     overlapMatrix[x][y]++;
@@ -1793,11 +1814,11 @@ public class TApplication implements Runnable {
                 long newOverlapN = 0;
                 // Start by adding each new cell.
                 for (int wx = x; wx < x + window.getWidth(); wx++) {
-                    if (wx == width) {
+                    if (wx >= width) {
                         continue;
                     }
                     for (int wy = y; wy < y + window.getHeight(); wy++) {
-                        if (wy == height) {
+                        if (wy >= height) {
                             continue;
                         }
                         newMatrix[wx][wy]++;