Bug fixes
[nikiroo-utils.git] / src / jexer / backend / SwingTerminal.java
index c2fbfb437eae6b54f43f4b0a497d703b45f0d950..8ac6c2b54afaa708f28616c29c0110018ebcdf8e 100644 (file)
@@ -500,7 +500,6 @@ public final class SwingTerminal extends LogicalScreen
         // monospace.
         textHeight = fm.getMaxAscent() + maxDescent - leading;
 
-        // TODO: is this still necessary?
         if (gotTerminus == true) {
             textHeight++;
         }
@@ -634,6 +633,8 @@ public final class SwingTerminal extends LogicalScreen
     private void drawCursor(final Graphics gr) {
 
         if (cursorVisible
+            && (cursorY >= 0)
+            && (cursorX >= 0)
             && (cursorY <= height - 1)
             && (cursorX <= width - 1)
             && cursorBlinkVisible
@@ -658,6 +659,16 @@ public final class SwingTerminal extends LogicalScreen
         }
     }
 
+    /**
+     * Reset the blink timer.
+     */
+    private void resetBlinkTimer() {
+        // See if it is time to flip the blink time.
+        long nowTime = (new Date()).getTime();
+        lastBlinkTime = nowTime;
+        cursorBlinkVisible = true;
+    }
+
     /**
      * Paint redraws the whole screen.
      *
@@ -933,6 +944,8 @@ public final class SwingTerminal extends LogicalScreen
         }
 
         if (cursorVisible
+            && (cursorY >= 0)
+            && (cursorX >= 0)
             && (cursorY <= height - 1)
             && (cursorX <= width - 1)
         ) {
@@ -1069,9 +1082,9 @@ public final class SwingTerminal extends LogicalScreen
 
         // Pull the system property for triple buffering.
         if (System.getProperty("jexer.Swing.tripleBuffer") != null) {
-            if (System.getProperty("jexer.Swing.tripleBuffer").
-                equals("false")) {
-
+            if (System.getProperty("jexer.Swing.tripleBuffer").equals("true")) {
+                SwingComponent.tripleBuffer = true;
+            } else {
                 SwingComponent.tripleBuffer = false;
             }
         }
@@ -1142,7 +1155,8 @@ public final class SwingTerminal extends LogicalScreen
                     SwingTerminal.this.sessionInfo =
                         new SwingSessionInfo(SwingTerminal.this.swing,
                             SwingTerminal.this.textWidth,
-                            SwingTerminal.this.textHeight);
+                            SwingTerminal.this.textHeight,
+                            windowWidth, windowHeight);
 
                     SwingTerminal.this.setDimensions(sessionInfo.getWindowWidth(),
                         sessionInfo.getWindowHeight());
@@ -1171,7 +1185,7 @@ public final class SwingTerminal extends LogicalScreen
     }
 
     /**
-     * Public constructor creates a new JFrame to render to.
+     * Public constructor renders to an existing JComponent.
      *
      * @param component the Swing component to render to
      * @param windowWidth the number of text columns to start with
@@ -1539,9 +1553,12 @@ public final class SwingTerminal extends LogicalScreen
         // Save it and we are done.
         synchronized (eventQueue) {
             eventQueue.add(new TKeypressEvent(keypress));
+            resetBlinkTimer();
         }
-        synchronized (listener) {
-            listener.notifyAll();
+        if (listener != null) {
+            synchronized (listener) {
+                listener.notifyAll();
+            }
         }
     }
 
@@ -1575,9 +1592,12 @@ public final class SwingTerminal extends LogicalScreen
         // Drop a cmAbort and walk away
         synchronized (eventQueue) {
             eventQueue.add(new TCommandEvent(cmAbort));
+            resetBlinkTimer();
         }
-        synchronized (listener) {
-            listener.notifyAll();
+        if (listener != null) {
+            synchronized (listener) {
+                listener.notifyAll();
+            }
         }
     }
 
@@ -1663,9 +1683,12 @@ public final class SwingTerminal extends LogicalScreen
             TResizeEvent windowResize = new TResizeEvent(TResizeEvent.Type.SCREEN,
                 sessionInfo.getWindowWidth(), sessionInfo.getWindowHeight());
             eventQueue.add(windowResize);
+            resetBlinkTimer();
         }
-        synchronized (listener) {
-            listener.notifyAll();
+        if (listener != null) {
+            synchronized (listener) {
+                listener.notifyAll();
+            }
         }
     }
 
@@ -1699,9 +1722,12 @@ public final class SwingTerminal extends LogicalScreen
 
         synchronized (eventQueue) {
             eventQueue.add(mouseEvent);
+            resetBlinkTimer();
         }
-        synchronized (listener) {
-            listener.notifyAll();
+        if (listener != null) {
+            synchronized (listener) {
+                listener.notifyAll();
+            }
         }
     }
 
@@ -1725,9 +1751,12 @@ public final class SwingTerminal extends LogicalScreen
 
         synchronized (eventQueue) {
             eventQueue.add(mouseEvent);
+            resetBlinkTimer();
         }
-        synchronized (listener) {
-            listener.notifyAll();
+        if (listener != null) {
+            synchronized (listener) {
+                listener.notifyAll();
+            }
         }
     }
 
@@ -1788,9 +1817,12 @@ public final class SwingTerminal extends LogicalScreen
 
         synchronized (eventQueue) {
             eventQueue.add(mouseEvent);
+            resetBlinkTimer();
         }
-        synchronized (listener) {
-            listener.notifyAll();
+        if (listener != null) {
+            synchronized (listener) {
+                listener.notifyAll();
+            }
         }
     }
 
@@ -1833,9 +1865,12 @@ public final class SwingTerminal extends LogicalScreen
 
         synchronized (eventQueue) {
             eventQueue.add(mouseEvent);
+            resetBlinkTimer();
         }
-        synchronized (listener) {
-            listener.notifyAll();
+        if (listener != null) {
+            synchronized (listener) {
+                listener.notifyAll();
+            }
         }
     }
 
@@ -1877,9 +1912,12 @@ public final class SwingTerminal extends LogicalScreen
 
         synchronized (eventQueue) {
             eventQueue.add(mouseEvent);
+            resetBlinkTimer();
         }
-        synchronized (listener) {
-            listener.notifyAll();
+        if (listener != null) {
+            synchronized (listener) {
+                listener.notifyAll();
+            }
         }
     }