X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbackend%2FSwingTerminal.java;h=58b8f799cf7f1e1153f2ef60f2af486ba96d03da;hb=0c28ec38449a59cf34cf5b3c13ea02add1ee57c5;hp=4efff3c22e0b5538cf32c892f9970f5797ed99ab;hpb=f4dcc69022c18bb522e12259bbb670180da7d144;p=nikiroo-utils.git diff --git a/src/jexer/backend/SwingTerminal.java b/src/jexer/backend/SwingTerminal.java index 4efff3c..58b8f79 100644 --- a/src/jexer/backend/SwingTerminal.java +++ b/src/jexer/backend/SwingTerminal.java @@ -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. @@ -301,6 +301,13 @@ public class SwingTerminal extends LogicalScreen // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * Static constructor. + */ + static { + setDOSColors(); + } + /** * Public constructor creates a new JFrame to render to. * @@ -316,7 +323,6 @@ public class SwingTerminal extends LogicalScreen this.fontSize = fontSize; - setDOSColors(); reloadOptions(); try { @@ -411,7 +417,7 @@ public class SwingTerminal extends LogicalScreen mouse1 = false; mouse2 = false; mouse3 = false; - eventQueue = new LinkedList(); + eventQueue = new ArrayList(); // Add listeners to Swing. swing.addKeyListener(this); @@ -438,7 +444,6 @@ public class SwingTerminal extends LogicalScreen this.fontSize = fontSize; - setDOSColors(); reloadOptions(); try { @@ -525,7 +530,7 @@ public class SwingTerminal extends LogicalScreen mouse1 = false; mouse2 = false; mouse3 = false; - eventQueue = new LinkedList(); + eventQueue = new ArrayList(); // Add listeners to Swing. swing.addKeyListener(this); @@ -567,7 +572,6 @@ public class SwingTerminal extends LogicalScreen && (swing.getBufferStrategy() != null) ) { do { - clearPhysical(); do { drawToSwing(); } while (swing.getBufferStrategy().contentsRestored()); @@ -715,6 +719,15 @@ public class SwingTerminal extends LogicalScreen return blinkMillis; } + /** + * Get the current status of the blink flag. + * + * @return true if the cursor and blinking text should be visible + */ + public boolean getCursorBlinkVisible() { + return cursorBlinkVisible; + } + /** * Get the font size in points. * @@ -882,7 +895,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; @@ -939,7 +952,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; @@ -1187,8 +1200,7 @@ public class SwingTerminal extends LogicalScreen gr2 = (Graphics2D) gr; } - Cell cellColor = new Cell(); - cellColor.setTo(cell); + Cell cellColor = new Cell(cell); // Check for reverse if (cell.isReverse()) { @@ -1220,8 +1232,7 @@ public class SwingTerminal extends LogicalScreen // We need a new key that will not be mutated by // invertCell(). - Cell key = new Cell(); - key.setTo(cell); + Cell key = new Cell(cell); if (cell.isBlink() && !cursorBlinkVisible) { glyphCacheBlink.put(key, image); } else { @@ -1843,9 +1854,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) { @@ -1935,6 +1946,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) {