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
.backend
.Screen
;
34 import jexer
.bits
.Cell
;
35 import jexer
.bits
.CellAttributes
;
36 import jexer
.bits
.GraphicsChars
;
37 import jexer
.event
.TCommandEvent
;
38 import jexer
.event
.TKeypressEvent
;
39 import jexer
.event
.TMenuEvent
;
40 import jexer
.event
.TMouseEvent
;
41 import jexer
.event
.TResizeEvent
;
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
)) {
994 * Only permit keyboard resizing if the window was RESIZABLE.
996 if ((flags
& RESIZABLE
) != 0) {
998 if (keypress
.equals(kbShiftLeft
)) {
999 if ((getWidth() > minimumWindowWidth
)
1000 || (minimumWindowWidth
<= 0)
1002 setWidth(getWidth() - 1);
1005 if (keypress
.equals(kbShiftRight
)) {
1006 if ((getWidth() < maximumWindowWidth
)
1007 || (maximumWindowWidth
<= 0)
1009 setWidth(getWidth() + 1);
1012 if (keypress
.equals(kbShiftUp
)) {
1013 if ((getHeight() > minimumWindowHeight
)
1014 || (minimumWindowHeight
<= 0)
1016 setHeight(getHeight() - 1);
1019 if (keypress
.equals(kbShiftDown
)) {
1020 if ((getHeight() < maximumWindowHeight
)
1021 || (maximumWindowHeight
<= 0)
1023 setHeight(getHeight() + 1);
1027 // Pass a resize event to my children
1028 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1029 getWidth(), getHeight()));
1031 } // if ((flags & RESIZABLE) != 0)
1036 // Give the shortcut bar a shot at this.
1037 if (statusBar
!= null) {
1038 if (statusBar
.statusBarKeypress(keypress
)) {
1043 // These keystrokes will typically not be seen unless a subclass
1044 // overrides onMenu() due to how TApplication dispatches
1047 if (!(this instanceof TDesktop
)) {
1049 // Ctrl-W - close window
1050 if (keypress
.equals(kbCtrlW
)) {
1051 if ((flags
& NOCLOSEBOX
) == 0) {
1052 application
.closeWindow(this);
1057 // F6 - behave like Alt-TAB
1058 if (keypress
.equals(kbF6
)) {
1059 application
.switchWindow(true);
1063 // Shift-F6 - behave like Shift-Alt-TAB
1064 if (keypress
.equals(kbShiftF6
)) {
1065 application
.switchWindow(false);
1070 if (keypress
.equals(kbF5
)) {
1078 // Ctrl-F5 - size/move
1079 if (keypress
.equals(kbCtrlF5
)) {
1080 inKeyboardResize
= !inKeyboardResize
;
1083 } // if (!(this instanceof TDesktop))
1085 // I didn't take it, pass it on to my children
1086 super.onKeypress(keypress
);
1090 * Handle posted command events.
1092 * @param command command event
1095 public void onCommand(final TCommandEvent command
) {
1097 // These commands will typically not be seen unless a subclass
1098 // overrides onMenu() due to how TApplication dispatches
1101 if (!(this instanceof TDesktop
)) {
1103 if (command
.equals(cmWindowClose
)) {
1104 if ((flags
& NOCLOSEBOX
) == 0) {
1105 application
.closeWindow(this);
1110 if (command
.equals(cmWindowNext
)) {
1111 application
.switchWindow(true);
1115 if (command
.equals(cmWindowPrevious
)) {
1116 application
.switchWindow(false);
1120 if (command
.equals(cmWindowMove
)) {
1121 inKeyboardResize
= true;
1125 if (command
.equals(cmWindowZoom
)) {
1133 } // if (!(this instanceof TDesktop))
1135 // I didn't take it, pass it on to my children
1136 super.onCommand(command
);
1140 * Handle posted menu events.
1142 * @param menu menu event
1145 public void onMenu(final TMenuEvent menu
) {
1147 if (!(this instanceof TDesktop
)) {
1149 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
1150 if ((flags
& NOCLOSEBOX
) == 0) {
1151 application
.closeWindow(this);
1156 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
1157 application
.switchWindow(true);
1161 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
1162 application
.switchWindow(false);
1166 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
1167 inKeyboardResize
= true;
1171 if (menu
.getId() == TMenu
.MID_WINDOW_ZOOM
) {
1180 } // if (!(this instanceof TDesktop))
1182 // I didn't take it, pass it on to my children
1186 // ------------------------------------------------------------------------
1187 // Passthru for Screen functions ------------------------------------------
1188 // ------------------------------------------------------------------------
1191 * Get the attributes at one location.
1193 * @param x column coordinate. 0 is the left-most column.
1194 * @param y row coordinate. 0 is the top-most row.
1195 * @return attributes at (x, y)
1197 public final CellAttributes
getAttrXY(final int x
, final int y
) {
1198 return getScreen().getAttrXY(x
, y
);
1202 * Set the attributes at one location.
1204 * @param x column coordinate. 0 is the left-most column.
1205 * @param y row coordinate. 0 is the top-most row.
1206 * @param attr attributes to use (bold, foreColor, backColor)
1208 public final void putAttrXY(final int x
, final int y
,
1209 final CellAttributes attr
) {
1211 getScreen().putAttrXY(x
, y
, attr
);
1215 * Set the attributes at one location.
1217 * @param x column coordinate. 0 is the left-most column.
1218 * @param y row coordinate. 0 is the top-most row.
1219 * @param attr attributes to use (bold, foreColor, backColor)
1220 * @param clip if true, honor clipping/offset
1222 public final void putAttrXY(final int x
, final int y
,
1223 final CellAttributes attr
, final boolean clip
) {
1225 getScreen().putAttrXY(x
, y
, attr
, clip
);
1229 * Fill the entire screen with one character with attributes.
1231 * @param ch character to draw
1232 * @param attr attributes to use (bold, foreColor, backColor)
1234 public final void putAll(final char ch
, final CellAttributes attr
) {
1235 getScreen().putAll(ch
, attr
);
1239 * Render one character with attributes.
1241 * @param x column coordinate. 0 is the left-most column.
1242 * @param y row coordinate. 0 is the top-most row.
1243 * @param ch character + attributes to draw
1245 public final void putCharXY(final int x
, final int y
, final Cell ch
) {
1246 getScreen().putCharXY(x
, y
, ch
);
1250 * Render one character with attributes.
1252 * @param x column coordinate. 0 is the left-most column.
1253 * @param y row coordinate. 0 is the top-most row.
1254 * @param ch character to draw
1255 * @param attr attributes to use (bold, foreColor, backColor)
1257 public final void putCharXY(final int x
, final int y
, final char ch
,
1258 final CellAttributes attr
) {
1260 getScreen().putCharXY(x
, y
, ch
, attr
);
1264 * Render one character without changing the underlying attributes.
1266 * @param x column coordinate. 0 is the left-most column.
1267 * @param y row coordinate. 0 is the top-most row.
1268 * @param ch character to draw
1270 public final void putCharXY(final int x
, final int y
, final char ch
) {
1271 getScreen().putCharXY(x
, y
, ch
);
1275 * Render a string. Does not wrap if the string exceeds the line.
1277 * @param x column coordinate. 0 is the left-most column.
1278 * @param y row coordinate. 0 is the top-most row.
1279 * @param str string to draw
1280 * @param attr attributes to use (bold, foreColor, backColor)
1282 public final void putStringXY(final int x
, final int y
, final String str
,
1283 final CellAttributes attr
) {
1285 getScreen().putStringXY(x
, y
, str
, attr
);
1289 * Render a string without changing the underlying attribute. Does not
1290 * wrap if the string exceeds the line.
1292 * @param x column coordinate. 0 is the left-most column.
1293 * @param y row coordinate. 0 is the top-most row.
1294 * @param str string to draw
1296 public final void putStringXY(final int x
, final int y
, final String str
) {
1297 getScreen().putStringXY(x
, y
, str
);
1301 * Draw a vertical line from (x, y) to (x, y + n).
1303 * @param x column coordinate. 0 is the left-most column.
1304 * @param y row coordinate. 0 is the top-most row.
1305 * @param n number of characters to draw
1306 * @param ch character to draw
1307 * @param attr attributes to use (bold, foreColor, backColor)
1309 public final void vLineXY(final int x
, final int y
, final int n
,
1310 final char ch
, final CellAttributes attr
) {
1312 getScreen().vLineXY(x
, y
, n
, ch
, attr
);
1316 * Draw a horizontal line from (x, y) to (x + n, y).
1318 * @param x column coordinate. 0 is the left-most column.
1319 * @param y row coordinate. 0 is the top-most row.
1320 * @param n number of characters to draw
1321 * @param ch character to draw
1322 * @param attr attributes to use (bold, foreColor, backColor)
1324 public final void hLineXY(final int x
, final int y
, final int n
,
1325 final char ch
, final CellAttributes attr
) {
1327 getScreen().hLineXY(x
, y
, n
, ch
, attr
);