PMD code sweep, #6 don't add MyWindow twice to MyApplication
[fanfix.git] / src / jexer / backend / TTYSessionInfo.java
index e69fc7018664b4c25515040c55aedc46d2501c04..28b4bd65d793f3652e69865155bbc61e07fcf1fb 100644 (file)
@@ -31,7 +31,6 @@ package jexer.backend;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.io.IOException;
-import java.util.Date;
 import java.util.StringTokenizer;
 
 /**
@@ -41,6 +40,10 @@ import java.util.StringTokenizer;
  */
 public final class TTYSessionInfo implements SessionInfo {
 
+    // ------------------------------------------------------------------------
+    // Variables --------------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * User name.
      */
@@ -64,7 +67,25 @@ public final class TTYSessionInfo implements SessionInfo {
     /**
      * Time at which the window size was refreshed.
      */
-    private Date lastQueryWindowTime;
+    private long lastQueryWindowTime;
+
+    // ------------------------------------------------------------------------
+    // Constructors -----------------------------------------------------------
+    // ------------------------------------------------------------------------
+
+    /**
+     * Public constructor.
+     */
+    public TTYSessionInfo() {
+        // Populate lang and user from the environment
+        username = System.getProperty("user.name");
+        language = System.getProperty("user.language");
+        queryWindowSize();
+    }
+
+    // ------------------------------------------------------------------------
+    // SessionInfo ------------------------------------------------------------
+    // ------------------------------------------------------------------------
 
     /**
      * Username getter.
@@ -102,6 +123,60 @@ public final class TTYSessionInfo implements SessionInfo {
         this.language = language;
     }
 
+    /**
+     * Text window width getter.
+     *
+     * @return the window width
+     */
+    public int getWindowWidth() {
+        if (System.getProperty("os.name").startsWith("Windows")) {
+            // Always use 80x25 for Windows (same as DOS)
+            return 80;
+        }
+        return windowWidth;
+    }
+
+    /**
+     * Text window height getter.
+     *
+     * @return the window height
+     */
+    public int getWindowHeight() {
+        if (System.getProperty("os.name").startsWith("Windows")) {
+            // Always use 80x25 for Windows (same as DOS)
+            return 25;
+        }
+        return windowHeight;
+    }
+
+    /**
+     * Re-query the text window size.
+     */
+    public void queryWindowSize() {
+        if (lastQueryWindowTime == 0) {
+            lastQueryWindowTime = System.currentTimeMillis();
+        } else {
+            long nowTime = System.currentTimeMillis();
+            if (nowTime - lastQueryWindowTime < 1000) {
+                // Don't re-spawn stty if it hasn't been a full second since
+                // the last time.
+                return;
+            }
+        }
+        if (System.getProperty("os.name").startsWith("Linux")
+            || System.getProperty("os.name").startsWith("Mac OS X")
+            || System.getProperty("os.name").startsWith("SunOS")
+            || System.getProperty("os.name").startsWith("FreeBSD")
+        ) {
+            // Use stty to get the window size
+            sttyWindowSize();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // TTYSessionInfo ---------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * Call 'stty size' to obtain the tty window size.  windowWidth and
      * windowHeight are set automatically.
@@ -150,62 +225,4 @@ public final class TTYSessionInfo implements SessionInfo {
         }
     }
 
-    /**
-     * Text window width getter.
-     *
-     * @return the window width
-     */
-    public int getWindowWidth() {
-        if (System.getProperty("os.name").startsWith("Windows")) {
-            // Always use 80x25 for Windows (same as DOS)
-            return 80;
-        }
-        return windowWidth;
-    }
-
-    /**
-     * Text window height getter.
-     *
-     * @return the window height
-     */
-    public int getWindowHeight() {
-        if (System.getProperty("os.name").startsWith("Windows")) {
-            // Always use 80x25 for Windows (same as DOS)
-            return 25;
-        }
-        return windowHeight;
-    }
-
-    /**
-     * Re-query the text window size.
-     */
-    public void queryWindowSize() {
-        if (lastQueryWindowTime == null) {
-            lastQueryWindowTime = new Date();
-        } else {
-            Date now = new Date();
-            if (now.getTime() - lastQueryWindowTime.getTime() < 3000) {
-                // Don't re-spawn stty, it's been too soon.
-                return;
-            }
-        }
-        if (System.getProperty("os.name").startsWith("Linux")
-            || System.getProperty("os.name").startsWith("Mac OS X")
-            || System.getProperty("os.name").startsWith("SunOS")
-            || System.getProperty("os.name").startsWith("FreeBSD")
-        ) {
-            // Use stty to get the window size
-            sttyWindowSize();
-        }
-    }
-
-    /**
-     * Public constructor.
-     */
-    public TTYSessionInfo() {
-        // Populate lang and user from the environment
-        username = System.getProperty("user.name");
-        language = System.getProperty("user.language");
-        queryWindowSize();
-    }
 }