2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
32 import java
.io
.InputStream
;
33 import java
.io
.IOException
;
34 import java
.io
.OutputStream
;
35 import java
.io
.PrintWriter
;
36 import java
.io
.Reader
;
37 import java
.io
.UnsupportedEncodingException
;
38 import java
.text
.MessageFormat
;
39 import java
.util
.ArrayList
;
40 import java
.util
.Collections
;
41 import java
.util
.Date
;
42 import java
.util
.HashMap
;
43 import java
.util
.LinkedList
;
44 import java
.util
.List
;
46 import java
.util
.ResourceBundle
;
48 import jexer
.bits
.Cell
;
49 import jexer
.bits
.CellAttributes
;
50 import jexer
.bits
.Clipboard
;
51 import jexer
.bits
.ColorTheme
;
52 import jexer
.bits
.StringUtils
;
53 import jexer
.event
.TCommandEvent
;
54 import jexer
.event
.TInputEvent
;
55 import jexer
.event
.TKeypressEvent
;
56 import jexer
.event
.TMenuEvent
;
57 import jexer
.event
.TMouseEvent
;
58 import jexer
.event
.TResizeEvent
;
59 import jexer
.backend
.Backend
;
60 import jexer
.backend
.MultiBackend
;
61 import jexer
.backend
.Screen
;
62 import jexer
.backend
.SwingBackend
;
63 import jexer
.backend
.ECMA48Backend
;
64 import jexer
.backend
.TWindowBackend
;
65 import jexer
.menu
.TMenu
;
66 import jexer
.menu
.TMenuItem
;
67 import jexer
.menu
.TSubMenu
;
68 import static jexer
.TCommand
.*;
69 import static jexer
.TKeypress
.*;
72 * TApplication is the main driver class for a full Text User Interface
73 * application. It manages windows, provides a menu bar and status bar, and
74 * processes events received from the user.
76 public class TApplication
implements Runnable
{
81 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(TApplication
.class.getName());
83 // ------------------------------------------------------------------------
84 // Constants --------------------------------------------------------------
85 // ------------------------------------------------------------------------
88 * If true, emit thread stuff to System.err.
90 private static final boolean debugThreads
= false;
93 * If true, emit events being processed to System.err.
95 private static final boolean debugEvents
= false;
98 * If true, do "smart placement" on new windows that are not specified to
101 private static final boolean smartWindowPlacement
= true;
104 * Two backend types are available.
106 public static enum BackendType
{
113 * An ECMA48 / ANSI X3.64 / XTERM style terminal.
118 * Synonym for ECMA48.
123 // ------------------------------------------------------------------------
124 // Variables --------------------------------------------------------------
125 // ------------------------------------------------------------------------
128 * The primary event handler thread.
130 private volatile WidgetEventHandler primaryEventHandler
;
133 * The secondary event handler thread.
135 private volatile WidgetEventHandler secondaryEventHandler
;
138 * The screen handler thread.
140 private volatile ScreenHandler screenHandler
;
143 * The widget receiving events from the secondary event handler thread.
145 private volatile TWidget secondaryEventReceiver
;
148 * Access to the physical screen, keyboard, and mouse.
150 private Backend backend
;
153 * The clipboard for copy and paste.
155 private Clipboard clipboard
= new Clipboard();
158 * Actual mouse coordinate X.
163 * Actual mouse coordinate Y.
168 * Old drawn version of mouse coordinate X.
170 private int oldDrawnMouseX
;
173 * Old drawn version mouse coordinate Y.
175 private int oldDrawnMouseY
;
178 * Old drawn version mouse cell.
180 private Cell oldDrawnMouseCell
= new Cell();
183 * The last mouse up click time, used to determine if this is a mouse
186 private long lastMouseUpTime
;
189 * The amount of millis between mouse up events to assume a double-click.
191 private long doubleClickTime
= 250;
194 * Event queue that is filled by run().
196 private List
<TInputEvent
> fillEventQueue
;
199 * Event queue that will be drained by either primary or secondary
202 private List
<TInputEvent
> drainEventQueue
;
205 * Top-level menus in this application.
207 private List
<TMenu
> menus
;
210 * Stack of activated sub-menus in this application.
212 private List
<TMenu
> subMenus
;
215 * The currently active menu.
217 private TMenu activeMenu
= null;
220 * Active keyboard accelerators.
222 private Map
<TKeypress
, TMenuItem
> accelerators
;
227 private List
<TMenuItem
> menuItems
;
230 * Windows and widgets pull colors from this ColorTheme.
232 private ColorTheme theme
;
235 * The top-level windows (but not menus).
237 private List
<TWindow
> windows
;
240 * The currently acive window.
242 private TWindow activeWindow
= null;
245 * Timers that are being ticked.
247 private List
<TTimer
> timers
;
250 * When true, the application has been started.
252 private volatile boolean started
= false;
255 * When true, exit the application.
257 private volatile boolean quit
= false;
260 * When true, repaint the entire screen.
262 private volatile boolean repaint
= true;
265 * Y coordinate of the top edge of the desktop. For now this is a
266 * constant. Someday it would be nice to have a multi-line menu or
269 private int desktopTop
= 1;
272 * Y coordinate of the bottom edge of the desktop.
274 private int desktopBottom
;
277 * An optional TDesktop background window that is drawn underneath
280 private TDesktop desktop
;
283 * If true, focus follows mouse: windows automatically raised if the
284 * mouse passes over them.
286 private boolean focusFollowsMouse
= false;
289 * If true, display a text-based mouse cursor.
291 private boolean textMouse
= true;
294 * If true, hide the mouse after typing a keystroke.
296 private boolean hideMouseWhenTyping
= false;
299 * If true, the mouse should not be displayed because a keystroke was
302 private boolean typingHidMouse
= false;
305 * If true, hide the status bar.
307 private boolean hideStatusBar
= false;
310 * If true, hide the menu bar.
312 private boolean hideMenuBar
= false;
315 * The list of commands to run before the next I/O check.
317 private List
<Runnable
> invokeLaters
= new LinkedList
<Runnable
>();
320 * The last time the screen was resized.
322 private long screenResizeTime
= 0;
325 * If true, screen selection is a rectangle.
327 private boolean screenSelectionRectangle
= false;
330 * If true, the mouse is dragging a screen selection.
332 private boolean inScreenSelection
= false;
335 * Screen selection starting X.
337 private int screenSelectionX0
;
340 * Screen selection starting Y.
342 private int screenSelectionY0
;
345 * Screen selection ending X.
347 private int screenSelectionX1
;
350 * Screen selection ending Y.
352 private int screenSelectionY1
;
355 * WidgetEventHandler is the main event consumer loop. There are at most
356 * two such threads in existence: the primary for normal case and a
357 * secondary that is used for TMessageBox, TInputBox, and similar.
359 private class WidgetEventHandler
implements Runnable
{
361 * The main application.
363 private TApplication application
;
366 * Whether or not this WidgetEventHandler is the primary or secondary
369 private boolean primary
= true;
372 * Public constructor.
374 * @param application the main application
375 * @param primary if true, this is the primary event handler thread
377 public WidgetEventHandler(final TApplication application
,
378 final boolean primary
) {
380 this.application
= application
;
381 this.primary
= primary
;
388 // Wrap everything in a try, so that if we go belly up we can let
389 // the user have their terminal back.
392 } catch (Throwable t
) {
393 this.application
.restoreConsole();
395 this.application
.exit();
402 private void runImpl() {
403 boolean first
= true;
406 while (!application
.quit
) {
408 // Wait until application notifies me
409 while (!application
.quit
) {
411 synchronized (application
.drainEventQueue
) {
412 if (application
.drainEventQueue
.size() > 0) {
421 timeout
= application
.getSleepTime(1000);
425 // A timer needs to fire, break out.
430 System
.err
.printf("%d %s %s %s sleep %d millis\n",
431 System
.currentTimeMillis(), this,
432 primary ?
"primary" : "secondary",
433 Thread
.currentThread(), timeout
);
436 synchronized (this) {
441 System
.err
.printf("%d %s %s %s AWAKE\n",
442 System
.currentTimeMillis(), this,
443 primary ?
"primary" : "secondary",
444 Thread
.currentThread());
448 && (application
.secondaryEventReceiver
== null)
450 // Secondary thread, emergency exit. If we got
451 // here then something went wrong with the
452 // handoff between yield() and closeWindow().
453 synchronized (application
.primaryEventHandler
) {
454 application
.primaryEventHandler
.notify();
456 application
.secondaryEventHandler
= null;
457 throw new RuntimeException("secondary exited " +
461 } catch (InterruptedException e
) {
464 } // while (!application.quit)
466 // Pull all events off the queue
468 TInputEvent event
= null;
469 synchronized (application
.drainEventQueue
) {
470 if (application
.drainEventQueue
.size() == 0) {
473 event
= application
.drainEventQueue
.remove(0);
476 // We will have an event to process, so repaint the
477 // screen at the end.
478 application
.repaint
= true;
481 primaryHandleEvent(event
);
483 secondaryHandleEvent(event
);
486 && (application
.secondaryEventReceiver
== null)
488 // Secondary thread, time to exit.
490 // Eliminate my reference so that wakeEventHandler()
491 // resumes working on the primary.
492 application
.secondaryEventHandler
= null;
494 // We are ready to exit, wake up the primary thread.
495 // Remember that it is currently sleeping inside its
496 // primaryHandleEvent().
497 synchronized (application
.primaryEventHandler
) {
498 application
.primaryEventHandler
.notify();
507 // Fire timers, update screen.
509 application
.finishEventProcessing();
512 } // while (true) (main runnable loop)
517 * ScreenHandler pushes screen updates to the physical device.
519 private class ScreenHandler
implements Runnable
{
521 * The main application.
523 private TApplication application
;
528 private boolean dirty
= false;
531 * Public constructor.
533 * @param application the main application
535 public ScreenHandler(final TApplication application
) {
536 this.application
= application
;
540 * The screen update loop.
543 // Wrap everything in a try, so that if we go belly up we can let
544 // the user have their terminal back.
547 } catch (Throwable t
) {
548 this.application
.restoreConsole();
550 this.application
.exit();
557 private void runImpl() {
560 while (!application
.quit
) {
562 // Wait until application notifies me
563 while (!application
.quit
) {
565 synchronized (this) {
571 // Always check within 50 milliseconds.
574 } catch (InterruptedException e
) {
577 } // while (!application.quit)
579 // Flush the screen contents
581 System
.err
.printf("%d %s backend.flushScreen()\n",
582 System
.currentTimeMillis(), Thread
.currentThread());
584 synchronized (getScreen()) {
585 backend
.flushScreen();
587 } // while (true) (main runnable loop)
589 // Shutdown the user I/O thread(s)
594 * Set the dirty flag.
596 public void setDirty() {
597 synchronized (this) {
604 // ------------------------------------------------------------------------
605 // Constructors -----------------------------------------------------------
606 // ------------------------------------------------------------------------
609 * Public constructor.
611 * @param backendType BackendType.XTERM, BackendType.ECMA48 or
613 * @param windowWidth the number of text columns to start with
614 * @param windowHeight the number of text rows to start with
615 * @param fontSize the size in points
616 * @throws UnsupportedEncodingException if an exception is thrown when
617 * creating the InputStreamReader
619 public TApplication(final BackendType backendType
, final int windowWidth
,
620 final int windowHeight
, final int fontSize
)
621 throws UnsupportedEncodingException
{
623 switch (backendType
) {
625 backend
= new SwingBackend(this, windowWidth
, windowHeight
,
631 backend
= new ECMA48Backend(this, null, null, windowWidth
,
632 windowHeight
, fontSize
);
635 throw new IllegalArgumentException("Invalid backend type: "
642 * Public constructor.
644 * @param backendType BackendType.XTERM, BackendType.ECMA48 or
646 * @throws UnsupportedEncodingException if an exception is thrown when
647 * creating the InputStreamReader
649 public TApplication(final BackendType backendType
)
650 throws UnsupportedEncodingException
{
652 switch (backendType
) {
654 // The default SwingBackend is 80x25, 20 pt font. If you want to
655 // change that, you can pass the extra arguments to the
656 // SwingBackend constructor here. For example, if you wanted
657 // 90x30, 16 pt font:
659 // backend = new SwingBackend(this, 90, 30, 16);
660 backend
= new SwingBackend(this);
665 backend
= new ECMA48Backend(this, null, null);
668 throw new IllegalArgumentException("Invalid backend type: "
675 * Public constructor. The backend type will be BackendType.ECMA48.
677 * @param input an InputStream connected to the remote user, or null for
678 * System.in. If System.in is used, then on non-Windows systems it will
679 * be put in raw mode; shutdown() will (blindly!) put System.in in cooked
680 * mode. input is always converted to a Reader with UTF-8 encoding.
681 * @param output an OutputStream connected to the remote user, or null
682 * for System.out. output is always converted to a Writer with UTF-8
684 * @throws UnsupportedEncodingException if an exception is thrown when
685 * creating the InputStreamReader
687 public TApplication(final InputStream input
,
688 final OutputStream output
) throws UnsupportedEncodingException
{
690 backend
= new ECMA48Backend(this, input
, output
);
695 * Public constructor. The backend type will be BackendType.ECMA48.
697 * @param input the InputStream underlying 'reader'. Its available()
698 * method is used to determine if reader.read() will block or not.
699 * @param reader a Reader connected to the remote user.
700 * @param writer a PrintWriter connected to the remote user.
701 * @param setRawMode if true, set System.in into raw mode with stty.
702 * This should in general not be used. It is here solely for Demo3,
703 * which uses System.in.
704 * @throws IllegalArgumentException if input, reader, or writer are null.
706 public TApplication(final InputStream input
, final Reader reader
,
707 final PrintWriter writer
, final boolean setRawMode
) {
709 backend
= new ECMA48Backend(this, input
, reader
, writer
, setRawMode
);
714 * Public constructor. The backend type will be BackendType.ECMA48.
716 * @param input the InputStream underlying 'reader'. Its available()
717 * method is used to determine if reader.read() will block or not.
718 * @param reader a Reader connected to the remote user.
719 * @param writer a PrintWriter connected to the remote user.
720 * @throws IllegalArgumentException if input, reader, or writer are null.
722 public TApplication(final InputStream input
, final Reader reader
,
723 final PrintWriter writer
) {
725 this(input
, reader
, writer
, false);
729 * Public constructor. This hook enables use with new non-Jexer
732 * @param backend a Backend that is already ready to go.
734 public TApplication(final Backend backend
) {
735 this.backend
= backend
;
736 backend
.setListener(this);
741 * Finish construction once the backend is set.
743 private void TApplicationImpl() {
744 // Text block mouse option
745 if (System
.getProperty("jexer.textMouse", "true").equals("false")) {
749 // Hide mouse when typing option
750 if (System
.getProperty("jexer.hideMouseWhenTyping",
751 "false").equals("true")) {
753 hideMouseWhenTyping
= true;
756 // Hide status bar option
757 if (System
.getProperty("jexer.hideStatusBar",
758 "false").equals("true")) {
759 hideStatusBar
= true;
762 // Hide menu bar option
763 if (System
.getProperty("jexer.hideMenuBar", "false").equals("true")) {
767 theme
= new ColorTheme();
768 desktopTop
= (hideMenuBar ?
0 : 1);
769 desktopBottom
= getScreen().getHeight() - 1 + (hideStatusBar ?
1 : 0);
770 fillEventQueue
= new LinkedList
<TInputEvent
>();
771 drainEventQueue
= new LinkedList
<TInputEvent
>();
772 windows
= new LinkedList
<TWindow
>();
773 menus
= new ArrayList
<TMenu
>();
774 subMenus
= new ArrayList
<TMenu
>();
775 timers
= new LinkedList
<TTimer
>();
776 accelerators
= new HashMap
<TKeypress
, TMenuItem
>();
777 menuItems
= new LinkedList
<TMenuItem
>();
778 desktop
= new TDesktop(this);
780 // Special case: the Swing backend needs to have a timer to drive its
782 if ((backend
instanceof SwingBackend
)
783 || (backend
instanceof MultiBackend
)
785 // Default to 500 millis, unless a SwingBackend has its own
788 if (backend
instanceof SwingBackend
) {
789 millis
= ((SwingBackend
) backend
).getBlinkMillis();
792 addTimer(millis
, true,
795 TApplication
.this.doRepaint();
804 // ------------------------------------------------------------------------
805 // Runnable ---------------------------------------------------------------
806 // ------------------------------------------------------------------------
809 * Run this application until it exits.
812 // System.err.println("*** TApplication.run() begins ***");
814 // Start the screen updater thread
815 screenHandler
= new ScreenHandler(this);
816 (new Thread(screenHandler
)).start();
818 // Start the main consumer thread
819 primaryEventHandler
= new WidgetEventHandler(this, true);
820 (new Thread(primaryEventHandler
)).start();
825 synchronized (this) {
826 boolean doWait
= false;
828 if (!backend
.hasEvents()) {
829 synchronized (fillEventQueue
) {
830 if (fillEventQueue
.size() == 0) {
837 // No I/O to dispatch, so wait until the backend
841 System
.err
.println(System
.currentTimeMillis() +
842 " " + Thread
.currentThread() + " MAIN sleep");
848 System
.err
.println(System
.currentTimeMillis() +
849 " " + Thread
.currentThread() + " MAIN AWAKE");
851 } catch (InterruptedException e
) {
852 // I'm awake and don't care why, let's see what's
853 // going on out there.
857 } // synchronized (this)
859 synchronized (fillEventQueue
) {
860 // Pull any pending I/O events
861 backend
.getEvents(fillEventQueue
);
863 // Dispatch each event to the appropriate handler, one at a
866 TInputEvent event
= null;
867 if (fillEventQueue
.size() == 0) {
870 event
= fillEventQueue
.remove(0);
871 metaHandleEvent(event
);
875 // Wake a consumer thread if we have any pending events.
876 if (drainEventQueue
.size() > 0) {
882 // Shutdown the event consumer threads
883 if (secondaryEventHandler
!= null) {
884 synchronized (secondaryEventHandler
) {
885 secondaryEventHandler
.notify();
888 if (primaryEventHandler
!= null) {
889 synchronized (primaryEventHandler
) {
890 primaryEventHandler
.notify();
894 // Close all the windows. This gives them an opportunity to release
898 // Close the desktop.
899 if (desktop
!= null) {
903 // Give the overarching application an opportunity to release
907 // System.err.println("*** TApplication.run() exits ***");
910 // ------------------------------------------------------------------------
911 // Event handlers ---------------------------------------------------------
912 // ------------------------------------------------------------------------
915 * Method that TApplication subclasses can override to handle menu or
916 * posted command events.
918 * @param command command event
919 * @return if true, this event was consumed
921 protected boolean onCommand(final TCommandEvent command
) {
922 // Default: handle cmExit
923 if (command
.equals(cmExit
)) {
924 if (messageBox(i18n
.getString("exitDialogTitle"),
925 i18n
.getString("exitDialogText"),
926 TMessageBox
.Type
.YESNO
).isYes()) {
933 if (command
.equals(cmShell
)) {
934 openTerminal(0, 0, TWindow
.RESIZABLE
);
938 if (command
.equals(cmTile
)) {
942 if (command
.equals(cmCascade
)) {
946 if (command
.equals(cmCloseAll
)) {
951 if (command
.equals(cmMenu
) && (hideMenuBar
== false)) {
952 if (!modalWindowActive() && (activeMenu
== null)) {
953 if (menus
.size() > 0) {
954 menus
.get(0).setActive(true);
955 activeMenu
= menus
.get(0);
965 * Method that TApplication subclasses can override to handle menu
968 * @param menu menu event
969 * @return if true, this event was consumed
971 protected boolean onMenu(final TMenuEvent menu
) {
973 // Default: handle MID_EXIT
974 if (menu
.getId() == TMenu
.MID_EXIT
) {
975 if (messageBox(i18n
.getString("exitDialogTitle"),
976 i18n
.getString("exitDialogText"),
977 TMessageBox
.Type
.YESNO
).isYes()) {
984 if (menu
.getId() == TMenu
.MID_SHELL
) {
985 openTerminal(0, 0, TWindow
.RESIZABLE
);
989 if (menu
.getId() == TMenu
.MID_TILE
) {
993 if (menu
.getId() == TMenu
.MID_CASCADE
) {
997 if (menu
.getId() == TMenu
.MID_CLOSE_ALL
) {
1001 if (menu
.getId() == TMenu
.MID_ABOUT
) {
1005 if (menu
.getId() == TMenu
.MID_REPAINT
) {
1006 getScreen().clearPhysical();
1010 if (menu
.getId() == TMenu
.MID_VIEW_IMAGE
) {
1014 if (menu
.getId() == TMenu
.MID_SCREEN_OPTIONS
) {
1015 new TFontChooserWindow(this);
1019 if (menu
.getId() == TMenu
.MID_CUT
) {
1020 postMenuEvent(new TCommandEvent(cmCut
));
1023 if (menu
.getId() == TMenu
.MID_COPY
) {
1024 postMenuEvent(new TCommandEvent(cmCopy
));
1027 if (menu
.getId() == TMenu
.MID_PASTE
) {
1028 postMenuEvent(new TCommandEvent(cmPaste
));
1031 if (menu
.getId() == TMenu
.MID_CLEAR
) {
1032 postMenuEvent(new TCommandEvent(cmClear
));
1040 * Method that TApplication subclasses can override to handle keystrokes.
1042 * @param keypress keystroke event
1043 * @return if true, this event was consumed
1045 protected boolean onKeypress(final TKeypressEvent keypress
) {
1046 // Default: only menu shortcuts
1048 // Process Alt-F, Alt-E, etc. menu shortcut keys
1049 if (!keypress
.getKey().isFnKey()
1050 && keypress
.getKey().isAlt()
1051 && !keypress
.getKey().isCtrl()
1052 && (activeMenu
== null)
1053 && !modalWindowActive()
1054 && (hideMenuBar
== false)
1057 assert (subMenus
.size() == 0);
1059 for (TMenu menu
: menus
) {
1060 if (Character
.toLowerCase(menu
.getMnemonic().getShortcut())
1061 == Character
.toLowerCase(keypress
.getKey().getChar())
1064 menu
.setActive(true);
1074 * Process background events, and update the screen.
1076 private void finishEventProcessing() {
1078 System
.err
.printf(System
.currentTimeMillis() + " " +
1079 Thread
.currentThread() + " finishEventProcessing()\n");
1082 // See if we need to enable/disable the edit menu.
1083 EditMenuUser widget
= null;
1084 if (activeMenu
== null) {
1085 if (activeWindow
!= null) {
1086 if (activeWindow
.getActiveChild() instanceof EditMenuUser
) {
1087 widget
= (EditMenuUser
) activeWindow
.getActiveChild();
1089 } else if (desktop
!= null) {
1090 if (desktop
.getActiveChild() instanceof EditMenuUser
) {
1091 widget
= (EditMenuUser
) desktop
.getActiveChild();
1094 if (widget
== null) {
1095 disableMenuItem(TMenu
.MID_CUT
);
1096 disableMenuItem(TMenu
.MID_COPY
);
1097 disableMenuItem(TMenu
.MID_PASTE
);
1098 disableMenuItem(TMenu
.MID_CLEAR
);
1100 if (widget
.isEditMenuCut()) {
1101 enableMenuItem(TMenu
.MID_CUT
);
1103 disableMenuItem(TMenu
.MID_CUT
);
1105 if (widget
.isEditMenuCopy()) {
1106 enableMenuItem(TMenu
.MID_COPY
);
1108 disableMenuItem(TMenu
.MID_COPY
);
1110 if (widget
.isEditMenuPaste()) {
1111 enableMenuItem(TMenu
.MID_PASTE
);
1113 disableMenuItem(TMenu
.MID_PASTE
);
1115 if (widget
.isEditMenuClear()) {
1116 enableMenuItem(TMenu
.MID_CLEAR
);
1118 disableMenuItem(TMenu
.MID_CLEAR
);
1123 // Process timers and call doIdle()'s
1126 // Update the screen
1127 synchronized (getScreen()) {
1131 // Wake up the screen repainter
1132 wakeScreenHandler();
1135 System
.err
.printf(System
.currentTimeMillis() + " " +
1136 Thread
.currentThread() + " finishEventProcessing() END\n");
1141 * Peek at certain application-level events, add to eventQueue, and wake
1142 * up the consuming Thread.
1144 * @param event the input event to consume
1146 private void metaHandleEvent(final TInputEvent event
) {
1149 System
.err
.printf(String
.format("metaHandleEvents event: %s\n",
1150 event
)); System
.err
.flush();
1154 // Do no more processing if the application is already trying
1159 // Special application-wide events -------------------------------
1162 if (event
instanceof TCommandEvent
) {
1163 TCommandEvent command
= (TCommandEvent
) event
;
1164 if (command
.equals(cmAbort
)) {
1170 synchronized (drainEventQueue
) {
1172 if (event
instanceof TResizeEvent
) {
1173 TResizeEvent resize
= (TResizeEvent
) event
;
1174 synchronized (getScreen()) {
1175 if ((System
.currentTimeMillis() - screenResizeTime
>= 15)
1176 || (resize
.getWidth() < getScreen().getWidth())
1177 || (resize
.getHeight() < getScreen().getHeight())
1179 getScreen().setDimensions(resize
.getWidth(),
1180 resize
.getHeight());
1181 screenResizeTime
= System
.currentTimeMillis();
1183 desktopBottom
= getScreen().getHeight() - 1;
1184 if (hideStatusBar
) {
1190 if (desktop
!= null) {
1191 desktop
.setDimensions(0, desktopTop
, resize
.getWidth(),
1192 (desktopBottom
- desktopTop
));
1193 desktop
.onResize(resize
);
1196 // Change menu edges if needed.
1199 // We are dirty, redraw the screen.
1203 System.err.println("New screen: " + resize.getWidth() +
1204 " x " + resize.getHeight());
1209 // Put into the main queue
1210 drainEventQueue
.add(event
);
1215 * Dispatch one event to the appropriate widget or application-level
1216 * event handler. This is the primary event handler, it has the normal
1217 * application-wide event handling.
1219 * @param event the input event to consume
1220 * @see #secondaryHandleEvent(TInputEvent event)
1222 private void primaryHandleEvent(final TInputEvent event
) {
1225 System
.err
.printf("%s primaryHandleEvent: %s\n",
1226 Thread
.currentThread(), event
);
1228 TMouseEvent doubleClick
= null;
1230 // Special application-wide events -----------------------------------
1232 if (event
instanceof TKeypressEvent
) {
1233 if (hideMouseWhenTyping
) {
1234 typingHidMouse
= true;
1238 // Peek at the mouse position
1239 if (event
instanceof TMouseEvent
) {
1240 typingHidMouse
= false;
1242 TMouseEvent mouse
= (TMouseEvent
) event
;
1243 if (mouse
.isMouse1() && (mouse
.isShift() || mouse
.isCtrl())) {
1244 // Screen selection.
1245 if (inScreenSelection
) {
1246 screenSelectionX1
= mouse
.getX();
1247 screenSelectionY1
= mouse
.getY();
1249 inScreenSelection
= true;
1250 screenSelectionX0
= mouse
.getX();
1251 screenSelectionY0
= mouse
.getY();
1252 screenSelectionX1
= mouse
.getX();
1253 screenSelectionY1
= mouse
.getY();
1254 screenSelectionRectangle
= mouse
.isCtrl();
1257 if (inScreenSelection
) {
1258 getScreen().copySelection(clipboard
, screenSelectionX0
,
1259 screenSelectionY0
, screenSelectionX1
, screenSelectionY1
,
1260 screenSelectionRectangle
);
1262 inScreenSelection
= false;
1265 if ((mouseX
!= mouse
.getX()) || (mouseY
!= mouse
.getY())) {
1266 mouseX
= mouse
.getX();
1267 mouseY
= mouse
.getY();
1269 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
1270 && (!mouse
.isMouseWheelUp())
1271 && (!mouse
.isMouseWheelDown())
1273 if ((mouse
.getTime().getTime() - lastMouseUpTime
) <
1276 // This is a double-click.
1277 doubleClick
= new TMouseEvent(TMouseEvent
.Type
.
1279 mouse
.getX(), mouse
.getY(),
1280 mouse
.getAbsoluteX(), mouse
.getAbsoluteY(),
1281 mouse
.isMouse1(), mouse
.isMouse2(),
1283 mouse
.isMouseWheelUp(), mouse
.isMouseWheelDown(),
1284 mouse
.isAlt(), mouse
.isCtrl(), mouse
.isShift());
1287 // The first click of a potential double-click.
1288 lastMouseUpTime
= mouse
.getTime().getTime();
1293 // See if we need to switch focus to another window or the menu
1294 checkSwitchFocus((TMouseEvent
) event
);
1297 // Handle menu events
1298 if ((activeMenu
!= null) && !(event
instanceof TCommandEvent
)) {
1299 TMenu menu
= activeMenu
;
1301 if (event
instanceof TMouseEvent
) {
1302 TMouseEvent mouse
= (TMouseEvent
) event
;
1304 while (subMenus
.size() > 0) {
1305 TMenu subMenu
= subMenus
.get(subMenus
.size() - 1);
1306 if (subMenu
.mouseWouldHit(mouse
)) {
1309 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
)
1310 && (!mouse
.isMouse1())
1311 && (!mouse
.isMouse2())
1312 && (!mouse
.isMouse3())
1313 && (!mouse
.isMouseWheelUp())
1314 && (!mouse
.isMouseWheelDown())
1318 // We navigated away from a sub-menu, so close it
1322 // Convert the mouse relative x/y to menu coordinates
1323 assert (mouse
.getX() == mouse
.getAbsoluteX());
1324 assert (mouse
.getY() == mouse
.getAbsoluteY());
1325 if (subMenus
.size() > 0) {
1326 menu
= subMenus
.get(subMenus
.size() - 1);
1328 mouse
.setX(mouse
.getX() - menu
.getX());
1329 mouse
.setY(mouse
.getY() - menu
.getY());
1331 menu
.handleEvent(event
);
1335 if (event
instanceof TKeypressEvent
) {
1336 TKeypressEvent keypress
= (TKeypressEvent
) event
;
1338 // See if this key matches an accelerator, and is not being
1339 // shortcutted by the active window, and if so dispatch the menu
1341 boolean windowWillShortcut
= false;
1342 if (activeWindow
!= null) {
1343 assert (activeWindow
.isShown());
1344 if (activeWindow
.isShortcutKeypress(keypress
.getKey())) {
1345 // We do not process this key, it will be passed to the
1347 windowWillShortcut
= true;
1351 if (!windowWillShortcut
&& !modalWindowActive()) {
1352 TKeypress keypressLowercase
= keypress
.getKey().toLowerCase();
1353 TMenuItem item
= null;
1354 synchronized (accelerators
) {
1355 item
= accelerators
.get(keypressLowercase
);
1358 if (item
.isEnabled()) {
1359 // Let the menu item dispatch
1365 // Handle the keypress
1366 if (onKeypress(keypress
)) {
1372 if (event
instanceof TCommandEvent
) {
1373 if (onCommand((TCommandEvent
) event
)) {
1378 if (event
instanceof TMenuEvent
) {
1379 if (onMenu((TMenuEvent
) event
)) {
1384 // Dispatch events to the active window -------------------------------
1385 boolean dispatchToDesktop
= true;
1386 TWindow window
= activeWindow
;
1387 if (window
!= null) {
1388 assert (window
.isActive());
1389 assert (window
.isShown());
1390 if (event
instanceof TMouseEvent
) {
1391 TMouseEvent mouse
= (TMouseEvent
) event
;
1392 // Convert the mouse relative x/y to window coordinates
1393 assert (mouse
.getX() == mouse
.getAbsoluteX());
1394 assert (mouse
.getY() == mouse
.getAbsoluteY());
1395 mouse
.setX(mouse
.getX() - window
.getX());
1396 mouse
.setY(mouse
.getY() - window
.getY());
1398 if (doubleClick
!= null) {
1399 doubleClick
.setX(doubleClick
.getX() - window
.getX());
1400 doubleClick
.setY(doubleClick
.getY() - window
.getY());
1403 if (window
.mouseWouldHit(mouse
)) {
1404 dispatchToDesktop
= false;
1406 } else if (event
instanceof TKeypressEvent
) {
1407 dispatchToDesktop
= false;
1408 } else if (event
instanceof TMenuEvent
) {
1409 dispatchToDesktop
= false;
1413 System
.err
.printf("TApplication dispatch event: %s\n",
1416 window
.handleEvent(event
);
1417 if (doubleClick
!= null) {
1418 window
.handleEvent(doubleClick
);
1421 if (dispatchToDesktop
) {
1422 // This event is fair game for the desktop to process.
1423 if (desktop
!= null) {
1424 desktop
.handleEvent(event
);
1425 if (doubleClick
!= null) {
1426 desktop
.handleEvent(doubleClick
);
1433 * Dispatch one event to the appropriate widget or application-level
1434 * event handler. This is the secondary event handler used by certain
1435 * special dialogs (currently TMessageBox and TFileOpenBox).
1437 * @param event the input event to consume
1438 * @see #primaryHandleEvent(TInputEvent event)
1440 private void secondaryHandleEvent(final TInputEvent event
) {
1441 TMouseEvent doubleClick
= null;
1444 System
.err
.printf("%s secondaryHandleEvent: %s\n",
1445 Thread
.currentThread(), event
);
1448 // Peek at the mouse position
1449 if (event
instanceof TMouseEvent
) {
1450 typingHidMouse
= false;
1452 TMouseEvent mouse
= (TMouseEvent
) event
;
1453 if ((mouseX
!= mouse
.getX()) || (mouseY
!= mouse
.getY())) {
1454 mouseX
= mouse
.getX();
1455 mouseY
= mouse
.getY();
1457 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
1458 && (!mouse
.isMouseWheelUp())
1459 && (!mouse
.isMouseWheelDown())
1461 if ((mouse
.getTime().getTime() - lastMouseUpTime
) <
1464 // This is a double-click.
1465 doubleClick
= new TMouseEvent(TMouseEvent
.Type
.
1467 mouse
.getX(), mouse
.getY(),
1468 mouse
.getAbsoluteX(), mouse
.getAbsoluteY(),
1469 mouse
.isMouse1(), mouse
.isMouse2(),
1471 mouse
.isMouseWheelUp(), mouse
.isMouseWheelDown(),
1472 mouse
.isAlt(), mouse
.isCtrl(), mouse
.isShift());
1475 // The first click of a potential double-click.
1476 lastMouseUpTime
= mouse
.getTime().getTime();
1482 secondaryEventReceiver
.handleEvent(event
);
1483 // Note that it is possible for secondaryEventReceiver to be null
1484 // now, because its handleEvent() might have finished out on the
1485 // secondary thread. So put any extra processing inside a null
1487 if (secondaryEventReceiver
!= null) {
1488 if (doubleClick
!= null) {
1489 secondaryEventReceiver
.handleEvent(doubleClick
);
1495 * Enable a widget to override the primary event thread.
1497 * @param widget widget that will receive events
1499 public final void enableSecondaryEventReceiver(final TWidget widget
) {
1501 System
.err
.println(System
.currentTimeMillis() +
1502 " enableSecondaryEventReceiver()");
1505 assert (secondaryEventReceiver
== null);
1506 assert (secondaryEventHandler
== null);
1507 assert ((widget
instanceof TMessageBox
)
1508 || (widget
instanceof TFileOpenBox
));
1509 secondaryEventReceiver
= widget
;
1510 secondaryEventHandler
= new WidgetEventHandler(this, false);
1512 (new Thread(secondaryEventHandler
)).start();
1516 * Yield to the secondary thread.
1518 public final void yield() {
1520 System
.err
.printf(System
.currentTimeMillis() + " " +
1521 Thread
.currentThread() + " yield()\n");
1524 assert (secondaryEventReceiver
!= null);
1526 while (secondaryEventReceiver
!= null) {
1527 synchronized (primaryEventHandler
) {
1529 primaryEventHandler
.wait();
1530 } catch (InterruptedException e
) {
1538 * Do stuff when there is no user input.
1540 private void doIdle() {
1542 System
.err
.printf(System
.currentTimeMillis() + " " +
1543 Thread
.currentThread() + " doIdle()\n");
1546 synchronized (timers
) {
1549 System
.err
.printf(System
.currentTimeMillis() + " " +
1550 Thread
.currentThread() + " doIdle() 2\n");
1553 // Run any timers that have timed out
1554 Date now
= new Date();
1555 List
<TTimer
> keepTimers
= new LinkedList
<TTimer
>();
1556 for (TTimer timer
: timers
) {
1557 if (timer
.getNextTick().getTime() <= now
.getTime()) {
1558 // Something might change, so repaint the screen.
1561 if (timer
.recurring
) {
1562 keepTimers
.add(timer
);
1565 keepTimers
.add(timer
);
1569 timers
.addAll(keepTimers
);
1573 for (TWindow window
: windows
) {
1576 if (desktop
!= null) {
1580 // Run any invokeLaters. We make a copy, and run that, because one
1581 // of these Runnables might add call TApplication.invokeLater().
1582 List
<Runnable
> invokes
= new ArrayList
<Runnable
>();
1583 synchronized (invokeLaters
) {
1584 invokes
.addAll(invokeLaters
);
1585 invokeLaters
.clear();
1587 for (Runnable invoke
: invokes
) {
1595 * Wake the sleeping active event handler.
1597 private void wakeEventHandler() {
1602 if (secondaryEventHandler
!= null) {
1603 synchronized (secondaryEventHandler
) {
1604 secondaryEventHandler
.notify();
1607 assert (primaryEventHandler
!= null);
1608 synchronized (primaryEventHandler
) {
1609 primaryEventHandler
.notify();
1615 * Wake the sleeping screen handler.
1617 private void wakeScreenHandler() {
1622 synchronized (screenHandler
) {
1623 screenHandler
.notify();
1627 // ------------------------------------------------------------------------
1628 // TApplication -----------------------------------------------------------
1629 // ------------------------------------------------------------------------
1632 * Place a command on the run queue, and run it before the next round of
1635 * @param command the command to run later
1637 public void invokeLater(final Runnable command
) {
1638 synchronized (invokeLaters
) {
1639 invokeLaters
.add(command
);
1645 * Restore the console to sane defaults. This is meant to be used for
1646 * improper exits (e.g. a caught exception in main()), and should not be
1647 * necessary for normal program termination.
1649 public void restoreConsole() {
1650 if (backend
!= null) {
1651 if (backend
instanceof ECMA48Backend
) {
1660 * @return the Backend
1662 public final Backend
getBackend() {
1669 * @return the Screen
1671 public final Screen
getScreen() {
1672 if (backend
instanceof TWindowBackend
) {
1673 // We are being rendered to a TWindow. We can't use its
1674 // getScreen() method because that is how it is rendering to a
1675 // hardware backend somewhere. Instead use its getOtherScreen()
1677 return ((TWindowBackend
) backend
).getOtherScreen();
1679 return backend
.getScreen();
1684 * Get the color theme.
1688 public final ColorTheme
getTheme() {
1693 * Get the clipboard.
1695 * @return the clipboard
1697 public final Clipboard
getClipboard() {
1702 * Repaint the screen on the next update.
1704 public void doRepaint() {
1710 * Get Y coordinate of the top edge of the desktop.
1712 * @return Y coordinate of the top edge of the desktop
1714 public final int getDesktopTop() {
1719 * Get Y coordinate of the bottom edge of the desktop.
1721 * @return Y coordinate of the bottom edge of the desktop
1723 public final int getDesktopBottom() {
1724 return desktopBottom
;
1728 * Set the TDesktop instance.
1730 * @param desktop a TDesktop instance, or null to remove the one that is
1733 public final void setDesktop(final TDesktop desktop
) {
1734 if (this.desktop
!= null) {
1735 this.desktop
.onPreClose();
1736 this.desktop
.onUnfocus();
1737 this.desktop
.onClose();
1739 this.desktop
= desktop
;
1743 * Get the TDesktop instance.
1745 * @return the desktop, or null if it is not set
1747 public final TDesktop
getDesktop() {
1752 * Get the current active window.
1754 * @return the active window, or null if it is not set
1756 public final TWindow
getActiveWindow() {
1757 return activeWindow
;
1761 * Get a (shallow) copy of the window list.
1763 * @return a copy of the list of windows for this application
1765 public final List
<TWindow
> getAllWindows() {
1766 List
<TWindow
> result
= new ArrayList
<TWindow
>();
1767 result
.addAll(windows
);
1772 * Get focusFollowsMouse flag.
1774 * @return true if focus follows mouse: windows automatically raised if
1775 * the mouse passes over them
1777 public boolean getFocusFollowsMouse() {
1778 return focusFollowsMouse
;
1782 * Set focusFollowsMouse flag.
1784 * @param focusFollowsMouse if true, focus follows mouse: windows
1785 * automatically raised if the mouse passes over them
1787 public void setFocusFollowsMouse(final boolean focusFollowsMouse
) {
1788 this.focusFollowsMouse
= focusFollowsMouse
;
1792 * Display the about dialog.
1794 protected void showAboutDialog() {
1795 String version
= getClass().getPackage().getImplementationVersion();
1796 if (version
== null) {
1797 // This is Java 9+, use a hardcoded string here.
1800 messageBox(i18n
.getString("aboutDialogTitle"),
1801 MessageFormat
.format(i18n
.getString("aboutDialogText"), version
),
1802 TMessageBox
.Type
.OK
);
1806 * Handle the Tool | Open image menu item.
1808 private void openImage() {
1810 List
<String
> filters
= new ArrayList
<String
>();
1811 filters
.add("^.*\\.[Jj][Pp][Gg]$");
1812 filters
.add("^.*\\.[Jj][Pp][Ee][Gg]$");
1813 filters
.add("^.*\\.[Pp][Nn][Gg]$");
1814 filters
.add("^.*\\.[Gg][Ii][Ff]$");
1815 filters
.add("^.*\\.[Bb][Mm][Pp]$");
1816 String filename
= fileOpenBox(".", TFileOpenBox
.Type
.OPEN
, filters
);
1817 if (filename
!= null) {
1818 new TImageWindow(this, new File(filename
));
1820 } catch (IOException e
) {
1821 // Show this exception to the user.
1822 new TExceptionDialog(this, e
);
1827 * Check if application is still running.
1829 * @return true if the application is running
1831 public final boolean isRunning() {
1838 // ------------------------------------------------------------------------
1839 // Screen refresh loop ----------------------------------------------------
1840 // ------------------------------------------------------------------------
1843 * Draw the text mouse at position.
1845 * @param x column position
1846 * @param y row position
1848 private void drawTextMouse(final int x
, final int y
) {
1851 System
.err
.printf("%d %s drawTextMouse() %d %d\n",
1852 System
.currentTimeMillis(), Thread
.currentThread(), x
, y
);
1854 if (activeWindow
!= null) {
1855 System
.err
.println("activeWindow.hasHiddenMouse() " +
1856 activeWindow
.hasHiddenMouse());
1860 // If this cell is on top of a visible window that has requested a
1861 // hidden mouse, bail out.
1862 if ((activeWindow
!= null) && (activeMenu
== null)) {
1863 if ((activeWindow
.hasHiddenMouse() == true)
1864 && (x
> activeWindow
.getX())
1865 && (x
< activeWindow
.getX() + activeWindow
.getWidth() - 1)
1866 && (y
> activeWindow
.getY())
1867 && (y
< activeWindow
.getY() + activeWindow
.getHeight() - 1)
1873 // If this cell is on top of the desktop, and the desktop has
1874 // requested a hidden mouse, bail out.
1875 if ((desktop
!= null) && (activeWindow
== null) && (activeMenu
== null)) {
1876 if ((desktop
.hasHiddenMouse() == true)
1877 && (x
> desktop
.getX())
1878 && (x
< desktop
.getX() + desktop
.getWidth() - 1)
1879 && (y
> desktop
.getY())
1880 && (y
< desktop
.getY() + desktop
.getHeight() - 1)
1886 getScreen().invertCell(x
, y
);
1892 private void drawAll() {
1893 boolean menuIsActive
= false;
1896 System
.err
.printf("%d %s drawAll() enter\n",
1897 System
.currentTimeMillis(), Thread
.currentThread());
1900 // I don't think this does anything useful anymore...
1903 System
.err
.printf("%d %s drawAll() !repaint\n",
1904 System
.currentTimeMillis(), Thread
.currentThread());
1906 if ((oldDrawnMouseX
!= mouseX
) || (oldDrawnMouseY
!= mouseY
)) {
1908 System
.err
.printf("%d %s drawAll() !repaint MOUSE\n",
1909 System
.currentTimeMillis(), Thread
.currentThread());
1912 // The only thing that has happened is the mouse moved.
1914 // Redraw the old cell at that position, and save the cell at
1915 // the new mouse position.
1917 System
.err
.printf("%d %s restoreImage() %d %d\n",
1918 System
.currentTimeMillis(), Thread
.currentThread(),
1919 oldDrawnMouseX
, oldDrawnMouseY
);
1921 oldDrawnMouseCell
.restoreImage();
1922 getScreen().putCharXY(oldDrawnMouseX
, oldDrawnMouseY
,
1924 oldDrawnMouseCell
= getScreen().getCharXY(mouseX
, mouseY
);
1925 if (backend
instanceof ECMA48Backend
) {
1926 // Special case: the entire row containing the mouse has
1927 // to be re-drawn if it has any image data, AND any rows
1929 if (oldDrawnMouseY
!= mouseY
) {
1930 for (int i
= oldDrawnMouseY
; ;) {
1931 getScreen().unsetImageRow(i
);
1935 if (oldDrawnMouseY
< mouseY
) {
1942 getScreen().unsetImageRow(mouseY
);
1946 if (inScreenSelection
) {
1947 getScreen().setSelection(screenSelectionX0
,
1948 screenSelectionY0
, screenSelectionX1
, screenSelectionY1
,
1949 screenSelectionRectangle
);
1952 if ((textMouse
== true) && (typingHidMouse
== false)) {
1953 // Draw mouse at the new position.
1954 drawTextMouse(mouseX
, mouseY
);
1957 oldDrawnMouseX
= mouseX
;
1958 oldDrawnMouseY
= mouseY
;
1960 if (getScreen().isDirty()) {
1961 screenHandler
.setDirty();
1967 System
.err
.printf("%d %s drawAll() REDRAW\n",
1968 System
.currentTimeMillis(), Thread
.currentThread());
1971 // If true, the cursor is not visible
1972 boolean cursor
= false;
1974 // Start with a clean screen
1975 getScreen().clear();
1978 if (desktop
!= null) {
1979 desktop
.drawChildren();
1982 // Draw each window in reverse Z order
1983 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
1984 Collections
.sort(sorted
);
1985 TWindow topLevel
= null;
1986 if (sorted
.size() > 0) {
1987 topLevel
= sorted
.get(0);
1989 Collections
.reverse(sorted
);
1990 for (TWindow window
: sorted
) {
1991 if (window
.isShown()) {
1992 window
.drawChildren();
1996 if (hideMenuBar
== false) {
1998 // Draw the blank menubar line - reset the screen clipping first
1999 // so it won't trim it out.
2000 getScreen().resetClipping();
2001 getScreen().hLineXY(0, 0, getScreen().getWidth(), ' ',
2002 theme
.getColor("tmenu"));
2003 // Now draw the menus.
2005 for (TMenu menu
: menus
) {
2006 CellAttributes menuColor
;
2007 CellAttributes menuMnemonicColor
;
2008 if (menu
.isActive()) {
2009 menuIsActive
= true;
2010 menuColor
= theme
.getColor("tmenu.highlighted");
2011 menuMnemonicColor
= theme
.getColor("tmenu.mnemonic.highlighted");
2014 menuColor
= theme
.getColor("tmenu");
2015 menuMnemonicColor
= theme
.getColor("tmenu.mnemonic");
2017 // Draw the menu title
2018 getScreen().hLineXY(x
, 0,
2019 StringUtils
.width(menu
.getTitle()) + 2, ' ', menuColor
);
2020 getScreen().putStringXY(x
+ 1, 0, menu
.getTitle(), menuColor
);
2021 // Draw the highlight character
2022 getScreen().putCharXY(x
+ 1 +
2023 menu
.getMnemonic().getScreenShortcutIdx(),
2024 0, menu
.getMnemonic().getShortcut(), menuMnemonicColor
);
2026 if (menu
.isActive()) {
2027 ((TWindow
) menu
).drawChildren();
2028 // Reset the screen clipping so we can draw the next
2030 getScreen().resetClipping();
2032 x
+= StringUtils
.width(menu
.getTitle()) + 2;
2035 for (TMenu menu
: subMenus
) {
2036 // Reset the screen clipping so we can draw the next
2038 getScreen().resetClipping();
2039 ((TWindow
) menu
).drawChildren();
2042 getScreen().resetClipping();
2044 if (hideStatusBar
== false) {
2045 // Draw the status bar of the top-level window
2046 TStatusBar statusBar
= null;
2047 if (topLevel
!= null) {
2048 if (topLevel
.isShown()) {
2049 statusBar
= topLevel
.getStatusBar();
2052 if (statusBar
!= null) {
2053 getScreen().resetClipping();
2054 statusBar
.setWidth(getScreen().getWidth());
2055 statusBar
.setY(getScreen().getHeight() - topLevel
.getY());
2058 CellAttributes barColor
= new CellAttributes();
2059 barColor
.setTo(getTheme().getColor("tstatusbar.text"));
2060 getScreen().hLineXY(0, desktopBottom
, getScreen().getWidth(),
2065 // Draw the mouse pointer
2067 System
.err
.printf("%d %s restoreImage() %d %d\n",
2068 System
.currentTimeMillis(), Thread
.currentThread(),
2069 oldDrawnMouseX
, oldDrawnMouseY
);
2071 oldDrawnMouseCell
= getScreen().getCharXY(mouseX
, mouseY
);
2072 if (backend
instanceof ECMA48Backend
) {
2073 // Special case: the entire row containing the mouse has to be
2074 // re-drawn if it has any image data, AND any rows in between.
2075 if (oldDrawnMouseY
!= mouseY
) {
2076 for (int i
= oldDrawnMouseY
; ;) {
2077 getScreen().unsetImageRow(i
);
2081 if (oldDrawnMouseY
< mouseY
) {
2088 getScreen().unsetImageRow(mouseY
);
2092 if (inScreenSelection
) {
2093 getScreen().setSelection(screenSelectionX0
, screenSelectionY0
,
2094 screenSelectionX1
, screenSelectionY1
, screenSelectionRectangle
);
2097 if ((textMouse
== true) && (typingHidMouse
== false)) {
2098 drawTextMouse(mouseX
, mouseY
);
2100 oldDrawnMouseX
= mouseX
;
2101 oldDrawnMouseY
= mouseY
;
2103 // Place the cursor if it is visible
2104 if (!menuIsActive
) {
2106 int visibleWindowCount
= 0;
2107 for (TWindow window
: sorted
) {
2108 if (window
.isShown()) {
2109 visibleWindowCount
++;
2112 if (visibleWindowCount
== 0) {
2113 // No windows are visible, only the desktop. Allow it to
2115 if (desktop
!= null) {
2116 sorted
.add(desktop
);
2120 TWidget activeWidget
= null;
2121 if (sorted
.size() > 0) {
2122 activeWidget
= sorted
.get(sorted
.size() - 1).getActiveChild();
2123 int cursorClipTop
= desktopTop
;
2124 int cursorClipBottom
= desktopBottom
;
2125 if (activeWidget
.isCursorVisible()) {
2126 if ((activeWidget
.getCursorAbsoluteY() <= cursorClipBottom
)
2127 && (activeWidget
.getCursorAbsoluteY() >= cursorClipTop
)
2129 getScreen().putCursor(true,
2130 activeWidget
.getCursorAbsoluteX(),
2131 activeWidget
.getCursorAbsoluteY());
2134 // Turn off the cursor. Also place it at 0,0.
2135 getScreen().putCursor(false, 0, 0);
2144 getScreen().hideCursor();
2147 if (getScreen().isDirty()) {
2148 screenHandler
.setDirty();
2154 * Force this application to exit.
2156 public void exit() {
2158 synchronized (this) {
2164 * Subclasses can use this hook to cleanup resources. Called as the last
2165 * step of TApplication.run().
2167 public void onExit() {
2168 // Default does nothing.
2171 // ------------------------------------------------------------------------
2172 // TWindow management -----------------------------------------------------
2173 // ------------------------------------------------------------------------
2176 * Return the total number of windows.
2178 * @return the total number of windows
2180 public final int windowCount() {
2181 return windows
.size();
2185 * Return the number of windows that are showing.
2187 * @return the number of windows that are showing on screen
2189 public final int shownWindowCount() {
2191 for (TWindow w
: windows
) {
2200 * Return the number of windows that are hidden.
2202 * @return the number of windows that are hidden
2204 public final int hiddenWindowCount() {
2206 for (TWindow w
: windows
) {
2215 * Check if a window instance is in this application's window list.
2217 * @param window window to look for
2218 * @return true if this window is in the list
2220 public final boolean hasWindow(final TWindow window
) {
2221 if (windows
.size() == 0) {
2224 for (TWindow w
: windows
) {
2226 assert (window
.getApplication() == this);
2234 * Activate a window: bring it to the top and have it receive events.
2236 * @param window the window to become the new active window
2238 public void activateWindow(final TWindow window
) {
2239 if (hasWindow(window
) == false) {
2241 * Someone has a handle to a window I don't have. Ignore this
2247 // Whatever window might be moving/dragging, stop it now.
2248 for (TWindow w
: windows
) {
2249 if (w
.inMovements()) {
2254 assert (windows
.size() > 0);
2256 if (window
.isHidden()) {
2257 // Unhiding will also activate.
2261 assert (window
.isShown());
2263 if (windows
.size() == 1) {
2264 assert (window
== windows
.get(0));
2265 if (activeWindow
== null) {
2266 activeWindow
= window
;
2268 activeWindow
.setActive(true);
2269 activeWindow
.onFocus();
2272 assert (window
.isActive());
2273 assert (activeWindow
== window
);
2277 if (activeWindow
== window
) {
2278 assert (window
.isActive());
2280 // Window is already active, do nothing.
2284 assert (!window
.isActive());
2285 if (activeWindow
!= null) {
2286 activeWindow
.setActive(false);
2288 // Increment every window Z that is on top of window
2289 for (TWindow w
: windows
) {
2293 if (w
.getZ() < window
.getZ()) {
2294 w
.setZ(w
.getZ() + 1);
2298 // Unset activeWindow now before unfocus, so that a window
2299 // lifecycle change inside onUnfocus() doesn't call
2300 // switchWindow() and lead to a stack overflow.
2301 TWindow oldActiveWindow
= activeWindow
;
2302 activeWindow
= null;
2303 oldActiveWindow
.onUnfocus();
2305 activeWindow
= window
;
2306 activeWindow
.setZ(0);
2307 activeWindow
.setActive(true);
2308 activeWindow
.onFocus();
2315 * @param window the window to hide
2317 public void hideWindow(final TWindow window
) {
2318 if (hasWindow(window
) == false) {
2320 * Someone has a handle to a window I don't have. Ignore this
2326 // Whatever window might be moving/dragging, stop it now.
2327 for (TWindow w
: windows
) {
2328 if (w
.inMovements()) {
2333 assert (windows
.size() > 0);
2335 if (!window
.hidden
) {
2336 if (window
== activeWindow
) {
2337 if (shownWindowCount() > 1) {
2340 activeWindow
= null;
2341 window
.setActive(false);
2345 window
.hidden
= true;
2353 * @param window the window to show
2355 public void showWindow(final TWindow window
) {
2356 if (hasWindow(window
) == false) {
2358 * Someone has a handle to a window I don't have. Ignore this
2364 // Whatever window might be moving/dragging, stop it now.
2365 for (TWindow w
: windows
) {
2366 if (w
.inMovements()) {
2371 assert (windows
.size() > 0);
2373 if (window
.hidden
) {
2374 window
.hidden
= false;
2376 activateWindow(window
);
2381 * Close window. Note that the window's destructor is NOT called by this
2382 * method, instead the GC is assumed to do the cleanup.
2384 * @param window the window to remove
2386 public final void closeWindow(final TWindow window
) {
2387 if (hasWindow(window
) == false) {
2389 * Someone has a handle to a window I don't have. Ignore this
2395 // Let window know that it is about to be closed, while it is still
2396 // visible on screen.
2397 window
.onPreClose();
2399 synchronized (windows
) {
2400 // Whatever window might be moving/dragging, stop it now.
2401 for (TWindow w
: windows
) {
2402 if (w
.inMovements()) {
2407 int z
= window
.getZ();
2410 windows
.remove(window
);
2411 Collections
.sort(windows
);
2412 activeWindow
= null;
2414 boolean foundNextWindow
= false;
2416 for (TWindow w
: windows
) {
2420 // Do not activate a hidden window.
2425 if (foundNextWindow
== false) {
2426 foundNextWindow
= true;
2429 assert (activeWindow
== null);
2441 // Perform window cleanup
2444 // Check if we are closing a TMessageBox or similar
2445 if (secondaryEventReceiver
!= null) {
2446 assert (secondaryEventHandler
!= null);
2448 // Do not send events to the secondaryEventReceiver anymore, the
2449 // window is closed.
2450 secondaryEventReceiver
= null;
2452 // Wake the secondary thread, it will wake the primary as it
2454 synchronized (secondaryEventHandler
) {
2455 secondaryEventHandler
.notify();
2459 // Permit desktop to be active if it is the only thing left.
2460 if (desktop
!= null) {
2461 if (windows
.size() == 0) {
2462 desktop
.setActive(true);
2468 * Switch to the next window.
2470 * @param forward if true, then switch to the next window in the list,
2471 * otherwise switch to the previous window in the list
2473 public final void switchWindow(final boolean forward
) {
2474 // Only switch if there are multiple visible windows
2475 if (shownWindowCount() < 2) {
2478 assert (activeWindow
!= null);
2480 synchronized (windows
) {
2481 // Whatever window might be moving/dragging, stop it now.
2482 for (TWindow w
: windows
) {
2483 if (w
.inMovements()) {
2488 // Swap z/active between active window and the next in the list
2489 int activeWindowI
= -1;
2490 for (int i
= 0; i
< windows
.size(); i
++) {
2491 if (windows
.get(i
) == activeWindow
) {
2492 assert (activeWindow
.isActive());
2496 assert (!windows
.get(0).isActive());
2499 assert (activeWindowI
>= 0);
2501 // Do not switch if a window is modal
2502 if (activeWindow
.isModal()) {
2506 int nextWindowI
= activeWindowI
;
2510 nextWindowI
%= windows
.size();
2513 if (nextWindowI
< 0) {
2514 nextWindowI
= windows
.size() - 1;
2518 if (windows
.get(nextWindowI
).isShown()) {
2519 activateWindow(windows
.get(nextWindowI
));
2523 } // synchronized (windows)
2528 * Add a window to my window list and make it active. Note package
2531 * @param window new window to add
2533 final void addWindowToApplication(final TWindow window
) {
2535 // Do not add menu windows to the window list.
2536 if (window
instanceof TMenu
) {
2540 // Do not add the desktop to the window list.
2541 if (window
instanceof TDesktop
) {
2545 synchronized (windows
) {
2546 if (windows
.contains(window
)) {
2547 throw new IllegalArgumentException("Window " + window
+
2548 " is already in window list");
2551 // Whatever window might be moving/dragging, stop it now.
2552 for (TWindow w
: windows
) {
2553 if (w
.inMovements()) {
2558 // Do not allow a modal window to spawn a non-modal window. If a
2559 // modal window is active, then this window will become modal
2561 if (modalWindowActive()) {
2562 window
.flags
|= TWindow
.MODAL
;
2563 window
.flags
|= TWindow
.CENTERED
;
2564 window
.hidden
= false;
2566 if (window
.isShown()) {
2567 for (TWindow w
: windows
) {
2572 w
.setZ(w
.getZ() + 1);
2575 windows
.add(window
);
2576 if (window
.isShown()) {
2577 activeWindow
= window
;
2578 activeWindow
.setZ(0);
2579 activeWindow
.setActive(true);
2580 activeWindow
.onFocus();
2583 if (((window
.flags
& TWindow
.CENTERED
) == 0)
2584 && ((window
.flags
& TWindow
.ABSOLUTEXY
) == 0)
2585 && (smartWindowPlacement
== true)
2586 && (!(window
instanceof TDesktop
))
2589 doSmartPlacement(window
);
2593 // Desktop cannot be active over any other window.
2594 if (desktop
!= null) {
2595 desktop
.setActive(false);
2600 * Check if there is a system-modal window on top.
2602 * @return true if the active window is modal
2604 private boolean modalWindowActive() {
2605 if (windows
.size() == 0) {
2609 for (TWindow w
: windows
) {
2619 * Check if there is a window with overridden menu flag on top.
2621 * @return true if the active window is overriding the menu
2623 private boolean overrideMenuWindowActive() {
2624 if (activeWindow
!= null) {
2625 if (activeWindow
.hasOverriddenMenu()) {
2634 * Close all open windows.
2636 private void closeAllWindows() {
2637 // Don't do anything if we are in the menu
2638 if (activeMenu
!= null) {
2641 while (windows
.size() > 0) {
2642 closeWindow(windows
.get(0));
2647 * Re-layout the open windows as non-overlapping tiles. This produces
2648 * almost the same results as Turbo Pascal 7.0's IDE.
2650 private void tileWindows() {
2651 synchronized (windows
) {
2652 // Don't do anything if we are in the menu
2653 if (activeMenu
!= null) {
2656 int z
= windows
.size();
2662 a
= (int)(Math
.sqrt(z
));
2666 if (((a
* b
) + c
) == z
) {
2674 int newWidth
= (getScreen().getWidth() / a
);
2675 int newHeight1
= ((getScreen().getHeight() - 1) / b
);
2676 int newHeight2
= ((getScreen().getHeight() - 1) / (b
+ c
));
2678 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
2679 Collections
.sort(sorted
);
2680 Collections
.reverse(sorted
);
2681 for (int i
= 0; i
< sorted
.size(); i
++) {
2682 int logicalX
= i
/ b
;
2683 int logicalY
= i
% b
;
2684 if (i
>= ((a
- 1) * b
)) {
2686 logicalY
= i
- ((a
- 1) * b
);
2689 TWindow w
= sorted
.get(i
);
2690 int oldWidth
= w
.getWidth();
2691 int oldHeight
= w
.getHeight();
2693 w
.setX(logicalX
* newWidth
);
2694 w
.setWidth(newWidth
);
2695 if (i
>= ((a
- 1) * b
)) {
2696 w
.setY((logicalY
* newHeight2
) + 1);
2697 w
.setHeight(newHeight2
);
2699 w
.setY((logicalY
* newHeight1
) + 1);
2700 w
.setHeight(newHeight1
);
2702 if ((w
.getWidth() != oldWidth
)
2703 || (w
.getHeight() != oldHeight
)
2705 w
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
2706 w
.getWidth(), w
.getHeight()));
2713 * Re-layout the open windows as overlapping cascaded windows.
2715 private void cascadeWindows() {
2716 synchronized (windows
) {
2717 // Don't do anything if we are in the menu
2718 if (activeMenu
!= null) {
2723 List
<TWindow
> sorted
= new ArrayList
<TWindow
>(windows
);
2724 Collections
.sort(sorted
);
2725 Collections
.reverse(sorted
);
2726 for (TWindow window
: sorted
) {
2731 if (x
> getScreen().getWidth()) {
2734 if (y
>= getScreen().getHeight()) {
2742 * Place a window to minimize its overlap with other windows.
2744 * @param window the window to place
2746 public final void doSmartPlacement(final TWindow window
) {
2747 // This is a pretty dumb algorithm, but seems to work. The hardest
2748 // part is computing these "overlap" values seeking a minimum average
2751 int yMin
= desktopTop
;
2752 int xMax
= getScreen().getWidth() - window
.getWidth() + 1;
2753 int yMax
= desktopBottom
- window
.getHeight() + 1;
2761 if ((xMin
== xMax
) && (yMin
== yMax
)) {
2762 // No work to do, bail out.
2766 // Compute the overlap matrix without the new window.
2767 int width
= getScreen().getWidth();
2768 int height
= getScreen().getHeight();
2769 int overlapMatrix
[][] = new int[width
][height
];
2770 for (TWindow w
: windows
) {
2774 for (int x
= w
.getX(); x
< w
.getX() + w
.getWidth(); x
++) {
2781 for (int y
= w
.getY(); y
< w
.getY() + w
.getHeight(); y
++) {
2788 overlapMatrix
[x
][y
]++;
2793 long oldOverlapTotal
= 0;
2794 long oldOverlapN
= 0;
2795 for (int x
= 0; x
< width
; x
++) {
2796 for (int y
= 0; y
< height
; y
++) {
2797 oldOverlapTotal
+= overlapMatrix
[x
][y
];
2798 if (overlapMatrix
[x
][y
] > 0) {
2805 double oldOverlapAvg
= (double) oldOverlapTotal
/ (double) oldOverlapN
;
2806 boolean first
= true;
2807 int windowX
= window
.getX();
2808 int windowY
= window
.getY();
2810 // For each possible (x, y) position for the new window, compute a
2811 // new overlap matrix.
2812 for (int x
= xMin
; x
< xMax
; x
++) {
2813 for (int y
= yMin
; y
< yMax
; y
++) {
2815 // Start with the matrix minus this window.
2816 int newMatrix
[][] = new int[width
][height
];
2817 for (int mx
= 0; mx
< width
; mx
++) {
2818 for (int my
= 0; my
< height
; my
++) {
2819 newMatrix
[mx
][my
] = overlapMatrix
[mx
][my
];
2823 // Add this window's values to the new overlap matrix.
2824 long newOverlapTotal
= 0;
2825 long newOverlapN
= 0;
2826 // Start by adding each new cell.
2827 for (int wx
= x
; wx
< x
+ window
.getWidth(); wx
++) {
2831 for (int wy
= y
; wy
< y
+ window
.getHeight(); wy
++) {
2835 newMatrix
[wx
][wy
]++;
2838 // Now figure out the new value for total coverage.
2839 for (int mx
= 0; mx
< width
; mx
++) {
2840 for (int my
= 0; my
< height
; my
++) {
2841 newOverlapTotal
+= newMatrix
[x
][y
];
2842 if (newMatrix
[mx
][my
] > 0) {
2847 double newOverlapAvg
= (double) newOverlapTotal
/ (double) newOverlapN
;
2850 // First time: just record what we got.
2851 oldOverlapAvg
= newOverlapAvg
;
2854 // All other times: pick a new best (x, y) and save the
2856 if (newOverlapAvg
< oldOverlapAvg
) {
2859 oldOverlapAvg
= newOverlapAvg
;
2863 } // for (int x = xMin; x < xMax; x++)
2865 } // for (int y = yMin; y < yMax; y++)
2867 // Finally, set the window's new coordinates.
2868 window
.setX(windowX
);
2869 window
.setY(windowY
);
2872 // ------------------------------------------------------------------------
2873 // TMenu management -------------------------------------------------------
2874 // ------------------------------------------------------------------------
2877 * Check if a mouse event would hit either the active menu or any open
2880 * @param mouse mouse event
2881 * @return true if the mouse would hit the active menu or an open
2884 private boolean mouseOnMenu(final TMouseEvent mouse
) {
2885 assert (activeMenu
!= null);
2886 List
<TMenu
> menus
= new ArrayList
<TMenu
>(subMenus
);
2887 Collections
.reverse(menus
);
2888 for (TMenu menu
: menus
) {
2889 if (menu
.mouseWouldHit(mouse
)) {
2893 return activeMenu
.mouseWouldHit(mouse
);
2897 * See if we need to switch window or activate the menu based on
2900 * @param mouse mouse event
2902 private void checkSwitchFocus(final TMouseEvent mouse
) {
2904 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2905 && (activeMenu
!= null)
2906 && (mouse
.getAbsoluteY() != 0)
2907 && (!mouseOnMenu(mouse
))
2909 // They clicked outside the active menu, turn it off
2910 activeMenu
.setActive(false);
2912 for (TMenu menu
: subMenus
) {
2913 menu
.setActive(false);
2919 // See if they hit the menu bar
2920 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2921 && (mouse
.isMouse1())
2922 && (!modalWindowActive())
2923 && (!overrideMenuWindowActive())
2924 && (mouse
.getAbsoluteY() == 0)
2925 && (hideMenuBar
== false)
2928 for (TMenu menu
: subMenus
) {
2929 menu
.setActive(false);
2933 // They selected the menu, go activate it
2934 for (TMenu menu
: menus
) {
2935 if ((mouse
.getAbsoluteX() >= menu
.getTitleX())
2936 && (mouse
.getAbsoluteX() < menu
.getTitleX()
2937 + StringUtils
.width(menu
.getTitle()) + 2)
2939 menu
.setActive(true);
2942 menu
.setActive(false);
2948 // See if they hit the menu bar
2949 if ((mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
)
2950 && (mouse
.isMouse1())
2951 && (activeMenu
!= null)
2952 && (mouse
.getAbsoluteY() == 0)
2953 && (hideMenuBar
== false)
2956 TMenu oldMenu
= activeMenu
;
2957 for (TMenu menu
: subMenus
) {
2958 menu
.setActive(false);
2962 // See if we should switch menus
2963 for (TMenu menu
: menus
) {
2964 if ((mouse
.getAbsoluteX() >= menu
.getTitleX())
2965 && (mouse
.getAbsoluteX() < menu
.getTitleX()
2966 + StringUtils
.width(menu
.getTitle()) + 2)
2968 menu
.setActive(true);
2972 if (oldMenu
!= activeMenu
) {
2973 // They switched menus
2974 oldMenu
.setActive(false);
2979 // If a menu is still active, don't switch windows
2980 if (activeMenu
!= null) {
2984 // Only switch if there are multiple windows
2985 if (windows
.size() < 2) {
2989 if (((focusFollowsMouse
== true)
2990 && (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
))
2991 || (mouse
.getType() == TMouseEvent
.Type
.MOUSE_DOWN
)
2993 synchronized (windows
) {
2994 Collections
.sort(windows
);
2995 if (windows
.get(0).isModal()) {
2996 // Modal windows don't switch
3000 for (TWindow window
: windows
) {
3001 assert (!window
.isModal());
3003 if (window
.isHidden()) {
3004 assert (!window
.isActive());
3008 if (window
.mouseWouldHit(mouse
)) {
3009 if (window
== windows
.get(0)) {
3010 // Clicked on the same window, nothing to do
3011 assert (window
.isActive());
3015 // We will be switching to another window
3016 assert (windows
.get(0).isActive());
3017 assert (windows
.get(0) == activeWindow
);
3018 assert (!window
.isActive());
3019 if (activeWindow
!= null) {
3020 activeWindow
.onUnfocus();
3021 activeWindow
.setActive(false);
3022 activeWindow
.setZ(window
.getZ());
3024 activeWindow
= window
;
3026 window
.setActive(true);
3033 // Clicked on the background, nothing to do
3037 // Nothing to do: this isn't a mouse up, or focus isn't following
3043 * Turn off the menu.
3045 public final void closeMenu() {
3046 if (activeMenu
!= null) {
3047 activeMenu
.setActive(false);
3049 for (TMenu menu
: subMenus
) {
3050 menu
.setActive(false);
3057 * Get a (shallow) copy of the menu list.
3059 * @return a copy of the menu list
3061 public final List
<TMenu
> getAllMenus() {
3062 return new ArrayList
<TMenu
>(menus
);
3066 * Add a top-level menu to the list.
3068 * @param menu the menu to add
3069 * @throws IllegalArgumentException if the menu is already used in
3070 * another TApplication
3072 public final void addMenu(final TMenu menu
) {
3073 if ((menu
.getApplication() != null)
3074 && (menu
.getApplication() != this)
3076 throw new IllegalArgumentException("Menu " + menu
+ " is already " +
3077 "part of application " + menu
.getApplication());
3085 * Remove a top-level menu from the list.
3087 * @param menu the menu to remove
3088 * @throws IllegalArgumentException if the menu is already used in
3089 * another TApplication
3091 public final void removeMenu(final TMenu menu
) {
3092 if ((menu
.getApplication() != null)
3093 && (menu
.getApplication() != this)
3095 throw new IllegalArgumentException("Menu " + menu
+ " is already " +
3096 "part of application " + menu
.getApplication());
3104 * Turn off a sub-menu.
3106 public final void closeSubMenu() {
3107 assert (activeMenu
!= null);
3108 TMenu item
= subMenus
.get(subMenus
.size() - 1);
3109 assert (item
!= null);
3110 item
.setActive(false);
3111 subMenus
.remove(subMenus
.size() - 1);
3115 * Switch to the next menu.
3117 * @param forward if true, then switch to the next menu in the list,
3118 * otherwise switch to the previous menu in the list
3120 public final void switchMenu(final boolean forward
) {
3121 assert (activeMenu
!= null);
3122 assert (hideMenuBar
== false);
3124 for (TMenu menu
: subMenus
) {
3125 menu
.setActive(false);
3129 for (int i
= 0; i
< menus
.size(); i
++) {
3130 if (activeMenu
== menus
.get(i
)) {
3132 if (i
< menus
.size() - 1) {
3141 i
= menus
.size() - 1;
3144 activeMenu
.setActive(false);
3145 activeMenu
= menus
.get(i
);
3146 activeMenu
.setActive(true);
3153 * Add a menu item to the global list. If it has a keyboard accelerator,
3154 * that will be added the global hash.
3156 * @param item the menu item
3158 public final void addMenuItem(final TMenuItem item
) {
3159 menuItems
.add(item
);
3161 TKeypress key
= item
.getKey();
3163 synchronized (accelerators
) {
3164 assert (accelerators
.get(key
) == null);
3165 accelerators
.put(key
.toLowerCase(), item
);
3171 * Disable one menu item.
3173 * @param id the menu item ID
3175 public final void disableMenuItem(final int id
) {
3176 for (TMenuItem item
: menuItems
) {
3177 if (item
.getId() == id
) {
3178 item
.setEnabled(false);
3184 * Disable the range of menu items with ID's between lower and upper,
3187 * @param lower the lowest menu item ID
3188 * @param upper the highest menu item ID
3190 public final void disableMenuItems(final int lower
, final int upper
) {
3191 for (TMenuItem item
: menuItems
) {
3192 if ((item
.getId() >= lower
) && (item
.getId() <= upper
)) {
3193 item
.setEnabled(false);
3194 item
.getParent().activate(0);
3200 * Enable one menu item.
3202 * @param id the menu item ID
3204 public final void enableMenuItem(final int id
) {
3205 for (TMenuItem item
: menuItems
) {
3206 if (item
.getId() == id
) {
3207 item
.setEnabled(true);
3208 item
.getParent().activate(0);
3214 * Enable the range of menu items with ID's between lower and upper,
3217 * @param lower the lowest menu item ID
3218 * @param upper the highest menu item ID
3220 public final void enableMenuItems(final int lower
, final int upper
) {
3221 for (TMenuItem item
: menuItems
) {
3222 if ((item
.getId() >= lower
) && (item
.getId() <= upper
)) {
3223 item
.setEnabled(true);
3224 item
.getParent().activate(0);
3230 * Get the menu item associated with this ID.
3232 * @param id the menu item ID
3233 * @return the menu item, or null if not found
3235 public final TMenuItem
getMenuItem(final int id
) {
3236 for (TMenuItem item
: menuItems
) {
3237 if (item
.getId() == id
) {
3245 * Recompute menu x positions based on their title length.
3247 public final void recomputeMenuX() {
3249 for (TMenu menu
: menus
) {
3252 x
+= StringUtils
.width(menu
.getTitle()) + 2;
3254 // Don't let the menu window exceed the screen width
3255 int rightEdge
= menu
.getX() + menu
.getWidth();
3256 if (rightEdge
> getScreen().getWidth()) {
3257 menu
.setX(getScreen().getWidth() - menu
.getWidth());
3263 * Post an event to process.
3265 * @param event new event to add to the queue
3267 public final void postEvent(final TInputEvent event
) {
3268 synchronized (this) {
3269 synchronized (fillEventQueue
) {
3270 fillEventQueue
.add(event
);
3273 System
.err
.println(System
.currentTimeMillis() + " " +
3274 Thread
.currentThread() + " postEvent() wake up main");
3281 * Post an event to process and turn off the menu.
3283 * @param event new event to add to the queue
3285 public final void postMenuEvent(final TInputEvent event
) {
3286 synchronized (this) {
3287 synchronized (fillEventQueue
) {
3288 fillEventQueue
.add(event
);
3291 System
.err
.println(System
.currentTimeMillis() + " " +
3292 Thread
.currentThread() + " postMenuEvent() wake up main");
3300 * Add a sub-menu to the list of open sub-menus.
3302 * @param menu sub-menu
3304 public final void addSubMenu(final TMenu menu
) {
3309 * Convenience function to add a top-level menu.
3311 * @param title menu title
3312 * @return the new menu
3314 public final TMenu
addMenu(final String title
) {
3317 TMenu menu
= new TMenu(this, x
, y
, title
);
3324 * Convenience function to add a default tools (hamburger) menu.
3326 * @return the new menu
3328 public final TMenu
addToolMenu() {
3329 TMenu toolMenu
= addMenu(i18n
.getString("toolMenuTitle"));
3330 toolMenu
.addDefaultItem(TMenu
.MID_REPAINT
);
3331 toolMenu
.addDefaultItem(TMenu
.MID_VIEW_IMAGE
);
3332 toolMenu
.addDefaultItem(TMenu
.MID_SCREEN_OPTIONS
);
3333 TStatusBar toolStatusBar
= toolMenu
.newStatusBar(i18n
.
3334 getString("toolMenuStatus"));
3335 toolStatusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3340 * Convenience function to add a default "File" menu.
3342 * @return the new menu
3344 public final TMenu
addFileMenu() {
3345 TMenu fileMenu
= addMenu(i18n
.getString("fileMenuTitle"));
3346 fileMenu
.addDefaultItem(TMenu
.MID_SHELL
);
3347 fileMenu
.addSeparator();
3348 fileMenu
.addDefaultItem(TMenu
.MID_EXIT
);
3349 TStatusBar statusBar
= fileMenu
.newStatusBar(i18n
.
3350 getString("fileMenuStatus"));
3351 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3356 * Convenience function to add a default "Edit" menu.
3358 * @return the new menu
3360 public final TMenu
addEditMenu() {
3361 TMenu editMenu
= addMenu(i18n
.getString("editMenuTitle"));
3362 editMenu
.addDefaultItem(TMenu
.MID_CUT
, false);
3363 editMenu
.addDefaultItem(TMenu
.MID_COPY
, false);
3364 editMenu
.addDefaultItem(TMenu
.MID_PASTE
, false);
3365 editMenu
.addDefaultItem(TMenu
.MID_CLEAR
, false);
3366 TStatusBar statusBar
= editMenu
.newStatusBar(i18n
.
3367 getString("editMenuStatus"));
3368 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3373 * Convenience function to add a default "Window" menu.
3375 * @return the new menu
3377 public final TMenu
addWindowMenu() {
3378 TMenu windowMenu
= addMenu(i18n
.getString("windowMenuTitle"));
3379 windowMenu
.addDefaultItem(TMenu
.MID_TILE
);
3380 windowMenu
.addDefaultItem(TMenu
.MID_CASCADE
);
3381 windowMenu
.addDefaultItem(TMenu
.MID_CLOSE_ALL
);
3382 windowMenu
.addSeparator();
3383 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_MOVE
);
3384 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_ZOOM
);
3385 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_NEXT
);
3386 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_PREVIOUS
);
3387 windowMenu
.addDefaultItem(TMenu
.MID_WINDOW_CLOSE
);
3388 TStatusBar statusBar
= windowMenu
.newStatusBar(i18n
.
3389 getString("windowMenuStatus"));
3390 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3395 * Convenience function to add a default "Help" menu.
3397 * @return the new menu
3399 public final TMenu
addHelpMenu() {
3400 TMenu helpMenu
= addMenu(i18n
.getString("helpMenuTitle"));
3401 helpMenu
.addDefaultItem(TMenu
.MID_HELP_CONTENTS
);
3402 helpMenu
.addDefaultItem(TMenu
.MID_HELP_INDEX
);
3403 helpMenu
.addDefaultItem(TMenu
.MID_HELP_SEARCH
);
3404 helpMenu
.addDefaultItem(TMenu
.MID_HELP_PREVIOUS
);
3405 helpMenu
.addDefaultItem(TMenu
.MID_HELP_HELP
);
3406 helpMenu
.addDefaultItem(TMenu
.MID_HELP_ACTIVE_FILE
);
3407 helpMenu
.addSeparator();
3408 helpMenu
.addDefaultItem(TMenu
.MID_ABOUT
);
3409 TStatusBar statusBar
= helpMenu
.newStatusBar(i18n
.
3410 getString("helpMenuStatus"));
3411 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3416 * Convenience function to add a default "Table" menu.
3418 * @return the new menu
3420 public final TMenu
addTableMenu() {
3421 TMenu tableMenu
= addMenu(i18n
.getString("tableMenuTitle"));
3422 tableMenu
.addDefaultItem(TMenu
.MID_TABLE_RENAME_COLUMN
, false);
3423 tableMenu
.addDefaultItem(TMenu
.MID_TABLE_RENAME_ROW
, false);
3424 tableMenu
.addSeparator();
3426 TSubMenu viewMenu
= tableMenu
.addSubMenu(i18n
.
3427 getString("tableSubMenuView"));
3428 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_ROW_LABELS
, false);
3429 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_COLUMN_LABELS
, false);
3430 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_HIGHLIGHT_ROW
, false);
3431 viewMenu
.addDefaultItem(TMenu
.MID_TABLE_VIEW_HIGHLIGHT_COLUMN
, false);
3433 TSubMenu borderMenu
= tableMenu
.addSubMenu(i18n
.
3434 getString("tableSubMenuBorders"));
3435 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_NONE
, false);
3436 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_ALL
, false);
3437 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_CELL_NONE
, false);
3438 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_CELL_ALL
, false);
3439 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_RIGHT
, false);
3440 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_LEFT
, false);
3441 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_TOP
, false);
3442 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_BOTTOM
, false);
3443 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_DOUBLE_BOTTOM
, false);
3444 borderMenu
.addDefaultItem(TMenu
.MID_TABLE_BORDER_THICK_BOTTOM
, false);
3445 TSubMenu deleteMenu
= tableMenu
.addSubMenu(i18n
.
3446 getString("tableSubMenuDelete"));
3447 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_LEFT
, false);
3448 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_UP
, false);
3449 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_ROW
, false);
3450 deleteMenu
.addDefaultItem(TMenu
.MID_TABLE_DELETE_COLUMN
, false);
3451 TSubMenu insertMenu
= tableMenu
.addSubMenu(i18n
.
3452 getString("tableSubMenuInsert"));
3453 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_LEFT
, false);
3454 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_RIGHT
, false);
3455 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_ABOVE
, false);
3456 insertMenu
.addDefaultItem(TMenu
.MID_TABLE_INSERT_BELOW
, false);
3457 TSubMenu columnMenu
= tableMenu
.addSubMenu(i18n
.
3458 getString("tableSubMenuColumn"));
3459 columnMenu
.addDefaultItem(TMenu
.MID_TABLE_COLUMN_NARROW
, false);
3460 columnMenu
.addDefaultItem(TMenu
.MID_TABLE_COLUMN_WIDEN
, false);
3461 TSubMenu fileMenu
= tableMenu
.addSubMenu(i18n
.
3462 getString("tableSubMenuFile"));
3463 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_OPEN_CSV
, false);
3464 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_SAVE_CSV
, false);
3465 fileMenu
.addDefaultItem(TMenu
.MID_TABLE_FILE_SAVE_TEXT
, false);
3467 TStatusBar statusBar
= tableMenu
.newStatusBar(i18n
.
3468 getString("tableMenuStatus"));
3469 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, i18n
.getString("Help"));
3473 // ------------------------------------------------------------------------
3474 // TTimer management ------------------------------------------------------
3475 // ------------------------------------------------------------------------
3478 * Get the amount of time I can sleep before missing a Timer tick.
3480 * @param timeout = initial (maximum) timeout in millis
3481 * @return number of milliseconds between now and the next timer event
3483 private long getSleepTime(final long timeout
) {
3484 Date now
= new Date();
3485 long nowTime
= now
.getTime();
3486 long sleepTime
= timeout
;
3488 synchronized (timers
) {
3489 for (TTimer timer
: timers
) {
3490 long nextTickTime
= timer
.getNextTick().getTime();
3491 if (nextTickTime
< nowTime
) {
3495 long timeDifference
= nextTickTime
- nowTime
;
3496 if (timeDifference
< sleepTime
) {
3497 sleepTime
= timeDifference
;
3502 assert (sleepTime
>= 0);
3503 assert (sleepTime
<= timeout
);
3508 * Convenience function to add a timer.
3510 * @param duration number of milliseconds to wait between ticks
3511 * @param recurring if true, re-schedule this timer after every tick
3512 * @param action function to call when button is pressed
3515 public final TTimer
addTimer(final long duration
, final boolean recurring
,
3516 final TAction action
) {
3518 TTimer timer
= new TTimer(duration
, recurring
, action
);
3519 synchronized (timers
) {
3526 * Convenience function to remove a timer.
3528 * @param timer timer to remove
3530 public final void removeTimer(final TTimer timer
) {
3531 synchronized (timers
) {
3532 timers
.remove(timer
);
3536 // ------------------------------------------------------------------------
3537 // Other TWindow constructors ---------------------------------------------
3538 // ------------------------------------------------------------------------
3541 * Convenience function to spawn a message box.
3543 * @param title window title, will be centered along the top border
3544 * @param caption message to display. Use embedded newlines to get a
3546 * @return the new message box
3548 public final TMessageBox
messageBox(final String title
,
3549 final String caption
) {
3551 return new TMessageBox(this, title
, caption
, TMessageBox
.Type
.OK
);
3555 * Convenience function to spawn a message box.
3557 * @param title window title, will be centered along the top border
3558 * @param caption message to display. Use embedded newlines to get a
3560 * @param type one of the TMessageBox.Type constants. Default is
3562 * @return the new message box
3564 public final TMessageBox
messageBox(final String title
,
3565 final String caption
, final TMessageBox
.Type type
) {
3567 return new TMessageBox(this, title
, caption
, type
);
3571 * Convenience function to spawn an input box.
3573 * @param title window title, will be centered along the top border
3574 * @param caption message to display. Use embedded newlines to get a
3576 * @return the new input box
3578 public final TInputBox
inputBox(final String title
, final String caption
) {
3580 return new TInputBox(this, title
, caption
);
3584 * Convenience function to spawn an input box.
3586 * @param title window title, will be centered along the top border
3587 * @param caption message to display. Use embedded newlines to get a
3589 * @param text initial text to seed the field with
3590 * @return the new input box
3592 public final TInputBox
inputBox(final String title
, final String caption
,
3593 final String text
) {
3595 return new TInputBox(this, title
, caption
, text
);
3599 * Convenience function to spawn an input box.
3601 * @param title window title, will be centered along the top border
3602 * @param caption message to display. Use embedded newlines to get a
3604 * @param text initial text to seed the field with
3605 * @param type one of the Type constants. Default is Type.OK.
3606 * @return the new input box
3608 public final TInputBox
inputBox(final String title
, final String caption
,
3609 final String text
, final TInputBox
.Type type
) {
3611 return new TInputBox(this, title
, caption
, text
, type
);
3615 * Convenience function to open a terminal window.
3617 * @param x column relative to parent
3618 * @param y row relative to parent
3619 * @return the terminal new window
3621 public final TTerminalWindow
openTerminal(final int x
, final int y
) {
3622 return openTerminal(x
, y
, TWindow
.RESIZABLE
);
3626 * Convenience function to open a terminal window.
3628 * @param x column relative to parent
3629 * @param y row relative to parent
3630 * @param closeOnExit if true, close the window when the command exits
3631 * @return the terminal new window
3633 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3634 final boolean closeOnExit
) {
3636 return openTerminal(x
, y
, TWindow
.RESIZABLE
, closeOnExit
);
3640 * Convenience function to open a terminal window.
3642 * @param x column relative to parent
3643 * @param y row relative to parent
3644 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3645 * @return the terminal new window
3647 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3650 return new TTerminalWindow(this, x
, y
, flags
);
3654 * Convenience function to open a terminal window.
3656 * @param x column relative to parent
3657 * @param y row relative to parent
3658 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3659 * @param closeOnExit if true, close the window when the command exits
3660 * @return the terminal new window
3662 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3663 final int flags
, final boolean closeOnExit
) {
3665 return new TTerminalWindow(this, x
, y
, flags
, closeOnExit
);
3669 * Convenience function to open a terminal window and execute a custom
3670 * command line inside it.
3672 * @param x column relative to parent
3673 * @param y row relative to parent
3674 * @param commandLine the command line to execute
3675 * @return the terminal new window
3677 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3678 final String commandLine
) {
3680 return openTerminal(x
, y
, TWindow
.RESIZABLE
, commandLine
);
3684 * Convenience function to open a terminal window and execute a custom
3685 * command line inside it.
3687 * @param x column relative to parent
3688 * @param y row relative to parent
3689 * @param commandLine the command line to execute
3690 * @param closeOnExit if true, close the window when the command exits
3691 * @return the terminal new window
3693 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3694 final String commandLine
, final boolean closeOnExit
) {
3696 return openTerminal(x
, y
, TWindow
.RESIZABLE
, commandLine
, closeOnExit
);
3700 * Convenience function to open a terminal window and execute a custom
3701 * command line inside it.
3703 * @param x column relative to parent
3704 * @param y row relative to parent
3705 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3706 * @param command the command line to execute
3707 * @return the terminal new window
3709 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3710 final int flags
, final String
[] command
) {
3712 return new TTerminalWindow(this, x
, y
, flags
, command
);
3716 * Convenience function to open a terminal window and execute a custom
3717 * command line inside it.
3719 * @param x column relative to parent
3720 * @param y row relative to parent
3721 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3722 * @param command the command line to execute
3723 * @param closeOnExit if true, close the window when the command exits
3724 * @return the terminal new window
3726 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3727 final int flags
, final String
[] command
, final boolean closeOnExit
) {
3729 return new TTerminalWindow(this, x
, y
, flags
, command
, closeOnExit
);
3733 * Convenience function to open a terminal window and execute a custom
3734 * command line inside it.
3736 * @param x column relative to parent
3737 * @param y row relative to parent
3738 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3739 * @param commandLine the command line to execute
3740 * @return the terminal new window
3742 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3743 final int flags
, final String commandLine
) {
3745 return new TTerminalWindow(this, x
, y
, flags
, commandLine
.split("\\s+"));
3749 * Convenience function to open a terminal window and execute a custom
3750 * command line inside it.
3752 * @param x column relative to parent
3753 * @param y row relative to parent
3754 * @param flags mask of CENTERED, MODAL, or RESIZABLE
3755 * @param commandLine the command line to execute
3756 * @param closeOnExit if true, close the window when the command exits
3757 * @return the terminal new window
3759 public final TTerminalWindow
openTerminal(final int x
, final int y
,
3760 final int flags
, final String commandLine
, final boolean closeOnExit
) {
3762 return new TTerminalWindow(this, x
, y
, flags
, commandLine
.split("\\s+"),
3767 * Convenience function to spawn an file open box.
3769 * @param path path of selected file
3770 * @return the result of the new file open box
3771 * @throws IOException if java.io operation throws
3773 public final String
fileOpenBox(final String path
) throws IOException
{
3775 TFileOpenBox box
= new TFileOpenBox(this, path
, TFileOpenBox
.Type
.OPEN
);
3776 return box
.getFilename();
3780 * Convenience function to spawn an file open box.
3782 * @param path path of selected file
3783 * @param type one of the Type constants
3784 * @return the result of the new file open box
3785 * @throws IOException if java.io operation throws
3787 public final String
fileOpenBox(final String path
,
3788 final TFileOpenBox
.Type type
) throws IOException
{
3790 TFileOpenBox box
= new TFileOpenBox(this, path
, type
);
3791 return box
.getFilename();
3795 * Convenience function to spawn a file open box.
3797 * @param path path of selected file
3798 * @param type one of the Type constants
3799 * @param filter a string that files must match to be displayed
3800 * @return the result of the new file open box
3801 * @throws IOException of a java.io operation throws
3803 public final String
fileOpenBox(final String path
,
3804 final TFileOpenBox
.Type type
, final String filter
) throws IOException
{
3806 ArrayList
<String
> filters
= new ArrayList
<String
>();
3807 filters
.add(filter
);
3809 TFileOpenBox box
= new TFileOpenBox(this, path
, type
, filters
);
3810 return box
.getFilename();
3814 * Convenience function to spawn a file open box.
3816 * @param path path of selected file
3817 * @param type one of the Type constants
3818 * @param filters a list of strings that files must match to be displayed
3819 * @return the result of the new file open box
3820 * @throws IOException of a java.io operation throws
3822 public final String
fileOpenBox(final String path
,
3823 final TFileOpenBox
.Type type
,
3824 final List
<String
> filters
) throws IOException
{
3826 TFileOpenBox box
= new TFileOpenBox(this, path
, type
, filters
);
3827 return box
.getFilename();
3831 * Convenience function to create a new window and make it active.
3832 * Window will be located at (0, 0).
3834 * @param title window title, will be centered along the top border
3835 * @param width width of window
3836 * @param height height of window
3837 * @return the new window
3839 public final TWindow
addWindow(final String title
, final int width
,
3842 TWindow window
= new TWindow(this, title
, 0, 0, width
, height
);
3847 * Convenience function to create a new window and make it active.
3848 * Window will be located at (0, 0).
3850 * @param title window title, will be centered along the top border
3851 * @param width width of window
3852 * @param height height of window
3853 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
3854 * @return the new window
3856 public final TWindow
addWindow(final String title
,
3857 final int width
, final int height
, final int flags
) {
3859 TWindow window
= new TWindow(this, title
, 0, 0, width
, height
, flags
);
3864 * Convenience function to create a new window and make it active.
3866 * @param title window title, will be centered along the top border
3867 * @param x column relative to parent
3868 * @param y row relative to parent
3869 * @param width width of window
3870 * @param height height of window
3871 * @return the new window
3873 public final TWindow
addWindow(final String title
,
3874 final int x
, final int y
, final int width
, final int height
) {
3876 TWindow window
= new TWindow(this, title
, x
, y
, width
, height
);
3881 * Convenience function to create a new window and make it active.
3883 * @param title window title, will be centered along the top border
3884 * @param x column relative to parent
3885 * @param y row relative to parent
3886 * @param width width of window
3887 * @param height height of window
3888 * @param flags mask of RESIZABLE, CENTERED, or MODAL
3889 * @return the new window
3891 public final TWindow
addWindow(final String title
,
3892 final int x
, final int y
, final int width
, final int height
,
3895 TWindow window
= new TWindow(this, title
, x
, y
, width
, height
, flags
);