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 version of mouse coordinate X.
170 private int oldMouseX
;
173 * Old version mouse coordinate Y.
175 private int oldMouseY
;
178 * Old drawn version of mouse coordinate X.
180 private int oldDrawnMouseX
;
183 * Old drawn version mouse coordinate Y.
185 private int oldDrawnMouseY
;
188 * Old drawn version mouse cell.
190 private Cell oldDrawnMouseCell
= new Cell();
193 * The last mouse up click time, used to determine if this is a mouse
196 private long lastMouseUpTime
;
199 * The amount of millis between mouse up events to assume a double-click.
201 private long doubleClickTime
= 250;
204 * Event queue that is filled by run().
206 private List
<TInputEvent
> fillEventQueue
;
209 * Event queue that will be drained by either primary or secondary
212 private List
<TInputEvent
> drainEventQueue
;
215 * Top-level menus in this application.
217 private List
<TMenu
> menus
;
220 * Stack of activated sub-menus in this application.
222 private List
<TMenu
> subMenus
;
225 * The currently active menu.
227 private TMenu activeMenu
= null;
230 * Active keyboard accelerators.
232 private Map
<TKeypress
, TMenuItem
> accelerators
;
237 private List
<TMenuItem
> menuItems
;
240 * Windows and widgets pull colors from this ColorTheme.
242 private ColorTheme theme
;
245 * The top-level windows (but not menus).
247 private List
<TWindow
> windows
;
250 * The currently acive window.
252 private TWindow activeWindow
= null;
255 * Timers that are being ticked.
257 private List
<TTimer
> timers
;
260 * When true, the application has been started.
262 private volatile boolean started
= false;
265 * When true, exit the application.
267 private volatile boolean quit
= false;
270 * When true, repaint the entire screen.
272 private volatile boolean repaint
= true;
275 * Y coordinate of the top edge of the desktop. For now this is a
276 * constant. Someday it would be nice to have a multi-line menu or
279 private int desktopTop
= 1;
282 * Y coordinate of the bottom edge of the desktop.
284 private int desktopBottom
;
287 * An optional TDesktop background window that is drawn underneath
290 private TDesktop desktop
;
293 * If true, focus follows mouse: windows automatically raised if the
294 * mouse passes over them.
296 private boolean focusFollowsMouse
= false;
299 * If true, display a text-based mouse cursor.
301 private boolean textMouse
= true;
304 * If true, hide the mouse after typing a keystroke.
306 private boolean hideMouseWhenTyping
= false;
309 * If true, the mouse should not be displayed because a keystroke was
312 private boolean typingHidMouse
= false;
315 * If true, hide the status bar.
317 private boolean hideStatusBar
= false;
320 * If true, hide the menu bar.
322 private boolean hideMenuBar
= false;
325 * The list of commands to run before the next I/O check.
327 private List
<Runnable
> invokeLaters
= new LinkedList
<Runnable
>();
330 * The last time the screen was resized.
332 private long screenResizeTime
= 0;
335 * If true, screen selection is a rectangle.
337 private boolean screenSelectionRectangle
= false;
340 * If true, the mouse is dragging a screen selection.
342 private boolean inScreenSelection
= false;
345 * Screen selection starting X.
347 private int screenSelectionX0
;
350 * Screen selection starting Y.
352 private int screenSelectionY0
;
355 * Screen selection ending X.
357 private int screenSelectionX1
;
360 * Screen selection ending Y.
362 private int screenSelectionY1
;
365 * WidgetEventHandler is the main event consumer loop. There are at most
366 * two such threads in existence: the primary for normal case and a
367 * secondary that is used for TMessageBox, TInputBox, and similar.
369 private class WidgetEventHandler
implements Runnable
{
371 * The main application.
373 private TApplication application
;
376 * Whether or not this WidgetEventHandler is the primary or secondary
379 private boolean primary
= true;
382 * Public constructor.
384 * @param application the main application
385 * @param primary if true, this is the primary event handler thread
387 public WidgetEventHandler(final TApplication application
,
388 final boolean primary
) {
390 this.application
= application
;
391 this.primary
= primary
;
398 // Wrap everything in a try, so that if we go belly up we can let
399 // the user have their terminal back.
402 } catch (Throwable t
) {
403 this.application
.restoreConsole();
405 this.application
.exit();
412 private void runImpl() {
413 boolean first
= true;
416 while (!application
.quit
) {
418 // Wait until application notifies me
419 while (!application
.quit
) {
421 synchronized (application
.drainEventQueue
) {
422 if (application
.drainEventQueue
.size() > 0) {
431 timeout
= application
.getSleepTime(1000);
435 // A timer needs to fire, break out.
440 System
.err
.printf("%d %s %s %s sleep %d millis\n",
441 System
.currentTimeMillis(), this,
442 primary ?
"primary" : "secondary",
443 Thread
.currentThread(), timeout
);
446 synchronized (this) {
451 System
.err
.printf("%d %s %s %s AWAKE\n",
452 System
.currentTimeMillis(), this,
453 primary ?
"primary" : "secondary",
454 Thread
.currentThread());
458 && (application
.secondaryEventReceiver
== null)
460 // Secondary thread, emergency exit. If we got
461 // here then something went wrong with the
462 // handoff between yield() and closeWindow().
463 synchronized (application
.primaryEventHandler
) {
464 application
.primaryEventHandler
.notify();
466 application
.secondaryEventHandler
= null;
467 throw new RuntimeException("secondary exited " +
471 } catch (InterruptedException e
) {
474 } // while (!application.quit)
476 // Pull all events off the queue
478 TInputEvent event
= null;
479 synchronized (application
.drainEventQueue
) {
480 if (application
.drainEventQueue
.size() == 0) {
483 event
= application
.drainEventQueue
.remove(0);
486 // We will have an event to process, so repaint the
487 // screen at the end.
488 application
.repaint
= true;
491 primaryHandleEvent(event
);
493 secondaryHandleEvent(event
);
496 && (application
.secondaryEventReceiver
== null)
498 // Secondary thread, time to exit.
500 // Eliminate my reference so that wakeEventHandler()
501 // resumes working on the primary.
502 application
.secondaryEventHandler
= null;
504 // We are ready to exit, wake up the primary thread.
505 // Remember that it is currently sleeping inside its
506 // primaryHandleEvent().
507 synchronized (application
.primaryEventHandler
) {
508 application
.primaryEventHandler
.notify();
517 // Fire timers, update screen.
519 application
.finishEventProcessing();
522 } // while (true) (main runnable loop)
527 * ScreenHandler pushes screen updates to the physical device.
529 private class ScreenHandler
implements Runnable
{
531 * The main application.
533 private TApplication application
;
538 private boolean dirty
= false;
541 * Public constructor.
543 * @param application the main application
545 public ScreenHandler(final TApplication application
) {
546 this.application
= application
;
550 * The screen update loop.
553 // Wrap everything in a try, so that if we go belly up we can let
554 // the user have their terminal back.
557 } catch (Throwable t
) {
558 this.application
.restoreConsole();
560 this.application
.exit();
567 private void runImpl() {
570 while (!application
.quit
) {
572 // Wait until application notifies me
573 while (!application
.quit
) {
575 synchronized (this) {
581 // Always check within 50 milliseconds.
584 } catch (InterruptedException e
) {
587 } // while (!application.quit)
589 // Flush the screen contents
591 System
.err
.printf("%d %s backend.flushScreen()\n",
592 System
.currentTimeMillis(), Thread
.currentThread());
594 synchronized (getScreen()) {
595 backend
.flushScreen();
597 } // while (true) (main runnable loop)
599 // Shutdown the user I/O thread(s)
604 * Set the dirty flag.
606 public void setDirty() {
607 synchronized (this) {
614 // ------------------------------------------------------------------------
615 // Constructors -----------------------------------------------------------
616 // ------------------------------------------------------------------------
619 * Public constructor.
621 * @param backendType BackendType.XTERM, BackendType.ECMA48 or
623 * @param windowWidth the number of text columns to start with
624 * @param windowHeight the number of text rows to start with
625 * @param fontSize the size in points
626 * @throws UnsupportedEncodingException if an exception is thrown when
627 * creating the InputStreamReader
629 public TApplication(final BackendType backendType
, final int windowWidth
,
630 final int windowHeight
, final int fontSize
)
631 throws UnsupportedEncodingException
{
633 switch (backendType
) {
635 backend
= new SwingBackend(this, windowWidth
, windowHeight
,
641 backend
= new ECMA48Backend(this, null, null, windowWidth
,
642 windowHeight
, fontSize
);
645 throw new IllegalArgumentException("Invalid backend type: "
652 * Public constructor.
654 * @param backendType BackendType.XTERM, BackendType.ECMA48 or
656 * @throws UnsupportedEncodingException if an exception is thrown when
657 * creating the InputStreamReader
659 public TApplication(final BackendType backendType
)
660 throws UnsupportedEncodingException
{
662 switch (backendType
) {
664 // The default SwingBackend is 80x25, 20 pt font. If you want to
665 // change that, you can pass the extra arguments to the
666 // SwingBackend constructor here. For example, if you wanted
667 // 90x30, 16 pt font:
669 // backend = new SwingBackend(this, 90, 30, 16);
670 backend
= new SwingBackend(this);
675 backend
= new ECMA48Backend(this, null, null);
678 throw new IllegalArgumentException("Invalid backend type: "
685 * Public constructor. The backend type will be BackendType.ECMA48.
687 * @param input an InputStream connected to the remote user, or null for
688 * System.in. If System.in is used, then on non-Windows systems it will
689 * be put in raw mode; shutdown() will (blindly!) put System.in in cooked
690 * mode. input is always converted to a Reader with UTF-8 encoding.
691 * @param output an OutputStream connected to the remote user, or null
692 * for System.out. output is always converted to a Writer with UTF-8
694 * @throws UnsupportedEncodingException if an exception is thrown when
695 * creating the InputStreamReader
697 public TApplication(final InputStream input
,
698 final OutputStream output
) throws UnsupportedEncodingException
{
700 backend
= new ECMA48Backend(this, input
, output
);
705 * Public constructor. The backend type will be BackendType.ECMA48.
707 * @param input the InputStream underlying 'reader'. Its available()
708 * method is used to determine if reader.read() will block or not.
709 * @param reader a Reader connected to the remote user.
710 * @param writer a PrintWriter connected to the remote user.
711 * @param setRawMode if true, set System.in into raw mode with stty.
712 * This should in general not be used. It is here solely for Demo3,
713 * which uses System.in.
714 * @throws IllegalArgumentException if input, reader, or writer are null.
716 public TApplication(final InputStream input
, final Reader reader
,
717 final PrintWriter writer
, final boolean setRawMode
) {
719 backend
= new ECMA48Backend(this, input
, reader
, writer
, setRawMode
);
724 * Public constructor. The backend type will be BackendType.ECMA48.
726 * @param input the InputStream underlying 'reader'. Its available()
727 * method is used to determine if reader.read() will block or not.
728 * @param reader a Reader connected to the remote user.
729 * @param writer a PrintWriter connected to the remote user.
730 * @throws IllegalArgumentException if input, reader, or writer are null.
732 public TApplication(final InputStream input
, final Reader reader
,
733 final PrintWriter writer
) {
735 this(input
, reader
, writer
, false);
739 * Public constructor. This hook enables use with new non-Jexer
742 * @param backend a Backend that is already ready to go.
744 public TApplication(final Backend backend
) {
745 this.backend
= backend
;
746 backend
.setListener(this);
751 * Finish construction once the backend is set.
753 private void TApplicationImpl() {
754 // Text block mouse option
755 if (System
.getProperty("jexer.textMouse", "true").equals("false")) {
759 // Hide mouse when typing option
760 if (System
.getProperty("jexer.hideMouseWhenTyping",
761 "false").equals("true")) {
763 hideMouseWhenTyping
= true;
766 // Hide status bar option
767 if (System
.getProperty("jexer.hideStatusBar",
768 "false").equals("true")) {
769 hideStatusBar
= true;
772 // Hide menu bar option
773 if (System
.getProperty("jexer.hideMenuBar", "false").equals("true")) {
777 theme
= new ColorTheme();
778 desktopTop
= (hideMenuBar ?
0 : 1);
779 desktopBottom
= getScreen().getHeight() - 1 + (hideStatusBar ?
1 : 0);
780 fillEventQueue
= new LinkedList
<TInputEvent
>();
781 drainEventQueue
= new LinkedList
<TInputEvent
>();
782 windows
= new LinkedList
<TWindow
>();
783 menus
= new ArrayList
<TMenu
>();
784 subMenus
= new ArrayList
<TMenu
>();
785 timers
= new LinkedList
<TTimer
>();
786 accelerators
= new HashMap
<TKeypress
, TMenuItem
>();
787 menuItems
= new LinkedList
<TMenuItem
>();
788 desktop
= new TDesktop(this);
790 // Special case: the Swing backend needs to have a timer to drive its
792 if ((backend
instanceof SwingBackend
)
793 || (backend
instanceof MultiBackend
)
795 // Default to 500 millis, unless a SwingBackend has its own
798 if (backend
instanceof SwingBackend
) {
799 millis
= ((SwingBackend
) backend
).getBlinkMillis();
802 addTimer(millis
, true,
805 TApplication
.this.doRepaint();
814 // ------------------------------------------------------------------------
815 // Runnable ---------------------------------------------------------------
816 // ------------------------------------------------------------------------
819 * Run this application until it exits.
822 // System.err.println("*** TApplication.run() begins ***");
824 // Start the screen updater thread
825 screenHandler
= new ScreenHandler(this);
826 (new Thread(screenHandler
)).start();
828 // Start the main consumer thread
829 primaryEventHandler
= new WidgetEventHandler(this, true);
830 (new Thread(primaryEventHandler
)).start();
835 synchronized (this) {
836 boolean doWait
= false;
838 if (!backend
.hasEvents()) {
839 synchronized (fillEventQueue
) {
840 if (fillEventQueue
.size() == 0) {
847 // No I/O to dispatch, so wait until the backend
851 System
.err
.println(System
.currentTimeMillis() +
852 " " + Thread
.currentThread() + " MAIN sleep");
858 System
.err
.println(System
.currentTimeMillis() +
859 " " + Thread
.currentThread() + " MAIN AWAKE");
861 } catch (InterruptedException e
) {
862 // I'm awake and don't care why, let's see what's
863 // going on out there.
867 } // synchronized (this)
869 synchronized (fillEventQueue
) {
870 // Pull any pending I/O events
871 backend
.getEvents(fillEventQueue
);
873 // Dispatch each event to the appropriate handler, one at a
876 TInputEvent event
= null;
877 if (fillEventQueue
.size() == 0) {
880 event
= fillEventQueue
.remove(0);
881 metaHandleEvent(event
);
885 // Wake a consumer thread if we have any pending events.
886 if (drainEventQueue
.size() > 0) {
892 // Shutdown the event consumer threads
893 if (secondaryEventHandler
!= null) {
894 synchronized (secondaryEventHandler
) {
895 secondaryEventHandler
.notify();
898 if (primaryEventHandler
!= null) {
899 synchronized (primaryEventHandler
) {
900 primaryEventHandler
.notify();
904 // Close all the windows. This gives them an opportunity to release
908 // Close the desktop.
909 if (desktop
!= null) {
913 // Give the overarching application an opportunity to release
917 // System.err.println("*** TApplication.run() exits ***");
920 // ------------------------------------------------------------------------
921 // Event handlers ---------------------------------------------------------
922 // ------------------------------------------------------------------------
925 * Method that TApplication subclasses can override to handle menu or
926 * posted command events.
928 * @param command command event
929 * @return if true, this event was consumed
931 protected boolean onCommand(final TCommandEvent command
) {
932 // Default: handle cmExit
933 if (command
.equals(cmExit
)) {
934 if (messageBox(i18n
.getString("exitDialogTitle"),
935 i18n
.getString("exitDialogText"),
936 TMessageBox
.Type
.YESNO
).isYes()) {
943 if (command
.equals(cmShell
)) {
944 openTerminal(0, 0, TWindow
.RESIZABLE
);
948 if (command
.equals(cmTile
)) {
952 if (command
.equals(cmCascade
)) {
956 if (command
.equals(cmCloseAll
)) {
961 if (command
.equals(cmMenu
) && (hideMenuBar
== false)) {
962 if (!modalWindowActive() && (activeMenu
== null)) {
963 if (menus
.size() > 0) {
964 menus
.get(0).setActive(true);
965 activeMenu
= menus
.get(0);
975 * Method that TApplication subclasses can override to handle menu
978 * @param menu menu event
979 * @return if true, this event was consumed
981 protected boolean onMenu(final TMenuEvent menu
) {
983 // Default: handle MID_EXIT
984 if (menu
.getId() == TMenu
.MID_EXIT
) {
985 if (messageBox(i18n
.getString("exitDialogTitle"),
986 i18n
.getString("exitDialogText"),
987 TMessageBox
.Type
.YESNO
).isYes()) {
994 if (menu
.getId() == TMenu
.MID_SHELL
) {
995 openTerminal(0, 0, TWindow
.RESIZABLE
);
999 if (menu
.getId() == TMenu
.MID_TILE
) {
1003 if (menu
.getId() == TMenu
.MID_CASCADE
) {
1007 if (menu
.getId() == TMenu
.MID_CLOSE_ALL
) {
1011 if (menu
.getId() == TMenu
.MID_ABOUT
) {
1015 if (menu
.getId() == TMenu
.MID_REPAINT
) {
1016 getScreen().clearPhysical();
1020 if (menu
.getId() == TMenu
.MID_VIEW_IMAGE
) {
1024 if (menu
.getId() == TMenu
.MID_SCREEN_OPTIONS
) {
1025 new TFontChooserWindow(this);
1029 if (menu
.getId() == TMenu
.MID_CUT
) {
1030 postMenuEvent(new TCommandEvent(cmCut
));
1033 if (menu
.getId() == TMenu
.MID_COPY
) {
1034 postMenuEvent(new TCommandEvent(cmCopy
));
1037 if (menu
.getId() == TMenu
.MID_PASTE
) {
1038 postMenuEvent(new TCommandEvent(cmPaste
));
1041 if (menu
.getId() == TMenu
.MID_CLEAR
) {
1042 postMenuEvent(new TCommandEvent(cmClear
));
1050 * Method that TApplication subclasses can override to handle keystrokes.
1052 * @param keypress keystroke event
1053 * @return if true, this event was consumed
1055 protected boolean onKeypress(final TKeypressEvent keypress
) {
1056 // Default: only menu shortcuts
1058 // Process Alt-F, Alt-E, etc. menu shortcut keys
1059 if (!keypress
.getKey().isFnKey()
1060 && keypress
.getKey().isAlt()
1061 && !keypress
.getKey().isCtrl()
1062 && (activeMenu
== null)
1063 && !modalWindowActive()
1064 && (hideMenuBar
== false)
1067 assert (subMenus
.size() == 0);
1069 for (TMenu menu
: menus
) {
1070 if (Character
.toLowerCase(menu
.getMnemonic().getShortcut())
1071 == Character
.toLowerCase(keypress
.getKey().getChar())
1074 menu
.setActive(true);
1084 * Process background events, and update the screen.
1086 private void finishEventProcessing() {
1088 System
.err
.printf(System
.currentTimeMillis() + " " +
1089 Thread
.currentThread() + " finishEventProcessing()\n");
1092 // See if we need to enable/disable the edit menu.
1093 EditMenuUser widget
= null;
1094 if (activeMenu
== null) {
1095 if (activeWindow
!= null) {
1096 if (activeWindow
.getActiveChild() instanceof EditMenuUser
) {
1097 widget
= (EditMenuUser
) activeWindow
.getActiveChild();
1099 } else if (desktop
!= null) {
1100 if (desktop
.getActiveChild() instanceof EditMenuUser
) {
1101 widget
= (EditMenuUser
) desktop
.getActiveChild();
1104 if (widget
== null) {
1105 disableMenuItem(TMenu
.MID_CUT
);
1106 disableMenuItem(TMenu
.MID_COPY
);
1107 disableMenuItem(TMenu
.MID_PASTE
);
1108 disableMenuItem(TMenu
.MID_CLEAR
);
1110 if (widget
.isEditMenuCut()) {
1111 enableMenuItem(TMenu
.MID_CUT
);
1113 disableMenuItem(TMenu
.MID_CUT
);
1115 if (widget
.isEditMenuCopy()) {
1116 enableMenuItem(TMenu
.MID_COPY
);
1118 disableMenuItem(TMenu
.MID_COPY
);
1120 if (widget
.isEditMenuPaste()) {
1121 enableMenuItem(TMenu
.MID_PASTE
);
1123 disableMenuItem(TMenu
.MID_PASTE
);
1125 if (widget
.isEditMenuClear()) {
1126 enableMenuItem(TMenu
.MID_CLEAR
);
1128 disableMenuItem(TMenu
.MID_CLEAR
);
1133 // Process timers and call doIdle()'s
1136 // Update the screen
1137 synchronized (getScreen()) {
1141 // Wake up the screen repainter
1142 wakeScreenHandler();
1145 System
.err
.printf(System
.currentTimeMillis() + " " +
1146 Thread
.currentThread() + " finishEventProcessing() END\n");
1151 * Peek at certain application-level events, add to eventQueue, and wake
1152 * up the consuming Thread.
1154 * @param event the input event to consume
1156 private void metaHandleEvent(final TInputEvent event
) {
1159 System
.err
.printf(String
.format("metaHandleEvents event: %s\n",
1160 event
)); System
.err
.flush();
1164 // Do no more processing if the application is already trying
1169 // Special application-wide events -------------------------------
1172 if (event
instanceof TCommandEvent
) {
1173 TCommandEvent command
= (TCommandEvent
) event
;
1174 if (command
.equals(cmAbort
)) {
1180 synchronized (drainEventQueue
) {
1182 if (event
instanceof TResizeEvent
) {
1183 TResizeEvent resize
= (TResizeEvent
) event
;
1184 synchronized (getScreen()) {
1185 if ((System
.currentTimeMillis() - screenResizeTime
>= 15)
1186 || (resize
.getWidth() < getScreen().getWidth())
1187 || (resize
.getHeight() < getScreen().getHeight())
1189 getScreen().setDimensions(resize
.getWidth(),
1190 resize
.getHeight());
1191 screenResizeTime
= System
.currentTimeMillis();
1193 desktopBottom
= getScreen().getHeight() - 1;
1194 if (hideStatusBar
) {
1202 if (desktop
!= null) {
1203 desktop
.setDimensions(0, desktopTop
, resize
.getWidth(),
1204 (desktopBottom
- desktopTop
));
1205 desktop
.onResize(resize
);
1208 // Change menu edges if needed.
1211 // We are dirty, redraw the screen.
1215 System.err.println("New screen: " + resize.getWidth() +
1216 " x " + resize.getHeight());
1221 // Put into the main queue
1222 drainEventQueue
.add(event
);
1227 * Dispatch one event to the appropriate widget or application-level
1228 * event handler. This is the primary event handler, it has the normal
1229 * application-wide event handling.
1231 * @param event the input event to consume
1232 * @see #secondaryHandleEvent(TInputEvent event)
1234 private void primaryHandleEvent(final TInputEvent event
) {
1237 System
.err
.printf("%s primaryHandleEvent: %s\n",
1238 Thread
.currentThread(), event
);
1240 TMouseEvent doubleClick
= null;
1242 // Special application-wide events -----------------------------------
1244 if (event
instanceof TKeypressEvent
) {
1245 if (hideMouseWhenTyping
) {
1246 typingHidMouse
= true;
1250 // Peek at the mouse position
1251 if (event
instanceof TMouseEvent
) {
1252 typingHidMouse
= false;
1254 TMouseEvent mouse
= (TMouseEvent
) event
;
1255 if (mouse
.isMouse1() && (mouse
.isShift() || mouse
.isCtrl())) {
1256 // Screen selection.
1257 if (inScreenSelection
) {
1258 screenSelectionX1
= mouse
.getX();
1259 screenSelectionY1
= mouse
.getY();
1261 inScreenSelection
= true;
1262 screenSelectionX0
= mouse
.getX();
1263 screenSelectionY0
= mouse
.getY();
1264 screenSelectionX1
= mouse
.getX();
1265 screenSelectionY1
= mouse
.getY();
1266 screenSelectionRectangle
= mouse
.isCtrl();
1269 if (inScreenSelection
) {
1270 getScreen().copySelection(clipboard
, screenSelectionX0
,
1271 screenSelectionY0
, screenSelectionX1
, screenSelectionY1
,
1272 screenSelectionRectangle
);
1274 inScreenSelection
= false;
1277 if ((mouseX
!= mouse
.getX()) || (mouseY
!= mouse
.getY())) {
1280 mouseX
= mouse
.getX();
1281 mouseY
= mouse
.getY();
1283 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
1284 && (!mouse
.isMouseWheelUp())
1285 && (!mouse
.isMouseWheelDown())
1287 if ((mouse
.getTime().getTime() - lastMouseUpTime
) <
1290 // This is a double-click.
1291 doubleClick
= new TMouseEvent(TMouseEvent
.Type
.
1293 mouse
.getX(), mouse
.getY(),
1294 mouse
.getAbsoluteX(), mouse
.getAbsoluteY(),
1295 mouse
.isMouse1(), mouse
.isMouse2(),
1297 mouse
.isMouseWheelUp(), mouse
.isMouseWheelDown(),
1298 mouse
.isAlt(), mouse
.isCtrl(), mouse
.isShift());
1301 // The first click of a potential double-click.
1302 lastMouseUpTime
= mouse
.getTime().getTime();
1307 // See if we need to switch focus to another window or the menu
1308 checkSwitchFocus((TMouseEvent
) event
);
1311 // Handle menu events
1312 if ((activeMenu
!= null) && !(event
instanceof TCommandEvent
)) {
1313 TMenu menu
= activeMenu
;
1315 if (event
instanceof TMouseEvent
) {
1316 TMouseEvent mouse
= (TMouseEvent
) event
;
1318 while (subMenus
.size() > 0) {
1319 TMenu subMenu
= subMenus
.get(subMenus
.size() - 1);
1320 if (subMenu
.mouseWouldHit(mouse
)) {
1323 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
)
1324 && (!mouse
.isMouse1())
1325 && (!mouse
.isMouse2())
1326 && (!mouse
.isMouse3())
1327 && (!mouse
.isMouseWheelUp())
1328 && (!mouse
.isMouseWheelDown())
1332 // We navigated away from a sub-menu, so close it
1336 // Convert the mouse relative x/y to menu coordinates
1337 assert (mouse
.getX() == mouse
.getAbsoluteX());
1338 assert (mouse
.getY() == mouse
.getAbsoluteY());
1339 if (subMenus
.size() > 0) {
1340 menu
= subMenus
.get(subMenus
.size() - 1);
1342 mouse
.setX(mouse
.getX() - menu
.getX());
1343 mouse
.setY(mouse
.getY() - menu
.getY());
1345 menu
.handleEvent(event
);
1349 if (event
instanceof TKeypressEvent
) {
1350 TKeypressEvent keypress
= (TKeypressEvent
) event
;
1352 // See if this key matches an accelerator, and is not being
1353 // shortcutted by the active window, and if so dispatch the menu
1355 boolean windowWillShortcut
= false;
1356 if (activeWindow
!= null) {
1357 assert (activeWindow
.isShown());
1358 if (activeWindow
.isShortcutKeypress(keypress
.getKey())) {
1359 // We do not process this key, it will be passed to the
1361 windowWillShortcut
= true;
1365 if (!windowWillShortcut
&& !modalWindowActive()) {
1366 TKeypress keypressLowercase
= keypress
.getKey().toLowerCase();
1367 TMenuItem item
= null;
1368 synchronized (accelerators
) {
1369 item
= accelerators
.get(keypressLowercase
);
1372 if (item
.isEnabled()) {
1373 // Let the menu item dispatch
1379 // Handle the keypress
1380 if (onKeypress(keypress
)) {
1386 if (event
instanceof TCommandEvent
) {
1387 if (onCommand((TCommandEvent
) event
)) {
1392 if (event
instanceof TMenuEvent
) {
1393 if (onMenu((TMenuEvent
) event
)) {
1398 // Dispatch events to the active window -------------------------------
1399 boolean dispatchToDesktop
= true;
1400 TWindow window
= activeWindow
;
1401 if (window
!= null) {
1402 assert (window
.isActive());
1403 assert (window
.isShown());
1404 if (event
instanceof TMouseEvent
) {
1405 TMouseEvent mouse
= (TMouseEvent
) event
;
1406 // Convert the mouse relative x/y to window coordinates
1407 assert (mouse
.getX() == mouse
.getAbsoluteX());
1408 assert (mouse
.getY() == mouse
.getAbsoluteY());
1409 mouse
.setX(mouse
.getX() - window
.getX());
1410 mouse
.setY(mouse
.getY() - window
.getY());
1412 if (doubleClick
!= null) {
1413 doubleClick
.setX(doubleClick
.getX() - window
.getX());
1414 doubleClick
.setY(doubleClick
.getY() - window
.getY());
1417 if (window
.mouseWouldHit(mouse
)) {
1418 dispatchToDesktop
= false;
1420 } else if (event
instanceof TKeypressEvent
) {
1421 dispatchToDesktop
= false;
1422 } else if (event
instanceof TMenuEvent
) {
1423 dispatchToDesktop
= false;
1427 System
.err
.printf("TApplication dispatch event: %s\n",
1430 window
.handleEvent(event
);
1431 if (doubleClick
!= null) {
1432 window
.handleEvent(doubleClick
);
1435 if (dispatchToDesktop
) {
1436 // This event is fair game for the desktop to process.
1437 if (desktop
!= null) {
1438 desktop
.handleEvent(event
);
1439 if (doubleClick
!= null) {
1440 desktop
.handleEvent(doubleClick
);
1447 * Dispatch one event to the appropriate widget or application-level
1448 * event handler. This is the secondary event handler used by certain
1449 * special dialogs (currently TMessageBox and TFileOpenBox).
1451 * @param event the input event to consume
1452 * @see #primaryHandleEvent(TInputEvent event)
1454 private void secondaryHandleEvent(final TInputEvent event
) {
1455 TMouseEvent doubleClick
= null;
1458 System
.err
.printf("%s secondaryHandleEvent: %s\n",
1459 Thread
.currentThread(), event
);
1462 // Peek at the mouse position
1463 if (event
instanceof TMouseEvent
) {
1464 typingHidMouse
= false;
1466 TMouseEvent mouse
= (TMouseEvent
) event
;
1467 if ((mouseX
!= mouse
.getX()) || (mouseY
!= mouse
.getY())) {
1470 mouseX
= mouse
.getX();
1471 mouseY
= mouse
.getY();
1473 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
1474 && (!mouse
.isMouseWheelUp())
1475 && (!mouse
.isMouseWheelDown())
1477 if ((mouse
.getTime().getTime() - lastMouseUpTime
) <
1480 // This is a double-click.
1481 doubleClick
= new TMouseEvent(TMouseEvent
.Type
.
1483 mouse
.getX(), mouse
.getY(),
1484 mouse
.getAbsoluteX(), mouse
.getAbsoluteY(),
1485 mouse
.isMouse1(), mouse
.isMouse2(),
1487 mouse
.isMouseWheelUp(), mouse
.isMouseWheelDown(),
1488 mouse
.isAlt(), mouse
.isCtrl(), mouse
.isShift());
1491 // The first click of a potential double-click.
1492 lastMouseUpTime
= mouse
.getTime().getTime();
1498 secondaryEventReceiver
.handleEvent(event
);
1499 // Note that it is possible for secondaryEventReceiver to be null
1500 // now, because its handleEvent() might have finished out on the
1501 // secondary thread. So put any extra processing inside a null
1503 if (secondaryEventReceiver
!= null) {
1504 if (doubleClick
!= null) {
1505 secondaryEventReceiver
.handleEvent(doubleClick
);
1511 * Enable a widget to override the primary event thread.
1513 * @param widget widget that will receive events
1515 public final void enableSecondaryEventReceiver(final TWidget widget
) {
1517 System
.err
.println(System
.currentTimeMillis() +
1518 " enableSecondaryEventReceiver()");
1521 assert (secondaryEventReceiver
== null);
1522 assert (secondaryEventHandler
== null);
1523 assert ((widget
instanceof TMessageBox
)
1524 || (widget
instanceof TFileOpenBox
));
1525 secondaryEventReceiver
= widget
;
1526 secondaryEventHandler
= new WidgetEventHandler(this, false);
1528 (new Thread(secondaryEventHandler
)).start();
1532 * Yield to the secondary thread.
1534 public final void yield() {
1536 System
.err
.printf(System
.currentTimeMillis() + " " +
1537 Thread
.currentThread() + " yield()\n");
1540 assert (secondaryEventReceiver
!= null);
1542 while (secondaryEventReceiver
!= null) {
1543 synchronized (primaryEventHandler
) {
1545 primaryEventHandler
.wait();
1546 } catch (InterruptedException e
) {
1554 * Do stuff when there is no user input.
1556 private void doIdle() {
1558 System
.err
.printf(System
.currentTimeMillis() + " " +
1559 Thread
.currentThread() + " doIdle()\n");
1562 synchronized (timers
) {
1565 System
.err
.printf(System
.currentTimeMillis() + " " +
1566 Thread
.currentThread() + " doIdle() 2\n");
1569 // Run any timers that have timed out
1570 Date now
= new Date();
1571 List
<TTimer
> keepTimers
= new LinkedList
<TTimer
>();
1572 for (TTimer timer
: timers
) {
1573 if (timer
.getNextTick().getTime() <= now
.getTime()) {
1574 // Something might change, so repaint the screen.
1577 if (timer
.recurring
) {
1578 keepTimers
.add(timer
);
1581 keepTimers
.add(timer
);
1585 timers
.addAll(keepTimers
);
1589 for (TWindow window
: windows
) {
1592 if (desktop
!= null) {
1596 // Run any invokeLaters
1597 synchronized (invokeLaters
) {
1598 for (Runnable invoke
: invokeLaters
) {
1601 invokeLaters
.clear();
1607 * Wake the sleeping active event handler.
1609 private void wakeEventHandler() {
1614 if (secondaryEventHandler
!= null) {
1615 synchronized (secondaryEventHandler
) {
1616 secondaryEventHandler
.notify();
1619 assert (primaryEventHandler
!= null);
1620 synchronized (primaryEventHandler
) {
1621 primaryEventHandler
.notify();
1627 * Wake the sleeping screen handler.
1629 private void wakeScreenHandler() {
1634 synchronized (screenHandler
) {
1635 screenHandler
.notify();
1639 // ------------------------------------------------------------------------
1640 // TApplication -----------------------------------------------------------
1641 // ------------------------------------------------------------------------
1644 * Place a command on the run queue, and run it before the next round of
1647 * @param command the command to run later
1649 public void invokeLater(final Runnable command
) {
1650 synchronized (invokeLaters
) {
1651 invokeLaters
.add(command
);
1657 * Restore the console to sane defaults. This is meant to be used for
1658 * improper exits (e.g. a caught exception in main()), and should not be
1659 * necessary for normal program termination.
1661 public void restoreConsole() {
1662 if (backend
!= null) {
1663 if (backend
instanceof ECMA48Backend
) {
1672 * @return the Backend
1674 public final Backend
getBackend() {
1681 * @return the Screen
1683 public final Screen
getScreen() {
1684 if (backend
instanceof TWindowBackend
) {
1685 // We are being rendered to a TWindow. We can't use its
1686 // getScreen() method because that is how it is rendering to a
1687 // hardware backend somewhere. Instead use its getOtherScreen()
1689 return ((TWindowBackend
) backend
).getOtherScreen();
1691 return backend
.getScreen();
1696 * Get the color theme.
1700 public final ColorTheme
getTheme() {
1705 * Get the clipboard.
1707 * @return the clipboard
1709 public final Clipboard
getClipboard() {
1714 * Repaint the screen on the next update.
1716 public void doRepaint() {
1722 * Get Y coordinate of the top edge of the desktop.
1724 * @return Y coordinate of the top edge of the desktop
1726 public final int getDesktopTop() {
1731 * Get Y coordinate of the bottom edge of the desktop.
1733 * @return Y coordinate of the bottom edge of the desktop
1735 public final int getDesktopBottom() {
1736 return desktopBottom
;
1740 * Set the TDesktop instance.
1742 * @param desktop a TDesktop instance, or null to remove the one that is
1745 public final void setDesktop(final TDesktop desktop
) {
1746 if (this.desktop
!= null) {
1747 this.desktop
.onPreClose();
1748 this.desktop
.onUnfocus();
1749 this.desktop
.onClose();
1751 this.desktop
= desktop
;
1755 * Get the TDesktop instance.
1757 * @return the desktop, or null if it is not set
1759 public final TDesktop
getDesktop() {
1764 * Get the current active window.
1766 * @return the active window, or null if it is not set
1768 public final TWindow
getActiveWindow() {
1769 return activeWindow
;
1773 * Get a (shallow) copy of the window list.
1775 * @return a copy of the list of windows for this application
1777 public final List
<TWindow
> getAllWindows() {
1778 List
<TWindow
> result
= new ArrayList
<TWindow
>();
1779 result
.addAll(windows
);
1784 * Get focusFollowsMouse flag.
1786 * @return true if focus follows mouse: windows automatically raised if
1787 * the mouse passes over them
1789 public boolean getFocusFollowsMouse() {
1790 return focusFollowsMouse
;
1794 * Set focusFollowsMouse flag.
1796 * @param focusFollowsMouse if true, focus follows mouse: windows
1797 * automatically raised if the mouse passes over them
1799 public void setFocusFollowsMouse(final boolean focusFollowsMouse
) {
1800 this.focusFollowsMouse
= focusFollowsMouse
;
1804 * Display the about dialog.
1806 protected void showAboutDialog() {
1807 String version
= getClass().getPackage().getImplementationVersion();
1808 if (version
== null) {
1809 // This is Java 9+, use a hardcoded string here.
1812 messageBox(i18n
.getString("aboutDialogTitle"),
1813 MessageFormat
.format(i18n
.getString("aboutDialogText"), version
),
1814 TMessageBox
.Type
.OK
);
1818 * Handle the Tool | Open image menu item.
1820 private void openImage() {
1822 List
<String
> filters
= new ArrayList
<String
>();
1823 filters
.add("^.*\\.[Jj][Pp][Gg]$");
1824 filters
.add("^.*\\.[Jj][Pp][Ee][Gg]$");
1825 filters
.add("^.*\\.[Pp][Nn][Gg]$");
1826 filters
.add("^.*\\.[Gg][Ii][Ff]$");
1827 filters
.add("^.*\\.[Bb][Mm][Pp]$");
1828 String filename
= fileOpenBox(".", TFileOpenBox
.Type
.OPEN
, filters
);
1829 if (filename
!= null) {
1830 new TImageWindow(this, new File(filename
));
1832 } catch (IOException e
) {
1833 // Show this exception to the user.
1834 new TExceptionDialog(this, e
);
1839 * Check if application is still running.
1841 * @return true if the application is running
1843 public final boolean isRunning() {
1850 // ------------------------------------------------------------------------
1851 // Screen refresh loop ----------------------------------------------------
1852 // ------------------------------------------------------------------------
1855 * Draw the text mouse at position.
1857 * @param x column position
1858 * @param y row position
1860 private void drawTextMouse(final int x
, final int y
) {
1863 System
.err
.printf("%d %s drawTextMouse() %d %d\n",
1864 System
.currentTimeMillis(), Thread
.currentThread(), x
, y
);
1866 if (activeWindow
!= null) {
1867 System
.err
.println("activeWindow.hasHiddenMouse() " +
1868 activeWindow
.hasHiddenMouse());
1872 // If this cell is on top of a visible window that has requested a
1873 // hidden mouse, bail out.
1874 if ((activeWindow
!= null) && (activeMenu
== null)) {
1875 if ((activeWindow
.hasHiddenMouse() == true)
1876 && (x
> activeWindow
.getX())
1877 && (x
< activeWindow
.getX() + activeWindow
.getWidth() - 1)
1878 && (y
> activeWindow
.getY())
1879 && (y
< activeWindow
.getY() + activeWindow
.getHeight() - 1)
1885 // If this cell is on top of the desktop, and the desktop has
1886 // requested a hidden mouse, bail out.
1887 if ((desktop
!= null) && (activeWindow
== null) && (activeMenu
== null)) {
1888 if ((desktop
.hasHiddenMouse() == true)
1889 && (x
> desktop
.getX())
1890 && (x
< desktop
.getX() + desktop
.getWidth() - 1)
1891 && (y
> desktop
.getY())
1892 && (y
< desktop
.getY() + desktop
.getHeight() - 1)
1898 getScreen().invertCell(x
, y
);
1904 private void drawAll() {
1905 boolean menuIsActive
= false;
1908 System
.err
.printf("%d %s drawAll() enter\n",
1909 System
.currentTimeMillis(), Thread
.currentThread());
1912 // I don't think this does anything useful anymore...
1915 System
.err
.printf("%d %s drawAll() !repaint\n",
1916 System
.currentTimeMillis(), Thread
.currentThread());
1918 if ((oldDrawnMouseX
!= mouseX
) || (oldDrawnMouseY
!= mouseY
)) {
1920 System
.err
.printf("%d %s drawAll() !repaint MOUSE\n",
1921 System
.currentTimeMillis(), Thread
.currentThread());
1924 // The only thing that has happened is the mouse moved.
1926 // Redraw the old cell at that position, and save the cell at
1927 // the new mouse position.
1929 System
.err
.printf("%d %s restoreImage() %d %d\n",
1930 System
.currentTimeMillis(), Thread
.currentThread(),
1931 oldDrawnMouseX
, oldDrawnMouseY
);
1933 oldDrawnMouseCell
.restoreImage();
1934 getScreen().putCharXY(oldDrawnMouseX
, oldDrawnMouseY
,
1936 oldDrawnMouseCell
= getScreen().getCharXY(mouseX
, mouseY
);
1937 if (backend
instanceof ECMA48Backend
) {
1938 // Special case: the entire row containing the mouse has
1939 // to be re-drawn if it has any image data, AND any rows
1941 if (oldDrawnMouseY
!= mouseY
) {
1942 for (int i
= oldDrawnMouseY
; ;) {
1943 getScreen().unsetImageRow(i
);
1947 if (oldDrawnMouseY
< mouseY
) {
1954 getScreen().unsetImageRow(mouseY
);
1958 if (inScreenSelection
) {
1959 getScreen().setSelection(screenSelectionX0
,
1960 screenSelectionY0
, screenSelectionX1
, screenSelectionY1
,
1961 screenSelectionRectangle
);
1964 if ((textMouse
== true) && (typingHidMouse
== false)) {
1965 // Draw mouse at the new position.
1966 drawTextMouse(mouseX
, mouseY
);
1969 oldDrawnMouseX
= mouseX
;
1970 oldDrawnMouseY
= mouseY
;
1972 if (getScreen().isDirty()) {
1973 screenHandler
.setDirty();
1979 System
.err
.printf("%d %s drawAll() REDRAW\n",
1980 System
.currentTimeMillis(), Thread
.currentThread());
1983 // If true, the cursor is not visible
1984 boolean cursor
= false;
1986 // Start with a clean screen
1987 getScreen().clear();
1990 if (desktop
!= null) {
1991 desktop
.drawChildren();
1994 // Draw each window in reverse Z order
1995 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
1996 Collections
.sort(sorted
);
1997 TWindow topLevel
= null;
1998 if (sorted
.size() > 0) {
1999 topLevel
= sorted
.get(0);
2001 Collections
.reverse(sorted
);
2002 for (TWindow window
: sorted
) {
2003 if (window
.isShown()) {
2004 window
.drawChildren();
2008 if (hideMenuBar
== false) {
2010 // Draw the blank menubar line - reset the screen clipping first
2011 // so it won't trim it out.
2012 getScreen().resetClipping();
2013 getScreen().hLineXY(0, 0, getScreen().getWidth(), ' ',
2014 theme
.getColor("tmenu"));
2015 // Now draw the menus.
2017 for (TMenu menu
: menus
) {
2018 CellAttributes menuColor
;
2019 CellAttributes menuMnemonicColor
;
2020 if (menu
.isActive()) {
2021 menuIsActive
= true;
2022 menuColor
= theme
.getColor("tmenu.highlighted");
2023 menuMnemonicColor
= theme
.getColor("tmenu.mnemonic.highlighted");
2026 menuColor
= theme
.getColor("tmenu");
2027 menuMnemonicColor
= theme
.getColor("tmenu.mnemonic");
2029 // Draw the menu title
2030 getScreen().hLineXY(x
, 0,
2031 StringUtils
.width(menu
.getTitle()) + 2, ' ', menuColor
);
2032 getScreen().putStringXY(x
+ 1, 0, menu
.getTitle(), menuColor
);
2033 // Draw the highlight character
2034 getScreen().putCharXY(x
+ 1 +
2035 menu
.getMnemonic().getScreenShortcutIdx(),
2036 0, menu
.getMnemonic().getShortcut(), menuMnemonicColor
);
2038 if (menu
.isActive()) {
2039 ((TWindow
) menu
).drawChildren();
2040 // Reset the screen clipping so we can draw the next
2042 getScreen().resetClipping();
2044 x
+= StringUtils
.width(menu
.getTitle()) + 2;
2047 for (TMenu menu
: subMenus
) {
2048 // Reset the screen clipping so we can draw the next
2050 getScreen().resetClipping();
2051 ((TWindow
) menu
).drawChildren();
2054 getScreen().resetClipping();
2056 if (hideStatusBar
== false) {
2057 // Draw the status bar of the top-level window
2058 TStatusBar statusBar
= null;
2059 if (topLevel
!= null) {
2060 statusBar
= topLevel
.getStatusBar();
2062 if (statusBar
!= null) {
2063 getScreen().resetClipping();
2064 statusBar
.setWidth(getScreen().getWidth());
2065 statusBar
.setY(getScreen().getHeight() - topLevel
.getY());
2068 CellAttributes barColor
= new CellAttributes();
2069 barColor
.setTo(getTheme().getColor("tstatusbar.text"));
2070 getScreen().hLineXY(0, desktopBottom
, getScreen().getWidth(),
2075 // Draw the mouse pointer
2077 System
.err
.printf("%d %s restoreImage() %d %d\n",
2078 System
.currentTimeMillis(), Thread
.currentThread(),
2079 oldDrawnMouseX
, oldDrawnMouseY
);
2081 oldDrawnMouseCell
= getScreen().getCharXY(mouseX
, mouseY
);
2082 if (backend
instanceof ECMA48Backend
) {
2083 // Special case: the entire row containing the mouse has to be
2084 // re-drawn if it has any image data, AND any rows in between.
2085 if (oldDrawnMouseY
!= mouseY
) {
2086 for (int i
= oldDrawnMouseY
; ;) {
2087 getScreen().unsetImageRow(i
);
2091 if (oldDrawnMouseY
< mouseY
) {
2098 getScreen().unsetImageRow(mouseY
);
2102 if (inScreenSelection
) {
2103 getScreen().setSelection(screenSelectionX0
, screenSelectionY0
,
2104 screenSelectionX1
, screenSelectionY1
, screenSelectionRectangle
);
2107 if ((textMouse
== true) && (typingHidMouse
== false)) {
2108 drawTextMouse(mouseX
, mouseY
);
2110 oldDrawnMouseX
= mouseX
;
2111 oldDrawnMouseY
= mouseY
;
2113 // Place the cursor if it is visible
2114 if (!menuIsActive
) {
2116 int visibleWindowCount
= 0;
2117 for (TWindow window
: sorted
) {
2118 if (window
.isShown()) {
2119 visibleWindowCount
++;
2122 if (visibleWindowCount
== 0) {
2123 // No windows are visible, only the desktop. Allow it to
2125 if (desktop
!= null) {
2126 sorted
.add(desktop
);
2130 TWidget activeWidget
= null;
2131 if (sorted
.size() > 0) {
2132 activeWidget
= sorted
.get(sorted
.size() - 1).getActiveChild();
2133 int cursorClipTop
= desktopTop
;
2134 int cursorClipBottom
= desktopBottom
;
2135 if (activeWidget
.isCursorVisible()) {
2136 if ((activeWidget
.getCursorAbsoluteY() <= cursorClipBottom
)
2137 && (activeWidget
.getCursorAbsoluteY() >= cursorClipTop
)
2139 getScreen().putCursor(true,
2140 activeWidget
.getCursorAbsoluteX(),
2141 activeWidget
.getCursorAbsoluteY());
2144 // Turn off the cursor. Also place it at 0,0.
2145 getScreen().putCursor(false, 0, 0);
2154 getScreen().hideCursor();
2157 if (getScreen().isDirty()) {
2158 screenHandler
.setDirty();
2164 * Force this application to exit.
2166 public void exit() {
2168 synchronized (this) {
2174 * Subclasses can use this hook to cleanup resources. Called as the last
2175 * step of TApplication.run().
2177 public void onExit() {
2178 // Default does nothing.
2181 // ------------------------------------------------------------------------
2182 // TWindow management -----------------------------------------------------
2183 // ------------------------------------------------------------------------
2186 * Return the total number of windows.
2188 * @return the total number of windows
2190 public final int windowCount() {
2191 return windows
.size();
2195 * Return the number of windows that are showing.
2197 * @return the number of windows that are showing on screen
2199 public final int shownWindowCount() {
2201 for (TWindow w
: windows
) {
2210 * Return the number of windows that are hidden.
2212 * @return the number of windows that are hidden
2214 public final int hiddenWindowCount() {
2216 for (TWindow w
: windows
) {
2225 * Check if a window instance is in this application's window list.
2227 * @param window window to look for
2228 * @return true if this window is in the list
2230 public final boolean hasWindow(final TWindow window
) {
2231 if (windows
.size() == 0) {
2234 for (TWindow w
: windows
) {
2236 assert (window
.getApplication() == this);
2244 * Activate a window: bring it to the top and have it receive events.
2246 * @param window the window to become the new active window
2248 public void activateWindow(final TWindow window
) {
2249 if (hasWindow(window
) == false) {
2251 * Someone has a handle to a window I don't have. Ignore this
2257 // Whatever window might be moving/dragging, stop it now.
2258 for (TWindow w
: windows
) {
2259 if (w
.inMovements()) {
2264 assert (windows
.size() > 0);
2266 if (window
.isHidden()) {
2267 // Unhiding will also activate.
2271 assert (window
.isShown());
2273 if (windows
.size() == 1) {
2274 assert (window
== windows
.get(0));
2275 if (activeWindow
== null) {
2276 activeWindow
= window
;
2278 activeWindow
.setActive(true);
2279 activeWindow
.onFocus();
2282 assert (window
.isActive());
2283 assert (activeWindow
== window
);
2287 if (activeWindow
== window
) {
2288 assert (window
.isActive());
2290 // Window is already active, do nothing.
2294 assert (!window
.isActive());
2295 if (activeWindow
!= null) {
2296 activeWindow
.setActive(false);
2298 // Increment every window Z that is on top of window
2299 for (TWindow w
: windows
) {
2303 if (w
.getZ() < window
.getZ()) {
2304 w
.setZ(w
.getZ() + 1);
2308 // Unset activeWindow now before unfocus, so that a window
2309 // lifecycle change inside onUnfocus() doesn't call
2310 // switchWindow() and lead to a stack overflow.
2311 TWindow oldActiveWindow
= activeWindow
;
2312 activeWindow
= null;
2313 oldActiveWindow
.onUnfocus();
2315 activeWindow
= window
;
2316 activeWindow
.setZ(0);
2317 activeWindow
.setActive(true);
2318 activeWindow
.onFocus();
2325 * @param window the window to hide
2327 public void hideWindow(final TWindow window
) {
2328 if (hasWindow(window
) == false) {
2330 * Someone has a handle to a window I don't have. Ignore this
2336 // Whatever window might be moving/dragging, stop it now.
2337 for (TWindow w
: windows
) {
2338 if (w
.inMovements()) {
2343 assert (windows
.size() > 0);
2345 if (!window
.hidden
) {
2346 if (window
== activeWindow
) {
2347 if (shownWindowCount() > 1) {
2350 activeWindow
= null;
2351 window
.setActive(false);
2355 window
.hidden
= true;
2363 * @param window the window to show
2365 public void showWindow(final TWindow window
) {
2366 if (hasWindow(window
) == false) {
2368 * Someone has a handle to a window I don't have. Ignore this
2374 // Whatever window might be moving/dragging, stop it now.
2375 for (TWindow w
: windows
) {
2376 if (w
.inMovements()) {
2381 assert (windows
.size() > 0);
2383 if (window
.hidden
) {
2384 window
.hidden
= false;
2386 activateWindow(window
);
2391 * Close window. Note that the window's destructor is NOT called by this
2392 * method, instead the GC is assumed to do the cleanup.
2394 * @param window the window to remove
2396 public final void closeWindow(final TWindow window
) {
2397 if (hasWindow(window
) == false) {
2399 * Someone has a handle to a window I don't have. Ignore this
2405 // Let window know that it is about to be closed, while it is still
2406 // visible on screen.
2407 window
.onPreClose();
2409 synchronized (windows
) {
2410 // Whatever window might be moving/dragging, stop it now.
2411 for (TWindow w
: windows
) {
2412 if (w
.inMovements()) {
2417 int z
= window
.getZ();
2420 windows
.remove(window
);
2421 Collections
.sort(windows
);
2422 activeWindow
= null;
2424 boolean foundNextWindow
= false;
2426 for (TWindow w
: windows
) {
2430 // Do not activate a hidden window.
2435 if (foundNextWindow
== false) {
2436 foundNextWindow
= true;
2439 assert (activeWindow
== null);
2451 // Perform window cleanup
2454 // Check if we are closing a TMessageBox or similar
2455 if (secondaryEventReceiver
!= null) {
2456 assert (secondaryEventHandler
!= null);
2458 // Do not send events to the secondaryEventReceiver anymore, the
2459 // window is closed.
2460 secondaryEventReceiver
= null;
2462 // Wake the secondary thread, it will wake the primary as it
2464 synchronized (secondaryEventHandler
) {
2465 secondaryEventHandler
.notify();
2469 // Permit desktop to be active if it is the only thing left.
2470 if (desktop
!= null) {
2471 if (windows
.size() == 0) {
2472 desktop
.setActive(true);
2478 * Switch to the next window.
2480 * @param forward if true, then switch to the next window in the list,
2481 * otherwise switch to the previous window in the list
2483 public final void switchWindow(final boolean forward
) {
2484 // Only switch if there are multiple visible windows
2485 if (shownWindowCount() < 2) {
2488 assert (activeWindow
!= null);
2490 synchronized (windows
) {
2491 // Whatever window might be moving/dragging, stop it now.
2492 for (TWindow w
: windows
) {
2493 if (w
.inMovements()) {
2498 // Swap z/active between active window and the next in the list
2499 int activeWindowI
= -1;
2500 for (int i
= 0; i
< windows
.size(); i
++) {
2501 if (windows
.get(i
) == activeWindow
) {
2502 assert (activeWindow
.isActive());
2506 assert (!windows
.get(0).isActive());
2509 assert (activeWindowI
>= 0);
2511 // Do not switch if a window is modal
2512 if (activeWindow
.isModal()) {
2516 int nextWindowI
= activeWindowI
;
2520 nextWindowI
%= windows
.size();
2523 if (nextWindowI
< 0) {
2524 nextWindowI
= windows
.size() - 1;
2528 if (windows
.get(nextWindowI
).isShown()) {
2529 activateWindow(windows
.get(nextWindowI
));
2533 } // synchronized (windows)
2538 * Add a window to my window list and make it active. Note package
2541 * @param window new window to add
2543 final void addWindowToApplication(final TWindow window
) {
2545 // Do not add menu windows to the window list.
2546 if (window
instanceof TMenu
) {
2550 // Do not add the desktop to the window list.
2551 if (window
instanceof TDesktop
) {
2555 synchronized (windows
) {
2556 if (windows
.contains(window
)) {
2557 throw new IllegalArgumentException("Window " + window
+
2558 " is already in window list");
2561 // Whatever window might be moving/dragging, stop it now.
2562 for (TWindow w
: windows
) {
2563 if (w
.inMovements()) {
2568 // Do not allow a modal window to spawn a non-modal window. If a
2569 // modal window is active, then this window will become modal
2571 if (modalWindowActive()) {
2572 window
.flags
|= TWindow
.MODAL
;
2573 window
.flags
|= TWindow
.CENTERED
;
2574 window
.hidden
= false;
2576 if (window
.isShown()) {
2577 for (TWindow w
: windows
) {
2582 w
.setZ(w
.getZ() + 1);
2585 windows
.add(window
);
2586 if (window
.isShown()) {
2587 activeWindow
= window
;
2588 activeWindow
.setZ(0);
2589 activeWindow
.setActive(true);
2590 activeWindow
.onFocus();
2593 if (((window
.flags
& TWindow
.CENTERED
) == 0)
2594 && ((window
.flags
& TWindow
.ABSOLUTEXY
) == 0)
2595 && (smartWindowPlacement
== true)
2596 && (!(window
instanceof TDesktop
))
2599 doSmartPlacement(window
);
2603 // Desktop cannot be active over any other window.
2604 if (desktop
!= null) {
2605 desktop
.setActive(false);
2610 * Check if there is a system-modal window on top.
2612 * @return true if the active window is modal
2614 private boolean modalWindowActive() {
2615 if (windows
.size() == 0) {
2619 for (TWindow w
: windows
) {
2629 * Check if there is a window with overridden menu flag on top.
2631 * @return true if the active window is overriding the menu
2633 private boolean overrideMenuWindowActive() {
2634 if (activeWindow
!= null) {
2635 if (activeWindow
.hasOverriddenMenu()) {
2644 * Close all open windows.
2646 private void closeAllWindows() {
2647 // Don't do anything if we are in the menu
2648 if (activeMenu
!= null) {
2651 while (windows
.size() > 0) {
2652 closeWindow(windows
.get(0));
2657 * Re-layout the open windows as non-overlapping tiles. This produces
2658 * almost the same results as Turbo Pascal 7.0's IDE.
2660 private void tileWindows() {
2661 synchronized (windows
) {
2662 // Don't do anything if we are in the menu
2663 if (activeMenu
!= null) {
2666 int z
= windows
.size();
2672 a
= (int)(Math
.sqrt(z
));
2676 if (((a
* b
) + c
) == z
) {
2684 int newWidth
= (getScreen().getWidth() / a
);
2685 int newHeight1
= ((getScreen().getHeight() - 1) / b
);
2686 int newHeight2
= ((getScreen().getHeight() - 1) / (b
+ c
));
2688 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
2689 Collections
.sort(sorted
);
2690 Collections
.reverse(sorted
);
2691 for (int i
= 0; i
< sorted
.size(); i
++) {
2692 int logicalX
= i
/ b
;
2693 int logicalY
= i
% b
;
2694 if (i
>= ((a
- 1) * b
)) {
2696 logicalY
= i
- ((a
- 1) * b
);
2699 TWindow w
= sorted
.get(i
);
2700 int oldWidth
= w
.getWidth();
2701 int oldHeight
= w
.getHeight();
2703 w
.setX(logicalX
* newWidth
);
2704 w
.setWidth(newWidth
);
2705 if (i
>= ((a
- 1) * b
)) {
2706 w
.setY((logicalY
* newHeight2
) + 1);
2707 w
.setHeight(newHeight2
);
2709 w
.setY((logicalY
* newHeight1
) + 1);
2710 w
.setHeight(newHeight1
);
2712 if ((w
.getWidth() != oldWidth
)
2713 || (w
.getHeight() != oldHeight
)
2715 w
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
2716 w
.getWidth(), w
.getHeight()));
2723 * Re-layout the open windows as overlapping cascaded windows.
2725 private void cascadeWindows() {
2726 synchronized (windows
) {
2727 // Don't do anything if we are in the menu
2728 if (activeMenu
!= null) {
2733 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
2734 Collections
.sort(sorted
);
2735 Collections
.reverse(sorted
);
2736 for (TWindow window
: sorted
) {
2741 if (x
> getScreen().getWidth()) {
2744 if (y
>= getScreen().getHeight()) {
2752 * Place a window to minimize its overlap with other windows.
2754 * @param window the window to place
2756 public final void doSmartPlacement(final TWindow window
) {
2757 // This is a pretty dumb algorithm, but seems to work. The hardest
2758 // part is computing these "overlap" values seeking a minimum average
2761 int yMin
= desktopTop
;
2762 int xMax
= getScreen().getWidth() - window
.getWidth() + 1;
2763 int yMax
= desktopBottom
- window
.getHeight() + 1;
2771 if ((xMin
== xMax
) && (yMin
== yMax
)) {
2772 // No work to do, bail out.
2776 // Compute the overlap matrix without the new window.
2777 int width
= getScreen().getWidth();
2778 int height
= getScreen().getHeight();
2779 int overlapMatrix
[][] = new int[width
][height
];
2780 for (TWindow w
: windows
) {
2784 for (int x
= w
.getX(); x
< w
.getX() + w
.getWidth(); x
++) {
2791 for (int y
= w
.getY(); y
< w
.getY() + w
.getHeight(); y
++) {
2798 overlapMatrix
[x
][y
]++;
2803 long oldOverlapTotal
= 0;
2804 long oldOverlapN
= 0;
2805 for (int x
= 0; x
< width
; x
++) {
2806 for (int y
= 0; y
< height
; y
++) {
2807 oldOverlapTotal
+= overlapMatrix
[x
][y
];
2808 if (overlapMatrix
[x
][y
] > 0) {
2815 double oldOverlapAvg
= (double) oldOverlapTotal
/ (double) oldOverlapN
;
2816 boolean first
= true;
2817 int windowX
= window
.getX();
2818 int windowY
= window
.getY();
2820 // For each possible (x, y) position for the new window, compute a
2821 // new overlap matrix.
2822 for (int x
= xMin
; x
< xMax
; x
++) {
2823 for (int y
= yMin
; y
< yMax
; y
++) {
2825 // Start with the matrix minus this window.
2826 int newMatrix
[][] = new int[width
][height
];
2827 for (int mx
= 0; mx
< width
; mx
++) {
2828 for (int my
= 0; my
< height
; my
++) {
2829 newMatrix
[mx
][my
] = overlapMatrix
[mx
][my
];
2833 // Add this window's values to the new overlap matrix.
2834 long newOverlapTotal
= 0;
2835 long newOverlapN
= 0;
2836 // Start by adding each new cell.
2837 for (int wx
= x
; wx
< x
+ window
.getWidth(); wx
++) {
2841 for (int wy
= y
; wy
< y
+ window
.getHeight(); wy
++) {
2845 newMatrix
[wx
][wy
]++;
2848 // Now figure out the new value for total coverage.
2849 for (int mx
= 0; mx
< width
; mx
++) {
2850 for (int my
= 0; my
< height
; my
++) {
2851 newOverlapTotal
+= newMatrix
[x
][y
];
2852 if (newMatrix
[mx
][my
] > 0) {
2857 double newOverlapAvg
= (double) newOverlapTotal
/ (double) newOverlapN
;
2860 // First time: just record what we got.
2861 oldOverlapAvg
= newOverlapAvg
;
2864 // All other times: pick a new best (x, y) and save the
2866 if (newOverlapAvg
< oldOverlapAvg
) {
2869 oldOverlapAvg
= newOverlapAvg
;
2873 } // for (int x = xMin; x < xMax; x++)
2875 } // for (int y = yMin; y < yMax; y++)
2877 // Finally, set the window's new coordinates.
2878 window
.setX(windowX
);
2879 window
.setY(windowY
);
2882 // ------------------------------------------------------------------------
2883 // TMenu management -------------------------------------------------------
2884 // ------------------------------------------------------------------------
2887 * Check if a mouse event would hit either the active menu or any open
2890 * @param mouse mouse event
2891 * @return true if the mouse would hit the active menu or an open
2894 private boolean mouseOnMenu(final TMouseEvent mouse
) {
2895 assert (activeMenu
!= null);
2896 List
<TMenu
> menus
= new ArrayList
<TMenu
>(subMenus
);
2897 Collections
.reverse(menus
);
2898 for (TMenu menu
: menus
) {
2899 if (menu
.mouseWouldHit(mouse
)) {
2903 return activeMenu
.mouseWouldHit(mouse
);
2907 * See if we need to switch window or activate the menu based on
2910 * @param mouse mouse event
2912 private void checkSwitchFocus(final TMouseEvent mouse
) {
2914 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2915 && (activeMenu
!= null)
2916 && (mouse
.getAbsoluteY() != 0)
2917 && (!mouseOnMenu(mouse
))
2919 // They clicked outside the active menu, turn it off
2920 activeMenu
.setActive(false);
2922 for (TMenu menu
: subMenus
) {
2923 menu
.setActive(false);
2929 // See if they hit the menu bar
2930 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2931 && (mouse
.isMouse1())
2932 && (!modalWindowActive())
2933 && (!overrideMenuWindowActive())
2934 && (mouse
.getAbsoluteY() == 0)
2935 && (hideMenuBar
== false)
2938 for (TMenu menu
: subMenus
) {
2939 menu
.setActive(false);
2943 // They selected the menu, go activate it
2944 for (TMenu menu
: menus
) {
2945 if ((mouse
.getAbsoluteX() >= menu
.getTitleX())
2946 && (mouse
.getAbsoluteX() < menu
.getTitleX()
2947 + StringUtils
.width(menu
.getTitle()) + 2)
2949 menu
.setActive(true);
2952 menu
.setActive(false);
2958 // See if they hit the menu bar
2959 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
)
2960 && (mouse
.isMouse1())
2961 && (activeMenu
!= null)
2962 && (mouse
.getAbsoluteY() == 0)
2963 && (hideMenuBar
== false)
2966 TMenu oldMenu
= activeMenu
;
2967 for (TMenu menu
: subMenus
) {
2968 menu
.setActive(false);
2972 // See if we should switch menus
2973 for (TMenu menu
: menus
) {
2974 if ((mouse
.getAbsoluteX() >= menu
.getTitleX())
2975 && (mouse
.getAbsoluteX() < menu
.getTitleX()
2976 + StringUtils
.width(menu
.getTitle()) + 2)
2978 menu
.setActive(true);
2982 if (oldMenu
!= activeMenu
) {
2983 // They switched menus
2984 oldMenu
.setActive(false);
2989 // If a menu is still active, don't switch windows
2990 if (activeMenu
!= null) {
2994 // Only switch if there are multiple windows
2995 if (windows
.size() < 2) {
2999 if (((focusFollowsMouse
== true)
3000 && (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
))
3001 || (mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
3003 synchronized (windows
) {
3004 Collections
.sort(windows
);
3005 if (windows
.get(0).isModal()) {
3006 // Modal windows don't switch
3010 for (TWindow window
: windows
) {
3011 assert (!window
.isModal());
3013 if (window
.isHidden()) {
3014 assert (!window
.isActive());
3018 if (window
.mouseWouldHit(mouse
)) {
3019 if (window
== windows
.get(0)) {
3020 // Clicked on the same window, nothing to do
3021 assert (window
.isActive());
3025 // We will be switching to another window
3026 assert (windows
.get(0).isActive());
3027 assert (windows
.get(0) == activeWindow
);
3028 assert (!window
.isActive());
3029 if (activeWindow
!= null) {
3030 activeWindow
.onUnfocus();
3031 activeWindow
.setActive(false);
3032 activeWindow
.setZ(window
.getZ());
3034 activeWindow
= window
;
3036 window
.setActive(true);
3043 // Clicked on the background, nothing to do
3047 // Nothing to do: this isn't a mouse up, or focus isn't following
3053 * Turn off the menu.
3055 public final void closeMenu() {
3056 if (activeMenu
!= null) {
3057 activeMenu
.setActive(false);
3059 for (TMenu menu
: subMenus
) {
3060 menu
.setActive(false);
3067 * Get a (shallow) copy of the menu list.
3069 * @return a copy of the menu list
3071 public final List
<TMenu
> getAllMenus() {
3072 return new ArrayList
<TMenu
>(menus
);
3076 * Add a top-level menu to the list.
3078 * @param menu the menu to add
3079 * @throws IllegalArgumentException if the menu is already used in
3080 * another TApplication
3082 public final void addMenu(final TMenu menu
) {
3083 if ((menu
.getApplication() != null)
3084 && (menu
.getApplication() != this)
3086 throw new IllegalArgumentException("Menu " + menu
+ " is already " +
3087 "part of application " + menu
.getApplication());
3095 * Remove a top-level menu from the list.
3097 * @param menu the menu to remove
3098 * @throws IllegalArgumentException if the menu is already used in
3099 * another TApplication
3101 public final void removeMenu(final TMenu menu
) {
3102 if ((menu
.getApplication() != null)
3103 && (menu
.getApplication() != this)
3105 throw new IllegalArgumentException("Menu " + menu
+ " is already " +
3106 "part of application " + menu
.getApplication());
3114 * Turn off a sub-menu.
3116 public final void closeSubMenu() {
3117 assert (activeMenu
!= null);
3118 TMenu item
= subMenus
.get(subMenus
.size() - 1);
3119 assert (item
!= null);
3120 item
.setActive(false);
3121 subMenus
.remove(subMenus
.size() - 1);
3125 * Switch to the next menu.
3127 * @param forward if true, then switch to the next menu in the list,
3128 * otherwise switch to the previous menu in the list
3130 public final void switchMenu(final boolean forward
) {
3131 assert (activeMenu
!= null);
3132 assert (hideMenuBar
== false);
3134 for (TMenu menu
: subMenus
) {
3135 menu
.setActive(false);
3139 for (int i
= 0; i
< menus
.size(); i
++) {
3140 if (activeMenu
== menus
.get(i
)) {
3142 if (i
< menus
.size() - 1) {
3151 i
= menus
.size() - 1;
3154 activeMenu
.setActive(false);
3155 activeMenu
= menus
.get(i
);
3156 activeMenu
.setActive(true);
3163 * Add a menu item to the global list. If it has a keyboard accelerator,
3164 * that will be added the global hash.
3166 * @param item the menu item
3168 public final void addMenuItem(final TMenuItem item
) {
3169 menuItems
.add(item
);
3171 TKeypress key
= item
.getKey();
3173 synchronized (accelerators
) {
3174 assert (accelerators
.get(key
) == null);
3175 accelerators
.put(key
.toLowerCase(), item
);
3181 * Disable one menu item.
3183 * @param id the menu item ID
3185 public final void disableMenuItem(final int id
) {
3186 for (TMenuItem item
: menuItems
) {
3187 if (item
.getId() == id
) {
3188 item
.setEnabled(false);
3194 * Disable the range of menu items with ID's between lower and upper,
3197 * @param lower the lowest menu item ID
3198 * @param upper the highest menu item ID
3200 public final void disableMenuItems(final int lower
, final int upper
) {
3201 for (TMenuItem item
: menuItems
) {
3202 if ((item
.getId() >= lower
) && (item
.getId() <= upper
)) {
3203 item
.setEnabled(false);
3204 item
.getParent().activate(0);
3210 * Enable one menu item.
3212 * @param id the menu item ID
3214 public final void enableMenuItem(final int id
) {
3215 for (TMenuItem item
: menuItems
) {
3216 if (item
.getId() == id
) {
3217 item
.setEnabled(true);
3218 item
.getParent().activate(0);
3224 * Enable the range of menu items with ID's between lower and upper,
3227 * @param lower the lowest menu item ID
3228 * @param upper the highest menu item ID
3230 public final void enableMenuItems(final int lower
, final int upper
) {
3231 for (TMenuItem item
: menuItems
) {
3232 if ((item
.getId() >= lower
) && (item
.getId() <= upper
)) {
3233 item
.setEnabled(true);
3234 item
.getParent().activate(0);
3240 * Get the menu item associated with this ID.
3242 * @param id the menu item ID
3243 * @return the menu item, or null if not found
3245 public final TMenuItem
getMenuItem(final int id
) {
3246 for (TMenuItem item
: menuItems
) {
3247 if (item
.getId() == id
) {
3255 * Recompute menu x positions based on their title length.
3257 public final void recomputeMenuX() {
3259 for (TMenu menu
: menus
) {
3262 x
+= StringUtils
.width(menu
.getTitle()) + 2;
3264 // Don't let the menu window exceed the screen width
3265 int rightEdge
= menu
.getX() + menu
.getWidth();
3266 if (rightEdge
> getScreen().getWidth()) {
3267 menu
.setX(getScreen().getWidth() - menu
.getWidth());
3273 * Post an event to process.
3275 * @param event new event to add to the queue
3277 public final void postEvent(final TInputEvent event
) {
3278 synchronized (this) {
3279 synchronized (fillEventQueue
) {
3280 fillEventQueue
.add(event
);
3283 System
.err
.println(System
.currentTimeMillis() + " " +
3284 Thread
.currentThread() + " postEvent() wake up main");
3291 * Post an event to process and turn off the menu.
3293 * @param event new event to add to the queue
3295 public final void postMenuEvent(final TInputEvent event
) {
3296 synchronized (this) {
3297 synchronized (fillEventQueue
) {
3298 fillEventQueue
.add(event
);
3301 System
.err
.println(System
.currentTimeMillis() + " " +
3302 Thread
.currentThread() + " postMenuEvent() wake up main");
3310 * Add a sub-menu to the list of open sub-menus.
3312 * @param menu sub-menu
3314 public final void addSubMenu(final TMenu menu
) {
3319 * Convenience function to add a top-level menu.
3321 * @param title menu title
3322 * @return the new menu
3324 public final TMenu
addMenu(final String title
) {
3327 TMenu menu
= new TMenu(this, x
, y
, title
);
3334 * Convenience function to add a default tools (hamburger) menu.
3336 * @return the new menu
3338 public final TMenu
addToolMenu() {
3339 TMenu toolMenu
= addMenu(i18n
.getString("toolMenuTitle"));
3340 toolMenu
.addDefaultItem(TMenu
.MID_REPAINT
);
3341 toolMenu
.addDefaultItem(TMenu
.MID_VIEW_IMAGE
);
3342 toolMenu
.addDefaultItem(TMenu
.MID_SCREEN_OPTIONS
);
3343 TStatusBar toolStatusBar
= toolMenu
.newStatusBar(i18n
.
3344 getString("toolMenuStatus"));
3345 toolStatusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3350 * Convenience function to add a default "File" menu.
3352 * @return the new menu
3354 public final TMenu
addFileMenu() {
3355 TMenu fileMenu
= addMenu(i18n
.getString("fileMenuTitle"));
3356 fileMenu
.addDefaultItem(TMenu
.MID_SHELL
);
3357 fileMenu
.addSeparator();
3358 fileMenu
.addDefaultItem(TMenu
.MID_EXIT
);
3359 TStatusBar statusBar
= fileMenu
.newStatusBar(i18n
.
3360 getString("fileMenuStatus"));
3361 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3366 * Convenience function to add a default "Edit" menu.
3368 * @return the new menu
3370 public final TMenu
addEditMenu() {
3371 TMenu editMenu
= addMenu(i18n
.getString("editMenuTitle"));
3372 editMenu
.addDefaultItem(TMenu
.MID_CUT
, false);
3373 editMenu
.addDefaultItem(TMenu
.MID_COPY
, false);
3374 editMenu
.addDefaultItem(TMenu
.MID_PASTE
, false);
3375 editMenu
.addDefaultItem(TMenu
.MID_CLEAR
, false);
3376 TStatusBar statusBar
= editMenu
.newStatusBar(i18n
.
3377 getString("editMenuStatus"));
3378 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3383 * Convenience function to add a default "Window" menu.
3385 * @return the new menu
3387 public final TMenu
addWindowMenu() {
3388 TMenu windowMenu
= addMenu(i18n
.getString("windowMenuTitle"));
3389 windowMenu
.addDefaultItem(TMenu
.MID_TILE
);
3390 windowMenu
.addDefaultItem(TMenu
.MID_CASCADE
);
3391 windowMenu
.addDefaultItem(TMenu
.MID_CLOSE_ALL
);
3392 windowMenu
.addSeparator();
3393 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_MOVE
);
3394 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_ZOOM
);
3395 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_NEXT
);
3396 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_PREVIOUS
);
3397 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_CLOSE
);
3398 TStatusBar statusBar
= windowMenu
.newStatusBar(i18n
.
3399 getString("windowMenuStatus"));
3400 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3405 * Convenience function to add a default "Help" menu.
3407 * @return the new menu
3409 public final TMenu
addHelpMenu() {
3410 TMenu helpMenu
= addMenu(i18n
.getString("helpMenuTitle"));
3411 helpMenu
.addDefaultItem(TMenu
.MID_HELP_CONTENTS
);
3412 helpMenu
.addDefaultItem(TMenu
.MID_HELP_INDEX
);
3413 helpMenu
.addDefaultItem(TMenu
.MID_HELP_SEARCH
);
3414 helpMenu
.addDefaultItem(TMenu
.MID_HELP_PREVIOUS
);
3415 helpMenu
.addDefaultItem(TMenu
.MID_HELP_HELP
);
3416 helpMenu
.addDefaultItem(TMenu
.MID_HELP_ACTIVE_FILE
);
3417 helpMenu
.addSeparator();
3418 helpMenu
.addDefaultItem(TMenu
.MID_ABOUT
);
3419 TStatusBar statusBar
= helpMenu
.newStatusBar(i18n
.
3420 getString("helpMenuStatus"));
3421 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3426 * Convenience function to add a default "Table" menu.
3428 * @return the new menu
3430 public final TMenu
addTableMenu() {
3431 TMenu tableMenu
= addMenu(i18n
.getString("tableMenuTitle"));
3432 tableMenu
.addDefaultItem(TMenu
.MID_TABLE_RENAME_COLUMN
, false);
3433 tableMenu
.addDefaultItem(TMenu
.MID_TABLE_RENAME_ROW
, false);
3434 tableMenu
.addSeparator();
3436 TSubMenu viewMenu
= tableMenu
.addSubMenu(i18n
.
3437 getString("tableSubMenuView"));
3438 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_ROW_LABELS
, false);
3439 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_COLUMN_LABELS
, false);
3440 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_HIGHLIGHT_ROW
, false);
3441 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_HIGHLIGHT_COLUMN
, false);
3443 TSubMenu borderMenu
= tableMenu
.addSubMenu(i18n
.
3444 getString("tableSubMenuBorders"));
3445 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_NONE
, false);
3446 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_ALL
, false);
3447 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_CELL_NONE
, false);
3448 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_CELL_ALL
, false);
3449 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_RIGHT
, false);
3450 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_LEFT
, false);
3451 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_TOP
, false);
3452 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_BOTTOM
, false);
3453 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_DOUBLE_BOTTOM
, false);
3454 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_THICK_BOTTOM
, false);
3455 TSubMenu deleteMenu
= tableMenu
.addSubMenu(i18n
.
3456 getString("tableSubMenuDelete"));
3457 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_LEFT
, false);
3458 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_UP
, false);
3459 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_ROW
, false);
3460 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_COLUMN
, false);
3461 TSubMenu insertMenu
= tableMenu
.addSubMenu(i18n
.
3462 getString("tableSubMenuInsert"));
3463 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_LEFT
, false);
3464 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_RIGHT
, false);
3465 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_ABOVE
, false);
3466 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_BELOW
, false);
3467 TSubMenu columnMenu
= tableMenu
.addSubMenu(i18n
.
3468 getString("tableSubMenuColumn"));
3469 columnMenu
.addDefaultItem(TMenu
.MID_TABLE_COLUMN_NARROW
, false);
3470 columnMenu
.addDefaultItem(TMenu
.MID_TABLE_COLUMN_WIDEN
, false);
3471 TSubMenu fileMenu
= tableMenu
.addSubMenu(i18n
.
3472 getString("tableSubMenuFile"));
3473 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_OPEN_CSV
, false);
3474 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_SAVE_CSV
, false);
3475 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_SAVE_TEXT
, false);
3477 TStatusBar statusBar
= tableMenu
.newStatusBar(i18n
.
3478 getString("tableMenuStatus"));
3479 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3483 // ------------------------------------------------------------------------
3484 // TTimer management ------------------------------------------------------
3485 // ------------------------------------------------------------------------
3488 * Get the amount of time I can sleep before missing a Timer tick.
3490 * @param timeout = initial (maximum) timeout in millis
3491 * @return number of milliseconds between now and the next timer event
3493 private long getSleepTime(final long timeout
) {
3494 Date now
= new Date();
3495 long nowTime
= now
.getTime();
3496 long sleepTime
= timeout
;
3498 synchronized (timers
) {
3499 for (TTimer timer
: timers
) {
3500 long nextTickTime
= timer
.getNextTick().getTime();
3501 if (nextTickTime
< nowTime
) {
3505 long timeDifference
= nextTickTime
- nowTime
;
3506 if (timeDifference
< sleepTime
) {
3507 sleepTime
= timeDifference
;
3512 assert (sleepTime
>= 0);
3513 assert (sleepTime
<= timeout
);
3518 * Convenience function to add a timer.
3520 * @param duration number of milliseconds to wait between ticks
3521 * @param recurring if true, re-schedule this timer after every tick
3522 * @param action function to call when button is pressed
3525 public final TTimer
addTimer(final long duration
, final boolean recurring
,
3526 final TAction action
) {
3528 TTimer timer
= new TTimer(duration
, recurring
, action
);
3529 synchronized (timers
) {
3536 * Convenience function to remove a timer.
3538 * @param timer timer to remove
3540 public final void removeTimer(final TTimer timer
) {
3541 synchronized (timers
) {
3542 timers
.remove(timer
);
3546 // ------------------------------------------------------------------------
3547 // Other TWindow constructors ---------------------------------------------
3548 // ------------------------------------------------------------------------
3551 * Convenience function to spawn a message box.
3553 * @param title window title, will be centered along the top border
3554 * @param caption message to display. Use embedded newlines to get a
3556 * @return the new message box
3558 public final TMessageBox
messageBox(final String title
,
3559 final String caption
) {
3561 return new TMessageBox(this, title
, caption
, TMessageBox
.Type
.OK
);
3565 * Convenience function to spawn a message box.
3567 * @param title window title, will be centered along the top border
3568 * @param caption message to display. Use embedded newlines to get a
3570 * @param type one of the TMessageBox.Type constants. Default is
3572 * @return the new message box
3574 public final TMessageBox
messageBox(final String title
,
3575 final String caption
, final TMessageBox
.Type type
) {
3577 return new TMessageBox(this, title
, caption
, type
);
3581 * Convenience function to spawn an input box.
3583 * @param title window title, will be centered along the top border
3584 * @param caption message to display. Use embedded newlines to get a
3586 * @return the new input box
3588 public final TInputBox
inputBox(final String title
, final String caption
) {
3590 return new TInputBox(this, title
, caption
);
3594 * Convenience function to spawn an input box.
3596 * @param title window title, will be centered along the top border
3597 * @param caption message to display. Use embedded newlines to get a
3599 * @param text initial text to seed the field with
3600 * @return the new input box
3602 public final TInputBox
inputBox(final String title
, final String caption
,
3603 final String text
) {
3605 return new TInputBox(this, title
, caption
, text
);
3609 * Convenience function to spawn an input box.
3611 * @param title window title, will be centered along the top border
3612 * @param caption message to display. Use embedded newlines to get a
3614 * @param text initial text to seed the field with
3615 * @param type one of the Type constants. Default is Type.OK.
3616 * @return the new input box
3618 public final TInputBox
inputBox(final String title
, final String caption
,
3619 final String text
, final TInputBox
.Type type
) {
3621 return new TInputBox(this, title
, caption
, text
, type
);
3625 * Convenience function to open a terminal window.
3627 * @param x column relative to parent
3628 * @param y row relative to parent
3629 * @return the terminal new window
3631 public final TTerminalWindow
openTerminal(final int x
, final int y
) {
3632 return openTerminal(x
, y
, TWindow
.RESIZABLE
);
3636 * Convenience function to open a terminal window.
3638 * @param x column relative to parent
3639 * @param y row relative to parent
3640 * @param closeOnExit if true, close the window when the command exits
3641 * @return the terminal new window
3643 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3644 final boolean closeOnExit
) {
3646 return openTerminal(x
, y
, TWindow
.RESIZABLE
, closeOnExit
);
3650 * Convenience function to open a terminal window.
3652 * @param x column relative to parent
3653 * @param y row relative to parent
3654 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3655 * @return the terminal new window
3657 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3660 return new TTerminalWindow(this, x
, y
, flags
);
3664 * Convenience function to open a terminal window.
3666 * @param x column relative to parent
3667 * @param y row relative to parent
3668 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3669 * @param closeOnExit if true, close the window when the command exits
3670 * @return the terminal new window
3672 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3673 final int flags
, final boolean closeOnExit
) {
3675 return new TTerminalWindow(this, x
, y
, flags
, closeOnExit
);
3679 * Convenience function to open a terminal window and execute a custom
3680 * command line inside it.
3682 * @param x column relative to parent
3683 * @param y row relative to parent
3684 * @param commandLine the command line to execute
3685 * @return the terminal new window
3687 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3688 final String commandLine
) {
3690 return openTerminal(x
, y
, TWindow
.RESIZABLE
, commandLine
);
3694 * Convenience function to open a terminal window and execute a custom
3695 * command line inside it.
3697 * @param x column relative to parent
3698 * @param y row relative to parent
3699 * @param commandLine the command line to execute
3700 * @param closeOnExit if true, close the window when the command exits
3701 * @return the terminal new window
3703 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3704 final String commandLine
, final boolean closeOnExit
) {
3706 return openTerminal(x
, y
, TWindow
.RESIZABLE
, commandLine
, closeOnExit
);
3710 * Convenience function to open a terminal window and execute a custom
3711 * command line inside it.
3713 * @param x column relative to parent
3714 * @param y row relative to parent
3715 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3716 * @param command the command line to execute
3717 * @return the terminal new window
3719 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3720 final int flags
, final String
[] command
) {
3722 return new TTerminalWindow(this, x
, y
, flags
, command
);
3726 * Convenience function to open a terminal window and execute a custom
3727 * command line inside it.
3729 * @param x column relative to parent
3730 * @param y row relative to parent
3731 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3732 * @param command the command line to execute
3733 * @param closeOnExit if true, close the window when the command exits
3734 * @return the terminal new window
3736 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3737 final int flags
, final String
[] command
, final boolean closeOnExit
) {
3739 return new TTerminalWindow(this, x
, y
, flags
, command
, closeOnExit
);
3743 * Convenience function to open a terminal window and execute a custom
3744 * command line inside it.
3746 * @param x column relative to parent
3747 * @param y row relative to parent
3748 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3749 * @param commandLine the command line to execute
3750 * @return the terminal new window
3752 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3753 final int flags
, final String commandLine
) {
3755 return new TTerminalWindow(this, x
, y
, flags
, commandLine
.split("\\s+"));
3759 * Convenience function to open a terminal window and execute a custom
3760 * command line inside it.
3762 * @param x column relative to parent
3763 * @param y row relative to parent
3764 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3765 * @param commandLine the command line to execute
3766 * @param closeOnExit if true, close the window when the command exits
3767 * @return the terminal new window
3769 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3770 final int flags
, final String commandLine
, final boolean closeOnExit
) {
3772 return new TTerminalWindow(this, x
, y
, flags
, commandLine
.split("\\s+"),
3777 * Convenience function to spawn an file open box.
3779 * @param path path of selected file
3780 * @return the result of the new file open box
3781 * @throws IOException if java.io operation throws
3783 public final String
fileOpenBox(final String path
) throws IOException
{
3785 TFileOpenBox box
= new TFileOpenBox(this, path
, TFileOpenBox
.Type
.OPEN
);
3786 return box
.getFilename();
3790 * Convenience function to spawn an file open box.
3792 * @param path path of selected file
3793 * @param type one of the Type constants
3794 * @return the result of the new file open box
3795 * @throws IOException if java.io operation throws
3797 public final String
fileOpenBox(final String path
,
3798 final TFileOpenBox
.Type type
) throws IOException
{
3800 TFileOpenBox box
= new TFileOpenBox(this, path
, type
);
3801 return box
.getFilename();
3805 * Convenience function to spawn a file open box.
3807 * @param path path of selected file
3808 * @param type one of the Type constants
3809 * @param filter a string that files must match to be displayed
3810 * @return the result of the new file open box
3811 * @throws IOException of a java.io operation throws
3813 public final String
fileOpenBox(final String path
,
3814 final TFileOpenBox
.Type type
, final String filter
) throws IOException
{
3816 ArrayList
<String
> filters
= new ArrayList
<String
>();
3817 filters
.add(filter
);
3819 TFileOpenBox box
= new TFileOpenBox(this, path
, type
, filters
);
3820 return box
.getFilename();
3824 * Convenience function to spawn a file open box.
3826 * @param path path of selected file
3827 * @param type one of the Type constants
3828 * @param filters a list of strings that files must match to be displayed
3829 * @return the result of the new file open box
3830 * @throws IOException of a java.io operation throws
3832 public final String
fileOpenBox(final String path
,
3833 final TFileOpenBox
.Type type
,
3834 final List
<String
> filters
) throws IOException
{
3836 TFileOpenBox box
= new TFileOpenBox(this, path
, type
, filters
);
3837 return box
.getFilename();
3841 * Convenience function to create a new window and make it active.
3842 * Window will be located at (0, 0).
3844 * @param title window title, will be centered along the top border
3845 * @param width width of window
3846 * @param height height of window
3847 * @return the new window
3849 public final TWindow
addWindow(final String title
, final int width
,
3852 TWindow window
= new TWindow(this, title
, 0, 0, width
, height
);
3857 * Convenience function to create a new window and make it active.
3858 * Window will be located at (0, 0).
3860 * @param title window title, will be centered along the top border
3861 * @param width width of window
3862 * @param height height of window
3863 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
3864 * @return the new window
3866 public final TWindow
addWindow(final String title
,
3867 final int width
, final int height
, final int flags
) {
3869 TWindow window
= new TWindow(this, title
, 0, 0, width
, height
, flags
);
3874 * Convenience function to create a new window and make it active.
3876 * @param title window title, will be centered along the top border
3877 * @param x column relative to parent
3878 * @param y row relative to parent
3879 * @param width width of window
3880 * @param height height of window
3881 * @return the new window
3883 public final TWindow
addWindow(final String title
,
3884 final int x
, final int y
, final int width
, final int height
) {
3886 TWindow window
= new TWindow(this, title
, x
, y
, width
, height
);
3891 * Convenience function to create a new window and make it active.
3893 * @param title window title, will be centered along the top border
3894 * @param x column relative to parent
3895 * @param y row relative to parent
3896 * @param width width of window
3897 * @param height height of window
3898 * @param flags mask of RESIZABLE, CENTERED, or MODAL
3899 * @return the new window
3901 public final TWindow
addWindow(final String title
,
3902 final int x
, final int y
, final int width
, final int height
,
3905 TWindow window
= new TWindow(this, title
, x
, y
, width
, height
, flags
);