2 import jexer
.TApplication
;
4 import jexer
.TTerminalWidget
;
6 import jexer
.event
.TKeypressEvent
;
7 import jexer
.event
.TMenuEvent
;
8 import jexer
.event
.TMouseEvent
;
9 import jexer
.event
.TResizeEvent
;
10 import jexer
.menu
.TMenu
;
13 * Implements a simple tiling window manager. A terminal widget is added to
14 * the desktop, which can be split horizontally or vertically. A close
15 * action is provided to each window to remove the split when its shell
18 * This example shows what can be done with minimal changes to stock Jexer
21 public class JexerTilingWindowManager2
extends TApplication
{
24 * Menu item: split the terminal vertically.
26 private static final int MENU_SPLIT_VERTICAL
= 2000;
29 * Menu item: split the terminal horizontally.
31 private static final int MENU_SPLIT_HORIZONTAL
= 2001;
34 * Handle to the root widget.
36 private TWidget root
= null;
41 public static void main(String
[] args
) throws Exception
{
42 // For this application, we must use ptypipe so that the terminal
43 // shells can be aware of their size.
44 System
.setProperty("jexer.TTerminal.ptypipe", "true");
46 // Let's also suppress the status line.
47 System
.setProperty("jexer.hideStatusBar", "true");
49 JexerTilingWindowManager2 jtwm
= new JexerTilingWindowManager2();
50 (new Thread(jtwm
)).start();
54 * Public constructor chooses the ECMA-48 / Xterm backend.
56 public JexerTilingWindowManager2() throws Exception
{
57 super(BackendType
.SWING
);
59 // The stock tool menu has items for redrawing the screen, opening
60 // images, and (when using the Swing backend) setting the font.
63 // We will have one menu containing a mix of new and stock commands
64 TMenu tileMenu
= addMenu("&Tile");
66 // New commands for this example: split vertical and horizontal.
67 tileMenu
.addItem(MENU_SPLIT_VERTICAL
, "&Vertical Split");
68 tileMenu
.addItem(MENU_SPLIT_HORIZONTAL
, "&Horizontal Split");
70 // Stock commands: a new shell with resizable window, previous, next,
71 // close, and exit program.
72 tileMenu
.addItem(TMenu
.MID_SHELL
, "&Floating");
73 tileMenu
.addSeparator();
74 tileMenu
.addDefaultItem(TMenu
.MID_WINDOW_PREVIOUS
);
75 tileMenu
.addDefaultItem(TMenu
.MID_WINDOW_NEXT
);
76 tileMenu
.addDefaultItem(TMenu
.MID_WINDOW_CLOSE
);
77 tileMenu
.addSeparator();
78 tileMenu
.addDefaultItem(TMenu
.MID_EXIT
);
80 // Spin up the root terminal
81 root
= new TTerminalWidget(getDesktop(), 0, 0,
82 getDesktop().getWidth(), getDesktop().getHeight(),
85 // TODO: if root's parent is TSplitPane, call
86 // TSplitPane.removeSplit(TWidget).
95 * Process menu events.
98 protected boolean onMenu(TMenuEvent event
) {
99 if (event
.getId() == MENU_SPLIT_VERTICAL
) {
103 if (event
.getId() == MENU_SPLIT_HORIZONTAL
) {
108 return super.onMenu(event
);
112 * Perform the vertical split.
114 private void splitVertical() {
119 * Perform the horizontal split.
121 private void splitHorizontal() {