#35 VT100 double-width support
[fanfix.git] / src / jexer / backend / SwingTerminal.java
index 6a3b203dbff2d5f4d8ad59ed992cf62b549ff75c..314e6f5a89e6854dc354e0cd70afac6531cbafc6 100644 (file)
@@ -51,8 +51,8 @@ import java.awt.event.WindowListener;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import javax.swing.JComponent;
@@ -98,7 +98,7 @@ public class SwingTerminal extends LogicalScreen
     /**
      * The terminus font resource filename.
      */
-    private static final String FONTFILE = "terminus-ttf-4.39/TerminusTTF-Bold-4.39.ttf";
+    public static final String FONTFILE = "terminus-ttf-4.39/TerminusTTF-Bold-4.39.ttf";
 
     /**
      * Cursor style to draw.
@@ -411,7 +411,7 @@ public class SwingTerminal extends LogicalScreen
         mouse1           = false;
         mouse2           = false;
         mouse3           = false;
-        eventQueue       = new LinkedList<TInputEvent>();
+        eventQueue       = new ArrayList<TInputEvent>();
 
         // Add listeners to Swing.
         swing.addKeyListener(this);
@@ -525,7 +525,7 @@ public class SwingTerminal extends LogicalScreen
         mouse1           = false;
         mouse2           = false;
         mouse3           = false;
-        eventQueue       = new LinkedList<TInputEvent>();
+        eventQueue       = new ArrayList<TInputEvent>();
 
         // Add listeners to Swing.
         swing.addKeyListener(this);
@@ -567,6 +567,7 @@ public class SwingTerminal extends LogicalScreen
             && (swing.getBufferStrategy() != null)
         ) {
             do {
+                clearPhysical();
                 do {
                     drawToSwing();
                 } while (swing.getBufferStrategy().contentsRestored());
@@ -881,7 +882,7 @@ public class SwingTerminal extends LogicalScreen
      * @param attr the text attributes
      * @return the Swing Color
      */
-    private Color attrToForegroundColor(final CellAttributes attr) {
+    public static Color attrToForegroundColor(final CellAttributes attr) {
         int rgb = attr.getForeColorRGB();
         if (rgb >= 0) {
             int red     = (rgb >> 16) & 0xFF;
@@ -938,7 +939,7 @@ public class SwingTerminal extends LogicalScreen
      * @param attr the text attributes
      * @return the Swing Color
      */
-    private Color attrToBackgroundColor(final CellAttributes attr) {
+    public static Color attrToBackgroundColor(final CellAttributes attr) {
         int rgb = attr.getBackColorRGB();
         if (rgb >= 0) {
             int red     = (rgb >> 16) & 0xFF;
@@ -1096,10 +1097,12 @@ public class SwingTerminal extends LogicalScreen
     }
 
     /**
-     * Resize to font dimensions.
+     * Resize the physical screen to match the logical screen dimensions.
      */
+    @Override
     public void resizeToScreen() {
-        swing.setDimensions(textWidth * (width + 1), textHeight * (height + 1));
+        swing.setDimensions(textWidth * width, textHeight * height);
+        clearPhysical();
     }
 
     /**
@@ -1840,9 +1843,9 @@ public class SwingTerminal extends LogicalScreen
      * @param event window event received
      */
     public void windowClosing(final WindowEvent event) {
-        // Drop a cmAbort and walk away
+        // Drop a cmBackendDisconnect and walk away
         synchronized (eventQueue) {
-            eventQueue.add(new TCommandEvent(cmAbort));
+            eventQueue.add(new TCommandEvent(cmBackendDisconnect));
             resetBlinkTimer();
         }
         if (listener != null) {
@@ -1932,6 +1935,12 @@ public class SwingTerminal extends LogicalScreen
             return;
         }
 
+        if (sessionInfo == null) {
+            // This is the initial component resize in construction, bail
+            // out.
+            return;
+        }
+
         // Drop a new TResizeEvent into the queue
         sessionInfo.queryWindowSize();
         synchronized (eventQueue) {