2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 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]
31 import java
.util
.HashSet
;
33 import jexer
.bits
.Cell
;
34 import jexer
.bits
.CellAttributes
;
35 import jexer
.bits
.GraphicsChars
;
36 import jexer
.event
.TCommandEvent
;
37 import jexer
.event
.TKeypressEvent
;
38 import jexer
.event
.TMenuEvent
;
39 import jexer
.event
.TMouseEvent
;
40 import jexer
.event
.TResizeEvent
;
41 import jexer
.io
.Screen
;
42 import jexer
.menu
.TMenu
;
43 import static jexer
.TCommand
.*;
44 import static jexer
.TKeypress
.*;
47 * TWindow is the top-level container and drawing surface for other widgets.
49 public class TWindow
extends TWidget
{
51 // ------------------------------------------------------------------------
52 // Public constants -------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * Window is resizable (default yes).
58 public static final int RESIZABLE
= 0x01;
61 * Window is modal (default no).
63 public static final int MODAL
= 0x02;
66 * Window is centered (default no).
68 public static final int CENTERED
= 0x04;
71 * Window has no close box (default no). Window can still be closed via
72 * TApplication.closeWindow() and TWindow.close().
74 public static final int NOCLOSEBOX
= 0x08;
76 // ------------------------------------------------------------------------
77 // Common window attributes -----------------------------------------------
78 // ------------------------------------------------------------------------
81 * Window flags. Note package private access.
83 int flags
= RESIZABLE
;
88 private String title
= "";
93 * @return window title
95 public final String
getTitle() {
102 * @param title new window title
104 public final void setTitle(final String title
) {
108 // ------------------------------------------------------------------------
109 // TApplication integration -----------------------------------------------
110 // ------------------------------------------------------------------------
113 * Window's parent TApplication.
115 private TApplication application
;
118 * Get this TWindow's parent TApplication.
120 * @return this TWindow's parent TApplication
123 public final TApplication
getApplication() {
133 public final Screen
getScreen() {
134 return application
.getScreen();
138 * Z order. Lower number means more in-front.
143 * Get Z order. Lower number means more in-front.
145 * @return Z value. Lower number means more in-front.
147 public final int getZ() {
152 * Set Z order. Lower number means more in-front.
154 * @param z the new Z value. Lower number means more in-front.
156 public final void setZ(final int z
) {
161 * Window's keyboard shortcuts. Any key in this set will be passed to
162 * the window directly rather than processed through the menu
165 private HashSet
<TKeypress
> keyboardShortcuts
= new HashSet
<TKeypress
>();
168 * Add a keypress to be overridden for this window.
170 * @param key the key to start taking control of
172 protected void addShortcutKeypress(final TKeypress key
) {
173 keyboardShortcuts
.add(key
);
177 * Remove a keypress to be overridden for this window.
179 * @param key the key to stop taking control of
181 protected void removeShortcutKeypress(final TKeypress key
) {
182 keyboardShortcuts
.remove(key
);
186 * Remove all keypresses to be overridden for this window.
188 protected void clearShortcutKeypresses() {
189 keyboardShortcuts
.clear();
193 * Determine if a keypress is overridden for this window.
195 * @param key the key to check
196 * @return true if this window wants to process this key on its own
198 public boolean isShortcutKeypress(final TKeypress key
) {
199 return keyboardShortcuts
.contains(key
);
203 * A window may have a status bar associated with it. TApplication will
204 * draw this status bar last, and will also route events to it first
207 protected TStatusBar statusBar
= null;
210 * Get the window's status bar, or null if it does not have one.
212 * @return the status bar, or null
214 public TStatusBar
getStatusBar() {
219 * Set the window's status bar to a new one.
221 * @param text the status bar text
222 * @return the status bar
224 public TStatusBar
newStatusBar(final String text
) {
225 statusBar
= new TStatusBar(this, text
);
229 // ------------------------------------------------------------------------
230 // Window movement/resizing support ---------------------------------------
231 // ------------------------------------------------------------------------
234 * If true, then the user clicked on the title bar and is moving the
237 protected boolean inWindowMove
= false;
240 * If true, then the user clicked on the bottom right corner and is
241 * resizing the window.
243 protected boolean inWindowResize
= false;
246 * If true, then the user selected "Size/Move" (or hit Ctrl-F5) and is
247 * resizing/moving the window via the keyboard.
249 private boolean inKeyboardResize
= false;
252 * If true, this window is maximized.
254 private boolean maximized
= false;
257 * Remember mouse state.
259 protected TMouseEvent mouse
;
261 // For moving the window. resizing also uses moveWindowMouseX/Y
262 private int moveWindowMouseX
;
263 private int moveWindowMouseY
;
264 private int oldWindowX
;
265 private int oldWindowY
;
268 private int resizeWindowWidth
;
269 private int resizeWindowHeight
;
270 private int minimumWindowWidth
= 10;
271 private int minimumWindowHeight
= 2;
272 private int maximumWindowWidth
= -1;
273 private int maximumWindowHeight
= -1;
275 // For maximize/restore
276 private int restoreWindowWidth
;
277 private int restoreWindowHeight
;
278 private int restoreWindowX
;
279 private int restoreWindowY
;
282 * Set the maximum width for this window.
284 * @param maximumWindowWidth new maximum width
286 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
287 this.maximumWindowWidth
= maximumWindowWidth
;
291 * Recenter the window on-screen.
293 public final void center() {
294 if ((flags
& CENTERED
) != 0) {
295 if (getWidth() < getScreen().getWidth()) {
296 setX((getScreen().getWidth() - getWidth()) / 2);
300 setY(((application
.getDesktopBottom()
301 - application
.getDesktopTop()) - getHeight()) / 2);
305 setY(getY() + application
.getDesktopTop());
312 public void maximize() {
317 restoreWindowWidth
= getWidth();
318 restoreWindowHeight
= getHeight();
319 restoreWindowX
= getX();
320 restoreWindowY
= getY();
321 setWidth(getScreen().getWidth());
322 setHeight(application
.getDesktopBottom() - 1);
329 * Restore (unmaximize) window.
331 public void restore() {
336 setWidth(restoreWindowWidth
);
337 setHeight(restoreWindowHeight
);
338 setX(restoreWindowX
);
339 setY(restoreWindowY
);
343 // ------------------------------------------------------------------------
344 // Window visibility ------------------------------------------------------
345 // ------------------------------------------------------------------------
348 * Hidden flag. A hidden window will still have its onIdle() called, and
349 * will also have onClose() called at application exit. Note package
350 * private access: TApplication will force hidden false if a modal window
353 boolean hidden
= false;
356 * Returns true if this window is hidden.
358 * @return true if this window is hidden, false if the window is shown
360 public final boolean isHidden() {
365 * Returns true if this window is shown.
367 * @return true if this window is shown, false if the window is hidden
369 public final boolean isShown() {
374 * Hide window. A hidden window will still have its onIdle() called, and
375 * will also have onClose() called at application exit. Hidden windows
376 * will not receive any other events.
379 application
.hideWindow(this);
386 application
.showWindow(this);
390 * Activate window (bring to top and receive events).
392 public void activate() {
393 application
.activateWindow(this);
397 * Close window. Note that windows without a close box can still be
398 * closed by calling the close() method.
400 public void close() {
401 application
.closeWindow(this);
404 // ------------------------------------------------------------------------
405 // Constructors -----------------------------------------------------------
406 // ------------------------------------------------------------------------
409 * Public constructor. Window will be located at (0, 0).
411 * @param application TApplication that manages this window
412 * @param title window title, will be centered along the top border
413 * @param width width of window
414 * @param height height of window
416 public TWindow(final TApplication application
, final String title
,
417 final int width
, final int height
) {
419 this(application
, title
, 0, 0, width
, height
, RESIZABLE
);
423 * Public constructor. Window will be located at (0, 0).
425 * @param application TApplication that manages this window
426 * @param title window title, will be centered along the top border
427 * @param width width of window
428 * @param height height of window
429 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
431 public TWindow(final TApplication application
, final String title
,
432 final int width
, final int height
, final int flags
) {
434 this(application
, title
, 0, 0, width
, height
, flags
);
438 * Public constructor.
440 * @param application TApplication that manages this window
441 * @param title window title, will be centered along the top border
442 * @param x column relative to parent
443 * @param y row relative to parent
444 * @param width width of window
445 * @param height height of window
447 public TWindow(final TApplication application
, final String title
,
448 final int x
, final int y
, final int width
, final int height
) {
450 this(application
, title
, x
, y
, width
, height
, RESIZABLE
);
454 * Public constructor.
456 * @param application TApplication that manages this window
457 * @param title window title, will be centered along the top border
458 * @param x column relative to parent
459 * @param y row relative to parent
460 * @param width width of window
461 * @param height height of window
462 * @param flags mask of RESIZABLE, CENTERED, or MODAL
464 public TWindow(final TApplication application
, final String title
,
465 final int x
, final int y
, final int width
, final int height
,
470 // I am my own window and parent
471 setupForTWindow(this, x
, y
+ application
.getDesktopTop(),
476 this.application
= application
;
479 // Minimum width/height are 10 and 2
480 assert (width
>= 10);
481 assert (getHeight() >= 2);
483 // MODAL implies CENTERED
485 this.flags
|= CENTERED
;
488 // Center window if specified
491 // Add me to the application
492 application
.addWindow(this);
495 // ------------------------------------------------------------------------
496 // General behavior -------------------------------------------------------
497 // ------------------------------------------------------------------------
500 * Returns true if this window is modal.
502 * @return true if this window is modal
504 public final boolean isModal() {
505 if ((flags
& MODAL
) == 0) {
512 * Returns true if this window has a close box.
514 * @return true if this window has a close box
516 public final boolean hasCloseBox() {
517 if ((flags
& NOCLOSEBOX
) != 0) {
524 * Retrieve the background color.
526 * @return the background color
528 public final CellAttributes
getBackground() {
530 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
533 return getTheme().getColor("twindow.background.windowmove");
534 } else if (isModal() && inWindowMove
) {
536 return getTheme().getColor("twindow.background.modal");
537 } else if (isModal()) {
539 return getTheme().getColor("twindow.background.modal");
541 return getTheme().getColor("twindow.background.modal.inactive");
542 } else if (isActive()) {
544 return getTheme().getColor("twindow.background");
547 return getTheme().getColor("twindow.background.inactive");
552 * Retrieve the border color.
554 * @return the border color
556 public CellAttributes
getBorder() {
558 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
561 return getTheme().getColor("twindow.border.windowmove");
562 } else if (isModal() && inWindowMove
) {
564 return getTheme().getColor("twindow.border.modal.windowmove");
565 } else if (isModal()) {
567 return getTheme().getColor("twindow.border.modal");
569 return getTheme().getColor("twindow.border.modal.inactive");
571 } else if (isActive()) {
573 return getTheme().getColor("twindow.border");
576 return getTheme().getColor("twindow.border.inactive");
581 * Retrieve the border line type.
583 * @return the border line type
585 private int getBorderType() {
587 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
591 } else if (isModal() && inWindowMove
) {
594 } else if (isModal()) {
600 } else if (isActive()) {
608 * Called by TApplication.drawChildren() to render on screen.
612 // Draw the box and background first.
613 CellAttributes border
= getBorder();
614 CellAttributes background
= getBackground();
615 int borderType
= getBorderType();
617 getScreen().drawBox(0, 0, getWidth(), getHeight(), border
,
618 background
, borderType
, true);
621 int titleLeft
= (getWidth() - title
.length() - 2) / 2;
622 putCharXY(titleLeft
, 0, ' ', border
);
623 putStringXY(titleLeft
+ 1, 0, title
);
624 putCharXY(titleLeft
+ title
.length() + 1, 0, ' ', border
);
628 // Draw the close button
629 if ((flags
& NOCLOSEBOX
) == 0) {
630 putCharXY(2, 0, '[', border
);
631 putCharXY(4, 0, ']', border
);
632 if (mouseOnClose() && mouse
.isMouse1()) {
633 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
635 ?
getTheme().getColor("twindow.border.windowmove")
636 : getTheme().getColor("twindow.border.modal.windowmove"));
638 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
640 ?
getTheme().getColor("twindow.border.windowmove")
641 : getTheme().getColor("twindow.border.modal.windowmove"));
645 // Draw the maximize button
648 putCharXY(getWidth() - 5, 0, '[', border
);
649 putCharXY(getWidth() - 3, 0, ']', border
);
650 if (mouseOnMaximize() && mouse
.isMouse1()) {
651 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
652 getTheme().getColor("twindow.border.windowmove"));
655 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
656 getTheme().getColor("twindow.border.windowmove"));
658 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
659 getTheme().getColor("twindow.border.windowmove"));
663 // Draw the resize corner
664 if ((flags
& RESIZABLE
) != 0) {
665 putCharXY(getWidth() - 2, getHeight() - 1,
666 GraphicsChars
.SINGLE_BAR
,
667 getTheme().getColor("twindow.border.windowmove"));
668 putCharXY(getWidth() - 1, getHeight() - 1,
669 GraphicsChars
.LRCORNER
,
670 getTheme().getColor("twindow.border.windowmove"));
676 // ------------------------------------------------------------------------
677 // Event handlers ---------------------------------------------------------
678 // ------------------------------------------------------------------------
681 * Returns true if the mouse is currently on the close button.
683 * @return true if mouse is currently on the close button
685 protected boolean mouseOnClose() {
686 if ((flags
& NOCLOSEBOX
) != 0) {
690 && (mouse
.getAbsoluteY() == getY())
691 && (mouse
.getAbsoluteX() == getX() + 3)
699 * Returns true if the mouse is currently on the maximize/restore button.
701 * @return true if the mouse is currently on the maximize/restore button
703 protected boolean mouseOnMaximize() {
706 && (mouse
.getAbsoluteY() == getY())
707 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
715 * Returns true if the mouse is currently on the resizable lower right
718 * @return true if the mouse is currently on the resizable lower right
721 protected boolean mouseOnResize() {
722 if (((flags
& RESIZABLE
) != 0)
725 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
726 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
727 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
735 * Subclasses should override this method to cleanup resources. This is
736 * called by application.closeWindow().
738 public void onClose() {
739 // Default: do nothing
743 * Called by application.switchWindow() when this window gets the
744 * focus, and also by application.addWindow().
746 public void onFocus() {
747 // Default: do nothing
751 * Called by application.switchWindow() when another window gets the
754 public void onUnfocus() {
755 // Default: do nothing
759 * Called by application.hideWindow().
761 public void onHide() {
762 // Default: do nothing
766 * Called by application.showWindow().
768 public void onShow() {
769 // Default: do nothing
773 * Handle mouse button presses.
775 * @param mouse mouse button event
778 public void onMouseDown(final TMouseEvent mouse
) {
781 inKeyboardResize
= false;
783 if ((mouse
.getAbsoluteY() == getY())
785 && (getX() <= mouse
.getAbsoluteX())
786 && (mouse
.getAbsoluteX() < getX() + getWidth())
788 && !mouseOnMaximize()
790 // Begin moving window
792 moveWindowMouseX
= mouse
.getAbsoluteX();
793 moveWindowMouseY
= mouse
.getAbsoluteY();
801 if (mouseOnResize()) {
802 // Begin window resize
803 inWindowResize
= true;
804 moveWindowMouseX
= mouse
.getAbsoluteX();
805 moveWindowMouseY
= mouse
.getAbsoluteY();
806 resizeWindowWidth
= getWidth();
807 resizeWindowHeight
= getHeight();
814 // Give the shortcut bar a shot at this.
815 if (statusBar
!= null) {
816 if (statusBar
.statusBarMouseDown(mouse
)) {
821 // I didn't take it, pass it on to my children
822 super.onMouseDown(mouse
);
826 * Handle mouse button releases.
828 * @param mouse mouse button release event
831 public void onMouseUp(final TMouseEvent mouse
) {
834 if ((inWindowMove
) && (mouse
.isMouse1())) {
835 // Stop moving window
836 inWindowMove
= false;
840 if ((inWindowResize
) && (mouse
.isMouse1())) {
841 // Stop resizing window
842 inWindowResize
= false;
846 if (mouse
.isMouse1() && mouseOnClose()) {
848 application
.closeWindow(this);
852 if ((mouse
.getAbsoluteY() == getY())
854 && mouseOnMaximize()) {
862 // Pass a resize event to my children
863 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
864 getWidth(), getHeight()));
868 // Give the shortcut bar a shot at this.
869 if (statusBar
!= null) {
870 if (statusBar
.statusBarMouseUp(mouse
)) {
875 // I didn't take it, pass it on to my children
876 super.onMouseUp(mouse
);
880 * Handle mouse movements.
882 * @param mouse mouse motion event
885 public void onMouseMotion(final TMouseEvent mouse
) {
890 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
891 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
892 // Don't cover up the menu bar
893 if (getY() < application
.getDesktopTop()) {
894 setY(application
.getDesktopTop());
896 // Don't go below the status bar
897 if (getY() >= application
.getDesktopBottom()) {
898 setY(application
.getDesktopBottom() - 1);
903 if (inWindowResize
) {
905 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
906 - moveWindowMouseX
));
907 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
908 - moveWindowMouseY
));
909 if (getX() + getWidth() > getScreen().getWidth()) {
910 setWidth(getScreen().getWidth() - getX());
912 if (getY() + getHeight() > application
.getDesktopBottom()) {
913 setY(application
.getDesktopBottom() - getHeight() + 1);
915 // Don't cover up the menu bar
916 if (getY() < application
.getDesktopTop()) {
917 setY(application
.getDesktopTop());
920 // Keep within min/max bounds
921 if (getWidth() < minimumWindowWidth
) {
922 setWidth(minimumWindowWidth
);
923 inWindowResize
= false;
925 if (getHeight() < minimumWindowHeight
) {
926 setHeight(minimumWindowHeight
);
927 inWindowResize
= false;
929 if ((maximumWindowWidth
> 0)
930 && (getWidth() > maximumWindowWidth
)
932 setWidth(maximumWindowWidth
);
933 inWindowResize
= false;
935 if ((maximumWindowHeight
> 0)
936 && (getHeight() > maximumWindowHeight
)
938 setHeight(maximumWindowHeight
);
939 inWindowResize
= false;
942 // Pass a resize event to my children
943 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
944 getWidth(), getHeight()));
948 // Give the shortcut bar a shot at this.
949 if (statusBar
!= null) {
950 statusBar
.statusBarMouseMotion(mouse
);
953 // I didn't take it, pass it on to my children
954 super.onMouseMotion(mouse
);
960 * @param keypress keystroke event
963 public void onKeypress(final TKeypressEvent keypress
) {
965 if (inKeyboardResize
) {
967 // ESC or ENTER - Exit size/move
968 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
969 inKeyboardResize
= false;
972 if (keypress
.equals(kbLeft
)) {
977 if (keypress
.equals(kbRight
)) {
978 if (getX() < getScreen().getWidth() - 1) {
982 if (keypress
.equals(kbDown
)) {
983 if (getY() < application
.getDesktopBottom() - 1) {
987 if (keypress
.equals(kbUp
)) {
992 if (keypress
.equals(kbShiftLeft
)) {
993 if ((getWidth() > minimumWindowWidth
)
994 || (minimumWindowWidth
<= 0)
996 setWidth(getWidth() - 1);
999 if (keypress
.equals(kbShiftRight
)) {
1000 if ((getWidth() < maximumWindowWidth
)
1001 || (maximumWindowWidth
<= 0)
1003 setWidth(getWidth() + 1);
1006 if (keypress
.equals(kbShiftUp
)) {
1007 if ((getHeight() > minimumWindowHeight
)
1008 || (minimumWindowHeight
<= 0)
1010 setHeight(getHeight() - 1);
1013 if (keypress
.equals(kbShiftDown
)) {
1014 if ((getHeight() < maximumWindowHeight
)
1015 || (maximumWindowHeight
<= 0)
1017 setHeight(getHeight() + 1);
1021 // Pass a resize event to my children
1022 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1023 getWidth(), getHeight()));
1028 // Give the shortcut bar a shot at this.
1029 if (statusBar
!= null) {
1030 if (statusBar
.statusBarKeypress(keypress
)) {
1035 // These keystrokes will typically not be seen unless a subclass
1036 // overrides onMenu() due to how TApplication dispatches
1039 if (!(this instanceof TDesktop
)) {
1041 // Ctrl-W - close window
1042 if (keypress
.equals(kbCtrlW
)) {
1043 if ((flags
& NOCLOSEBOX
) == 0) {
1044 application
.closeWindow(this);
1049 // F6 - behave like Alt-TAB
1050 if (keypress
.equals(kbF6
)) {
1051 application
.switchWindow(true);
1055 // Shift-F6 - behave like Shift-Alt-TAB
1056 if (keypress
.equals(kbShiftF6
)) {
1057 application
.switchWindow(false);
1062 if (keypress
.equals(kbF5
)) {
1070 // Ctrl-F5 - size/move
1071 if (keypress
.equals(kbCtrlF5
)) {
1072 inKeyboardResize
= !inKeyboardResize
;
1075 } // if (!(this instanceof TDesktop))
1077 // I didn't take it, pass it on to my children
1078 super.onKeypress(keypress
);
1082 * Handle posted command events.
1084 * @param command command event
1087 public void onCommand(final TCommandEvent command
) {
1089 // These commands will typically not be seen unless a subclass
1090 // overrides onMenu() due to how TApplication dispatches
1093 if (!(this instanceof TDesktop
)) {
1095 if (command
.equals(cmWindowClose
)) {
1096 if ((flags
& NOCLOSEBOX
) == 0) {
1097 application
.closeWindow(this);
1102 if (command
.equals(cmWindowNext
)) {
1103 application
.switchWindow(true);
1107 if (command
.equals(cmWindowPrevious
)) {
1108 application
.switchWindow(false);
1112 if (command
.equals(cmWindowMove
)) {
1113 inKeyboardResize
= true;
1117 if (command
.equals(cmWindowZoom
)) {
1125 } // if (!(this instanceof TDesktop))
1127 // I didn't take it, pass it on to my children
1128 super.onCommand(command
);
1132 * Handle posted menu events.
1134 * @param menu menu event
1137 public void onMenu(final TMenuEvent menu
) {
1139 if (!(this instanceof TDesktop
)) {
1141 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
1142 if ((flags
& NOCLOSEBOX
) == 0) {
1143 application
.closeWindow(this);
1148 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
1149 application
.switchWindow(true);
1153 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
1154 application
.switchWindow(false);
1158 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
1159 inKeyboardResize
= true;
1163 if (menu
.getId() == TMenu
.MID_WINDOW_ZOOM
) {
1172 } // if (!(this instanceof TDesktop))
1174 // I didn't take it, pass it on to my children
1178 // ------------------------------------------------------------------------
1179 // Passthru for Screen functions ------------------------------------------
1180 // ------------------------------------------------------------------------
1183 * Get the attributes at one location.
1185 * @param x column coordinate. 0 is the left-most column.
1186 * @param y row coordinate. 0 is the top-most row.
1187 * @return attributes at (x, y)
1189 public final CellAttributes
getAttrXY(final int x
, final int y
) {
1190 return getScreen().getAttrXY(x
, y
);
1194 * Set the attributes at one location.
1196 * @param x column coordinate. 0 is the left-most column.
1197 * @param y row coordinate. 0 is the top-most row.
1198 * @param attr attributes to use (bold, foreColor, backColor)
1200 public final void putAttrXY(final int x
, final int y
,
1201 final CellAttributes attr
) {
1203 getScreen().putAttrXY(x
, y
, attr
);
1207 * Set the attributes at one location.
1209 * @param x column coordinate. 0 is the left-most column.
1210 * @param y row coordinate. 0 is the top-most row.
1211 * @param attr attributes to use (bold, foreColor, backColor)
1212 * @param clip if true, honor clipping/offset
1214 public final void putAttrXY(final int x
, final int y
,
1215 final CellAttributes attr
, final boolean clip
) {
1217 getScreen().putAttrXY(x
, y
, attr
, clip
);
1221 * Fill the entire screen with one character with attributes.
1223 * @param ch character to draw
1224 * @param attr attributes to use (bold, foreColor, backColor)
1226 public final void putAll(final char ch
, final CellAttributes attr
) {
1227 getScreen().putAll(ch
, attr
);
1231 * Render one character with attributes.
1233 * @param x column coordinate. 0 is the left-most column.
1234 * @param y row coordinate. 0 is the top-most row.
1235 * @param ch character + attributes to draw
1237 public final void putCharXY(final int x
, final int y
, final Cell ch
) {
1238 getScreen().putCharXY(x
, y
, ch
);
1242 * Render one character with attributes.
1244 * @param x column coordinate. 0 is the left-most column.
1245 * @param y row coordinate. 0 is the top-most row.
1246 * @param ch character to draw
1247 * @param attr attributes to use (bold, foreColor, backColor)
1249 public final void putCharXY(final int x
, final int y
, final char ch
,
1250 final CellAttributes attr
) {
1252 getScreen().putCharXY(x
, y
, ch
, attr
);
1256 * Render one character without changing the underlying attributes.
1258 * @param x column coordinate. 0 is the left-most column.
1259 * @param y row coordinate. 0 is the top-most row.
1260 * @param ch character to draw
1262 public final void putCharXY(final int x
, final int y
, final char ch
) {
1263 getScreen().putCharXY(x
, y
, ch
);
1267 * Render a string. Does not wrap if the string exceeds the line.
1269 * @param x column coordinate. 0 is the left-most column.
1270 * @param y row coordinate. 0 is the top-most row.
1271 * @param str string to draw
1272 * @param attr attributes to use (bold, foreColor, backColor)
1274 public final void putStringXY(final int x
, final int y
, final String str
,
1275 final CellAttributes attr
) {
1277 getScreen().putStringXY(x
, y
, str
, attr
);
1281 * Render a string without changing the underlying attribute. Does not
1282 * wrap if the string exceeds the line.
1284 * @param x column coordinate. 0 is the left-most column.
1285 * @param y row coordinate. 0 is the top-most row.
1286 * @param str string to draw
1288 public final void putStringXY(final int x
, final int y
, final String str
) {
1289 getScreen().putStringXY(x
, y
, str
);
1293 * Draw a vertical line from (x, y) to (x, y + n).
1295 * @param x column coordinate. 0 is the left-most column.
1296 * @param y row coordinate. 0 is the top-most row.
1297 * @param n number of characters to draw
1298 * @param ch character to draw
1299 * @param attr attributes to use (bold, foreColor, backColor)
1301 public final void vLineXY(final int x
, final int y
, final int n
,
1302 final char ch
, final CellAttributes attr
) {
1304 getScreen().vLineXY(x
, y
, n
, ch
, attr
);
1308 * Draw a horizontal line from (x, y) to (x + n, y).
1310 * @param x column coordinate. 0 is the left-most column.
1311 * @param y row coordinate. 0 is the top-most row.
1312 * @param n number of characters to draw
1313 * @param ch character to draw
1314 * @param attr attributes to use (bold, foreColor, backColor)
1316 public final void hLineXY(final int x
, final int y
, final int n
,
1317 final char ch
, final CellAttributes attr
) {
1319 getScreen().hLineXY(x
, y
, n
, ch
, attr
);