remove(false);
if (keep == null) {
+ if (myParent instanceof TSplitPane) {
+ // TSplitPane has a left/right/top/bottom link to me
+ // somewhere, remove it.
+ ((TSplitPane) myParent).removeWidget(this);
+ }
+
// Nothing is left of either pane. Remove me and bail out.
return null;
}
- keep.setParent(myParent, false);
- keep.setDimensions(getX(), getY(), getWidth(), getHeight());
- keep.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(),
- getHeight()));
+ if (myParent instanceof TSplitPane) {
+ // TSplitPane has a left/right/top/bottom link to me
+ // somewhere, replace me with keep.
+ ((TSplitPane) myParent).replaceWidget(this, keep);
+ } else {
+ keep.setParent(myParent, false);
+ keep.setDimensions(getX(), getY(), getWidth(), getHeight());
+ keep.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(),
+ getHeight()));
+ }
+ // System.err.println("\nAfter removeSplit():\n" + myParent.toPrettyString());
+
return keep;
}
// Update the scroll bars
reflowData();
+ 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 ((scrollback == null) || emulator.isReading()) {
scrollback = copyBuffer(emulator.getScrollbackBuffer());
display = copyBuffer(emulator.getDisplayBuffer());
public void onShellExit() {
TApplication app = getApplication();
if (app != null) {
- app.invokeLater(new Runnable() {
- public void run() {
- if (closeAction != null) {
+ 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));
- }
- }
- });
+ });
+ }
+ if (getApplication() != null) {
+ getApplication().postEvent(new TMenuEvent(
+ TMenu.MID_REPAINT));
+ }
}
}
return window.getApplication().getTheme();
}
+ /**
+ * See if this widget can be drawn onto a screen.
+ *
+ * @return true if this widget is part of the hierarchy that can draw to
+ * a screen
+ */
+ public final boolean isDrawable() {
+ if ((window == null)
+ || (window.getScreen() == null)
+ || (parent == null)
+ ) {
+ return false;
+ }
+ if (parent == this) {
+ return true;
+ }
+ return (parent.isDrawable());
+ }
+
/**
* Draw my specific widget. When called, the screen rectangle I draw
* into is already setup (offset and clipping).
* Called by parent to render to TWindow. Note package private access.
*/
final void drawChildren() {
- if (window == null) {
+ if (!isDrawable()) {
return;
}
// Draw me
draw();
+ if (!isDrawable()) {
+ // An action taken by a draw method unhooked me from the UI.
+ // Bail out.
+ return;
+ }
+
assert (visible == true);
// Continue down the chain. Draw the active child last so that it
for (TWidget widget: children) {
if (widget.isVisible() && (widget != activeChild)) {
widget.drawChildren();
+ if (!isDrawable()) {
+ // An action taken by a draw method unhooked me from the UI.
+ // Bail out.
+ return;
+ }
}
}
if (activeChild != null) {