X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=examples%2FJexerTilingWindowManager2.java;h=2a1512d6ec7af63edb12d10c9fed309d093eef32;hb=686d4da2d2ecc203d5f8b524225a4327777825be;hp=accbf739317bf0212c1c7aa07c6fb2e934b84b11;hpb=90d87fca1ee987e6650b90beafc7831cbca0a457;p=nikiroo-utils.git diff --git a/examples/JexerTilingWindowManager2.java b/examples/JexerTilingWindowManager2.java index accbf73..2a1512d 100644 --- a/examples/JexerTilingWindowManager2.java +++ b/examples/JexerTilingWindowManager2.java @@ -1,11 +1,9 @@ import jexer.TAction; import jexer.TApplication; import jexer.TDesktop; -import jexer.TPanel; import jexer.TTerminalWidget; import jexer.TSplitPane; import jexer.TWidget; -import jexer.event.TKeypressEvent; import jexer.event.TMenuEvent; import jexer.menu.TMenu; @@ -29,6 +27,10 @@ public class JexerTilingWindowManager2 extends TApplication { * 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. @@ -54,7 +56,7 @@ public class JexerTilingWindowManager2 extends TApplication { * Public constructor chooses the ECMA-48 / Xterm backend. */ public JexerTilingWindowManager2() throws Exception { - super(BackendType.SWING); + super(BackendType.XTERM); // The stock tool menu has items for redrawing the screen, opening // images, and (when using the Swing backend) setting the font. @@ -66,17 +68,30 @@ public class JexerTilingWindowManager2 extends TApplication { // 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. - tileMenu.addItem(TMenu.MID_SHELL, "&Floating"); + // Stock commands: a new shell with resizable window, and exit + // program. tileMenu.addSeparator(); - tileMenu.addDefaultItem(TMenu.MID_WINDOW_PREVIOUS); - tileMenu.addDefaultItem(TMenu.MID_WINDOW_NEXT); - tileMenu.addDefaultItem(TMenu.MID_WINDOW_CLOSE); + tileMenu.addItem(TMenu.MID_SHELL, "&New Windowed Terminal"); tileMenu.addSeparator(); tileMenu.addDefaultItem(TMenu.MID_EXIT); + // TTerminalWidget can request the text-block mouse pointer be + // suppressed, but the default TDesktop will ignore it. Let's set a + // new TDesktop to pass that mouse pointer visibility option to + // TApplication. + setDesktop(new TDesktop(this) { + @Override + public boolean hasHiddenMouse() { + TWidget active = getActiveChild(); + if (active instanceof TTerminalWidget) { + return ((TTerminalWidget) active).hasHiddenMouse(); + } + return false; + } + }); + // Spin up the root terminal createRootTerminal(); } @@ -86,64 +101,43 @@ public class JexerTilingWindowManager2 extends TApplication { */ @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 = getDesktop().getActiveChild(); - TSplitPane split = active.splitVertical(false, - new TTerminalWidget(active, active.getX(), - active.getY(), active.getWidth(), active.getHeight(), - new TAction() { - public void DO() { - if (source.getParent() instanceof TSplitPane) { - ((TSplitPane) source.getParent()).removeSplit(source, true); - } else if (source == root) { - assert (root != null); - root.remove(); - root = null; - } - } - })); + split = active.splitVertical(false, createTerminal()); if (active == root) { root = split; } - System.err.println("\nAfter vertical split:"); - System.err.println(getDesktop().toPrettyString()); return true; - } - if (event.getId() == MENU_SPLIT_HORIZONTAL) { + + case MENU_SPLIT_HORIZONTAL: if (root == null) { assert (getDesktop().getActiveChild() == null); createRootTerminal(); return true; } - TWidget active = getDesktop().getActiveChild(); - TSplitPane split = active.splitHorizontal(false, - new TTerminalWidget(active, active.getX(), - active.getY(), active.getWidth(), active.getHeight(), - new TAction() { - public void DO() { - if (source.getParent() instanceof TSplitPane) { - ((TSplitPane) source.getParent()).removeSplit(source, true); - } else if (source == root) { - assert (root != null); - root.remove(); - root = null; - } - } - })); + split = active.splitHorizontal(false, createTerminal()); if (active == root) { root = split; } - System.err.println("\nAfter horizontal split:"); - System.err.println(getDesktop().toPrettyString()); return true; + + default: + return super.onMenu(event); } - return super.onMenu(event); } /** @@ -151,15 +145,27 @@ public class JexerTilingWindowManager2 extends TApplication { */ 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() { if (source.getParent() instanceof TSplitPane) { - ((TSplitPane) source.getParent()).removeSplit(source, true); - } else if (source == root) { - assert (root != null); - root.remove(); + ((TSplitPane) source.getParent()).removeSplit(source, + true); + } else { + source.getApplication().enableMenuItem( + MENU_RESPAWN_ROOT); + source.remove(); root = null; } }