#16 Refactor Swing backend, demo of multiple TApplications in one Swing frame
[fanfix.git] / src / jexer / backend / SwingSessionInfo.java
similarity index 74%
rename from src/jexer/session/SwingSessionInfo.java
rename to src/jexer/backend/SwingSessionInfo.java
index dcba27da5dc37a2778e4aa02ad5eb5483dab058d..7df751d8edc53a8e7bc9727d01490f7a58e44c3e 100644 (file)
  * @author Kevin Lamonte [kevin.lamonte@gmail.com]
  * @version 1
  */
-package jexer.session;
+package jexer.backend;
 
-import java.awt.Frame;
 import java.awt.Insets;
 
 /**
- * SwingSessionInfo provides a session implementation with a callback into an
- * Swing Frame to support queryWindowSize().  The username is blank, language
- * is "en_US", with a 132x40 text window.
+ * SwingSessionInfo provides a session implementation with a callback into
+ * Swing to support queryWindowSize().  The username is blank, language is
+ * "en_US", with a 80x25 text window.
  */
 public final class SwingSessionInfo implements SessionInfo {
 
     /**
-     * The Swing Frame.
+     * The Swing JFrame or JComponent.
      */
-    private Frame frame;
+    private SwingComponent swing;
 
     /**
      * The width of a text cell in pixels.
      */
-    private int textWidth;
+    private int textWidth = 10;
 
     /**
      * The height of a text cell in pixels.
      */
-    private int textHeight;
+    private int textHeight = 10;
 
     /**
      * User name.
@@ -127,40 +126,49 @@ public final class SwingSessionInfo implements SessionInfo {
         return windowHeight;
     }
 
+    /**
+     * Set the dimensions of a single text cell.
+     *
+     * @param textWidth the width of a cell in pixels
+     * @param textHeight the height of a cell in pixels
+     */
+    public void setTextCellDimensions(final int textWidth,
+        final int textHeight) {
+
+        this.textWidth  = textWidth;
+        this.textHeight = textHeight;
+    }
+
     /**
      * Public constructor.
      *
-     * @param frame the Swing Frame
+     * @param swing the Swing JFrame or JComponent
      * @param textWidth the width of a cell in pixels
      * @param textHeight the height of a cell in pixels
-     * @param windowWidth the number of text columns to start with
-     * @param windowHeight the number of text rows to start with
      */
-    public SwingSessionInfo(final Frame frame, final int textWidth,
-        final int textHeight, final int windowWidth, final int windowHeight) {
+    public SwingSessionInfo(final SwingComponent swing, final int textWidth,
+        final int textHeight) {
 
-        this.frame              = frame;
-        this.textWidth          = textWidth;
-        this.textHeight         = textHeight;
-        this.windowWidth        = windowWidth;
-        this.windowHeight       = windowHeight;
+        this.swing      = swing;
+        this.textWidth  = textWidth;
+        this.textHeight = textHeight;
     }
 
     /**
      * Re-query the text window size.
      */
     public void queryWindowSize() {
-        Insets insets = frame.getInsets();
-        int height = frame.getHeight() - insets.top - insets.bottom;
-        int width = frame.getWidth() - insets.left - insets.right;
+        Insets insets = swing.getInsets();
+        int width = swing.getWidth() - insets.left - insets.right;
+        int height = swing.getHeight() - insets.top - insets.bottom;
         windowWidth = width / textWidth;
         windowHeight = height / textHeight;
 
         /*
         System.err.printf("queryWindowSize(): frame %d %d window %d %d\n",
-            frame.getWidth(), frame.getHeight(),
+            swing.getWidth(), swing.getHeight(),
             windowWidth, windowHeight);
-         */
+        */
 
     }