+import java.util.ArrayList;
import jexer.TAction;
import jexer.TApplication;
import jexer.TDesktop;
* Menu item: split the terminal horizontally.
*/
private static final int MENU_SPLIT_HORIZONTAL = 2001;
+ /**
+ * Menu item: recreate the root terminal.
+ */
+ private static final int MENU_RESPAWN_ROOT = 2002;
/**
* Handle to the root widget.
// New commands for this example: split vertical and horizontal.
tileMenu.addItem(MENU_SPLIT_VERTICAL, "&Vertical Split");
tileMenu.addItem(MENU_SPLIT_HORIZONTAL, "&Horizontal Split");
+ tileMenu.addItem(MENU_RESPAWN_ROOT, "&Respawn Root Terminal");
// Stock commands: a new shell with resizable window, previous, next,
// close, and exit program.
*/
@Override
protected boolean onMenu(TMenuEvent event) {
- if (event.getId() == MENU_SPLIT_VERTICAL) {
+ TWidget active = getDesktop().getActiveChild();
+ TSplitPane split = null;
+
+ switch (event.getId()) {
+ case MENU_RESPAWN_ROOT:
+ assert (root == null);
+ createRootTerminal();
+ return true;
+
+ case MENU_SPLIT_VERTICAL:
if (root == null) {
+ assert (getDesktop().getActiveChild() == null);
createRootTerminal();
return true;
}
- TWidget active = root.getActiveChild();
- TSplitPane split = active.splitVertical(false,
- new TTerminalWidget(getDesktop(), active.getX(),
- active.getY(), active.getWidth(), active.getHeight(),
- new TAction() {
- public void DO() {
- // TODO
- }
- }));
+ split = active.splitVertical(false, createTerminal());
if (active == root) {
root = split;
}
return true;
- }
- if (event.getId() == MENU_SPLIT_HORIZONTAL) {
+
+ case MENU_SPLIT_HORIZONTAL:
if (root == null) {
+ assert (getDesktop().getActiveChild() == null);
createRootTerminal();
return true;
}
- TWidget active = root.getActiveChild();
- TSplitPane split = active.splitHorizontal(false,
- new TTerminalWidget(getDesktop(), active.getX(),
- active.getY(), active.getWidth(), active.getHeight(),
- new TAction() {
- public void DO() {
- // TODO
- }
- }));
+ split = active.splitHorizontal(false, createTerminal());
+ if (active == root) {
+ root = split;
+ }
return true;
+
+ default:
+ return super.onMenu(event);
}
- return super.onMenu(event);
}
/**
*/
private void createRootTerminal() {
assert (root == null);
- root = new TTerminalWidget(getDesktop(), 0, 0,
+ disableMenuItem(MENU_RESPAWN_ROOT);
+ root = createTerminal();
+ }
+
+ /**
+ * Create a new terminal.
+ *
+ * @return the new terminal
+ */
+ private TWidget createTerminal() {
+ return new TTerminalWidget(getDesktop(), 0, 0,
getDesktop().getWidth(), getDesktop().getHeight(),
new TAction() {
public void DO() {
- TWidget target = (TWidget) data;
- if (target.getParent() instanceof TPanel) {
- ((TSplitPane) target.getParent().getParent()).removeSplit(target, true);
+ if (source.getParent() instanceof TSplitPane) {
+ ((TSplitPane) source.getParent()).removeSplit(source,
+ true);
} else {
- assert (root != null);
- root.remove();
+ source.getApplication().enableMenuItem(
+ MENU_RESPAWN_ROOT);
+ source.remove();
root = null;
}
}