git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix status line for non-tiple-buffered case
[fanfix.git]
/
src
/
jexer
/
backend
/
SwingTerminal.java
diff --git
a/src/jexer/backend/SwingTerminal.java
b/src/jexer/backend/SwingTerminal.java
index 6a3b203dbff2d5f4d8ad59ed992cf62b549ff75c..ce26efee97ada8436701c5c373b650a5d9dd3909 100644
(file)
--- 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.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.swing.JComponent;
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.
*/
/**
* The terminus font resource filename.
*/
- p
rivate
static final String FONTFILE = "terminus-ttf-4.39/TerminusTTF-Bold-4.39.ttf";
+ p
ublic
static final String FONTFILE = "terminus-ttf-4.39/TerminusTTF-Bold-4.39.ttf";
/**
* Cursor style to draw.
/**
* Cursor style to draw.
@@
-182,12
+182,12
@@
public class SwingTerminal extends LogicalScreen
/**
* Width of a character cell in pixels.
*/
/**
* Width of a character cell in pixels.
*/
- private int textWidth = 1;
+ private int textWidth = 1
6
;
/**
* Height of a character cell in pixels.
*/
/**
* Height of a character cell in pixels.
*/
- private int textHeight =
1
;
+ private int textHeight =
20
;
/**
* Width of a character cell in pixels, as reported by font.
/**
* Width of a character cell in pixels, as reported by font.
@@
-301,6
+301,13
@@
public class SwingTerminal extends LogicalScreen
// Constructors -----------------------------------------------------------
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
// ------------------------------------------------------------------------
+ /**
+ * Static constructor.
+ */
+ static {
+ setDOSColors();
+ }
+
/**
* Public constructor creates a new JFrame to render to.
*
/**
* Public constructor creates a new JFrame to render to.
*
@@
-316,7
+323,6
@@
public class SwingTerminal extends LogicalScreen
this.fontSize = fontSize;
this.fontSize = fontSize;
- setDOSColors();
reloadOptions();
try {
reloadOptions();
try {
@@
-397,7
+403,7
@@
public class SwingTerminal extends LogicalScreen
SwingTerminal.this.setDimensions(sessionInfo.
getWindowWidth(), sessionInfo.getWindowHeight());
SwingTerminal.this.setDimensions(sessionInfo.
getWindowWidth(), sessionInfo.getWindowHeight());
- SwingTerminal.this.resizeToScreen();
+ SwingTerminal.this.resizeToScreen(
true
);
SwingTerminal.this.swing.setVisible(true);
}
});
SwingTerminal.this.swing.setVisible(true);
}
});
@@
-411,7
+417,7
@@
public class SwingTerminal extends LogicalScreen
mouse1 = false;
mouse2 = false;
mouse3 = false;
mouse1 = false;
mouse2 = false;
mouse3 = false;
- eventQueue = new
Linked
List<TInputEvent>();
+ eventQueue = new
Array
List<TInputEvent>();
// Add listeners to Swing.
swing.addKeyListener(this);
// Add listeners to Swing.
swing.addKeyListener(this);
@@
-438,7
+444,6
@@
public class SwingTerminal extends LogicalScreen
this.fontSize = fontSize;
this.fontSize = fontSize;
- setDOSColors();
reloadOptions();
try {
reloadOptions();
try {
@@
-525,7
+530,7
@@
public class SwingTerminal extends LogicalScreen
mouse1 = false;
mouse2 = false;
mouse3 = false;
mouse1 = false;
mouse2 = false;
mouse3 = false;
- eventQueue = new
Linked
List<TInputEvent>();
+ eventQueue = new
Array
List<TInputEvent>();
// Add listeners to Swing.
swing.addKeyListener(this);
// Add listeners to Swing.
swing.addKeyListener(this);
@@
-568,6
+573,7
@@
public class SwingTerminal extends LogicalScreen
) {
do {
do {
) {
do {
do {
+ clearPhysical();
drawToSwing();
} while (swing.getBufferStrategy().contentsRestored());
drawToSwing();
} while (swing.getBufferStrategy().contentsRestored());
@@
-714,6
+720,15
@@
public class SwingTerminal extends LogicalScreen
return blinkMillis;
}
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.
*
/**
* Get the font size in points.
*
@@
-746,7
+761,7
@@
public class SwingTerminal extends LogicalScreen
swing.setFont(font);
glyphCacheBlink = new HashMap<Cell, BufferedImage>();
glyphCache = new HashMap<Cell, BufferedImage>();
swing.setFont(font);
glyphCacheBlink = new HashMap<Cell, BufferedImage>();
glyphCache = new HashMap<Cell, BufferedImage>();
- resizeToScreen();
+ resizeToScreen(
true
);
}
}
}
}
@@
-881,7
+896,7
@@
public class SwingTerminal extends LogicalScreen
* @param attr the text attributes
* @return the Swing Color
*/
* @param attr the text attributes
* @return the Swing Color
*/
- p
rivate
Color attrToForegroundColor(final CellAttributes attr) {
+ p
ublic static
Color attrToForegroundColor(final CellAttributes attr) {
int rgb = attr.getForeColorRGB();
if (rgb >= 0) {
int red = (rgb >> 16) & 0xFF;
int rgb = attr.getForeColorRGB();
if (rgb >= 0) {
int red = (rgb >> 16) & 0xFF;
@@
-938,7
+953,7
@@
public class SwingTerminal extends LogicalScreen
* @param attr the text attributes
* @return the Swing Color
*/
* @param attr the text attributes
* @return the Swing Color
*/
- p
rivate
Color attrToBackgroundColor(final CellAttributes attr) {
+ p
ublic static
Color attrToBackgroundColor(final CellAttributes attr) {
int rgb = attr.getBackColorRGB();
if (rgb >= 0) {
int red = (rgb >> 16) & 0xFF;
int rgb = attr.getBackColorRGB();
if (rgb >= 0) {
int red = (rgb >> 16) & 0xFF;
@@
-1096,10
+1111,23
@@
public class SwingTerminal extends LogicalScreen
}
/**
}
/**
- * Resize to font dimensions.
+ * 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() {
public void resizeToScreen() {
-
swing.setDimensions(textWidth * (width + 1), textHeight * (height + 1)
);
+
resizeToScreen(false
);
}
/**
}
/**
@@
-1152,7
+1180,7
@@
public class SwingTerminal extends LogicalScreen
/*
System.err.println("drawGlyph(): " + xPixel + " " + yPixel +
" " + cell);
/*
System.err.println("drawGlyph(): " + xPixel + " " + yPixel +
" " + cell);
- */
+
*/
BufferedImage image = null;
if (cell.isBlink() && !cursorBlinkVisible) {
BufferedImage image = null;
if (cell.isBlink() && !cursorBlinkVisible) {
@@
-1184,8
+1212,7
@@
public class SwingTerminal extends LogicalScreen
gr2 = (Graphics2D) gr;
}
gr2 = (Graphics2D) gr;
}
- Cell cellColor = new Cell();
- cellColor.setTo(cell);
+ Cell cellColor = new Cell(cell);
// Check for reverse
if (cell.isReverse()) {
// Check for reverse
if (cell.isReverse()) {
@@
-1202,9
+1229,8
@@
public class SwingTerminal extends LogicalScreen
|| (cell.isBlink() && cursorBlinkVisible)
) {
gr2.setColor(attrToForegroundColor(cellColor));
|| (cell.isBlink() && cursorBlinkVisible)
) {
gr2.setColor(attrToForegroundColor(cellColor));
- char [] chars = new char[1];
- chars[0] = cell.getChar();
- gr2.drawChars(chars, 0, 1, gr2x + textAdjustX,
+ char [] chars = Character.toChars(cell.getChar());
+ gr2.drawChars(chars, 0, chars.length, gr2x + textAdjustX,
gr2y + textHeight - maxDescent + textAdjustY);
if (cell.isUnderline()) {
gr2y + textHeight - maxDescent + textAdjustY);
if (cell.isUnderline()) {
@@
-1217,8
+1243,7
@@
public class SwingTerminal extends LogicalScreen
// We need a new key that will not be mutated by
// invertCell().
// 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 {
if (cell.isBlink() && !cursorBlinkVisible) {
glyphCacheBlink.put(key, image);
} else {
@@
-1251,18
+1276,31
@@
public class SwingTerminal extends LogicalScreen
int xPixel = cursorX * textWidth + left;
int yPixel = cursorY * textHeight + top;
Cell lCell = logical[cursorX][cursorY];
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.setColor(attrToForegroundColor(lCell));
switch (cursorStyle) {
default:
// Fall through...
case UNDERLINE:
- gr.fillRect(xPixel, yPixel + textHeight - 2,
text
Width, 2);
+ gr.fillRect(xPixel, yPixel + textHeight - 2,
cursor
Width, 2);
break;
case BLOCK:
break;
case BLOCK:
- gr.fillRect(xPixel, yPixel,
text
Width, textHeight);
+ gr.fillRect(xPixel, yPixel,
cursor
Width, textHeight);
break;
case OUTLINE:
break;
case OUTLINE:
- gr.drawRect(xPixel, yPixel,
text
Width - 1, textHeight - 1);
+ gr.drawRect(xPixel, yPixel,
cursor
Width - 1, textHeight - 1);
break;
}
}
break;
}
}
@@
-1310,7
+1348,7
@@
public class SwingTerminal extends LogicalScreen
if (bounds != null) {
// Only update what is in the bounds
xCellMin = textColumn(bounds.x);
if (bounds != null) {
// Only update what is in the bounds
xCellMin = textColumn(bounds.x);
- xCellMax = textColumn(bounds.x + bounds.width);
+ xCellMax = textColumn(bounds.x + bounds.width)
+ 1
;
if (xCellMax > width) {
xCellMax = width;
}
if (xCellMax > width) {
xCellMax = width;
}
@@
-1321,7
+1359,7
@@
public class SwingTerminal extends LogicalScreen
xCellMin = 0;
}
yCellMin = textRow(bounds.y);
xCellMin = 0;
}
yCellMin = textRow(bounds.y);
- yCellMax = textRow(bounds.y + bounds.height);
+ yCellMax = textRow(bounds.y + bounds.height)
+ 1
;
if (yCellMax > height) {
yCellMax = height;
}
if (yCellMax > height) {
yCellMax = height;
}
@@
-1343,7
+1381,7
@@
public class SwingTerminal extends LogicalScreen
/*
System.err.printf("bounds %s X %d %d Y %d %d\n",
bounds, xCellMin, xCellMax, yCellMin, yCellMax);
/*
System.err.printf("bounds %s X %d %d Y %d %d\n",
bounds, xCellMin, xCellMax, yCellMin, yCellMax);
- */
+
*/
for (int y = yCellMin; y < yCellMax; y++) {
for (int x = xCellMin; x < xCellMax; x++) {
for (int y = yCellMin; y < yCellMax; y++) {
for (int x = xCellMin; x < xCellMax; x++) {
@@
-1790,6
+1828,7
@@
public class SwingTerminal extends LogicalScreen
break;
default:
if (!alt && ctrl && !shift) {
break;
default:
if (!alt && ctrl && !shift) {
+ // Control character, replace ch with 'A', 'B', etc.
ch = KeyEvent.getKeyText(key.getKeyCode()).charAt(0);
}
// Not a special key, put it together
ch = KeyEvent.getKeyText(key.getKeyCode()).charAt(0);
}
// Not a special key, put it together
@@
-1840,9
+1879,9
@@
public class SwingTerminal extends LogicalScreen
* @param event window event received
*/
public void windowClosing(final WindowEvent event) {
* @param event window event received
*/
public void windowClosing(final WindowEvent event) {
- // Drop a cm
Abor
t and walk away
+ // Drop a cm
BackendDisconnec
t and walk away
synchronized (eventQueue) {
synchronized (eventQueue) {
- eventQueue.add(new TCommandEvent(cm
Abor
t));
+ eventQueue.add(new TCommandEvent(cm
BackendDisconnec
t));
resetBlinkTimer();
}
if (listener != null) {
resetBlinkTimer();
}
if (listener != null) {
@@
-1932,6
+1971,12
@@
public class SwingTerminal extends LogicalScreen
return;
}
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) {
// Drop a new TResizeEvent into the queue
sessionInfo.queryWindowSize();
synchronized (eventQueue) {