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;
/**
* 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.
// Constructors -----------------------------------------------------------
// ------------------------------------------------------------------------
+ /**
+ * Static constructor.
+ */
+ static {
+ setDOSColors();
+ }
+
/**
* Public constructor creates a new JFrame to render to.
*
this.fontSize = fontSize;
- setDOSColors();
reloadOptions();
try {
SwingTerminal.this.setDimensions(sessionInfo.
getWindowWidth(), sessionInfo.getWindowHeight());
- SwingTerminal.this.resizeToScreen();
+ SwingTerminal.this.resizeToScreen(true);
SwingTerminal.this.swing.setVisible(true);
}
});
mouse1 = false;
mouse2 = false;
mouse3 = false;
- eventQueue = new LinkedList<TInputEvent>();
+ eventQueue = new ArrayList<TInputEvent>();
// Add listeners to Swing.
swing.addKeyListener(this);
this.fontSize = fontSize;
- setDOSColors();
reloadOptions();
try {
mouse1 = false;
mouse2 = false;
mouse3 = false;
- eventQueue = new LinkedList<TInputEvent>();
+ eventQueue = new ArrayList<TInputEvent>();
// Add listeners to Swing.
swing.addKeyListener(this);
) {
do {
do {
+ clearPhysical();
drawToSwing();
} while (swing.getBufferStrategy().contentsRestored());
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.
*
swing.setFont(font);
glyphCacheBlink = new HashMap<Cell, BufferedImage>();
glyphCache = new HashMap<Cell, BufferedImage>();
- resizeToScreen();
+ resizeToScreen(true);
}
}
* @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;
* @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;
gotFontDimensions = true;
}
+ /**
+ * Resize the physical screen to match the logical screen dimensions.
+ *
+ * @param resizeComponent if true, resize the Swing component
+ */
+ private void resizeToScreen(final boolean resizeComponent) {
+ if (resizeComponent) {
+ swing.setDimensions(textWidth * width, textHeight * height);
+ }
+ clearPhysical();
+ }
+
/**
* Resize the physical screen to match the logical screen dimensions.
*/
@Override
public void resizeToScreen() {
- swing.setDimensions(textWidth * width, textHeight * height);
+ resizeToScreen(false);
}
/**
gr2 = (Graphics2D) gr;
}
- Cell cellColor = new Cell();
- cellColor.setTo(cell);
+ Cell cellColor = new Cell(cell);
// Check for reverse
if (cell.isReverse()) {
// 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 {
int xPixel = cursorX * textWidth + left;
int yPixel = cursorY * textHeight + top;
Cell lCell = logical[cursorX][cursorY];
+ int cursorWidth = textWidth;
+ switch (lCell.getWidth()) {
+ case SINGLE:
+ // NOP
+ break;
+ case LEFT:
+ cursorWidth *= 2;
+ break;
+ case RIGHT:
+ cursorWidth *= 2;
+ xPixel -= textWidth;
+ break;
+ }
gr.setColor(attrToForegroundColor(lCell));
switch (cursorStyle) {
default:
// Fall through...
case UNDERLINE:
- gr.fillRect(xPixel, yPixel + textHeight - 2, textWidth, 2);
+ gr.fillRect(xPixel, yPixel + textHeight - 2, cursorWidth, 2);
break;
case BLOCK:
- gr.fillRect(xPixel, yPixel, textWidth, textHeight);
+ gr.fillRect(xPixel, yPixel, cursorWidth, textHeight);
break;
case OUTLINE:
- gr.drawRect(xPixel, yPixel, textWidth - 1, textHeight - 1);
+ gr.drawRect(xPixel, yPixel, cursorWidth - 1, textHeight - 1);
break;
}
}
* @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) {
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) {