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();
1608 * Wake the sleeping active event handler.
1610 private void wakeEventHandler() {
1615 if (secondaryEventHandler
!= null) {
1616 synchronized (secondaryEventHandler
) {
1617 secondaryEventHandler
.notify();
1620 assert (primaryEventHandler
!= null);
1621 synchronized (primaryEventHandler
) {
1622 primaryEventHandler
.notify();
1628 * Wake the sleeping screen handler.
1630 private void wakeScreenHandler() {
1635 synchronized (screenHandler
) {
1636 screenHandler
.notify();
1640 // ------------------------------------------------------------------------
1641 // TApplication -----------------------------------------------------------
1642 // ------------------------------------------------------------------------
1645 * Place a command on the run queue, and run it before the next round of
1648 * @param command the command to run later
1650 public void invokeLater(final Runnable command
) {
1651 synchronized (invokeLaters
) {
1652 invokeLaters
.add(command
);
1658 * Restore the console to sane defaults. This is meant to be used for
1659 * improper exits (e.g. a caught exception in main()), and should not be
1660 * necessary for normal program termination.
1662 public void restoreConsole() {
1663 if (backend
!= null) {
1664 if (backend
instanceof ECMA48Backend
) {
1673 * @return the Backend
1675 public final Backend
getBackend() {
1682 * @return the Screen
1684 public final Screen
getScreen() {
1685 if (backend
instanceof TWindowBackend
) {
1686 // We are being rendered to a TWindow. We can't use its
1687 // getScreen() method because that is how it is rendering to a
1688 // hardware backend somewhere. Instead use its getOtherScreen()
1690 return ((TWindowBackend
) backend
).getOtherScreen();
1692 return backend
.getScreen();
1697 * Get the color theme.
1701 public final ColorTheme
getTheme() {
1706 * Get the clipboard.
1708 * @return the clipboard
1710 public final Clipboard
getClipboard() {
1715 * Repaint the screen on the next update.
1717 public void doRepaint() {
1723 * Get Y coordinate of the top edge of the desktop.
1725 * @return Y coordinate of the top edge of the desktop
1727 public final int getDesktopTop() {
1732 * Get Y coordinate of the bottom edge of the desktop.
1734 * @return Y coordinate of the bottom edge of the desktop
1736 public final int getDesktopBottom() {
1737 return desktopBottom
;
1741 * Set the TDesktop instance.
1743 * @param desktop a TDesktop instance, or null to remove the one that is
1746 public final void setDesktop(final TDesktop desktop
) {
1747 if (this.desktop
!= null) {
1748 this.desktop
.onPreClose();
1749 this.desktop
.onUnfocus();
1750 this.desktop
.onClose();
1752 this.desktop
= desktop
;
1756 * Get the TDesktop instance.
1758 * @return the desktop, or null if it is not set
1760 public final TDesktop
getDesktop() {
1765 * Get the current active window.
1767 * @return the active window, or null if it is not set
1769 public final TWindow
getActiveWindow() {
1770 return activeWindow
;
1774 * Get a (shallow) copy of the window list.
1776 * @return a copy of the list of windows for this application
1778 public final List
<TWindow
> getAllWindows() {
1779 List
<TWindow
> result
= new ArrayList
<TWindow
>();
1780 result
.addAll(windows
);
1785 * Get focusFollowsMouse flag.
1787 * @return true if focus follows mouse: windows automatically raised if
1788 * the mouse passes over them
1790 public boolean getFocusFollowsMouse() {
1791 return focusFollowsMouse
;
1795 * Set focusFollowsMouse flag.
1797 * @param focusFollowsMouse if true, focus follows mouse: windows
1798 * automatically raised if the mouse passes over them
1800 public void setFocusFollowsMouse(final boolean focusFollowsMouse
) {
1801 this.focusFollowsMouse
= focusFollowsMouse
;
1805 * Display the about dialog.
1807 protected void showAboutDialog() {
1808 String version
= getClass().getPackage().getImplementationVersion();
1809 if (version
== null) {
1810 // This is Java 9+, use a hardcoded string here.
1813 messageBox(i18n
.getString("aboutDialogTitle"),
1814 MessageFormat
.format(i18n
.getString("aboutDialogText"), version
),
1815 TMessageBox
.Type
.OK
);
1819 * Handle the Tool | Open image menu item.
1821 private void openImage() {
1823 List
<String
> filters
= new ArrayList
<String
>();
1824 filters
.add("^.*\\.[Jj][Pp][Gg]$");
1825 filters
.add("^.*\\.[Jj][Pp][Ee][Gg]$");
1826 filters
.add("^.*\\.[Pp][Nn][Gg]$");
1827 filters
.add("^.*\\.[Gg][Ii][Ff]$");
1828 filters
.add("^.*\\.[Bb][Mm][Pp]$");
1829 String filename
= fileOpenBox(".", TFileOpenBox
.Type
.OPEN
, filters
);
1830 if (filename
!= null) {
1831 new TImageWindow(this, new File(filename
));
1833 } catch (IOException e
) {
1834 // Show this exception to the user.
1835 new TExceptionDialog(this, e
);
1840 * Check if application is still running.
1842 * @return true if the application is running
1844 public final boolean isRunning() {
1851 // ------------------------------------------------------------------------
1852 // Screen refresh loop ----------------------------------------------------
1853 // ------------------------------------------------------------------------
1856 * Draw the text mouse at position.
1858 * @param x column position
1859 * @param y row position
1861 private void drawTextMouse(final int x
, final int y
) {
1864 System
.err
.printf("%d %s drawTextMouse() %d %d\n",
1865 System
.currentTimeMillis(), Thread
.currentThread(), x
, y
);
1867 if (activeWindow
!= null) {
1868 System
.err
.println("activeWindow.hasHiddenMouse() " +
1869 activeWindow
.hasHiddenMouse());
1873 // If this cell is on top of a visible window that has requested a
1874 // hidden mouse, bail out.
1875 if ((activeWindow
!= null) && (activeMenu
== null)) {
1876 if ((activeWindow
.hasHiddenMouse() == true)
1877 && (x
> activeWindow
.getX())
1878 && (x
< activeWindow
.getX() + activeWindow
.getWidth() - 1)
1879 && (y
> activeWindow
.getY())
1880 && (y
< activeWindow
.getY() + activeWindow
.getHeight() - 1)
1886 // If this cell is on top of the desktop, and the desktop has
1887 // requested a hidden mouse, bail out.
1888 if ((desktop
!= null) && (activeWindow
== null) && (activeMenu
== null)) {
1889 if ((desktop
.hasHiddenMouse() == true)
1890 && (x
> desktop
.getX())
1891 && (x
< desktop
.getX() + desktop
.getWidth() - 1)
1892 && (y
> desktop
.getY())
1893 && (y
< desktop
.getY() + desktop
.getHeight() - 1)
1899 getScreen().invertCell(x
, y
);
1905 private void drawAll() {
1906 boolean menuIsActive
= false;
1909 System
.err
.printf("%d %s drawAll() enter\n",
1910 System
.currentTimeMillis(), Thread
.currentThread());
1913 // I don't think this does anything useful anymore...
1916 System
.err
.printf("%d %s drawAll() !repaint\n",
1917 System
.currentTimeMillis(), Thread
.currentThread());
1919 if ((oldDrawnMouseX
!= mouseX
) || (oldDrawnMouseY
!= mouseY
)) {
1921 System
.err
.printf("%d %s drawAll() !repaint MOUSE\n",
1922 System
.currentTimeMillis(), Thread
.currentThread());
1925 // The only thing that has happened is the mouse moved.
1927 // Redraw the old cell at that position, and save the cell at
1928 // the new mouse position.
1930 System
.err
.printf("%d %s restoreImage() %d %d\n",
1931 System
.currentTimeMillis(), Thread
.currentThread(),
1932 oldDrawnMouseX
, oldDrawnMouseY
);
1934 oldDrawnMouseCell
.restoreImage();
1935 getScreen().putCharXY(oldDrawnMouseX
, oldDrawnMouseY
,
1937 oldDrawnMouseCell
= getScreen().getCharXY(mouseX
, mouseY
);
1938 if (backend
instanceof ECMA48Backend
) {
1939 // Special case: the entire row containing the mouse has
1940 // to be re-drawn if it has any image data, AND any rows
1942 if (oldDrawnMouseY
!= mouseY
) {
1943 for (int i
= oldDrawnMouseY
; ;) {
1944 getScreen().unsetImageRow(i
);
1948 if (oldDrawnMouseY
< mouseY
) {
1955 getScreen().unsetImageRow(mouseY
);
1959 if (inScreenSelection
) {
1960 getScreen().setSelection(screenSelectionX0
,
1961 screenSelectionY0
, screenSelectionX1
, screenSelectionY1
,
1962 screenSelectionRectangle
);
1965 if ((textMouse
== true) && (typingHidMouse
== false)) {
1966 // Draw mouse at the new position.
1967 drawTextMouse(mouseX
, mouseY
);
1970 oldDrawnMouseX
= mouseX
;
1971 oldDrawnMouseY
= mouseY
;
1973 if (getScreen().isDirty()) {
1974 screenHandler
.setDirty();
1980 System
.err
.printf("%d %s drawAll() REDRAW\n",
1981 System
.currentTimeMillis(), Thread
.currentThread());
1984 // If true, the cursor is not visible
1985 boolean cursor
= false;
1987 // Start with a clean screen
1988 getScreen().clear();
1991 if (desktop
!= null) {
1992 desktop
.drawChildren();
1995 // Draw each window in reverse Z order
1996 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
1997 Collections
.sort(sorted
);
1998 TWindow topLevel
= null;
1999 if (sorted
.size() > 0) {
2000 topLevel
= sorted
.get(0);
2002 Collections
.reverse(sorted
);
2003 for (TWindow window
: sorted
) {
2004 if (window
.isShown()) {
2005 window
.drawChildren();
2009 if (hideMenuBar
== false) {
2011 // Draw the blank menubar line - reset the screen clipping first
2012 // so it won't trim it out.
2013 getScreen().resetClipping();
2014 getScreen().hLineXY(0, 0, getScreen().getWidth(), ' ',
2015 theme
.getColor("tmenu"));
2016 // Now draw the menus.
2018 for (TMenu menu
: menus
) {
2019 CellAttributes menuColor
;
2020 CellAttributes menuMnemonicColor
;
2021 if (menu
.isActive()) {
2022 menuIsActive
= true;
2023 menuColor
= theme
.getColor("tmenu.highlighted");
2024 menuMnemonicColor
= theme
.getColor("tmenu.mnemonic.highlighted");
2027 menuColor
= theme
.getColor("tmenu");
2028 menuMnemonicColor
= theme
.getColor("tmenu.mnemonic");
2030 // Draw the menu title
2031 getScreen().hLineXY(x
, 0,
2032 StringUtils
.width(menu
.getTitle()) + 2, ' ', menuColor
);
2033 getScreen().putStringXY(x
+ 1, 0, menu
.getTitle(), menuColor
);
2034 // Draw the highlight character
2035 getScreen().putCharXY(x
+ 1 +
2036 menu
.getMnemonic().getScreenShortcutIdx(),
2037 0, menu
.getMnemonic().getShortcut(), menuMnemonicColor
);
2039 if (menu
.isActive()) {
2040 ((TWindow
) menu
).drawChildren();
2041 // Reset the screen clipping so we can draw the next
2043 getScreen().resetClipping();
2045 x
+= StringUtils
.width(menu
.getTitle()) + 2;
2048 for (TMenu menu
: subMenus
) {
2049 // Reset the screen clipping so we can draw the next
2051 getScreen().resetClipping();
2052 ((TWindow
) menu
).drawChildren();
2055 getScreen().resetClipping();
2057 if (hideStatusBar
== false) {
2058 // Draw the status bar of the top-level window
2059 TStatusBar statusBar
= null;
2060 if (topLevel
!= null) {
2061 statusBar
= topLevel
.getStatusBar();
2063 if (statusBar
!= null) {
2064 getScreen().resetClipping();
2065 statusBar
.setWidth(getScreen().getWidth());
2066 statusBar
.setY(getScreen().getHeight() - topLevel
.getY());
2069 CellAttributes barColor
= new CellAttributes();
2070 barColor
.setTo(getTheme().getColor("tstatusbar.text"));
2071 getScreen().hLineXY(0, desktopBottom
, getScreen().getWidth(),
2076 // Draw the mouse pointer
2078 System
.err
.printf("%d %s restoreImage() %d %d\n",
2079 System
.currentTimeMillis(), Thread
.currentThread(),
2080 oldDrawnMouseX
, oldDrawnMouseY
);
2082 oldDrawnMouseCell
= getScreen().getCharXY(mouseX
, mouseY
);
2083 if (backend
instanceof ECMA48Backend
) {
2084 // Special case: the entire row containing the mouse has to be
2085 // re-drawn if it has any image data, AND any rows in between.
2086 if (oldDrawnMouseY
!= mouseY
) {
2087 for (int i
= oldDrawnMouseY
; ;) {
2088 getScreen().unsetImageRow(i
);
2092 if (oldDrawnMouseY
< mouseY
) {
2099 getScreen().unsetImageRow(mouseY
);
2103 if (inScreenSelection
) {
2104 getScreen().setSelection(screenSelectionX0
, screenSelectionY0
,
2105 screenSelectionX1
, screenSelectionY1
, screenSelectionRectangle
);
2108 if ((textMouse
== true) && (typingHidMouse
== false)) {
2109 drawTextMouse(mouseX
, mouseY
);
2111 oldDrawnMouseX
= mouseX
;
2112 oldDrawnMouseY
= mouseY
;
2114 // Place the cursor if it is visible
2115 if (!menuIsActive
) {
2117 int visibleWindowCount
= 0;
2118 for (TWindow window
: sorted
) {
2119 if (window
.isShown()) {
2120 visibleWindowCount
++;
2123 if (visibleWindowCount
== 0) {
2124 // No windows are visible, only the desktop. Allow it to
2126 if (desktop
!= null) {
2127 sorted
.add(desktop
);
2131 TWidget activeWidget
= null;
2132 if (sorted
.size() > 0) {
2133 activeWidget
= sorted
.get(sorted
.size() - 1).getActiveChild();
2134 int cursorClipTop
= desktopTop
;
2135 int cursorClipBottom
= desktopBottom
;
2136 if (activeWidget
.isCursorVisible()) {
2137 if ((activeWidget
.getCursorAbsoluteY() <= cursorClipBottom
)
2138 && (activeWidget
.getCursorAbsoluteY() >= cursorClipTop
)
2140 getScreen().putCursor(true,
2141 activeWidget
.getCursorAbsoluteX(),
2142 activeWidget
.getCursorAbsoluteY());
2145 // Turn off the cursor. Also place it at 0,0.
2146 getScreen().putCursor(false, 0, 0);
2155 getScreen().hideCursor();
2158 if (getScreen().isDirty()) {
2159 screenHandler
.setDirty();
2165 * Force this application to exit.
2167 public void exit() {
2169 synchronized (this) {
2175 * Subclasses can use this hook to cleanup resources. Called as the last
2176 * step of TApplication.run().
2178 public void onExit() {
2179 // Default does nothing.
2182 // ------------------------------------------------------------------------
2183 // TWindow management -----------------------------------------------------
2184 // ------------------------------------------------------------------------
2187 * Return the total number of windows.
2189 * @return the total number of windows
2191 public final int windowCount() {
2192 return windows
.size();
2196 * Return the number of windows that are showing.
2198 * @return the number of windows that are showing on screen
2200 public final int shownWindowCount() {
2202 for (TWindow w
: windows
) {
2211 * Return the number of windows that are hidden.
2213 * @return the number of windows that are hidden
2215 public final int hiddenWindowCount() {
2217 for (TWindow w
: windows
) {
2226 * Check if a window instance is in this application's window list.
2228 * @param window window to look for
2229 * @return true if this window is in the list
2231 public final boolean hasWindow(final TWindow window
) {
2232 if (windows
.size() == 0) {
2235 for (TWindow w
: windows
) {
2237 assert (window
.getApplication() == this);
2245 * Activate a window: bring it to the top and have it receive events.
2247 * @param window the window to become the new active window
2249 public void activateWindow(final TWindow window
) {
2250 if (hasWindow(window
) == false) {
2252 * Someone has a handle to a window I don't have. Ignore this
2258 // Whatever window might be moving/dragging, stop it now.
2259 for (TWindow w
: windows
) {
2260 if (w
.inMovements()) {
2265 assert (windows
.size() > 0);
2267 if (window
.isHidden()) {
2268 // Unhiding will also activate.
2272 assert (window
.isShown());
2274 if (windows
.size() == 1) {
2275 assert (window
== windows
.get(0));
2276 if (activeWindow
== null) {
2277 activeWindow
= window
;
2279 activeWindow
.setActive(true);
2280 activeWindow
.onFocus();
2283 assert (window
.isActive());
2284 assert (activeWindow
== window
);
2288 if (activeWindow
== window
) {
2289 assert (window
.isActive());
2291 // Window is already active, do nothing.
2295 assert (!window
.isActive());
2296 if (activeWindow
!= null) {
2297 activeWindow
.setActive(false);
2299 // Increment every window Z that is on top of window
2300 for (TWindow w
: windows
) {
2304 if (w
.getZ() < window
.getZ()) {
2305 w
.setZ(w
.getZ() + 1);
2309 // Unset activeWindow now before unfocus, so that a window
2310 // lifecycle change inside onUnfocus() doesn't call
2311 // switchWindow() and lead to a stack overflow.
2312 TWindow oldActiveWindow
= activeWindow
;
2313 activeWindow
= null;
2314 oldActiveWindow
.onUnfocus();
2316 activeWindow
= window
;
2317 activeWindow
.setZ(0);
2318 activeWindow
.setActive(true);
2319 activeWindow
.onFocus();
2326 * @param window the window to hide
2328 public void hideWindow(final TWindow window
) {
2329 if (hasWindow(window
) == false) {
2331 * Someone has a handle to a window I don't have. Ignore this
2337 // Whatever window might be moving/dragging, stop it now.
2338 for (TWindow w
: windows
) {
2339 if (w
.inMovements()) {
2344 assert (windows
.size() > 0);
2346 if (!window
.hidden
) {
2347 if (window
== activeWindow
) {
2348 if (shownWindowCount() > 1) {
2351 activeWindow
= null;
2352 window
.setActive(false);
2356 window
.hidden
= true;
2364 * @param window the window to show
2366 public void showWindow(final TWindow window
) {
2367 if (hasWindow(window
) == false) {
2369 * Someone has a handle to a window I don't have. Ignore this
2375 // Whatever window might be moving/dragging, stop it now.
2376 for (TWindow w
: windows
) {
2377 if (w
.inMovements()) {
2382 assert (windows
.size() > 0);
2384 if (window
.hidden
) {
2385 window
.hidden
= false;
2387 activateWindow(window
);
2392 * Close window. Note that the window's destructor is NOT called by this
2393 * method, instead the GC is assumed to do the cleanup.
2395 * @param window the window to remove
2397 public final void closeWindow(final TWindow window
) {
2398 if (hasWindow(window
) == false) {
2400 * Someone has a handle to a window I don't have. Ignore this
2406 // Let window know that it is about to be closed, while it is still
2407 // visible on screen.
2408 window
.onPreClose();
2410 synchronized (windows
) {
2411 // Whatever window might be moving/dragging, stop it now.
2412 for (TWindow w
: windows
) {
2413 if (w
.inMovements()) {
2418 int z
= window
.getZ();
2421 windows
.remove(window
);
2422 Collections
.sort(windows
);
2423 activeWindow
= null;
2425 boolean foundNextWindow
= false;
2427 for (TWindow w
: windows
) {
2431 // Do not activate a hidden window.
2436 if (foundNextWindow
== false) {
2437 foundNextWindow
= true;
2440 assert (activeWindow
== null);
2452 // Perform window cleanup
2455 // Check if we are closing a TMessageBox or similar
2456 if (secondaryEventReceiver
!= null) {
2457 assert (secondaryEventHandler
!= null);
2459 // Do not send events to the secondaryEventReceiver anymore, the
2460 // window is closed.
2461 secondaryEventReceiver
= null;
2463 // Wake the secondary thread, it will wake the primary as it
2465 synchronized (secondaryEventHandler
) {
2466 secondaryEventHandler
.notify();
2470 // Permit desktop to be active if it is the only thing left.
2471 if (desktop
!= null) {
2472 if (windows
.size() == 0) {
2473 desktop
.setActive(true);
2479 * Switch to the next window.
2481 * @param forward if true, then switch to the next window in the list,
2482 * otherwise switch to the previous window in the list
2484 public final void switchWindow(final boolean forward
) {
2485 // Only switch if there are multiple visible windows
2486 if (shownWindowCount() < 2) {
2489 assert (activeWindow
!= null);
2491 synchronized (windows
) {
2492 // Whatever window might be moving/dragging, stop it now.
2493 for (TWindow w
: windows
) {
2494 if (w
.inMovements()) {
2499 // Swap z/active between active window and the next in the list
2500 int activeWindowI
= -1;
2501 for (int i
= 0; i
< windows
.size(); i
++) {
2502 if (windows
.get(i
) == activeWindow
) {
2503 assert (activeWindow
.isActive());
2507 assert (!windows
.get(0).isActive());
2510 assert (activeWindowI
>= 0);
2512 // Do not switch if a window is modal
2513 if (activeWindow
.isModal()) {
2517 int nextWindowI
= activeWindowI
;
2521 nextWindowI
%= windows
.size();
2524 if (nextWindowI
< 0) {
2525 nextWindowI
= windows
.size() - 1;
2529 if (windows
.get(nextWindowI
).isShown()) {
2530 activateWindow(windows
.get(nextWindowI
));
2534 } // synchronized (windows)
2539 * Add a window to my window list and make it active. Note package
2542 * @param window new window to add
2544 final void addWindowToApplication(final TWindow window
) {
2546 // Do not add menu windows to the window list.
2547 if (window
instanceof TMenu
) {
2551 // Do not add the desktop to the window list.
2552 if (window
instanceof TDesktop
) {
2556 synchronized (windows
) {
2557 if (windows
.contains(window
)) {
2558 throw new IllegalArgumentException("Window " + window
+
2559 " is already in window list");
2562 // Whatever window might be moving/dragging, stop it now.
2563 for (TWindow w
: windows
) {
2564 if (w
.inMovements()) {
2569 // Do not allow a modal window to spawn a non-modal window. If a
2570 // modal window is active, then this window will become modal
2572 if (modalWindowActive()) {
2573 window
.flags
|= TWindow
.MODAL
;
2574 window
.flags
|= TWindow
.CENTERED
;
2575 window
.hidden
= false;
2577 if (window
.isShown()) {
2578 for (TWindow w
: windows
) {
2583 w
.setZ(w
.getZ() + 1);
2586 windows
.add(window
);
2587 if (window
.isShown()) {
2588 activeWindow
= window
;
2589 activeWindow
.setZ(0);
2590 activeWindow
.setActive(true);
2591 activeWindow
.onFocus();
2594 if (((window
.flags
& TWindow
.CENTERED
) == 0)
2595 && ((window
.flags
& TWindow
.ABSOLUTEXY
) == 0)
2596 && (smartWindowPlacement
== true)
2597 && (!(window
instanceof TDesktop
))
2600 doSmartPlacement(window
);
2604 // Desktop cannot be active over any other window.
2605 if (desktop
!= null) {
2606 desktop
.setActive(false);
2611 * Check if there is a system-modal window on top.
2613 * @return true if the active window is modal
2615 private boolean modalWindowActive() {
2616 if (windows
.size() == 0) {
2620 for (TWindow w
: windows
) {
2630 * Check if there is a window with overridden menu flag on top.
2632 * @return true if the active window is overriding the menu
2634 private boolean overrideMenuWindowActive() {
2635 if (activeWindow
!= null) {
2636 if (activeWindow
.hasOverriddenMenu()) {
2645 * Close all open windows.
2647 private void closeAllWindows() {
2648 // Don't do anything if we are in the menu
2649 if (activeMenu
!= null) {
2652 while (windows
.size() > 0) {
2653 closeWindow(windows
.get(0));
2658 * Re-layout the open windows as non-overlapping tiles. This produces
2659 * almost the same results as Turbo Pascal 7.0's IDE.
2661 private void tileWindows() {
2662 synchronized (windows
) {
2663 // Don't do anything if we are in the menu
2664 if (activeMenu
!= null) {
2667 int z
= windows
.size();
2673 a
= (int)(Math
.sqrt(z
));
2677 if (((a
* b
) + c
) == z
) {
2685 int newWidth
= (getScreen().getWidth() / a
);
2686 int newHeight1
= ((getScreen().getHeight() - 1) / b
);
2687 int newHeight2
= ((getScreen().getHeight() - 1) / (b
+ c
));
2689 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
2690 Collections
.sort(sorted
);
2691 Collections
.reverse(sorted
);
2692 for (int i
= 0; i
< sorted
.size(); i
++) {
2693 int logicalX
= i
/ b
;
2694 int logicalY
= i
% b
;
2695 if (i
>= ((a
- 1) * b
)) {
2697 logicalY
= i
- ((a
- 1) * b
);
2700 TWindow w
= sorted
.get(i
);
2701 int oldWidth
= w
.getWidth();
2702 int oldHeight
= w
.getHeight();
2704 w
.setX(logicalX
* newWidth
);
2705 w
.setWidth(newWidth
);
2706 if (i
>= ((a
- 1) * b
)) {
2707 w
.setY((logicalY
* newHeight2
) + 1);
2708 w
.setHeight(newHeight2
);
2710 w
.setY((logicalY
* newHeight1
) + 1);
2711 w
.setHeight(newHeight1
);
2713 if ((w
.getWidth() != oldWidth
)
2714 || (w
.getHeight() != oldHeight
)
2716 w
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
2717 w
.getWidth(), w
.getHeight()));
2724 * Re-layout the open windows as overlapping cascaded windows.
2726 private void cascadeWindows() {
2727 synchronized (windows
) {
2728 // Don't do anything if we are in the menu
2729 if (activeMenu
!= null) {
2734 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
2735 Collections
.sort(sorted
);
2736 Collections
.reverse(sorted
);
2737 for (TWindow window
: sorted
) {
2742 if (x
> getScreen().getWidth()) {
2745 if (y
>= getScreen().getHeight()) {
2753 * Place a window to minimize its overlap with other windows.
2755 * @param window the window to place
2757 public final void doSmartPlacement(final TWindow window
) {
2758 // This is a pretty dumb algorithm, but seems to work. The hardest
2759 // part is computing these "overlap" values seeking a minimum average
2762 int yMin
= desktopTop
;
2763 int xMax
= getScreen().getWidth() - window
.getWidth() + 1;
2764 int yMax
= desktopBottom
- window
.getHeight() + 1;
2772 if ((xMin
== xMax
) && (yMin
== yMax
)) {
2773 // No work to do, bail out.
2777 // Compute the overlap matrix without the new window.
2778 int width
= getScreen().getWidth();
2779 int height
= getScreen().getHeight();
2780 int overlapMatrix
[][] = new int[width
][height
];
2781 for (TWindow w
: windows
) {
2785 for (int x
= w
.getX(); x
< w
.getX() + w
.getWidth(); x
++) {
2792 for (int y
= w
.getY(); y
< w
.getY() + w
.getHeight(); y
++) {
2799 overlapMatrix
[x
][y
]++;
2804 long oldOverlapTotal
= 0;
2805 long oldOverlapN
= 0;
2806 for (int x
= 0; x
< width
; x
++) {
2807 for (int y
= 0; y
< height
; y
++) {
2808 oldOverlapTotal
+= overlapMatrix
[x
][y
];
2809 if (overlapMatrix
[x
][y
] > 0) {
2816 double oldOverlapAvg
= (double) oldOverlapTotal
/ (double) oldOverlapN
;
2817 boolean first
= true;
2818 int windowX
= window
.getX();
2819 int windowY
= window
.getY();
2821 // For each possible (x, y) position for the new window, compute a
2822 // new overlap matrix.
2823 for (int x
= xMin
; x
< xMax
; x
++) {
2824 for (int y
= yMin
; y
< yMax
; y
++) {
2826 // Start with the matrix minus this window.
2827 int newMatrix
[][] = new int[width
][height
];
2828 for (int mx
= 0; mx
< width
; mx
++) {
2829 for (int my
= 0; my
< height
; my
++) {
2830 newMatrix
[mx
][my
] = overlapMatrix
[mx
][my
];
2834 // Add this window's values to the new overlap matrix.
2835 long newOverlapTotal
= 0;
2836 long newOverlapN
= 0;
2837 // Start by adding each new cell.
2838 for (int wx
= x
; wx
< x
+ window
.getWidth(); wx
++) {
2842 for (int wy
= y
; wy
< y
+ window
.getHeight(); wy
++) {
2846 newMatrix
[wx
][wy
]++;
2849 // Now figure out the new value for total coverage.
2850 for (int mx
= 0; mx
< width
; mx
++) {
2851 for (int my
= 0; my
< height
; my
++) {
2852 newOverlapTotal
+= newMatrix
[x
][y
];
2853 if (newMatrix
[mx
][my
] > 0) {
2858 double newOverlapAvg
= (double) newOverlapTotal
/ (double) newOverlapN
;
2861 // First time: just record what we got.
2862 oldOverlapAvg
= newOverlapAvg
;
2865 // All other times: pick a new best (x, y) and save the
2867 if (newOverlapAvg
< oldOverlapAvg
) {
2870 oldOverlapAvg
= newOverlapAvg
;
2874 } // for (int x = xMin; x < xMax; x++)
2876 } // for (int y = yMin; y < yMax; y++)
2878 // Finally, set the window's new coordinates.
2879 window
.setX(windowX
);
2880 window
.setY(windowY
);
2883 // ------------------------------------------------------------------------
2884 // TMenu management -------------------------------------------------------
2885 // ------------------------------------------------------------------------
2888 * Check if a mouse event would hit either the active menu or any open
2891 * @param mouse mouse event
2892 * @return true if the mouse would hit the active menu or an open
2895 private boolean mouseOnMenu(final TMouseEvent mouse
) {
2896 assert (activeMenu
!= null);
2897 List
<TMenu
> menus
= new ArrayList
<TMenu
>(subMenus
);
2898 Collections
.reverse(menus
);
2899 for (TMenu menu
: menus
) {
2900 if (menu
.mouseWouldHit(mouse
)) {
2904 return activeMenu
.mouseWouldHit(mouse
);
2908 * See if we need to switch window or activate the menu based on
2911 * @param mouse mouse event
2913 private void checkSwitchFocus(final TMouseEvent mouse
) {
2915 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2916 && (activeMenu
!= null)
2917 && (mouse
.getAbsoluteY() != 0)
2918 && (!mouseOnMenu(mouse
))
2920 // They clicked outside the active menu, turn it off
2921 activeMenu
.setActive(false);
2923 for (TMenu menu
: subMenus
) {
2924 menu
.setActive(false);
2930 // See if they hit the menu bar
2931 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2932 && (mouse
.isMouse1())
2933 && (!modalWindowActive())
2934 && (!overrideMenuWindowActive())
2935 && (mouse
.getAbsoluteY() == 0)
2936 && (hideMenuBar
== false)
2939 for (TMenu menu
: subMenus
) {
2940 menu
.setActive(false);
2944 // They selected the menu, go activate it
2945 for (TMenu menu
: menus
) {
2946 if ((mouse
.getAbsoluteX() >= menu
.getTitleX())
2947 && (mouse
.getAbsoluteX() < menu
.getTitleX()
2948 + StringUtils
.width(menu
.getTitle()) + 2)
2950 menu
.setActive(true);
2953 menu
.setActive(false);
2959 // See if they hit the menu bar
2960 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
)
2961 && (mouse
.isMouse1())
2962 && (activeMenu
!= null)
2963 && (mouse
.getAbsoluteY() == 0)
2964 && (hideMenuBar
== false)
2967 TMenu oldMenu
= activeMenu
;
2968 for (TMenu menu
: subMenus
) {
2969 menu
.setActive(false);
2973 // See if we should switch menus
2974 for (TMenu menu
: menus
) {
2975 if ((mouse
.getAbsoluteX() >= menu
.getTitleX())
2976 && (mouse
.getAbsoluteX() < menu
.getTitleX()
2977 + StringUtils
.width(menu
.getTitle()) + 2)
2979 menu
.setActive(true);
2983 if (oldMenu
!= activeMenu
) {
2984 // They switched menus
2985 oldMenu
.setActive(false);
2990 // If a menu is still active, don't switch windows
2991 if (activeMenu
!= null) {
2995 // Only switch if there are multiple windows
2996 if (windows
.size() < 2) {
3000 if (((focusFollowsMouse
== true)
3001 && (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
))
3002 || (mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
3004 synchronized (windows
) {
3005 Collections
.sort(windows
);
3006 if (windows
.get(0).isModal()) {
3007 // Modal windows don't switch
3011 for (TWindow window
: windows
) {
3012 assert (!window
.isModal());
3014 if (window
.isHidden()) {
3015 assert (!window
.isActive());
3019 if (window
.mouseWouldHit(mouse
)) {
3020 if (window
== windows
.get(0)) {
3021 // Clicked on the same window, nothing to do
3022 assert (window
.isActive());
3026 // We will be switching to another window
3027 assert (windows
.get(0).isActive());
3028 assert (windows
.get(0) == activeWindow
);
3029 assert (!window
.isActive());
3030 if (activeWindow
!= null) {
3031 activeWindow
.onUnfocus();
3032 activeWindow
.setActive(false);
3033 activeWindow
.setZ(window
.getZ());
3035 activeWindow
= window
;
3037 window
.setActive(true);
3044 // Clicked on the background, nothing to do
3048 // Nothing to do: this isn't a mouse up, or focus isn't following
3054 * Turn off the menu.
3056 public final void closeMenu() {
3057 if (activeMenu
!= null) {
3058 activeMenu
.setActive(false);
3060 for (TMenu menu
: subMenus
) {
3061 menu
.setActive(false);
3068 * Get a (shallow) copy of the menu list.
3070 * @return a copy of the menu list
3072 public final List
<TMenu
> getAllMenus() {
3073 return new ArrayList
<TMenu
>(menus
);
3077 * Add a top-level menu to the list.
3079 * @param menu the menu to add
3080 * @throws IllegalArgumentException if the menu is already used in
3081 * another TApplication
3083 public final void addMenu(final TMenu menu
) {
3084 if ((menu
.getApplication() != null)
3085 && (menu
.getApplication() != this)
3087 throw new IllegalArgumentException("Menu " + menu
+ " is already " +
3088 "part of application " + menu
.getApplication());
3096 * Remove a top-level menu from the list.
3098 * @param menu the menu to remove
3099 * @throws IllegalArgumentException if the menu is already used in
3100 * another TApplication
3102 public final void removeMenu(final TMenu menu
) {
3103 if ((menu
.getApplication() != null)
3104 && (menu
.getApplication() != this)
3106 throw new IllegalArgumentException("Menu " + menu
+ " is already " +
3107 "part of application " + menu
.getApplication());
3115 * Turn off a sub-menu.
3117 public final void closeSubMenu() {
3118 assert (activeMenu
!= null);
3119 TMenu item
= subMenus
.get(subMenus
.size() - 1);
3120 assert (item
!= null);
3121 item
.setActive(false);
3122 subMenus
.remove(subMenus
.size() - 1);
3126 * Switch to the next menu.
3128 * @param forward if true, then switch to the next menu in the list,
3129 * otherwise switch to the previous menu in the list
3131 public final void switchMenu(final boolean forward
) {
3132 assert (activeMenu
!= null);
3133 assert (hideMenuBar
== false);
3135 for (TMenu menu
: subMenus
) {
3136 menu
.setActive(false);
3140 for (int i
= 0; i
< menus
.size(); i
++) {
3141 if (activeMenu
== menus
.get(i
)) {
3143 if (i
< menus
.size() - 1) {
3152 i
= menus
.size() - 1;
3155 activeMenu
.setActive(false);
3156 activeMenu
= menus
.get(i
);
3157 activeMenu
.setActive(true);
3164 * Add a menu item to the global list. If it has a keyboard accelerator,
3165 * that will be added the global hash.
3167 * @param item the menu item
3169 public final void addMenuItem(final TMenuItem item
) {
3170 menuItems
.add(item
);
3172 TKeypress key
= item
.getKey();
3174 synchronized (accelerators
) {
3175 assert (accelerators
.get(key
) == null);
3176 accelerators
.put(key
.toLowerCase(), item
);
3182 * Disable one menu item.
3184 * @param id the menu item ID
3186 public final void disableMenuItem(final int id
) {
3187 for (TMenuItem item
: menuItems
) {
3188 if (item
.getId() == id
) {
3189 item
.setEnabled(false);
3195 * Disable the range of menu items with ID's between lower and upper,
3198 * @param lower the lowest menu item ID
3199 * @param upper the highest menu item ID
3201 public final void disableMenuItems(final int lower
, final int upper
) {
3202 for (TMenuItem item
: menuItems
) {
3203 if ((item
.getId() >= lower
) && (item
.getId() <= upper
)) {
3204 item
.setEnabled(false);
3205 item
.getParent().activate(0);
3211 * Enable one menu item.
3213 * @param id the menu item ID
3215 public final void enableMenuItem(final int id
) {
3216 for (TMenuItem item
: menuItems
) {
3217 if (item
.getId() == id
) {
3218 item
.setEnabled(true);
3219 item
.getParent().activate(0);
3225 * Enable the range of menu items with ID's between lower and upper,
3228 * @param lower the lowest menu item ID
3229 * @param upper the highest menu item ID
3231 public final void enableMenuItems(final int lower
, final int upper
) {
3232 for (TMenuItem item
: menuItems
) {
3233 if ((item
.getId() >= lower
) && (item
.getId() <= upper
)) {
3234 item
.setEnabled(true);
3235 item
.getParent().activate(0);
3241 * Get the menu item associated with this ID.
3243 * @param id the menu item ID
3244 * @return the menu item, or null if not found
3246 public final TMenuItem
getMenuItem(final int id
) {
3247 for (TMenuItem item
: menuItems
) {
3248 if (item
.getId() == id
) {
3256 * Recompute menu x positions based on their title length.
3258 public final void recomputeMenuX() {
3260 for (TMenu menu
: menus
) {
3263 x
+= StringUtils
.width(menu
.getTitle()) + 2;
3265 // Don't let the menu window exceed the screen width
3266 int rightEdge
= menu
.getX() + menu
.getWidth();
3267 if (rightEdge
> getScreen().getWidth()) {
3268 menu
.setX(getScreen().getWidth() - menu
.getWidth());
3274 * Post an event to process.
3276 * @param event new event to add to the queue
3278 public final void postEvent(final TInputEvent event
) {
3279 synchronized (this) {
3280 synchronized (fillEventQueue
) {
3281 fillEventQueue
.add(event
);
3284 System
.err
.println(System
.currentTimeMillis() + " " +
3285 Thread
.currentThread() + " postEvent() wake up main");
3292 * Post an event to process and turn off the menu.
3294 * @param event new event to add to the queue
3296 public final void postMenuEvent(final TInputEvent event
) {
3297 synchronized (this) {
3298 synchronized (fillEventQueue
) {
3299 fillEventQueue
.add(event
);
3302 System
.err
.println(System
.currentTimeMillis() + " " +
3303 Thread
.currentThread() + " postMenuEvent() wake up main");
3311 * Add a sub-menu to the list of open sub-menus.
3313 * @param menu sub-menu
3315 public final void addSubMenu(final TMenu menu
) {
3320 * Convenience function to add a top-level menu.
3322 * @param title menu title
3323 * @return the new menu
3325 public final TMenu
addMenu(final String title
) {
3328 TMenu menu
= new TMenu(this, x
, y
, title
);
3335 * Convenience function to add a default tools (hamburger) menu.
3337 * @return the new menu
3339 public final TMenu
addToolMenu() {
3340 TMenu toolMenu
= addMenu(i18n
.getString("toolMenuTitle"));
3341 toolMenu
.addDefaultItem(TMenu
.MID_REPAINT
);
3342 toolMenu
.addDefaultItem(TMenu
.MID_VIEW_IMAGE
);
3343 toolMenu
.addDefaultItem(TMenu
.MID_SCREEN_OPTIONS
);
3344 TStatusBar toolStatusBar
= toolMenu
.newStatusBar(i18n
.
3345 getString("toolMenuStatus"));
3346 toolStatusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3351 * Convenience function to add a default "File" menu.
3353 * @return the new menu
3355 public final TMenu
addFileMenu() {
3356 TMenu fileMenu
= addMenu(i18n
.getString("fileMenuTitle"));
3357 fileMenu
.addDefaultItem(TMenu
.MID_SHELL
);
3358 fileMenu
.addSeparator();
3359 fileMenu
.addDefaultItem(TMenu
.MID_EXIT
);
3360 TStatusBar statusBar
= fileMenu
.newStatusBar(i18n
.
3361 getString("fileMenuStatus"));
3362 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3367 * Convenience function to add a default "Edit" menu.
3369 * @return the new menu
3371 public final TMenu
addEditMenu() {
3372 TMenu editMenu
= addMenu(i18n
.getString("editMenuTitle"));
3373 editMenu
.addDefaultItem(TMenu
.MID_CUT
, false);
3374 editMenu
.addDefaultItem(TMenu
.MID_COPY
, false);
3375 editMenu
.addDefaultItem(TMenu
.MID_PASTE
, false);
3376 editMenu
.addDefaultItem(TMenu
.MID_CLEAR
, false);
3377 TStatusBar statusBar
= editMenu
.newStatusBar(i18n
.
3378 getString("editMenuStatus"));
3379 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3384 * Convenience function to add a default "Window" menu.
3386 * @return the new menu
3388 public final TMenu
addWindowMenu() {
3389 TMenu windowMenu
= addMenu(i18n
.getString("windowMenuTitle"));
3390 windowMenu
.addDefaultItem(TMenu
.MID_TILE
);
3391 windowMenu
.addDefaultItem(TMenu
.MID_CASCADE
);
3392 windowMenu
.addDefaultItem(TMenu
.MID_CLOSE_ALL
);
3393 windowMenu
.addSeparator();
3394 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_MOVE
);
3395 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_ZOOM
);
3396 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_NEXT
);
3397 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_PREVIOUS
);
3398 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_CLOSE
);
3399 TStatusBar statusBar
= windowMenu
.newStatusBar(i18n
.
3400 getString("windowMenuStatus"));
3401 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3406 * Convenience function to add a default "Help" menu.
3408 * @return the new menu
3410 public final TMenu
addHelpMenu() {
3411 TMenu helpMenu
= addMenu(i18n
.getString("helpMenuTitle"));
3412 helpMenu
.addDefaultItem(TMenu
.MID_HELP_CONTENTS
);
3413 helpMenu
.addDefaultItem(TMenu
.MID_HELP_INDEX
);
3414 helpMenu
.addDefaultItem(TMenu
.MID_HELP_SEARCH
);
3415 helpMenu
.addDefaultItem(TMenu
.MID_HELP_PREVIOUS
);
3416 helpMenu
.addDefaultItem(TMenu
.MID_HELP_HELP
);
3417 helpMenu
.addDefaultItem(TMenu
.MID_HELP_ACTIVE_FILE
);
3418 helpMenu
.addSeparator();
3419 helpMenu
.addDefaultItem(TMenu
.MID_ABOUT
);
3420 TStatusBar statusBar
= helpMenu
.newStatusBar(i18n
.
3421 getString("helpMenuStatus"));
3422 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3427 * Convenience function to add a default "Table" menu.
3429 * @return the new menu
3431 public final TMenu
addTableMenu() {
3432 TMenu tableMenu
= addMenu(i18n
.getString("tableMenuTitle"));
3433 tableMenu
.addDefaultItem(TMenu
.MID_TABLE_RENAME_COLUMN
, false);
3434 tableMenu
.addDefaultItem(TMenu
.MID_TABLE_RENAME_ROW
, false);
3435 tableMenu
.addSeparator();
3437 TSubMenu viewMenu
= tableMenu
.addSubMenu(i18n
.
3438 getString("tableSubMenuView"));
3439 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_ROW_LABELS
, false);
3440 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_COLUMN_LABELS
, false);
3441 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_HIGHLIGHT_ROW
, false);
3442 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_HIGHLIGHT_COLUMN
, false);
3444 TSubMenu borderMenu
= tableMenu
.addSubMenu(i18n
.
3445 getString("tableSubMenuBorders"));
3446 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_NONE
, false);
3447 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_ALL
, false);
3448 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_CELL_NONE
, false);
3449 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_CELL_ALL
, false);
3450 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_RIGHT
, false);
3451 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_LEFT
, false);
3452 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_TOP
, false);
3453 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_BOTTOM
, false);
3454 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_DOUBLE_BOTTOM
, false);
3455 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_THICK_BOTTOM
, false);
3456 TSubMenu deleteMenu
= tableMenu
.addSubMenu(i18n
.
3457 getString("tableSubMenuDelete"));
3458 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_LEFT
, false);
3459 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_UP
, false);
3460 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_ROW
, false);
3461 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_COLUMN
, false);
3462 TSubMenu insertMenu
= tableMenu
.addSubMenu(i18n
.
3463 getString("tableSubMenuInsert"));
3464 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_LEFT
, false);
3465 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_RIGHT
, false);
3466 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_ABOVE
, false);
3467 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_BELOW
, false);
3468 TSubMenu columnMenu
= tableMenu
.addSubMenu(i18n
.
3469 getString("tableSubMenuColumn"));
3470 columnMenu
.addDefaultItem(TMenu
.MID_TABLE_COLUMN_NARROW
, false);
3471 columnMenu
.addDefaultItem(TMenu
.MID_TABLE_COLUMN_WIDEN
, false);
3472 TSubMenu fileMenu
= tableMenu
.addSubMenu(i18n
.
3473 getString("tableSubMenuFile"));
3474 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_OPEN_CSV
, false);
3475 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_SAVE_CSV
, false);
3476 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_SAVE_TEXT
, false);
3478 TStatusBar statusBar
= tableMenu
.newStatusBar(i18n
.
3479 getString("tableMenuStatus"));
3480 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3484 // ------------------------------------------------------------------------
3485 // TTimer management ------------------------------------------------------
3486 // ------------------------------------------------------------------------
3489 * Get the amount of time I can sleep before missing a Timer tick.
3491 * @param timeout = initial (maximum) timeout in millis
3492 * @return number of milliseconds between now and the next timer event
3494 private long getSleepTime(final long timeout
) {
3495 Date now
= new Date();
3496 long nowTime
= now
.getTime();
3497 long sleepTime
= timeout
;
3499 synchronized (timers
) {
3500 for (TTimer timer
: timers
) {
3501 long nextTickTime
= timer
.getNextTick().getTime();
3502 if (nextTickTime
< nowTime
) {
3506 long timeDifference
= nextTickTime
- nowTime
;
3507 if (timeDifference
< sleepTime
) {
3508 sleepTime
= timeDifference
;
3513 assert (sleepTime
>= 0);
3514 assert (sleepTime
<= timeout
);
3519 * Convenience function to add a timer.
3521 * @param duration number of milliseconds to wait between ticks
3522 * @param recurring if true, re-schedule this timer after every tick
3523 * @param action function to call when button is pressed
3526 public final TTimer
addTimer(final long duration
, final boolean recurring
,
3527 final TAction action
) {
3529 TTimer timer
= new TTimer(duration
, recurring
, action
);
3530 synchronized (timers
) {
3537 * Convenience function to remove a timer.
3539 * @param timer timer to remove
3541 public final void removeTimer(final TTimer timer
) {
3542 synchronized (timers
) {
3543 timers
.remove(timer
);
3547 // ------------------------------------------------------------------------
3548 // Other TWindow constructors ---------------------------------------------
3549 // ------------------------------------------------------------------------
3552 * Convenience function to spawn a message box.
3554 * @param title window title, will be centered along the top border
3555 * @param caption message to display. Use embedded newlines to get a
3557 * @return the new message box
3559 public final TMessageBox
messageBox(final String title
,
3560 final String caption
) {
3562 return new TMessageBox(this, title
, caption
, TMessageBox
.Type
.OK
);
3566 * Convenience function to spawn a message box.
3568 * @param title window title, will be centered along the top border
3569 * @param caption message to display. Use embedded newlines to get a
3571 * @param type one of the TMessageBox.Type constants. Default is
3573 * @return the new message box
3575 public final TMessageBox
messageBox(final String title
,
3576 final String caption
, final TMessageBox
.Type type
) {
3578 return new TMessageBox(this, title
, caption
, type
);
3582 * Convenience function to spawn an input box.
3584 * @param title window title, will be centered along the top border
3585 * @param caption message to display. Use embedded newlines to get a
3587 * @return the new input box
3589 public final TInputBox
inputBox(final String title
, final String caption
) {
3591 return new TInputBox(this, title
, caption
);
3595 * Convenience function to spawn an input box.
3597 * @param title window title, will be centered along the top border
3598 * @param caption message to display. Use embedded newlines to get a
3600 * @param text initial text to seed the field with
3601 * @return the new input box
3603 public final TInputBox
inputBox(final String title
, final String caption
,
3604 final String text
) {
3606 return new TInputBox(this, title
, caption
, text
);
3610 * Convenience function to spawn an input box.
3612 * @param title window title, will be centered along the top border
3613 * @param caption message to display. Use embedded newlines to get a
3615 * @param text initial text to seed the field with
3616 * @param type one of the Type constants. Default is Type.OK.
3617 * @return the new input box
3619 public final TInputBox
inputBox(final String title
, final String caption
,
3620 final String text
, final TInputBox
.Type type
) {
3622 return new TInputBox(this, title
, caption
, text
, type
);
3626 * Convenience function to open a terminal window.
3628 * @param x column relative to parent
3629 * @param y row relative to parent
3630 * @return the terminal new window
3632 public final TTerminalWindow
openTerminal(final int x
, final int y
) {
3633 return openTerminal(x
, y
, TWindow
.RESIZABLE
);
3637 * Convenience function to open a terminal window.
3639 * @param x column relative to parent
3640 * @param y row relative to parent
3641 * @param closeOnExit if true, close the window when the command exits
3642 * @return the terminal new window
3644 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3645 final boolean closeOnExit
) {
3647 return openTerminal(x
, y
, TWindow
.RESIZABLE
, closeOnExit
);
3651 * Convenience function to open a terminal window.
3653 * @param x column relative to parent
3654 * @param y row relative to parent
3655 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3656 * @return the terminal new window
3658 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3661 return new TTerminalWindow(this, x
, y
, flags
);
3665 * Convenience function to open a terminal window.
3667 * @param x column relative to parent
3668 * @param y row relative to parent
3669 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3670 * @param closeOnExit if true, close the window when the command exits
3671 * @return the terminal new window
3673 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3674 final int flags
, final boolean closeOnExit
) {
3676 return new TTerminalWindow(this, x
, y
, flags
, closeOnExit
);
3680 * Convenience function to open a terminal window and execute a custom
3681 * command line inside it.
3683 * @param x column relative to parent
3684 * @param y row relative to parent
3685 * @param commandLine the command line to execute
3686 * @return the terminal new window
3688 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3689 final String commandLine
) {
3691 return openTerminal(x
, y
, TWindow
.RESIZABLE
, commandLine
);
3695 * Convenience function to open a terminal window and execute a custom
3696 * command line inside it.
3698 * @param x column relative to parent
3699 * @param y row relative to parent
3700 * @param commandLine the command line to execute
3701 * @param closeOnExit if true, close the window when the command exits
3702 * @return the terminal new window
3704 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3705 final String commandLine
, final boolean closeOnExit
) {
3707 return openTerminal(x
, y
, TWindow
.RESIZABLE
, commandLine
, closeOnExit
);
3711 * Convenience function to open a terminal window and execute a custom
3712 * command line inside it.
3714 * @param x column relative to parent
3715 * @param y row relative to parent
3716 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3717 * @param command the command line to execute
3718 * @return the terminal new window
3720 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3721 final int flags
, final String
[] command
) {
3723 return new TTerminalWindow(this, x
, y
, flags
, command
);
3727 * Convenience function to open a terminal window and execute a custom
3728 * command line inside it.
3730 * @param x column relative to parent
3731 * @param y row relative to parent
3732 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3733 * @param command the command line to execute
3734 * @param closeOnExit if true, close the window when the command exits
3735 * @return the terminal new window
3737 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3738 final int flags
, final String
[] command
, final boolean closeOnExit
) {
3740 return new TTerminalWindow(this, x
, y
, flags
, command
, closeOnExit
);
3744 * Convenience function to open a terminal window and execute a custom
3745 * command line inside it.
3747 * @param x column relative to parent
3748 * @param y row relative to parent
3749 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3750 * @param commandLine the command line to execute
3751 * @return the terminal new window
3753 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3754 final int flags
, final String commandLine
) {
3756 return new TTerminalWindow(this, x
, y
, flags
, commandLine
.split("\\s+"));
3760 * Convenience function to open a terminal window and execute a custom
3761 * command line inside it.
3763 * @param x column relative to parent
3764 * @param y row relative to parent
3765 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3766 * @param commandLine the command line to execute
3767 * @param closeOnExit if true, close the window when the command exits
3768 * @return the terminal new window
3770 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3771 final int flags
, final String commandLine
, final boolean closeOnExit
) {
3773 return new TTerminalWindow(this, x
, y
, flags
, commandLine
.split("\\s+"),
3778 * Convenience function to spawn an file open box.
3780 * @param path path of selected file
3781 * @return the result of the new file open box
3782 * @throws IOException if java.io operation throws
3784 public final String
fileOpenBox(final String path
) throws IOException
{
3786 TFileOpenBox box
= new TFileOpenBox(this, path
, TFileOpenBox
.Type
.OPEN
);
3787 return box
.getFilename();
3791 * Convenience function to spawn an file open box.
3793 * @param path path of selected file
3794 * @param type one of the Type constants
3795 * @return the result of the new file open box
3796 * @throws IOException if java.io operation throws
3798 public final String
fileOpenBox(final String path
,
3799 final TFileOpenBox
.Type type
) throws IOException
{
3801 TFileOpenBox box
= new TFileOpenBox(this, path
, type
);
3802 return box
.getFilename();
3806 * Convenience function to spawn a file open box.
3808 * @param path path of selected file
3809 * @param type one of the Type constants
3810 * @param filter a string that files must match to be displayed
3811 * @return the result of the new file open box
3812 * @throws IOException of a java.io operation throws
3814 public final String
fileOpenBox(final String path
,
3815 final TFileOpenBox
.Type type
, final String filter
) throws IOException
{
3817 ArrayList
<String
> filters
= new ArrayList
<String
>();
3818 filters
.add(filter
);
3820 TFileOpenBox box
= new TFileOpenBox(this, path
, type
, filters
);
3821 return box
.getFilename();
3825 * Convenience function to spawn a file open box.
3827 * @param path path of selected file
3828 * @param type one of the Type constants
3829 * @param filters a list of strings that files must match to be displayed
3830 * @return the result of the new file open box
3831 * @throws IOException of a java.io operation throws
3833 public final String
fileOpenBox(final String path
,
3834 final TFileOpenBox
.Type type
,
3835 final List
<String
> filters
) throws IOException
{
3837 TFileOpenBox box
= new TFileOpenBox(this, path
, type
, filters
);
3838 return box
.getFilename();
3842 * Convenience function to create a new window and make it active.
3843 * Window will be located at (0, 0).
3845 * @param title window title, will be centered along the top border
3846 * @param width width of window
3847 * @param height height of window
3848 * @return the new window
3850 public final TWindow
addWindow(final String title
, final int width
,
3853 TWindow window
= new TWindow(this, title
, 0, 0, width
, height
);
3858 * Convenience function to create a new window and make it active.
3859 * Window will be located at (0, 0).
3861 * @param title window title, will be centered along the top border
3862 * @param width width of window
3863 * @param height height of window
3864 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
3865 * @return the new window
3867 public final TWindow
addWindow(final String title
,
3868 final int width
, final int height
, final int flags
) {
3870 TWindow window
= new TWindow(this, title
, 0, 0, width
, height
, flags
);
3875 * Convenience function to create a new window and make it active.
3877 * @param title window title, will be centered along the top border
3878 * @param x column relative to parent
3879 * @param y row relative to parent
3880 * @param width width of window
3881 * @param height height of window
3882 * @return the new window
3884 public final TWindow
addWindow(final String title
,
3885 final int x
, final int y
, final int width
, final int height
) {
3887 TWindow window
= new TWindow(this, title
, x
, y
, width
, height
);
3892 * Convenience function to create a new window and make it active.
3894 * @param title window title, will be centered along the top border
3895 * @param x column relative to parent
3896 * @param y row relative to parent
3897 * @param width width of window
3898 * @param height height of window
3899 * @param flags mask of RESIZABLE, CENTERED, or MODAL
3900 * @return the new window
3902 public final TWindow
addWindow(final String title
,
3903 final int x
, final int y
, final int width
, final int height
,
3906 TWindow window
= new TWindow(this, title
, x
, y
, width
, height
, flags
);