private boolean haveTimer = false;
/**
- * The last seen scrollback lines.
- */
- private List<DisplayLine> scrollback;
-
- /**
- * The last seen display lines.
+ * The last seen visible display.
*/
private List<DisplayLine> display;
int width = getDisplayWidth();
boolean syncEmulator = false;
- if ((System.currentTimeMillis() - lastUpdateTime >= 25)
+ if ((System.currentTimeMillis() - lastUpdateTime >= 20)
&& (dirty == true)
) {
// Too much time has passed, draw it all.
}
if ((syncEmulator == true)
- || (scrollback == null)
|| (display == null)
) {
// We want to minimize the amount of time we have the emulator
// Update the scroll bars
reflowData();
- if ((scrollback == null) || emulator.isReading()) {
- scrollback = copyBuffer(emulator.getScrollbackBuffer());
- display = copyBuffer(emulator.getDisplayBuffer());
+ if (!isDrawable()) {
+ // We lost the connection, onShellExit() called an action
+ // that ultimately removed this widget from the UI
+ // hierarchy, so no one cares if we update the display.
+ // Bail out.
+ return;
+ }
+
+ if ((display == null) || emulator.isReading()) {
+ display = emulator.getVisibleDisplay(getHeight(),
+ -getVerticalValue());
+ assert (display.size() == getHeight());
}
width = emulator.getWidth();
}
dirty = false;
}
- // Put together the visible rows
- int visibleHeight = getHeight();
- int visibleBottom = scrollback.size() + display.size()
- + getVerticalValue();
- assert (visibleBottom >= 0);
-
- List<DisplayLine> preceedingBlankLines = new ArrayList<DisplayLine>();
- int visibleTop = visibleBottom - visibleHeight;
- if (visibleTop < 0) {
- for (int i = visibleTop; i < 0; i++) {
- preceedingBlankLines.add(emulator.getBlankDisplayLine());
- }
- visibleTop = 0;
- }
- assert (visibleTop >= 0);
-
- List<DisplayLine> displayLines = new ArrayList<DisplayLine>();
- displayLines.addAll(scrollback);
- displayLines.addAll(display);
-
- List<DisplayLine> visibleLines = new ArrayList<DisplayLine>();
- visibleLines.addAll(preceedingBlankLines);
- visibleLines.addAll(displayLines.subList(visibleTop,
- visibleBottom));
-
- visibleHeight -= visibleLines.size();
- assert (visibleHeight >= 0);
-
// Now draw the emulator screen
int row = 0;
- for (DisplayLine line: visibleLines) {
+ for (DisplayLine line: display) {
int widthMax = width;
if (line.isDoubleWidth()) {
widthMax /= 2;
}
}
row++;
- if (row == getHeight()) {
- // Don't overwrite the box edge
- break;
- }
}
- CellAttributes background = new CellAttributes();
- // Fill in the blank lines on bottom
- for (int i = 0; i < visibleHeight; i++) {
- hLineXY(0, i + row, getWidth(), ' ', background);
- }
-
}
/**
|| keypress.equals(kbAltPgUp)
) {
bigVerticalDecrement();
+ dirty = true;
return;
}
if (keypress.equals(kbShiftPgDn)
|| keypress.equals(kbAltPgDn)
) {
bigVerticalIncrement();
+ dirty = true;
return;
}
if (emulator.getMouseProtocol() == ECMA48.MouseProtocol.OFF) {
if (mouse.isMouseWheelUp()) {
verticalDecrement();
+ dirty = true;
return;
}
if (mouse.isMouseWheelDown()) {
verticalIncrement();
+ dirty = true;
return;
}
}
public void onShellExit() {
TApplication app = getApplication();
if (app != null) {
- app.invokeLater(new Runnable() {
- public void run() {
- if (closeAction != null) {
- closeAction.DO();
- }
- if (getApplication() != null) {
- getApplication().postEvent(new TMenuEvent(
- TMenu.MID_REPAINT));
+ if (closeAction != null) {
+ // We have to put this action inside invokeLater() because it
+ // could be executed during draw() when syncing with ECMA48.
+ app.invokeLater(new Runnable() {
+ public void run() {
+ closeAction.DO(TTerminalWidget.this);
}
- }
- });
+ });
+ }
+ if (getApplication() != null) {
+ getApplication().postEvent(new TMenuEvent(
+ TMenu.MID_REPAINT));
+ }
}
}
return false;
}
- /**
- * Copy a display buffer.
- *
- * @param buffer the buffer to copy
- * @return a deep copy of the buffer's data
- */
- private List<DisplayLine> copyBuffer(final List<DisplayLine> buffer) {
- ArrayList<DisplayLine> result = new ArrayList<DisplayLine>(buffer.size());
- for (DisplayLine line: buffer) {
- result.add(new DisplayLine(line));
- }
- return result;
- }
-
/**
* Draw glyphs for a double-width or double-height VT100 cell to two
* screen cells.