2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
32 import java
.io
.InputStream
;
33 import java
.io
.IOException
;
34 import java
.io
.OutputStream
;
35 import java
.io
.PrintWriter
;
36 import java
.io
.Reader
;
37 import java
.io
.UnsupportedEncodingException
;
38 import java
.text
.MessageFormat
;
39 import java
.util
.ArrayList
;
40 import java
.util
.Collections
;
41 import java
.util
.Date
;
42 import java
.util
.HashMap
;
43 import java
.util
.LinkedList
;
44 import java
.util
.List
;
46 import java
.util
.ResourceBundle
;
48 import jexer
.bits
.Cell
;
49 import jexer
.bits
.CellAttributes
;
50 import jexer
.bits
.Clipboard
;
51 import jexer
.bits
.ColorTheme
;
52 import jexer
.bits
.StringUtils
;
53 import jexer
.event
.TCommandEvent
;
54 import jexer
.event
.TInputEvent
;
55 import jexer
.event
.TKeypressEvent
;
56 import jexer
.event
.TMenuEvent
;
57 import jexer
.event
.TMouseEvent
;
58 import jexer
.event
.TResizeEvent
;
59 import jexer
.backend
.Backend
;
60 import jexer
.backend
.MultiBackend
;
61 import jexer
.backend
.Screen
;
62 import jexer
.backend
.SwingBackend
;
63 import jexer
.backend
.ECMA48Backend
;
64 import jexer
.backend
.TWindowBackend
;
65 import jexer
.menu
.TMenu
;
66 import jexer
.menu
.TMenuItem
;
67 import jexer
.menu
.TSubMenu
;
68 import static jexer
.TCommand
.*;
69 import static jexer
.TKeypress
.*;
72 * TApplication is the main driver class for a full Text User Interface
73 * application. It manages windows, provides a menu bar and status bar, and
74 * processes events received from the user.
76 public class TApplication
implements Runnable
{
81 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(TApplication
.class.getName());
83 // ------------------------------------------------------------------------
84 // Constants --------------------------------------------------------------
85 // ------------------------------------------------------------------------
88 * If true, emit thread stuff to System.err.
90 private static final boolean debugThreads
= false;
93 * If true, emit events being processed to System.err.
95 private static final boolean debugEvents
= false;
98 * If true, do "smart placement" on new windows that are not specified to
101 private static final boolean smartWindowPlacement
= true;
104 * Two backend types are available.
106 public static enum BackendType
{
113 * An ECMA48 / ANSI X3.64 / XTERM style terminal.
118 * Synonym for ECMA48.
123 // ------------------------------------------------------------------------
124 // Variables --------------------------------------------------------------
125 // ------------------------------------------------------------------------
128 * The primary event handler thread.
130 private volatile WidgetEventHandler primaryEventHandler
;
133 * The secondary event handler thread.
135 private volatile WidgetEventHandler secondaryEventHandler
;
138 * The screen handler thread.
140 private volatile ScreenHandler screenHandler
;
143 * The widget receiving events from the secondary event handler thread.
145 private volatile TWidget secondaryEventReceiver
;
148 * Access to the physical screen, keyboard, and mouse.
150 private Backend backend
;
153 * The clipboard for copy and paste.
155 private Clipboard clipboard
= new Clipboard();
158 * Actual mouse coordinate X.
163 * Actual mouse coordinate Y.
168 * Old drawn version of mouse coordinate X.
170 private int oldDrawnMouseX
;
173 * Old drawn version mouse coordinate Y.
175 private int oldDrawnMouseY
;
178 * Old drawn version mouse cell.
180 private Cell oldDrawnMouseCell
= new Cell();
183 * The last mouse up click time, used to determine if this is a mouse
186 private long lastMouseUpTime
;
189 * The amount of millis between mouse up events to assume a double-click.
191 private long doubleClickTime
= 250;
194 * Event queue that is filled by run().
196 private List
<TInputEvent
> fillEventQueue
;
199 * Event queue that will be drained by either primary or secondary
202 private List
<TInputEvent
> drainEventQueue
;
205 * Top-level menus in this application.
207 private List
<TMenu
> menus
;
210 * Stack of activated sub-menus in this application.
212 private List
<TMenu
> subMenus
;
215 * The currently active menu.
217 private TMenu activeMenu
= null;
220 * Active keyboard accelerators.
222 private Map
<TKeypress
, TMenuItem
> accelerators
;
227 private List
<TMenuItem
> menuItems
;
230 * Windows and widgets pull colors from this ColorTheme.
232 private ColorTheme theme
;
235 * The top-level windows (but not menus).
237 private List
<TWindow
> windows
;
240 * Timers that are being ticked.
242 private List
<TTimer
> timers
;
245 * When true, the application has been started.
247 private volatile boolean started
= false;
250 * When true, exit the application.
252 private volatile boolean quit
= false;
255 * When true, repaint the entire screen.
257 private volatile boolean repaint
= true;
260 * Y coordinate of the top edge of the desktop. For now this is a
261 * constant. Someday it would be nice to have a multi-line menu or
264 private int desktopTop
= 1;
267 * Y coordinate of the bottom edge of the desktop.
269 private int desktopBottom
;
272 * An optional TDesktop background window that is drawn underneath
275 private TDesktop desktop
;
278 * If true, focus follows mouse: windows automatically raised if the
279 * mouse passes over them.
281 private boolean focusFollowsMouse
= false;
284 * If true, display a text-based mouse cursor.
286 private boolean textMouse
= true;
289 * If true, hide the mouse after typing a keystroke.
291 private boolean hideMouseWhenTyping
= false;
294 * If true, the mouse should not be displayed because a keystroke was
297 private boolean typingHidMouse
= false;
300 * If true, hide the status bar.
302 private boolean hideStatusBar
= false;
305 * If true, hide the menu bar.
307 private boolean hideMenuBar
= false;
310 * The list of commands to run before the next I/O check.
312 private List
<Runnable
> invokeLaters
= new LinkedList
<Runnable
>();
315 * The last time the screen was resized.
317 private long screenResizeTime
= 0;
320 * If true, screen selection is a rectangle.
322 private boolean screenSelectionRectangle
= false;
325 * If true, the mouse is dragging a screen selection.
327 private boolean inScreenSelection
= false;
330 * Screen selection starting X.
332 private int screenSelectionX0
;
335 * Screen selection starting Y.
337 private int screenSelectionY0
;
340 * Screen selection ending X.
342 private int screenSelectionX1
;
345 * Screen selection ending Y.
347 private int screenSelectionY1
;
350 * WidgetEventHandler is the main event consumer loop. There are at most
351 * two such threads in existence: the primary for normal case and a
352 * secondary that is used for TMessageBox, TInputBox, and similar.
354 private class WidgetEventHandler
implements Runnable
{
356 * The main application.
358 private TApplication application
;
361 * Whether or not this WidgetEventHandler is the primary or secondary
364 private boolean primary
= true;
367 * Public constructor.
369 * @param application the main application
370 * @param primary if true, this is the primary event handler thread
372 public WidgetEventHandler(final TApplication application
,
373 final boolean primary
) {
375 this.application
= application
;
376 this.primary
= primary
;
383 // Wrap everything in a try, so that if we go belly up we can let
384 // the user have their terminal back.
387 } catch (Throwable t
) {
388 this.application
.restoreConsole();
390 this.application
.exit();
397 private void runImpl() {
398 boolean first
= true;
401 while (!application
.quit
) {
403 // Wait until application notifies me
404 while (!application
.quit
) {
406 synchronized (application
.drainEventQueue
) {
407 if (application
.drainEventQueue
.size() > 0) {
416 timeout
= application
.getSleepTime(1000);
420 // A timer needs to fire, break out.
425 System
.err
.printf("%d %s %s %s sleep %d millis\n",
426 System
.currentTimeMillis(), this,
427 primary ?
"primary" : "secondary",
428 Thread
.currentThread(), timeout
);
431 synchronized (this) {
436 System
.err
.printf("%d %s %s %s AWAKE\n",
437 System
.currentTimeMillis(), this,
438 primary ?
"primary" : "secondary",
439 Thread
.currentThread());
443 && (application
.secondaryEventReceiver
== null)
445 // Secondary thread, emergency exit. If we got
446 // here then something went wrong with the
447 // handoff between yield() and closeWindow().
448 synchronized (application
.primaryEventHandler
) {
449 application
.primaryEventHandler
.notify();
451 application
.secondaryEventHandler
= null;
452 throw new RuntimeException("secondary exited " +
456 } catch (InterruptedException e
) {
459 } // while (!application.quit)
461 // Pull all events off the queue
463 TInputEvent event
= null;
464 synchronized (application
.drainEventQueue
) {
465 if (application
.drainEventQueue
.size() == 0) {
468 event
= application
.drainEventQueue
.remove(0);
471 // We will have an event to process, so repaint the
472 // screen at the end.
473 application
.repaint
= true;
476 primaryHandleEvent(event
);
478 secondaryHandleEvent(event
);
481 && (application
.secondaryEventReceiver
== null)
483 // Secondary thread, time to exit.
485 // Eliminate my reference so that wakeEventHandler()
486 // resumes working on the primary.
487 application
.secondaryEventHandler
= null;
489 // We are ready to exit, wake up the primary thread.
490 // Remember that it is currently sleeping inside its
491 // primaryHandleEvent().
492 synchronized (application
.primaryEventHandler
) {
493 application
.primaryEventHandler
.notify();
502 // Fire timers, update screen.
504 application
.finishEventProcessing();
507 } // while (true) (main runnable loop)
512 * ScreenHandler pushes screen updates to the physical device.
514 private class ScreenHandler
implements Runnable
{
516 * The main application.
518 private TApplication application
;
523 private boolean dirty
= false;
526 * Public constructor.
528 * @param application the main application
530 public ScreenHandler(final TApplication application
) {
531 this.application
= application
;
535 * The screen update loop.
538 // Wrap everything in a try, so that if we go belly up we can let
539 // the user have their terminal back.
542 } catch (Throwable t
) {
543 this.application
.restoreConsole();
545 this.application
.exit();
552 private void runImpl() {
555 while (!application
.quit
) {
557 // Wait until application notifies me
558 while (!application
.quit
) {
560 synchronized (this) {
566 // Always check within 50 milliseconds.
569 } catch (InterruptedException e
) {
572 } // while (!application.quit)
574 // Flush the screen contents
576 System
.err
.printf("%d %s backend.flushScreen()\n",
577 System
.currentTimeMillis(), Thread
.currentThread());
579 synchronized (getScreen()) {
580 backend
.flushScreen();
582 } // while (true) (main runnable loop)
584 // Shutdown the user I/O thread(s)
589 * Set the dirty flag.
591 public void setDirty() {
592 synchronized (this) {
599 // ------------------------------------------------------------------------
600 // Constructors -----------------------------------------------------------
601 // ------------------------------------------------------------------------
604 * Public constructor.
606 * @param backendType BackendType.XTERM, BackendType.ECMA48 or
608 * @param windowWidth the number of text columns to start with
609 * @param windowHeight the number of text rows to start with
610 * @param fontSize the size in points
611 * @throws UnsupportedEncodingException if an exception is thrown when
612 * creating the InputStreamReader
614 public TApplication(final BackendType backendType
, final int windowWidth
,
615 final int windowHeight
, final int fontSize
)
616 throws UnsupportedEncodingException
{
618 switch (backendType
) {
620 backend
= new SwingBackend(this, windowWidth
, windowHeight
,
626 backend
= new ECMA48Backend(this, null, null, windowWidth
,
627 windowHeight
, fontSize
);
630 throw new IllegalArgumentException("Invalid backend type: "
637 * Public constructor.
639 * @param backendType BackendType.XTERM, BackendType.ECMA48 or
641 * @throws UnsupportedEncodingException if an exception is thrown when
642 * creating the InputStreamReader
644 public TApplication(final BackendType backendType
)
645 throws UnsupportedEncodingException
{
647 switch (backendType
) {
649 // The default SwingBackend is 80x25, 20 pt font. If you want to
650 // change that, you can pass the extra arguments to the
651 // SwingBackend constructor here. For example, if you wanted
652 // 90x30, 16 pt font:
654 // backend = new SwingBackend(this, 90, 30, 16);
655 backend
= new SwingBackend(this);
660 backend
= new ECMA48Backend(this, null, null);
663 throw new IllegalArgumentException("Invalid backend type: "
670 * Public constructor. The backend type will be BackendType.ECMA48.
672 * @param input an InputStream connected to the remote user, or null for
673 * System.in. If System.in is used, then on non-Windows systems it will
674 * be put in raw mode; shutdown() will (blindly!) put System.in in cooked
675 * mode. input is always converted to a Reader with UTF-8 encoding.
676 * @param output an OutputStream connected to the remote user, or null
677 * for System.out. output is always converted to a Writer with UTF-8
679 * @throws UnsupportedEncodingException if an exception is thrown when
680 * creating the InputStreamReader
682 public TApplication(final InputStream input
,
683 final OutputStream output
) throws UnsupportedEncodingException
{
685 backend
= new ECMA48Backend(this, input
, output
);
690 * Public constructor. The backend type will be BackendType.ECMA48.
692 * @param input the InputStream underlying 'reader'. Its available()
693 * method is used to determine if reader.read() will block or not.
694 * @param reader a Reader connected to the remote user.
695 * @param writer a PrintWriter connected to the remote user.
696 * @param setRawMode if true, set System.in into raw mode with stty.
697 * This should in general not be used. It is here solely for Demo3,
698 * which uses System.in.
699 * @throws IllegalArgumentException if input, reader, or writer are null.
701 public TApplication(final InputStream input
, final Reader reader
,
702 final PrintWriter writer
, final boolean setRawMode
) {
704 backend
= new ECMA48Backend(this, input
, reader
, writer
, setRawMode
);
709 * Public constructor. The backend type will be BackendType.ECMA48.
711 * @param input the InputStream underlying 'reader'. Its available()
712 * method is used to determine if reader.read() will block or not.
713 * @param reader a Reader connected to the remote user.
714 * @param writer a PrintWriter connected to the remote user.
715 * @throws IllegalArgumentException if input, reader, or writer are null.
717 public TApplication(final InputStream input
, final Reader reader
,
718 final PrintWriter writer
) {
720 this(input
, reader
, writer
, false);
724 * Public constructor. This hook enables use with new non-Jexer
727 * @param backend a Backend that is already ready to go.
729 public TApplication(final Backend backend
) {
730 this.backend
= backend
;
731 backend
.setListener(this);
736 * Finish construction once the backend is set.
738 private void TApplicationImpl() {
739 // Text block mouse option
740 if (System
.getProperty("jexer.textMouse", "true").equals("false")) {
744 // Hide mouse when typing option
745 if (System
.getProperty("jexer.hideMouseWhenTyping",
746 "false").equals("true")) {
748 hideMouseWhenTyping
= true;
751 // Hide status bar option
752 if (System
.getProperty("jexer.hideStatusBar",
753 "false").equals("true")) {
754 hideStatusBar
= true;
757 // Hide menu bar option
758 if (System
.getProperty("jexer.hideMenuBar", "false").equals("true")) {
762 theme
= new ColorTheme();
763 desktopTop
= (hideMenuBar ?
0 : 1);
764 desktopBottom
= getScreen().getHeight() - 1 + (hideStatusBar ?
1 : 0);
765 fillEventQueue
= new LinkedList
<TInputEvent
>();
766 drainEventQueue
= new LinkedList
<TInputEvent
>();
767 windows
= new LinkedList
<TWindow
>();
768 menus
= new ArrayList
<TMenu
>();
769 subMenus
= new ArrayList
<TMenu
>();
770 timers
= new LinkedList
<TTimer
>();
771 accelerators
= new HashMap
<TKeypress
, TMenuItem
>();
772 menuItems
= new LinkedList
<TMenuItem
>();
773 desktop
= new TDesktop(this);
775 // Special case: the Swing backend needs to have a timer to drive its
777 if ((backend
instanceof SwingBackend
)
778 || (backend
instanceof MultiBackend
)
780 // Default to 500 millis, unless a SwingBackend has its own
783 if (backend
instanceof SwingBackend
) {
784 millis
= ((SwingBackend
) backend
).getBlinkMillis();
787 addTimer(millis
, true,
790 TApplication
.this.doRepaint();
799 // ------------------------------------------------------------------------
800 // Runnable ---------------------------------------------------------------
801 // ------------------------------------------------------------------------
804 * Run this application until it exits.
807 // System.err.println("*** TApplication.run() begins ***");
809 // Start the screen updater thread
810 screenHandler
= new ScreenHandler(this);
811 (new Thread(screenHandler
)).start();
813 // Start the main consumer thread
814 primaryEventHandler
= new WidgetEventHandler(this, true);
815 (new Thread(primaryEventHandler
)).start();
820 synchronized (this) {
821 boolean doWait
= false;
823 if (!backend
.hasEvents()) {
824 synchronized (fillEventQueue
) {
825 if (fillEventQueue
.size() == 0) {
832 // No I/O to dispatch, so wait until the backend
836 System
.err
.println(System
.currentTimeMillis() +
837 " " + Thread
.currentThread() + " MAIN sleep");
843 System
.err
.println(System
.currentTimeMillis() +
844 " " + Thread
.currentThread() + " MAIN AWAKE");
846 } catch (InterruptedException e
) {
847 // I'm awake and don't care why, let's see what's
848 // going on out there.
852 } // synchronized (this)
854 synchronized (fillEventQueue
) {
855 // Pull any pending I/O events
856 backend
.getEvents(fillEventQueue
);
858 // Dispatch each event to the appropriate handler, one at a
861 TInputEvent event
= null;
862 if (fillEventQueue
.size() == 0) {
865 event
= fillEventQueue
.remove(0);
866 metaHandleEvent(event
);
870 // Wake a consumer thread if we have any pending events.
871 if (drainEventQueue
.size() > 0) {
877 // Shutdown the event consumer threads
878 if (secondaryEventHandler
!= null) {
879 synchronized (secondaryEventHandler
) {
880 secondaryEventHandler
.notify();
883 if (primaryEventHandler
!= null) {
884 synchronized (primaryEventHandler
) {
885 primaryEventHandler
.notify();
889 // Close all the windows. This gives them an opportunity to release
893 // Close the desktop.
894 if (desktop
!= null) {
898 // Give the overarching application an opportunity to release
902 // System.err.println("*** TApplication.run() exits ***");
905 // ------------------------------------------------------------------------
906 // Event handlers ---------------------------------------------------------
907 // ------------------------------------------------------------------------
910 * Method that TApplication subclasses can override to handle menu or
911 * posted command events.
913 * @param command command event
914 * @return if true, this event was consumed
916 protected boolean onCommand(final TCommandEvent command
) {
917 // Default: handle cmExit
918 if (command
.equals(cmExit
)) {
919 if (messageBox(i18n
.getString("exitDialogTitle"),
920 i18n
.getString("exitDialogText"),
921 TMessageBox
.Type
.YESNO
).isYes()) {
928 if (command
.equals(cmShell
)) {
929 openTerminal(0, 0, TWindow
.RESIZABLE
);
933 if (command
.equals(cmTile
)) {
937 if (command
.equals(cmCascade
)) {
941 if (command
.equals(cmCloseAll
)) {
946 if (command
.equals(cmMenu
) && (hideMenuBar
== false)) {
947 if (!modalWindowActive() && (activeMenu
== null)) {
948 if (menus
.size() > 0) {
949 menus
.get(0).setActive(true);
950 activeMenu
= menus
.get(0);
960 * Method that TApplication subclasses can override to handle menu
963 * @param menu menu event
964 * @return if true, this event was consumed
966 protected boolean onMenu(final TMenuEvent menu
) {
968 // Default: handle MID_EXIT
969 if (menu
.getId() == TMenu
.MID_EXIT
) {
970 if (messageBox(i18n
.getString("exitDialogTitle"),
971 i18n
.getString("exitDialogText"),
972 TMessageBox
.Type
.YESNO
).isYes()) {
979 if (menu
.getId() == TMenu
.MID_SHELL
) {
980 openTerminal(0, 0, TWindow
.RESIZABLE
);
984 if (menu
.getId() == TMenu
.MID_TILE
) {
988 if (menu
.getId() == TMenu
.MID_CASCADE
) {
992 if (menu
.getId() == TMenu
.MID_CLOSE_ALL
) {
996 if (menu
.getId() == TMenu
.MID_ABOUT
) {
1000 if (menu
.getId() == TMenu
.MID_REPAINT
) {
1001 getScreen().clearPhysical();
1005 if (menu
.getId() == TMenu
.MID_VIEW_IMAGE
) {
1009 if (menu
.getId() == TMenu
.MID_SCREEN_OPTIONS
) {
1010 new TFontChooserWindow(this);
1014 if (menu
.getId() == TMenu
.MID_CUT
) {
1015 postMenuEvent(new TCommandEvent(cmCut
));
1018 if (menu
.getId() == TMenu
.MID_COPY
) {
1019 postMenuEvent(new TCommandEvent(cmCopy
));
1022 if (menu
.getId() == TMenu
.MID_PASTE
) {
1023 postMenuEvent(new TCommandEvent(cmPaste
));
1026 if (menu
.getId() == TMenu
.MID_CLEAR
) {
1027 postMenuEvent(new TCommandEvent(cmClear
));
1035 * Method that TApplication subclasses can override to handle keystrokes.
1037 * @param keypress keystroke event
1038 * @return if true, this event was consumed
1040 protected boolean onKeypress(final TKeypressEvent keypress
) {
1041 // Default: only menu shortcuts
1043 // Process Alt-F, Alt-E, etc. menu shortcut keys
1044 if (!keypress
.getKey().isFnKey()
1045 && keypress
.getKey().isAlt()
1046 && !keypress
.getKey().isCtrl()
1047 && (activeMenu
== null)
1048 && !modalWindowActive()
1049 && (hideMenuBar
== false)
1052 assert (subMenus
.size() == 0);
1054 for (TMenu menu
: menus
) {
1055 if (Character
.toLowerCase(menu
.getMnemonic().getShortcut())
1056 == Character
.toLowerCase(keypress
.getKey().getChar())
1059 menu
.setActive(true);
1069 * Process background events, and update the screen.
1071 private void finishEventProcessing() {
1073 System
.err
.printf(System
.currentTimeMillis() + " " +
1074 Thread
.currentThread() + " finishEventProcessing()\n");
1077 // See if we need to enable/disable the edit menu.
1078 EditMenuUser widget
= null;
1079 if (activeMenu
== null) {
1080 TWindow activeWindow
= getActiveWindow();
1081 if (activeWindow
!= null) {
1082 if (activeWindow
.getActiveChild() instanceof EditMenuUser
) {
1083 widget
= (EditMenuUser
) activeWindow
.getActiveChild();
1085 } else if (desktop
!= null) {
1086 if (desktop
.getActiveChild() instanceof EditMenuUser
) {
1087 widget
= (EditMenuUser
) desktop
.getActiveChild();
1090 if (widget
== null) {
1091 disableMenuItem(TMenu
.MID_CUT
);
1092 disableMenuItem(TMenu
.MID_COPY
);
1093 disableMenuItem(TMenu
.MID_PASTE
);
1094 disableMenuItem(TMenu
.MID_CLEAR
);
1096 if (widget
.isEditMenuCut()) {
1097 enableMenuItem(TMenu
.MID_CUT
);
1099 disableMenuItem(TMenu
.MID_CUT
);
1101 if (widget
.isEditMenuCopy()) {
1102 enableMenuItem(TMenu
.MID_COPY
);
1104 disableMenuItem(TMenu
.MID_COPY
);
1106 if (widget
.isEditMenuPaste()) {
1107 enableMenuItem(TMenu
.MID_PASTE
);
1109 disableMenuItem(TMenu
.MID_PASTE
);
1111 if (widget
.isEditMenuClear()) {
1112 enableMenuItem(TMenu
.MID_CLEAR
);
1114 disableMenuItem(TMenu
.MID_CLEAR
);
1119 // Process timers and call doIdle()'s
1122 // Update the screen
1123 synchronized (getScreen()) {
1127 // Wake up the screen repainter
1128 wakeScreenHandler();
1131 System
.err
.printf(System
.currentTimeMillis() + " " +
1132 Thread
.currentThread() + " finishEventProcessing() END\n");
1137 * Peek at certain application-level events, add to eventQueue, and wake
1138 * up the consuming Thread.
1140 * @param event the input event to consume
1142 private void metaHandleEvent(final TInputEvent event
) {
1145 System
.err
.printf(String
.format("metaHandleEvents event: %s\n",
1146 event
)); System
.err
.flush();
1150 // Do no more processing if the application is already trying
1155 // Special application-wide events -------------------------------
1158 if (event
instanceof TCommandEvent
) {
1159 TCommandEvent command
= (TCommandEvent
) event
;
1160 if (command
.equals(cmAbort
)) {
1166 synchronized (drainEventQueue
) {
1168 if (event
instanceof TResizeEvent
) {
1169 TResizeEvent resize
= (TResizeEvent
) event
;
1170 synchronized (getScreen()) {
1171 if ((System
.currentTimeMillis() - screenResizeTime
>= 15)
1172 || (resize
.getWidth() < getScreen().getWidth())
1173 || (resize
.getHeight() < getScreen().getHeight())
1175 getScreen().setDimensions(resize
.getWidth(),
1176 resize
.getHeight());
1177 screenResizeTime
= System
.currentTimeMillis();
1179 desktopBottom
= getScreen().getHeight() - 1;
1180 if (hideStatusBar
) {
1186 if (desktop
!= null) {
1187 desktop
.setDimensions(0, desktopTop
, resize
.getWidth(),
1188 (desktopBottom
- desktopTop
));
1189 desktop
.onResize(resize
);
1192 // Change menu edges if needed.
1195 // We are dirty, redraw the screen.
1199 System.err.println("New screen: " + resize.getWidth() +
1200 " x " + resize.getHeight());
1205 // Put into the main queue
1206 drainEventQueue
.add(event
);
1211 * Dispatch one event to the appropriate widget or application-level
1212 * event handler. This is the primary event handler, it has the normal
1213 * application-wide event handling.
1215 * @param event the input event to consume
1216 * @see #secondaryHandleEvent(TInputEvent event)
1218 private void primaryHandleEvent(final TInputEvent event
) {
1221 System
.err
.printf("%s primaryHandleEvent: %s\n",
1222 Thread
.currentThread(), event
);
1224 TMouseEvent doubleClick
= null;
1226 // Special application-wide events -----------------------------------
1228 if (event
instanceof TKeypressEvent
) {
1229 if (hideMouseWhenTyping
) {
1230 typingHidMouse
= true;
1234 // Peek at the mouse position
1235 if (event
instanceof TMouseEvent
) {
1236 typingHidMouse
= false;
1238 TMouseEvent mouse
= (TMouseEvent
) event
;
1239 if (mouse
.isMouse1() && (mouse
.isShift() || mouse
.isCtrl())) {
1240 // Screen selection.
1241 if (inScreenSelection
) {
1242 screenSelectionX1
= mouse
.getX();
1243 screenSelectionY1
= mouse
.getY();
1245 inScreenSelection
= true;
1246 screenSelectionX0
= mouse
.getX();
1247 screenSelectionY0
= mouse
.getY();
1248 screenSelectionX1
= mouse
.getX();
1249 screenSelectionY1
= mouse
.getY();
1250 screenSelectionRectangle
= mouse
.isCtrl();
1253 if (inScreenSelection
) {
1254 getScreen().copySelection(clipboard
, screenSelectionX0
,
1255 screenSelectionY0
, screenSelectionX1
, screenSelectionY1
,
1256 screenSelectionRectangle
);
1258 inScreenSelection
= false;
1261 if ((mouseX
!= mouse
.getX()) || (mouseY
!= mouse
.getY())) {
1262 mouseX
= mouse
.getX();
1263 mouseY
= mouse
.getY();
1265 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
1266 && (!mouse
.isMouseWheelUp())
1267 && (!mouse
.isMouseWheelDown())
1269 if ((mouse
.getTime().getTime() - lastMouseUpTime
) <
1272 // This is a double-click.
1273 doubleClick
= new TMouseEvent(TMouseEvent
.Type
.
1275 mouse
.getX(), mouse
.getY(),
1276 mouse
.getAbsoluteX(), mouse
.getAbsoluteY(),
1277 mouse
.isMouse1(), mouse
.isMouse2(),
1279 mouse
.isMouseWheelUp(), mouse
.isMouseWheelDown(),
1280 mouse
.isAlt(), mouse
.isCtrl(), mouse
.isShift());
1283 // The first click of a potential double-click.
1284 lastMouseUpTime
= mouse
.getTime().getTime();
1289 // See if we need to switch focus to another window or the menu
1290 checkSwitchFocus((TMouseEvent
) event
);
1293 // Handle menu events
1294 if ((activeMenu
!= null) && !(event
instanceof TCommandEvent
)) {
1295 TMenu menu
= activeMenu
;
1297 if (event
instanceof TMouseEvent
) {
1298 TMouseEvent mouse
= (TMouseEvent
) event
;
1300 while (subMenus
.size() > 0) {
1301 TMenu subMenu
= subMenus
.get(subMenus
.size() - 1);
1302 if (subMenu
.mouseWouldHit(mouse
)) {
1305 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
)
1306 && (!mouse
.isMouse1())
1307 && (!mouse
.isMouse2())
1308 && (!mouse
.isMouse3())
1309 && (!mouse
.isMouseWheelUp())
1310 && (!mouse
.isMouseWheelDown())
1314 // We navigated away from a sub-menu, so close it
1318 // Convert the mouse relative x/y to menu coordinates
1319 assert (mouse
.getX() == mouse
.getAbsoluteX());
1320 assert (mouse
.getY() == mouse
.getAbsoluteY());
1321 if (subMenus
.size() > 0) {
1322 menu
= subMenus
.get(subMenus
.size() - 1);
1324 mouse
.setX(mouse
.getX() - menu
.getX());
1325 mouse
.setY(mouse
.getY() - menu
.getY());
1327 menu
.handleEvent(event
);
1331 if (event
instanceof TKeypressEvent
) {
1332 TKeypressEvent keypress
= (TKeypressEvent
) event
;
1334 // See if this key matches an accelerator, and is not being
1335 // shortcutted by the active window, and if so dispatch the menu
1337 boolean windowWillShortcut
= false;
1338 TWindow activeWindow
= getActiveWindow();
1339 if (activeWindow
!= null) {
1340 assert (activeWindow
.isShown());
1341 if (activeWindow
.isShortcutKeypress(keypress
.getKey())) {
1342 // We do not process this key, it will be passed to the
1344 windowWillShortcut
= true;
1348 if (!windowWillShortcut
&& !modalWindowActive()) {
1349 TKeypress keypressLowercase
= keypress
.getKey().toLowerCase();
1350 TMenuItem item
= null;
1351 synchronized (accelerators
) {
1352 item
= accelerators
.get(keypressLowercase
);
1355 if (item
.isEnabled()) {
1356 // Let the menu item dispatch
1362 // Handle the keypress
1363 if (onKeypress(keypress
)) {
1369 if (event
instanceof TCommandEvent
) {
1370 if (onCommand((TCommandEvent
) event
)) {
1375 if (event
instanceof TMenuEvent
) {
1376 if (onMenu((TMenuEvent
) event
)) {
1381 // Dispatch events to the active window -------------------------------
1382 boolean dispatchToDesktop
= true;
1383 TWindow window
= getActiveWindow();
1384 if (window
!= null) {
1385 assert (window
.isActive());
1386 assert (window
.isShown());
1387 if (event
instanceof TMouseEvent
) {
1388 TMouseEvent mouse
= (TMouseEvent
) event
;
1389 // Convert the mouse relative x/y to window coordinates
1390 assert (mouse
.getX() == mouse
.getAbsoluteX());
1391 assert (mouse
.getY() == mouse
.getAbsoluteY());
1392 mouse
.setX(mouse
.getX() - window
.getX());
1393 mouse
.setY(mouse
.getY() - window
.getY());
1395 if (doubleClick
!= null) {
1396 doubleClick
.setX(doubleClick
.getX() - window
.getX());
1397 doubleClick
.setY(doubleClick
.getY() - window
.getY());
1400 if (window
.mouseWouldHit(mouse
)) {
1401 dispatchToDesktop
= false;
1403 } else if (event
instanceof TKeypressEvent
) {
1404 dispatchToDesktop
= false;
1405 } else if (event
instanceof TMenuEvent
) {
1406 dispatchToDesktop
= false;
1410 System
.err
.printf("TApplication dispatch event: %s\n",
1413 window
.handleEvent(event
);
1414 if (doubleClick
!= null) {
1415 window
.handleEvent(doubleClick
);
1418 if (dispatchToDesktop
) {
1419 // This event is fair game for the desktop to process.
1420 if (desktop
!= null) {
1421 desktop
.handleEvent(event
);
1422 if (doubleClick
!= null) {
1423 desktop
.handleEvent(doubleClick
);
1430 * Dispatch one event to the appropriate widget or application-level
1431 * event handler. This is the secondary event handler used by certain
1432 * special dialogs (currently TMessageBox and TFileOpenBox).
1434 * @param event the input event to consume
1435 * @see #primaryHandleEvent(TInputEvent event)
1437 private void secondaryHandleEvent(final TInputEvent event
) {
1438 TMouseEvent doubleClick
= null;
1441 System
.err
.printf("%s secondaryHandleEvent: %s\n",
1442 Thread
.currentThread(), event
);
1445 // Peek at the mouse position
1446 if (event
instanceof TMouseEvent
) {
1447 typingHidMouse
= false;
1449 TMouseEvent mouse
= (TMouseEvent
) event
;
1450 if ((mouseX
!= mouse
.getX()) || (mouseY
!= mouse
.getY())) {
1451 mouseX
= mouse
.getX();
1452 mouseY
= mouse
.getY();
1454 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
1455 && (!mouse
.isMouseWheelUp())
1456 && (!mouse
.isMouseWheelDown())
1458 if ((mouse
.getTime().getTime() - lastMouseUpTime
) <
1461 // This is a double-click.
1462 doubleClick
= new TMouseEvent(TMouseEvent
.Type
.
1464 mouse
.getX(), mouse
.getY(),
1465 mouse
.getAbsoluteX(), mouse
.getAbsoluteY(),
1466 mouse
.isMouse1(), mouse
.isMouse2(),
1468 mouse
.isMouseWheelUp(), mouse
.isMouseWheelDown(),
1469 mouse
.isAlt(), mouse
.isCtrl(), mouse
.isShift());
1472 // The first click of a potential double-click.
1473 lastMouseUpTime
= mouse
.getTime().getTime();
1479 secondaryEventReceiver
.handleEvent(event
);
1480 // Note that it is possible for secondaryEventReceiver to be null
1481 // now, because its handleEvent() might have finished out on the
1482 // secondary thread. So put any extra processing inside a null
1484 if (secondaryEventReceiver
!= null) {
1485 if (doubleClick
!= null) {
1486 secondaryEventReceiver
.handleEvent(doubleClick
);
1492 * Enable a widget to override the primary event thread.
1494 * @param widget widget that will receive events
1496 public final void enableSecondaryEventReceiver(final TWidget widget
) {
1498 System
.err
.println(System
.currentTimeMillis() +
1499 " enableSecondaryEventReceiver()");
1502 assert (secondaryEventReceiver
== null);
1503 assert (secondaryEventHandler
== null);
1504 assert ((widget
instanceof TMessageBox
)
1505 || (widget
instanceof TFileOpenBox
));
1506 secondaryEventReceiver
= widget
;
1507 secondaryEventHandler
= new WidgetEventHandler(this, false);
1509 (new Thread(secondaryEventHandler
)).start();
1513 * Yield to the secondary thread.
1515 public final void yield() {
1517 System
.err
.printf(System
.currentTimeMillis() + " " +
1518 Thread
.currentThread() + " yield()\n");
1521 assert (secondaryEventReceiver
!= null);
1523 while (secondaryEventReceiver
!= null) {
1524 synchronized (primaryEventHandler
) {
1526 primaryEventHandler
.wait();
1527 } catch (InterruptedException e
) {
1535 * Do stuff when there is no user input.
1537 private void doIdle() {
1539 System
.err
.printf(System
.currentTimeMillis() + " " +
1540 Thread
.currentThread() + " doIdle()\n");
1543 synchronized (timers
) {
1546 System
.err
.printf(System
.currentTimeMillis() + " " +
1547 Thread
.currentThread() + " doIdle() 2\n");
1550 // Run any timers that have timed out
1551 Date now
= new Date();
1552 List
<TTimer
> keepTimers
= new LinkedList
<TTimer
>();
1553 for (TTimer timer
: timers
) {
1554 if (timer
.getNextTick().getTime() <= now
.getTime()) {
1555 // Something might change, so repaint the screen.
1558 if (timer
.recurring
) {
1559 keepTimers
.add(timer
);
1562 keepTimers
.add(timer
);
1566 timers
.addAll(keepTimers
);
1570 for (TWindow window
: windows
) {
1573 if (desktop
!= null) {
1577 // Run any invokeLaters. We make a copy, and run that, because one
1578 // of these Runnables might add call TApplication.invokeLater().
1579 List
<Runnable
> invokes
= new ArrayList
<Runnable
>();
1580 synchronized (invokeLaters
) {
1581 invokes
.addAll(invokeLaters
);
1582 invokeLaters
.clear();
1584 for (Runnable invoke
: invokes
) {
1592 * Wake the sleeping active event handler.
1594 private void wakeEventHandler() {
1599 if (secondaryEventHandler
!= null) {
1600 synchronized (secondaryEventHandler
) {
1601 secondaryEventHandler
.notify();
1604 assert (primaryEventHandler
!= null);
1605 synchronized (primaryEventHandler
) {
1606 primaryEventHandler
.notify();
1612 * Wake the sleeping screen handler.
1614 private void wakeScreenHandler() {
1619 synchronized (screenHandler
) {
1620 screenHandler
.notify();
1624 // ------------------------------------------------------------------------
1625 // TApplication -----------------------------------------------------------
1626 // ------------------------------------------------------------------------
1629 * Place a command on the run queue, and run it before the next round of
1632 * @param command the command to run later
1634 public void invokeLater(final Runnable command
) {
1635 synchronized (invokeLaters
) {
1636 invokeLaters
.add(command
);
1642 * Restore the console to sane defaults. This is meant to be used for
1643 * improper exits (e.g. a caught exception in main()), and should not be
1644 * necessary for normal program termination.
1646 public void restoreConsole() {
1647 if (backend
!= null) {
1648 if (backend
instanceof ECMA48Backend
) {
1657 * @return the Backend
1659 public final Backend
getBackend() {
1666 * @return the Screen
1668 public final Screen
getScreen() {
1669 if (backend
instanceof TWindowBackend
) {
1670 // We are being rendered to a TWindow. We can't use its
1671 // getScreen() method because that is how it is rendering to a
1672 // hardware backend somewhere. Instead use its getOtherScreen()
1674 return ((TWindowBackend
) backend
).getOtherScreen();
1676 return backend
.getScreen();
1681 * Get the color theme.
1685 public final ColorTheme
getTheme() {
1690 * Get the clipboard.
1692 * @return the clipboard
1694 public final Clipboard
getClipboard() {
1699 * Repaint the screen on the next update.
1701 public void doRepaint() {
1707 * Get Y coordinate of the top edge of the desktop.
1709 * @return Y coordinate of the top edge of the desktop
1711 public final int getDesktopTop() {
1716 * Get Y coordinate of the bottom edge of the desktop.
1718 * @return Y coordinate of the bottom edge of the desktop
1720 public final int getDesktopBottom() {
1721 return desktopBottom
;
1725 * Set the TDesktop instance.
1727 * @param desktop a TDesktop instance, or null to remove the one that is
1730 public final void setDesktop(final TDesktop desktop
) {
1731 if (this.desktop
!= null) {
1732 this.desktop
.onPreClose();
1733 this.desktop
.onUnfocus();
1734 this.desktop
.onClose();
1736 this.desktop
= desktop
;
1740 * Get the TDesktop instance.
1742 * @return the desktop, or null if it is not set
1744 public final TDesktop
getDesktop() {
1749 * Get the current active window.
1751 * @return the active window, or null if it is not set
1753 public final TWindow
getActiveWindow() {
1754 for (TWindow window
: windows
) {
1755 if (window
.isShown() && window
.isActive()) {
1763 * Get a (shallow) copy of the window list.
1765 * @return a copy of the list of windows for this application
1767 public final List
<TWindow
> getAllWindows() {
1768 List
<TWindow
> result
= new ArrayList
<TWindow
>();
1769 result
.addAll(windows
);
1774 * Get focusFollowsMouse flag.
1776 * @return true if focus follows mouse: windows automatically raised if
1777 * the mouse passes over them
1779 public boolean getFocusFollowsMouse() {
1780 return focusFollowsMouse
;
1784 * Set focusFollowsMouse flag.
1786 * @param focusFollowsMouse if true, focus follows mouse: windows
1787 * automatically raised if the mouse passes over them
1789 public void setFocusFollowsMouse(final boolean focusFollowsMouse
) {
1790 this.focusFollowsMouse
= focusFollowsMouse
;
1794 * Display the about dialog.
1796 protected void showAboutDialog() {
1797 String version
= getClass().getPackage().getImplementationVersion();
1798 if (version
== null) {
1799 // This is Java 9+, use a hardcoded string here.
1802 messageBox(i18n
.getString("aboutDialogTitle"),
1803 MessageFormat
.format(i18n
.getString("aboutDialogText"), version
),
1804 TMessageBox
.Type
.OK
);
1808 * Handle the Tool | Open image menu item.
1810 private void openImage() {
1812 List
<String
> filters
= new ArrayList
<String
>();
1813 filters
.add("^.*\\.[Jj][Pp][Gg]$");
1814 filters
.add("^.*\\.[Jj][Pp][Ee][Gg]$");
1815 filters
.add("^.*\\.[Pp][Nn][Gg]$");
1816 filters
.add("^.*\\.[Gg][Ii][Ff]$");
1817 filters
.add("^.*\\.[Bb][Mm][Pp]$");
1818 String filename
= fileOpenBox(".", TFileOpenBox
.Type
.OPEN
, filters
);
1819 if (filename
!= null) {
1820 new TImageWindow(this, new File(filename
));
1822 } catch (IOException e
) {
1823 // Show this exception to the user.
1824 new TExceptionDialog(this, e
);
1829 * Check if application is still running.
1831 * @return true if the application is running
1833 public final boolean isRunning() {
1840 // ------------------------------------------------------------------------
1841 // Screen refresh loop ----------------------------------------------------
1842 // ------------------------------------------------------------------------
1845 * Draw the text mouse at position.
1847 * @param x column position
1848 * @param y row position
1850 private void drawTextMouse(final int x
, final int y
) {
1851 TWindow activeWindow
= getActiveWindow();
1854 System
.err
.printf("%d %s drawTextMouse() %d %d\n",
1855 System
.currentTimeMillis(), Thread
.currentThread(), x
, y
);
1857 if (activeWindow
!= null) {
1858 System
.err
.println("activeWindow.hasHiddenMouse() " +
1859 activeWindow
.hasHiddenMouse());
1863 // If this cell is on top of a visible window that has requested a
1864 // hidden mouse, bail out.
1865 if ((activeWindow
!= null) && (activeMenu
== null)) {
1866 if ((activeWindow
.hasHiddenMouse() == true)
1867 && (x
> activeWindow
.getX())
1868 && (x
< activeWindow
.getX() + activeWindow
.getWidth() - 1)
1869 && (y
> activeWindow
.getY())
1870 && (y
< activeWindow
.getY() + activeWindow
.getHeight() - 1)
1876 // If this cell is on top of the desktop, and the desktop has
1877 // requested a hidden mouse, bail out.
1878 if ((desktop
!= null) && (activeWindow
== null) && (activeMenu
== null)) {
1879 if ((desktop
.hasHiddenMouse() == true)
1880 && (x
> desktop
.getX())
1881 && (x
< desktop
.getX() + desktop
.getWidth() - 1)
1882 && (y
> desktop
.getY())
1883 && (y
< desktop
.getY() + desktop
.getHeight() - 1)
1889 getScreen().invertCell(x
, y
);
1895 private void drawAll() {
1896 boolean menuIsActive
= false;
1899 System
.err
.printf("%d %s drawAll() enter\n",
1900 System
.currentTimeMillis(), Thread
.currentThread());
1903 // I don't think this does anything useful anymore...
1906 System
.err
.printf("%d %s drawAll() !repaint\n",
1907 System
.currentTimeMillis(), Thread
.currentThread());
1909 if ((oldDrawnMouseX
!= mouseX
) || (oldDrawnMouseY
!= mouseY
)) {
1911 System
.err
.printf("%d %s drawAll() !repaint MOUSE\n",
1912 System
.currentTimeMillis(), Thread
.currentThread());
1915 // The only thing that has happened is the mouse moved.
1917 // Redraw the old cell at that position, and save the cell at
1918 // the new mouse position.
1920 System
.err
.printf("%d %s restoreImage() %d %d\n",
1921 System
.currentTimeMillis(), Thread
.currentThread(),
1922 oldDrawnMouseX
, oldDrawnMouseY
);
1924 oldDrawnMouseCell
.restoreImage();
1925 getScreen().putCharXY(oldDrawnMouseX
, oldDrawnMouseY
,
1927 oldDrawnMouseCell
= getScreen().getCharXY(mouseX
, mouseY
);
1928 if (backend
instanceof ECMA48Backend
) {
1929 // Special case: the entire row containing the mouse has
1930 // to be re-drawn if it has any image data, AND any rows
1932 if (oldDrawnMouseY
!= mouseY
) {
1933 for (int i
= oldDrawnMouseY
; ;) {
1934 getScreen().unsetImageRow(i
);
1938 if (oldDrawnMouseY
< mouseY
) {
1945 getScreen().unsetImageRow(mouseY
);
1949 if (inScreenSelection
) {
1950 getScreen().setSelection(screenSelectionX0
,
1951 screenSelectionY0
, screenSelectionX1
, screenSelectionY1
,
1952 screenSelectionRectangle
);
1955 if ((textMouse
== true) && (typingHidMouse
== false)) {
1956 // Draw mouse at the new position.
1957 drawTextMouse(mouseX
, mouseY
);
1960 oldDrawnMouseX
= mouseX
;
1961 oldDrawnMouseY
= mouseY
;
1963 if (getScreen().isDirty()) {
1964 screenHandler
.setDirty();
1970 System
.err
.printf("%d %s drawAll() REDRAW\n",
1971 System
.currentTimeMillis(), Thread
.currentThread());
1974 // If true, the cursor is not visible
1975 boolean cursor
= false;
1977 // Start with a clean screen
1978 getScreen().clear();
1981 if (desktop
!= null) {
1982 desktop
.drawChildren();
1985 // Draw each window in reverse Z order
1986 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
1987 Collections
.sort(sorted
);
1988 TWindow topLevel
= null;
1989 if (sorted
.size() > 0) {
1990 topLevel
= sorted
.get(0);
1992 Collections
.reverse(sorted
);
1993 for (TWindow window
: sorted
) {
1994 if (window
.isShown()) {
1995 window
.drawChildren();
1999 if (hideMenuBar
== false) {
2001 // Draw the blank menubar line - reset the screen clipping first
2002 // so it won't trim it out.
2003 getScreen().resetClipping();
2004 getScreen().hLineXY(0, 0, getScreen().getWidth(), ' ',
2005 theme
.getColor("tmenu"));
2006 // Now draw the menus.
2008 for (TMenu menu
: menus
) {
2009 CellAttributes menuColor
;
2010 CellAttributes menuMnemonicColor
;
2011 if (menu
.isActive()) {
2012 menuIsActive
= true;
2013 menuColor
= theme
.getColor("tmenu.highlighted");
2014 menuMnemonicColor
= theme
.getColor("tmenu.mnemonic.highlighted");
2017 menuColor
= theme
.getColor("tmenu");
2018 menuMnemonicColor
= theme
.getColor("tmenu.mnemonic");
2020 // Draw the menu title
2021 getScreen().hLineXY(x
, 0,
2022 StringUtils
.width(menu
.getTitle()) + 2, ' ', menuColor
);
2023 getScreen().putStringXY(x
+ 1, 0, menu
.getTitle(), menuColor
);
2024 // Draw the highlight character
2025 getScreen().putCharXY(x
+ 1 +
2026 menu
.getMnemonic().getScreenShortcutIdx(),
2027 0, menu
.getMnemonic().getShortcut(), menuMnemonicColor
);
2029 if (menu
.isActive()) {
2030 ((TWindow
) menu
).drawChildren();
2031 // Reset the screen clipping so we can draw the next
2033 getScreen().resetClipping();
2035 x
+= StringUtils
.width(menu
.getTitle()) + 2;
2038 for (TMenu menu
: subMenus
) {
2039 // Reset the screen clipping so we can draw the next
2041 getScreen().resetClipping();
2042 ((TWindow
) menu
).drawChildren();
2045 getScreen().resetClipping();
2047 if (hideStatusBar
== false) {
2048 // Draw the status bar of the top-level window
2049 TStatusBar statusBar
= null;
2050 if (topLevel
!= null) {
2051 if (topLevel
.isShown()) {
2052 statusBar
= topLevel
.getStatusBar();
2055 if (statusBar
!= null) {
2056 getScreen().resetClipping();
2057 statusBar
.setWidth(getScreen().getWidth());
2058 statusBar
.setY(getScreen().getHeight() - topLevel
.getY());
2061 CellAttributes barColor
= new CellAttributes();
2062 barColor
.setTo(getTheme().getColor("tstatusbar.text"));
2063 getScreen().hLineXY(0, desktopBottom
, getScreen().getWidth(),
2068 // Draw the mouse pointer
2070 System
.err
.printf("%d %s restoreImage() %d %d\n",
2071 System
.currentTimeMillis(), Thread
.currentThread(),
2072 oldDrawnMouseX
, oldDrawnMouseY
);
2074 oldDrawnMouseCell
= getScreen().getCharXY(mouseX
, mouseY
);
2075 if (backend
instanceof ECMA48Backend
) {
2076 // Special case: the entire row containing the mouse has to be
2077 // re-drawn if it has any image data, AND any rows in between.
2078 if (oldDrawnMouseY
!= mouseY
) {
2079 for (int i
= oldDrawnMouseY
; ;) {
2080 getScreen().unsetImageRow(i
);
2084 if (oldDrawnMouseY
< mouseY
) {
2091 getScreen().unsetImageRow(mouseY
);
2095 if (inScreenSelection
) {
2096 getScreen().setSelection(screenSelectionX0
, screenSelectionY0
,
2097 screenSelectionX1
, screenSelectionY1
, screenSelectionRectangle
);
2100 if ((textMouse
== true) && (typingHidMouse
== false)) {
2101 drawTextMouse(mouseX
, mouseY
);
2103 oldDrawnMouseX
= mouseX
;
2104 oldDrawnMouseY
= mouseY
;
2106 // Place the cursor if it is visible
2107 if (!menuIsActive
) {
2109 int visibleWindowCount
= 0;
2110 for (TWindow window
: sorted
) {
2111 if (window
.isShown()) {
2112 visibleWindowCount
++;
2115 if (visibleWindowCount
== 0) {
2116 // No windows are visible, only the desktop. Allow it to
2118 if (desktop
!= null) {
2119 sorted
.add(desktop
);
2123 TWidget activeWidget
= null;
2124 if (sorted
.size() > 0) {
2125 activeWidget
= sorted
.get(sorted
.size() - 1).getActiveChild();
2126 int cursorClipTop
= desktopTop
;
2127 int cursorClipBottom
= desktopBottom
;
2128 if (activeWidget
.isCursorVisible()) {
2129 if ((activeWidget
.getCursorAbsoluteY() <= cursorClipBottom
)
2130 && (activeWidget
.getCursorAbsoluteY() >= cursorClipTop
)
2132 getScreen().putCursor(true,
2133 activeWidget
.getCursorAbsoluteX(),
2134 activeWidget
.getCursorAbsoluteY());
2137 // Turn off the cursor. Also place it at 0,0.
2138 getScreen().putCursor(false, 0, 0);
2147 getScreen().hideCursor();
2150 if (getScreen().isDirty()) {
2151 screenHandler
.setDirty();
2157 * Force this application to exit.
2159 public void exit() {
2161 synchronized (this) {
2167 * Subclasses can use this hook to cleanup resources. Called as the last
2168 * step of TApplication.run().
2170 public void onExit() {
2171 // Default does nothing.
2174 // ------------------------------------------------------------------------
2175 // TWindow management -----------------------------------------------------
2176 // ------------------------------------------------------------------------
2179 * Return the total number of windows.
2181 * @return the total number of windows
2183 public final int windowCount() {
2184 return windows
.size();
2188 * Return the number of windows that are showing.
2190 * @return the number of windows that are showing on screen
2192 public final int shownWindowCount() {
2194 for (TWindow w
: windows
) {
2203 * Return the number of windows that are hidden.
2205 * @return the number of windows that are hidden
2207 public final int hiddenWindowCount() {
2209 for (TWindow w
: windows
) {
2218 * Check if a window instance is in this application's window list.
2220 * @param window window to look for
2221 * @return true if this window is in the list
2223 public final boolean hasWindow(final TWindow window
) {
2224 if (windows
.size() == 0) {
2227 for (TWindow w
: windows
) {
2229 assert (window
.getApplication() == this);
2237 * Activate a window: bring it to the top and have it receive events.
2239 * @param window the window to become the new active window
2241 public final void activateWindow(final TWindow window
) {
2242 if (hasWindow(window
) == false) {
2244 * Someone has a handle to a window I don't have. Ignore this
2250 if (modalWindowActive() && !window
.isModal()) {
2251 // Do not activate a non-modal on top of a modal.
2255 synchronized (windows
) {
2256 // Whatever window might be moving/dragging, stop it now.
2257 for (TWindow w
: windows
) {
2258 if (w
.inMovements()) {
2263 assert (windows
.size() > 0);
2265 if (window
.isHidden()) {
2266 // Unhiding will also activate.
2270 assert (window
.isShown());
2272 if (windows
.size() == 1) {
2273 assert (window
== windows
.get(0));
2275 window
.setActive(true);
2280 if (getActiveWindow() == window
) {
2281 assert (window
.isActive());
2283 // Window is already active, do nothing.
2287 assert (!window
.isActive());
2290 Collections
.sort(windows
);
2292 for (TWindow w
: windows
) {
2295 if ((w
!= window
) && w
.isActive()) {
2300 window
.setActive(true);
2303 } // synchronized (windows)
2311 * @param window the window to hide
2313 public void hideWindow(final TWindow window
) {
2314 if (hasWindow(window
) == false) {
2316 * Someone has a handle to a window I don't have. Ignore this
2322 synchronized (windows
) {
2324 // Whatever window might be moving/dragging, stop it now.
2325 for (TWindow w
: windows
) {
2326 if (w
.inMovements()) {
2331 assert (windows
.size() > 0);
2333 if (window
.hidden
) {
2337 window
.setActive(false);
2338 window
.hidden
= true;
2341 TWindow activeWindow
= null;
2342 for (TWindow w
: windows
) {
2348 assert (activeWindow
!= window
);
2349 if (activeWindow
!= null) {
2350 activateWindow(activeWindow
);
2353 } // synchronized (windows)
2360 * @param window the window to show
2362 public void showWindow(final TWindow window
) {
2363 if (hasWindow(window
) == false) {
2365 * Someone has a handle to a window I don't have. Ignore this
2371 if (window
.hidden
) {
2372 window
.hidden
= false;
2374 activateWindow(window
);
2382 * @param window the window to remove
2384 public final void closeWindow(final TWindow window
) {
2385 if (hasWindow(window
) == false) {
2387 * Someone has a handle to a window I don't have. Ignore this
2393 // Let window know that it is about to be closed, while it is still
2394 // visible on screen.
2395 window
.onPreClose();
2397 synchronized (windows
) {
2399 window
.stopMovements();
2401 windows
.remove(window
);
2402 Collections
.sort(windows
);
2404 TWindow nextWindow
= null;
2406 for (TWindow w
: windows
) {
2411 // Do not activate a hidden window.
2415 if (nextWindow
== null) {
2425 if (nextWindow
!= null) {
2426 nextWindow
.setActive(true);
2427 nextWindow
.onFocus();
2430 } // synchronized (windows)
2432 // Perform window cleanup
2435 // Check if we are closing a TMessageBox or similar
2436 if (secondaryEventReceiver
!= null) {
2437 assert (secondaryEventHandler
!= null);
2439 // Do not send events to the secondaryEventReceiver anymore, the
2440 // window is closed.
2441 secondaryEventReceiver
= null;
2443 // Wake the secondary thread, it will wake the primary as it
2445 synchronized (secondaryEventHandler
) {
2446 secondaryEventHandler
.notify();
2449 } // synchronized (windows)
2451 // Permit desktop to be active if it is the only thing left.
2452 if (desktop
!= null) {
2453 if (windows
.size() == 0) {
2454 desktop
.setActive(true);
2460 * Switch to the next window.
2462 * @param forward if true, then switch to the next window in the list,
2463 * otherwise switch to the previous window in the list
2465 public final void switchWindow(final boolean forward
) {
2466 // Only switch if there are multiple visible windows
2467 if (shownWindowCount() < 2) {
2471 if (modalWindowActive()) {
2472 // Do not switch if a window is modal
2476 synchronized (windows
) {
2478 TWindow window
= windows
.get(0);
2480 assert (window
!= null);
2482 window
.setZ(windows
.size());
2484 TWindow lastWindow
= windows
.get(windows
.size() - 1);
2485 lastWindow
.setZ(-1);
2488 Collections
.sort(windows
);
2490 for (TWindow w
: windows
) {
2495 window
= windows
.get(0);
2496 } while (!window
.isShown());
2498 // The next visible window is now on top. Renumber the list.
2499 for (TWindow w
: windows
) {
2501 if ((w
!= window
) && w
.isActive()) {
2502 assert (w
.isShown());
2508 // Next visible window is on top.
2509 assert (window
.isShown());
2510 window
.setActive(true);
2513 } // synchronized (windows)
2517 * Add a window to my window list and make it active. Note package
2520 * @param window new window to add
2522 final void addWindowToApplication(final TWindow window
) {
2524 // Do not add menu windows to the window list.
2525 if (window
instanceof TMenu
) {
2529 // Do not add the desktop to the window list.
2530 if (window
instanceof TDesktop
) {
2534 synchronized (windows
) {
2535 if (windows
.contains(window
)) {
2536 throw new IllegalArgumentException("Window " + window
+
2537 " is already in window list");
2540 // Whatever window might be moving/dragging, stop it now.
2541 for (TWindow w
: windows
) {
2542 if (w
.inMovements()) {
2547 // Do not allow a modal window to spawn a non-modal window. If a
2548 // modal window is active, then this window will become modal
2550 if (modalWindowActive()) {
2551 window
.flags
|= TWindow
.MODAL
;
2552 window
.flags
|= TWindow
.CENTERED
;
2553 window
.hidden
= false;
2555 if (window
.isShown()) {
2556 for (TWindow w
: windows
) {
2561 w
.setZ(w
.getZ() + 1);
2564 window
.setActive(true);
2566 windows
.add(0, window
);
2568 window
.setZ(windows
.size());
2569 windows
.add(window
);
2572 if (((window
.flags
& TWindow
.CENTERED
) == 0)
2573 && ((window
.flags
& TWindow
.ABSOLUTEXY
) == 0)
2574 && (smartWindowPlacement
== true)
2575 && (!(window
instanceof TDesktop
))
2578 doSmartPlacement(window
);
2582 // Desktop cannot be active over any other window.
2583 if (desktop
!= null) {
2584 desktop
.setActive(false);
2590 * Check if there is a system-modal window on top.
2592 * @return true if the active window is modal
2594 private boolean modalWindowActive() {
2595 if (windows
.size() == 0) {
2599 for (TWindow w
: windows
) {
2609 * Check if there is a window with overridden menu flag on top.
2611 * @return true if the active window is overriding the menu
2613 private boolean overrideMenuWindowActive() {
2614 TWindow activeWindow
= getActiveWindow();
2615 if (activeWindow
!= null) {
2616 if (activeWindow
.hasOverriddenMenu()) {
2625 * Close all open windows.
2627 private void closeAllWindows() {
2628 // Don't do anything if we are in the menu
2629 if (activeMenu
!= null) {
2632 while (windows
.size() > 0) {
2633 closeWindow(windows
.get(0));
2638 * Re-layout the open windows as non-overlapping tiles. This produces
2639 * almost the same results as Turbo Pascal 7.0's IDE.
2641 private void tileWindows() {
2642 synchronized (windows
) {
2643 // Don't do anything if we are in the menu
2644 if (activeMenu
!= null) {
2647 int z
= windows
.size();
2653 a
= (int)(Math
.sqrt(z
));
2657 if (((a
* b
) + c
) == z
) {
2665 int newWidth
= (getScreen().getWidth() / a
);
2666 int newHeight1
= ((getScreen().getHeight() - 1) / b
);
2667 int newHeight2
= ((getScreen().getHeight() - 1) / (b
+ c
));
2669 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
2670 Collections
.sort(sorted
);
2671 Collections
.reverse(sorted
);
2672 for (int i
= 0; i
< sorted
.size(); i
++) {
2673 int logicalX
= i
/ b
;
2674 int logicalY
= i
% b
;
2675 if (i
>= ((a
- 1) * b
)) {
2677 logicalY
= i
- ((a
- 1) * b
);
2680 TWindow w
= sorted
.get(i
);
2681 int oldWidth
= w
.getWidth();
2682 int oldHeight
= w
.getHeight();
2684 w
.setX(logicalX
* newWidth
);
2685 w
.setWidth(newWidth
);
2686 if (i
>= ((a
- 1) * b
)) {
2687 w
.setY((logicalY
* newHeight2
) + 1);
2688 w
.setHeight(newHeight2
);
2690 w
.setY((logicalY
* newHeight1
) + 1);
2691 w
.setHeight(newHeight1
);
2693 if ((w
.getWidth() != oldWidth
)
2694 || (w
.getHeight() != oldHeight
)
2696 w
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
2697 w
.getWidth(), w
.getHeight()));
2704 * Re-layout the open windows as overlapping cascaded windows.
2706 private void cascadeWindows() {
2707 synchronized (windows
) {
2708 // Don't do anything if we are in the menu
2709 if (activeMenu
!= null) {
2714 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
2715 Collections
.sort(sorted
);
2716 Collections
.reverse(sorted
);
2717 for (TWindow window
: sorted
) {
2722 if (x
> getScreen().getWidth()) {
2725 if (y
>= getScreen().getHeight()) {
2733 * Place a window to minimize its overlap with other windows.
2735 * @param window the window to place
2737 public final void doSmartPlacement(final TWindow window
) {
2738 // This is a pretty dumb algorithm, but seems to work. The hardest
2739 // part is computing these "overlap" values seeking a minimum average
2742 int yMin
= desktopTop
;
2743 int xMax
= getScreen().getWidth() - window
.getWidth() + 1;
2744 int yMax
= desktopBottom
- window
.getHeight() + 1;
2752 if ((xMin
== xMax
) && (yMin
== yMax
)) {
2753 // No work to do, bail out.
2757 // Compute the overlap matrix without the new window.
2758 int width
= getScreen().getWidth();
2759 int height
= getScreen().getHeight();
2760 int overlapMatrix
[][] = new int[width
][height
];
2761 for (TWindow w
: windows
) {
2765 for (int x
= w
.getX(); x
< w
.getX() + w
.getWidth(); x
++) {
2772 for (int y
= w
.getY(); y
< w
.getY() + w
.getHeight(); y
++) {
2779 overlapMatrix
[x
][y
]++;
2784 long oldOverlapTotal
= 0;
2785 long oldOverlapN
= 0;
2786 for (int x
= 0; x
< width
; x
++) {
2787 for (int y
= 0; y
< height
; y
++) {
2788 oldOverlapTotal
+= overlapMatrix
[x
][y
];
2789 if (overlapMatrix
[x
][y
] > 0) {
2796 double oldOverlapAvg
= (double) oldOverlapTotal
/ (double) oldOverlapN
;
2797 boolean first
= true;
2798 int windowX
= window
.getX();
2799 int windowY
= window
.getY();
2801 // For each possible (x, y) position for the new window, compute a
2802 // new overlap matrix.
2803 for (int x
= xMin
; x
< xMax
; x
++) {
2804 for (int y
= yMin
; y
< yMax
; y
++) {
2806 // Start with the matrix minus this window.
2807 int newMatrix
[][] = new int[width
][height
];
2808 for (int mx
= 0; mx
< width
; mx
++) {
2809 for (int my
= 0; my
< height
; my
++) {
2810 newMatrix
[mx
][my
] = overlapMatrix
[mx
][my
];
2814 // Add this window's values to the new overlap matrix.
2815 long newOverlapTotal
= 0;
2816 long newOverlapN
= 0;
2817 // Start by adding each new cell.
2818 for (int wx
= x
; wx
< x
+ window
.getWidth(); wx
++) {
2822 for (int wy
= y
; wy
< y
+ window
.getHeight(); wy
++) {
2826 newMatrix
[wx
][wy
]++;
2829 // Now figure out the new value for total coverage.
2830 for (int mx
= 0; mx
< width
; mx
++) {
2831 for (int my
= 0; my
< height
; my
++) {
2832 newOverlapTotal
+= newMatrix
[x
][y
];
2833 if (newMatrix
[mx
][my
] > 0) {
2838 double newOverlapAvg
= (double) newOverlapTotal
/ (double) newOverlapN
;
2841 // First time: just record what we got.
2842 oldOverlapAvg
= newOverlapAvg
;
2845 // All other times: pick a new best (x, y) and save the
2847 if (newOverlapAvg
< oldOverlapAvg
) {
2850 oldOverlapAvg
= newOverlapAvg
;
2854 } // for (int x = xMin; x < xMax; x++)
2856 } // for (int y = yMin; y < yMax; y++)
2858 // Finally, set the window's new coordinates.
2859 window
.setX(windowX
);
2860 window
.setY(windowY
);
2863 // ------------------------------------------------------------------------
2864 // TMenu management -------------------------------------------------------
2865 // ------------------------------------------------------------------------
2868 * Check if a mouse event would hit either the active menu or any open
2871 * @param mouse mouse event
2872 * @return true if the mouse would hit the active menu or an open
2875 private boolean mouseOnMenu(final TMouseEvent mouse
) {
2876 assert (activeMenu
!= null);
2877 List
<TMenu
> menus
= new ArrayList
<TMenu
>(subMenus
);
2878 Collections
.reverse(menus
);
2879 for (TMenu menu
: menus
) {
2880 if (menu
.mouseWouldHit(mouse
)) {
2884 return activeMenu
.mouseWouldHit(mouse
);
2888 * See if we need to switch window or activate the menu based on
2891 * @param mouse mouse event
2893 private void checkSwitchFocus(final TMouseEvent mouse
) {
2895 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2896 && (activeMenu
!= null)
2897 && (mouse
.getAbsoluteY() != 0)
2898 && (!mouseOnMenu(mouse
))
2900 // They clicked outside the active menu, turn it off
2901 activeMenu
.setActive(false);
2903 for (TMenu menu
: subMenus
) {
2904 menu
.setActive(false);
2910 // See if they hit the menu bar
2911 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2912 && (mouse
.isMouse1())
2913 && (!modalWindowActive())
2914 && (!overrideMenuWindowActive())
2915 && (mouse
.getAbsoluteY() == 0)
2916 && (hideMenuBar
== false)
2919 for (TMenu menu
: subMenus
) {
2920 menu
.setActive(false);
2924 // They selected the menu, go activate it
2925 for (TMenu menu
: menus
) {
2926 if ((mouse
.getAbsoluteX() >= menu
.getTitleX())
2927 && (mouse
.getAbsoluteX() < menu
.getTitleX()
2928 + StringUtils
.width(menu
.getTitle()) + 2)
2930 menu
.setActive(true);
2933 menu
.setActive(false);
2939 // See if they hit the menu bar
2940 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
)
2941 && (mouse
.isMouse1())
2942 && (activeMenu
!= null)
2943 && (mouse
.getAbsoluteY() == 0)
2944 && (hideMenuBar
== false)
2947 TMenu oldMenu
= activeMenu
;
2948 for (TMenu menu
: subMenus
) {
2949 menu
.setActive(false);
2953 // See if we should switch menus
2954 for (TMenu menu
: menus
) {
2955 if ((mouse
.getAbsoluteX() >= menu
.getTitleX())
2956 && (mouse
.getAbsoluteX() < menu
.getTitleX()
2957 + StringUtils
.width(menu
.getTitle()) + 2)
2959 menu
.setActive(true);
2963 if (oldMenu
!= activeMenu
) {
2964 // They switched menus
2965 oldMenu
.setActive(false);
2970 // If a menu is still active, don't switch windows
2971 if (activeMenu
!= null) {
2975 // Only switch if there are multiple windows
2976 if (windows
.size() < 2) {
2980 if (((focusFollowsMouse
== true)
2981 && (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
))
2982 || (mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2984 synchronized (windows
) {
2985 if (windows
.get(0).isModal()) {
2986 // Modal windows don't switch
2990 for (TWindow window
: windows
) {
2991 assert (!window
.isModal());
2993 if (window
.isHidden()) {
2994 assert (!window
.isActive());
2998 if (window
.mouseWouldHit(mouse
)) {
2999 activateWindow(window
);
3005 // Clicked on the background, nothing to do
3009 // Nothing to do: this isn't a mouse up, or focus isn't following
3015 * Turn off the menu.
3017 public final void closeMenu() {
3018 if (activeMenu
!= null) {
3019 activeMenu
.setActive(false);
3021 for (TMenu menu
: subMenus
) {
3022 menu
.setActive(false);
3029 * Get a (shallow) copy of the menu list.
3031 * @return a copy of the menu list
3033 public final List
<TMenu
> getAllMenus() {
3034 return new ArrayList
<TMenu
>(menus
);
3038 * Add a top-level menu to the list.
3040 * @param menu the menu to add
3041 * @throws IllegalArgumentException if the menu is already used in
3042 * another TApplication
3044 public final void addMenu(final TMenu menu
) {
3045 if ((menu
.getApplication() != null)
3046 && (menu
.getApplication() != this)
3048 throw new IllegalArgumentException("Menu " + menu
+ " is already " +
3049 "part of application " + menu
.getApplication());
3057 * Remove a top-level menu from the list.
3059 * @param menu the menu to remove
3060 * @throws IllegalArgumentException if the menu is already used in
3061 * another TApplication
3063 public final void removeMenu(final TMenu menu
) {
3064 if ((menu
.getApplication() != null)
3065 && (menu
.getApplication() != this)
3067 throw new IllegalArgumentException("Menu " + menu
+ " is already " +
3068 "part of application " + menu
.getApplication());
3076 * Turn off a sub-menu.
3078 public final void closeSubMenu() {
3079 assert (activeMenu
!= null);
3080 TMenu item
= subMenus
.get(subMenus
.size() - 1);
3081 assert (item
!= null);
3082 item
.setActive(false);
3083 subMenus
.remove(subMenus
.size() - 1);
3087 * Switch to the next menu.
3089 * @param forward if true, then switch to the next menu in the list,
3090 * otherwise switch to the previous menu in the list
3092 public final void switchMenu(final boolean forward
) {
3093 assert (activeMenu
!= null);
3094 assert (hideMenuBar
== false);
3096 for (TMenu menu
: subMenus
) {
3097 menu
.setActive(false);
3101 for (int i
= 0; i
< menus
.size(); i
++) {
3102 if (activeMenu
== menus
.get(i
)) {
3104 if (i
< menus
.size() - 1) {
3113 i
= menus
.size() - 1;
3116 activeMenu
.setActive(false);
3117 activeMenu
= menus
.get(i
);
3118 activeMenu
.setActive(true);
3125 * Add a menu item to the global list. If it has a keyboard accelerator,
3126 * that will be added the global hash.
3128 * @param item the menu item
3130 public final void addMenuItem(final TMenuItem item
) {
3131 menuItems
.add(item
);
3133 TKeypress key
= item
.getKey();
3135 synchronized (accelerators
) {
3136 assert (accelerators
.get(key
) == null);
3137 accelerators
.put(key
.toLowerCase(), item
);
3143 * Disable one menu item.
3145 * @param id the menu item ID
3147 public final void disableMenuItem(final int id
) {
3148 for (TMenuItem item
: menuItems
) {
3149 if (item
.getId() == id
) {
3150 item
.setEnabled(false);
3156 * Disable the range of menu items with ID's between lower and upper,
3159 * @param lower the lowest menu item ID
3160 * @param upper the highest menu item ID
3162 public final void disableMenuItems(final int lower
, final int upper
) {
3163 for (TMenuItem item
: menuItems
) {
3164 if ((item
.getId() >= lower
) && (item
.getId() <= upper
)) {
3165 item
.setEnabled(false);
3166 item
.getParent().activate(0);
3172 * Enable one menu item.
3174 * @param id the menu item ID
3176 public final void enableMenuItem(final int id
) {
3177 for (TMenuItem item
: menuItems
) {
3178 if (item
.getId() == id
) {
3179 item
.setEnabled(true);
3180 item
.getParent().activate(0);
3186 * Enable the range of menu items with ID's between lower and upper,
3189 * @param lower the lowest menu item ID
3190 * @param upper the highest menu item ID
3192 public final void enableMenuItems(final int lower
, final int upper
) {
3193 for (TMenuItem item
: menuItems
) {
3194 if ((item
.getId() >= lower
) && (item
.getId() <= upper
)) {
3195 item
.setEnabled(true);
3196 item
.getParent().activate(0);
3202 * Get the menu item associated with this ID.
3204 * @param id the menu item ID
3205 * @return the menu item, or null if not found
3207 public final TMenuItem
getMenuItem(final int id
) {
3208 for (TMenuItem item
: menuItems
) {
3209 if (item
.getId() == id
) {
3217 * Recompute menu x positions based on their title length.
3219 public final void recomputeMenuX() {
3221 for (TMenu menu
: menus
) {
3224 x
+= StringUtils
.width(menu
.getTitle()) + 2;
3226 // Don't let the menu window exceed the screen width
3227 int rightEdge
= menu
.getX() + menu
.getWidth();
3228 if (rightEdge
> getScreen().getWidth()) {
3229 menu
.setX(getScreen().getWidth() - menu
.getWidth());
3235 * Post an event to process.
3237 * @param event new event to add to the queue
3239 public final void postEvent(final TInputEvent event
) {
3240 synchronized (this) {
3241 synchronized (fillEventQueue
) {
3242 fillEventQueue
.add(event
);
3245 System
.err
.println(System
.currentTimeMillis() + " " +
3246 Thread
.currentThread() + " postEvent() wake up main");
3253 * Post an event to process and turn off the menu.
3255 * @param event new event to add to the queue
3257 public final void postMenuEvent(final TInputEvent event
) {
3258 synchronized (this) {
3259 synchronized (fillEventQueue
) {
3260 fillEventQueue
.add(event
);
3263 System
.err
.println(System
.currentTimeMillis() + " " +
3264 Thread
.currentThread() + " postMenuEvent() wake up main");
3272 * Add a sub-menu to the list of open sub-menus.
3274 * @param menu sub-menu
3276 public final void addSubMenu(final TMenu menu
) {
3281 * Convenience function to add a top-level menu.
3283 * @param title menu title
3284 * @return the new menu
3286 public final TMenu
addMenu(final String title
) {
3289 TMenu menu
= new TMenu(this, x
, y
, title
);
3296 * Convenience function to add a default tools (hamburger) menu.
3298 * @return the new menu
3300 public final TMenu
addToolMenu() {
3301 TMenu toolMenu
= addMenu(i18n
.getString("toolMenuTitle"));
3302 toolMenu
.addDefaultItem(TMenu
.MID_REPAINT
);
3303 toolMenu
.addDefaultItem(TMenu
.MID_VIEW_IMAGE
);
3304 toolMenu
.addDefaultItem(TMenu
.MID_SCREEN_OPTIONS
);
3305 TStatusBar toolStatusBar
= toolMenu
.newStatusBar(i18n
.
3306 getString("toolMenuStatus"));
3307 toolStatusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3312 * Convenience function to add a default "File" menu.
3314 * @return the new menu
3316 public final TMenu
addFileMenu() {
3317 TMenu fileMenu
= addMenu(i18n
.getString("fileMenuTitle"));
3318 fileMenu
.addDefaultItem(TMenu
.MID_SHELL
);
3319 fileMenu
.addSeparator();
3320 fileMenu
.addDefaultItem(TMenu
.MID_EXIT
);
3321 TStatusBar statusBar
= fileMenu
.newStatusBar(i18n
.
3322 getString("fileMenuStatus"));
3323 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3328 * Convenience function to add a default "Edit" menu.
3330 * @return the new menu
3332 public final TMenu
addEditMenu() {
3333 TMenu editMenu
= addMenu(i18n
.getString("editMenuTitle"));
3334 editMenu
.addDefaultItem(TMenu
.MID_CUT
, false);
3335 editMenu
.addDefaultItem(TMenu
.MID_COPY
, false);
3336 editMenu
.addDefaultItem(TMenu
.MID_PASTE
, false);
3337 editMenu
.addDefaultItem(TMenu
.MID_CLEAR
, false);
3338 TStatusBar statusBar
= editMenu
.newStatusBar(i18n
.
3339 getString("editMenuStatus"));
3340 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3345 * Convenience function to add a default "Window" menu.
3347 * @return the new menu
3349 public final TMenu
addWindowMenu() {
3350 TMenu windowMenu
= addMenu(i18n
.getString("windowMenuTitle"));
3351 windowMenu
.addDefaultItem(TMenu
.MID_TILE
);
3352 windowMenu
.addDefaultItem(TMenu
.MID_CASCADE
);
3353 windowMenu
.addDefaultItem(TMenu
.MID_CLOSE_ALL
);
3354 windowMenu
.addSeparator();
3355 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_MOVE
);
3356 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_ZOOM
);
3357 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_NEXT
);
3358 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_PREVIOUS
);
3359 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_CLOSE
);
3360 TStatusBar statusBar
= windowMenu
.newStatusBar(i18n
.
3361 getString("windowMenuStatus"));
3362 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3367 * Convenience function to add a default "Help" menu.
3369 * @return the new menu
3371 public final TMenu
addHelpMenu() {
3372 TMenu helpMenu
= addMenu(i18n
.getString("helpMenuTitle"));
3373 helpMenu
.addDefaultItem(TMenu
.MID_HELP_CONTENTS
);
3374 helpMenu
.addDefaultItem(TMenu
.MID_HELP_INDEX
);
3375 helpMenu
.addDefaultItem(TMenu
.MID_HELP_SEARCH
);
3376 helpMenu
.addDefaultItem(TMenu
.MID_HELP_PREVIOUS
);
3377 helpMenu
.addDefaultItem(TMenu
.MID_HELP_HELP
);
3378 helpMenu
.addDefaultItem(TMenu
.MID_HELP_ACTIVE_FILE
);
3379 helpMenu
.addSeparator();
3380 helpMenu
.addDefaultItem(TMenu
.MID_ABOUT
);
3381 TStatusBar statusBar
= helpMenu
.newStatusBar(i18n
.
3382 getString("helpMenuStatus"));
3383 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3388 * Convenience function to add a default "Table" menu.
3390 * @return the new menu
3392 public final TMenu
addTableMenu() {
3393 TMenu tableMenu
= addMenu(i18n
.getString("tableMenuTitle"));
3394 tableMenu
.addDefaultItem(TMenu
.MID_TABLE_RENAME_COLUMN
, false);
3395 tableMenu
.addDefaultItem(TMenu
.MID_TABLE_RENAME_ROW
, false);
3396 tableMenu
.addSeparator();
3398 TSubMenu viewMenu
= tableMenu
.addSubMenu(i18n
.
3399 getString("tableSubMenuView"));
3400 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_ROW_LABELS
, false);
3401 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_COLUMN_LABELS
, false);
3402 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_HIGHLIGHT_ROW
, false);
3403 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_HIGHLIGHT_COLUMN
, false);
3405 TSubMenu borderMenu
= tableMenu
.addSubMenu(i18n
.
3406 getString("tableSubMenuBorders"));
3407 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_NONE
, false);
3408 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_ALL
, false);
3409 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_CELL_NONE
, false);
3410 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_CELL_ALL
, false);
3411 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_RIGHT
, false);
3412 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_LEFT
, false);
3413 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_TOP
, false);
3414 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_BOTTOM
, false);
3415 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_DOUBLE_BOTTOM
, false);
3416 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_THICK_BOTTOM
, false);
3417 TSubMenu deleteMenu
= tableMenu
.addSubMenu(i18n
.
3418 getString("tableSubMenuDelete"));
3419 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_LEFT
, false);
3420 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_UP
, false);
3421 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_ROW
, false);
3422 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_COLUMN
, false);
3423 TSubMenu insertMenu
= tableMenu
.addSubMenu(i18n
.
3424 getString("tableSubMenuInsert"));
3425 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_LEFT
, false);
3426 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_RIGHT
, false);
3427 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_ABOVE
, false);
3428 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_BELOW
, false);
3429 TSubMenu columnMenu
= tableMenu
.addSubMenu(i18n
.
3430 getString("tableSubMenuColumn"));
3431 columnMenu
.addDefaultItem(TMenu
.MID_TABLE_COLUMN_NARROW
, false);
3432 columnMenu
.addDefaultItem(TMenu
.MID_TABLE_COLUMN_WIDEN
, false);
3433 TSubMenu fileMenu
= tableMenu
.addSubMenu(i18n
.
3434 getString("tableSubMenuFile"));
3435 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_OPEN_CSV
, false);
3436 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_SAVE_CSV
, false);
3437 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_SAVE_TEXT
, false);
3439 TStatusBar statusBar
= tableMenu
.newStatusBar(i18n
.
3440 getString("tableMenuStatus"));
3441 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3445 // ------------------------------------------------------------------------
3446 // TTimer management ------------------------------------------------------
3447 // ------------------------------------------------------------------------
3450 * Get the amount of time I can sleep before missing a Timer tick.
3452 * @param timeout = initial (maximum) timeout in millis
3453 * @return number of milliseconds between now and the next timer event
3455 private long getSleepTime(final long timeout
) {
3456 Date now
= new Date();
3457 long nowTime
= now
.getTime();
3458 long sleepTime
= timeout
;
3460 synchronized (timers
) {
3461 for (TTimer timer
: timers
) {
3462 long nextTickTime
= timer
.getNextTick().getTime();
3463 if (nextTickTime
< nowTime
) {
3467 long timeDifference
= nextTickTime
- nowTime
;
3468 if (timeDifference
< sleepTime
) {
3469 sleepTime
= timeDifference
;
3474 assert (sleepTime
>= 0);
3475 assert (sleepTime
<= timeout
);
3480 * Convenience function to add a timer.
3482 * @param duration number of milliseconds to wait between ticks
3483 * @param recurring if true, re-schedule this timer after every tick
3484 * @param action function to call when button is pressed
3487 public final TTimer
addTimer(final long duration
, final boolean recurring
,
3488 final TAction action
) {
3490 TTimer timer
= new TTimer(duration
, recurring
, action
);
3491 synchronized (timers
) {
3498 * Convenience function to remove a timer.
3500 * @param timer timer to remove
3502 public final void removeTimer(final TTimer timer
) {
3503 synchronized (timers
) {
3504 timers
.remove(timer
);
3508 // ------------------------------------------------------------------------
3509 // Other TWindow constructors ---------------------------------------------
3510 // ------------------------------------------------------------------------
3513 * Convenience function to spawn a message box.
3515 * @param title window title, will be centered along the top border
3516 * @param caption message to display. Use embedded newlines to get a
3518 * @return the new message box
3520 public final TMessageBox
messageBox(final String title
,
3521 final String caption
) {
3523 return new TMessageBox(this, title
, caption
, TMessageBox
.Type
.OK
);
3527 * Convenience function to spawn a message box.
3529 * @param title window title, will be centered along the top border
3530 * @param caption message to display. Use embedded newlines to get a
3532 * @param type one of the TMessageBox.Type constants. Default is
3534 * @return the new message box
3536 public final TMessageBox
messageBox(final String title
,
3537 final String caption
, final TMessageBox
.Type type
) {
3539 return new TMessageBox(this, title
, caption
, type
);
3543 * Convenience function to spawn an input box.
3545 * @param title window title, will be centered along the top border
3546 * @param caption message to display. Use embedded newlines to get a
3548 * @return the new input box
3550 public final TInputBox
inputBox(final String title
, final String caption
) {
3552 return new TInputBox(this, title
, caption
);
3556 * Convenience function to spawn an input box.
3558 * @param title window title, will be centered along the top border
3559 * @param caption message to display. Use embedded newlines to get a
3561 * @param text initial text to seed the field with
3562 * @return the new input box
3564 public final TInputBox
inputBox(final String title
, final String caption
,
3565 final String text
) {
3567 return new TInputBox(this, title
, caption
, text
);
3571 * Convenience function to spawn an input box.
3573 * @param title window title, will be centered along the top border
3574 * @param caption message to display. Use embedded newlines to get a
3576 * @param text initial text to seed the field with
3577 * @param type one of the Type constants. Default is Type.OK.
3578 * @return the new input box
3580 public final TInputBox
inputBox(final String title
, final String caption
,
3581 final String text
, final TInputBox
.Type type
) {
3583 return new TInputBox(this, title
, caption
, text
, type
);
3587 * Convenience function to open a terminal window.
3589 * @param x column relative to parent
3590 * @param y row relative to parent
3591 * @return the terminal new window
3593 public final TTerminalWindow
openTerminal(final int x
, final int y
) {
3594 return openTerminal(x
, y
, TWindow
.RESIZABLE
);
3598 * Convenience function to open a terminal window.
3600 * @param x column relative to parent
3601 * @param y row relative to parent
3602 * @param closeOnExit if true, close the window when the command exits
3603 * @return the terminal new window
3605 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3606 final boolean closeOnExit
) {
3608 return openTerminal(x
, y
, TWindow
.RESIZABLE
, closeOnExit
);
3612 * Convenience function to open a terminal window.
3614 * @param x column relative to parent
3615 * @param y row relative to parent
3616 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3617 * @return the terminal new window
3619 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3622 return new TTerminalWindow(this, x
, y
, flags
);
3626 * Convenience function to open a terminal window.
3628 * @param x column relative to parent
3629 * @param y row relative to parent
3630 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3631 * @param closeOnExit if true, close the window when the command exits
3632 * @return the terminal new window
3634 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3635 final int flags
, final boolean closeOnExit
) {
3637 return new TTerminalWindow(this, x
, y
, flags
, closeOnExit
);
3641 * Convenience function to open a terminal window and execute a custom
3642 * command line inside it.
3644 * @param x column relative to parent
3645 * @param y row relative to parent
3646 * @param commandLine the command line to execute
3647 * @return the terminal new window
3649 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3650 final String commandLine
) {
3652 return openTerminal(x
, y
, TWindow
.RESIZABLE
, commandLine
);
3656 * Convenience function to open a terminal window and execute a custom
3657 * command line inside it.
3659 * @param x column relative to parent
3660 * @param y row relative to parent
3661 * @param commandLine the command line to execute
3662 * @param closeOnExit if true, close the window when the command exits
3663 * @return the terminal new window
3665 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3666 final String commandLine
, final boolean closeOnExit
) {
3668 return openTerminal(x
, y
, TWindow
.RESIZABLE
, commandLine
, closeOnExit
);
3672 * Convenience function to open a terminal window and execute a custom
3673 * command line inside it.
3675 * @param x column relative to parent
3676 * @param y row relative to parent
3677 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3678 * @param command the command line to execute
3679 * @return the terminal new window
3681 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3682 final int flags
, final String
[] command
) {
3684 return new TTerminalWindow(this, x
, y
, flags
, command
);
3688 * Convenience function to open a terminal window and execute a custom
3689 * command line inside it.
3691 * @param x column relative to parent
3692 * @param y row relative to parent
3693 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3694 * @param command the command line to execute
3695 * @param closeOnExit if true, close the window when the command exits
3696 * @return the terminal new window
3698 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3699 final int flags
, final String
[] command
, final boolean closeOnExit
) {
3701 return new TTerminalWindow(this, x
, y
, flags
, command
, closeOnExit
);
3705 * Convenience function to open a terminal window and execute a custom
3706 * command line inside it.
3708 * @param x column relative to parent
3709 * @param y row relative to parent
3710 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3711 * @param commandLine the command line to execute
3712 * @return the terminal new window
3714 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3715 final int flags
, final String commandLine
) {
3717 return new TTerminalWindow(this, x
, y
, flags
, commandLine
.split("\\s+"));
3721 * Convenience function to open a terminal window and execute a custom
3722 * command line inside it.
3724 * @param x column relative to parent
3725 * @param y row relative to parent
3726 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3727 * @param commandLine the command line to execute
3728 * @param closeOnExit if true, close the window when the command exits
3729 * @return the terminal new window
3731 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3732 final int flags
, final String commandLine
, final boolean closeOnExit
) {
3734 return new TTerminalWindow(this, x
, y
, flags
, commandLine
.split("\\s+"),
3739 * Convenience function to spawn an file open box.
3741 * @param path path of selected file
3742 * @return the result of the new file open box
3743 * @throws IOException if java.io operation throws
3745 public final String
fileOpenBox(final String path
) throws IOException
{
3747 TFileOpenBox box
= new TFileOpenBox(this, path
, TFileOpenBox
.Type
.OPEN
);
3748 return box
.getFilename();
3752 * Convenience function to spawn an file open box.
3754 * @param path path of selected file
3755 * @param type one of the Type constants
3756 * @return the result of the new file open box
3757 * @throws IOException if java.io operation throws
3759 public final String
fileOpenBox(final String path
,
3760 final TFileOpenBox
.Type type
) throws IOException
{
3762 TFileOpenBox box
= new TFileOpenBox(this, path
, type
);
3763 return box
.getFilename();
3767 * Convenience function to spawn a file open box.
3769 * @param path path of selected file
3770 * @param type one of the Type constants
3771 * @param filter a string that files must match to be displayed
3772 * @return the result of the new file open box
3773 * @throws IOException of a java.io operation throws
3775 public final String
fileOpenBox(final String path
,
3776 final TFileOpenBox
.Type type
, final String filter
) throws IOException
{
3778 ArrayList
<String
> filters
= new ArrayList
<String
>();
3779 filters
.add(filter
);
3781 TFileOpenBox box
= new TFileOpenBox(this, path
, type
, filters
);
3782 return box
.getFilename();
3786 * Convenience function to spawn a file open box.
3788 * @param path path of selected file
3789 * @param type one of the Type constants
3790 * @param filters a list of strings that files must match to be displayed
3791 * @return the result of the new file open box
3792 * @throws IOException of a java.io operation throws
3794 public final String
fileOpenBox(final String path
,
3795 final TFileOpenBox
.Type type
,
3796 final List
<String
> filters
) throws IOException
{
3798 TFileOpenBox box
= new TFileOpenBox(this, path
, type
, filters
);
3799 return box
.getFilename();
3803 * Convenience function to create a new window and make it active.
3804 * Window will be located at (0, 0).
3806 * @param title window title, will be centered along the top border
3807 * @param width width of window
3808 * @param height height of window
3809 * @return the new window
3811 public final TWindow
addWindow(final String title
, final int width
,
3814 TWindow window
= new TWindow(this, title
, 0, 0, width
, height
);
3819 * Convenience function to create a new window and make it active.
3820 * Window will be located at (0, 0).
3822 * @param title window title, will be centered along the top border
3823 * @param width width of window
3824 * @param height height of window
3825 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
3826 * @return the new window
3828 public final TWindow
addWindow(final String title
,
3829 final int width
, final int height
, final int flags
) {
3831 TWindow window
= new TWindow(this, title
, 0, 0, width
, height
, flags
);
3836 * Convenience function to create a new window and make it active.
3838 * @param title window title, will be centered along the top border
3839 * @param x column relative to parent
3840 * @param y row relative to parent
3841 * @param width width of window
3842 * @param height height of window
3843 * @return the new window
3845 public final TWindow
addWindow(final String title
,
3846 final int x
, final int y
, final int width
, final int height
) {
3848 TWindow window
= new TWindow(this, title
, x
, y
, width
, height
);
3853 * Convenience function to create a new window and make it active.
3855 * @param title window title, will be centered along the top border
3856 * @param x column relative to parent
3857 * @param y row relative to parent
3858 * @param width width of window
3859 * @param height height of window
3860 * @param flags mask of RESIZABLE, CENTERED, or MODAL
3861 * @return the new window
3863 public final TWindow
addWindow(final String title
,
3864 final int x
, final int y
, final int width
, final int height
,
3867 TWindow window
= new TWindow(this, title
, x
, y
, width
, height
, flags
);