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 if ((maximumWindowWidth
!= -1)
288 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
290 throw new IllegalArgumentException("Maximum window width cannot " +
291 "be smaller than minimum window width + 1");
293 this.maximumWindowWidth
= maximumWindowWidth
;
297 * Set the minimum width for this window.
299 * @param minimumWindowWidth new minimum width
301 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
302 if ((maximumWindowWidth
!= -1)
303 && (minimumWindowWidth
> maximumWindowWidth
- 1)
305 throw new IllegalArgumentException("Minimum window width cannot " +
306 "be larger than maximum window width - 1");
308 this.minimumWindowWidth
= minimumWindowWidth
;
312 * Set the maximum height for this window.
314 * @param maximumWindowHeight new maximum height
316 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
317 if ((maximumWindowHeight
!= -1)
318 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
320 throw new IllegalArgumentException("Maximum window height cannot " +
321 "be smaller than minimum window height + 1");
323 this.maximumWindowHeight
= maximumWindowHeight
;
327 * Set the minimum height for this window.
329 * @param minimumWindowHeight new minimum height
331 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
332 if ((maximumWindowHeight
!= -1)
333 && (minimumWindowHeight
> maximumWindowHeight
- 1)
335 throw new IllegalArgumentException("Minimum window height cannot " +
336 "be larger than maximum window height - 1");
338 this.minimumWindowHeight
= minimumWindowHeight
;
342 * Recenter the window on-screen.
344 public final void center() {
345 if ((flags
& CENTERED
) != 0) {
346 if (getWidth() < getScreen().getWidth()) {
347 setX((getScreen().getWidth() - getWidth()) / 2);
351 setY(((application
.getDesktopBottom()
352 - application
.getDesktopTop()) - getHeight()) / 2);
356 setY(getY() + application
.getDesktopTop());
363 public void maximize() {
368 restoreWindowWidth
= getWidth();
369 restoreWindowHeight
= getHeight();
370 restoreWindowX
= getX();
371 restoreWindowY
= getY();
372 setWidth(getScreen().getWidth());
373 setHeight(application
.getDesktopBottom() - 1);
380 * Restore (unmaximize) window.
382 public void restore() {
387 setWidth(restoreWindowWidth
);
388 setHeight(restoreWindowHeight
);
389 setX(restoreWindowX
);
390 setY(restoreWindowY
);
394 // ------------------------------------------------------------------------
395 // Window visibility ------------------------------------------------------
396 // ------------------------------------------------------------------------
399 * Hidden flag. A hidden window will still have its onIdle() called, and
400 * will also have onClose() called at application exit. Note package
401 * private access: TApplication will force hidden false if a modal window
404 boolean hidden
= false;
407 * Returns true if this window is hidden.
409 * @return true if this window is hidden, false if the window is shown
411 public final boolean isHidden() {
416 * Returns true if this window is shown.
418 * @return true if this window is shown, false if the window is hidden
420 public final boolean isShown() {
425 * Hide window. A hidden window will still have its onIdle() called, and
426 * will also have onClose() called at application exit. Hidden windows
427 * will not receive any other events.
430 application
.hideWindow(this);
437 application
.showWindow(this);
441 * Activate window (bring to top and receive events).
443 public void activate() {
444 application
.activateWindow(this);
448 * Close window. Note that windows without a close box can still be
449 * closed by calling the close() method.
451 public void close() {
452 application
.closeWindow(this);
455 // ------------------------------------------------------------------------
456 // Constructors -----------------------------------------------------------
457 // ------------------------------------------------------------------------
460 * Public constructor. Window will be located at (0, 0).
462 * @param application TApplication that manages this window
463 * @param title window title, will be centered along the top border
464 * @param width width of window
465 * @param height height of window
467 public TWindow(final TApplication application
, final String title
,
468 final int width
, final int height
) {
470 this(application
, title
, 0, 0, width
, height
, RESIZABLE
);
474 * Public constructor. Window will be located at (0, 0).
476 * @param application TApplication that manages this window
477 * @param title window title, will be centered along the top border
478 * @param width width of window
479 * @param height height of window
480 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
482 public TWindow(final TApplication application
, final String title
,
483 final int width
, final int height
, final int flags
) {
485 this(application
, title
, 0, 0, width
, height
, flags
);
489 * Public constructor.
491 * @param application TApplication that manages this window
492 * @param title window title, will be centered along the top border
493 * @param x column relative to parent
494 * @param y row relative to parent
495 * @param width width of window
496 * @param height height of window
498 public TWindow(final TApplication application
, final String title
,
499 final int x
, final int y
, final int width
, final int height
) {
501 this(application
, title
, x
, y
, width
, height
, RESIZABLE
);
505 * Public constructor.
507 * @param application TApplication that manages this window
508 * @param title window title, will be centered along the top border
509 * @param x column relative to parent
510 * @param y row relative to parent
511 * @param width width of window
512 * @param height height of window
513 * @param flags mask of RESIZABLE, CENTERED, or MODAL
515 public TWindow(final TApplication application
, final String title
,
516 final int x
, final int y
, final int width
, final int height
,
521 // I am my own window and parent
522 setupForTWindow(this, x
, y
+ application
.getDesktopTop(),
527 this.application
= application
;
530 // Minimum width/height are 10 and 2
531 assert (width
>= 10);
532 assert (getHeight() >= 2);
534 // MODAL implies CENTERED
536 this.flags
|= CENTERED
;
539 // Center window if specified
542 // Add me to the application
543 application
.addWindow(this);
546 // ------------------------------------------------------------------------
547 // General behavior -------------------------------------------------------
548 // ------------------------------------------------------------------------
551 * Returns true if this window is modal.
553 * @return true if this window is modal
555 public final boolean isModal() {
556 if ((flags
& MODAL
) == 0) {
563 * Returns true if this window has a close box.
565 * @return true if this window has a close box
567 public final boolean hasCloseBox() {
568 if ((flags
& NOCLOSEBOX
) != 0) {
575 * Retrieve the background color.
577 * @return the background color
579 public final CellAttributes
getBackground() {
581 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
584 return getTheme().getColor("twindow.background.windowmove");
585 } else if (isModal() && inWindowMove
) {
587 return getTheme().getColor("twindow.background.modal");
588 } else if (isModal()) {
590 return getTheme().getColor("twindow.background.modal");
592 return getTheme().getColor("twindow.background.modal.inactive");
593 } else if (isActive()) {
595 return getTheme().getColor("twindow.background");
598 return getTheme().getColor("twindow.background.inactive");
603 * Retrieve the border color.
605 * @return the border color
607 public CellAttributes
getBorder() {
609 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
612 return getTheme().getColor("twindow.border.windowmove");
613 } else if (isModal() && inWindowMove
) {
615 return getTheme().getColor("twindow.border.modal.windowmove");
616 } else if (isModal()) {
618 return getTheme().getColor("twindow.border.modal");
620 return getTheme().getColor("twindow.border.modal.inactive");
622 } else if (isActive()) {
624 return getTheme().getColor("twindow.border");
627 return getTheme().getColor("twindow.border.inactive");
632 * Retrieve the border line type.
634 * @return the border line type
636 private int getBorderType() {
638 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
642 } else if (isModal() && inWindowMove
) {
645 } else if (isModal()) {
651 } else if (isActive()) {
659 * Called by TApplication.drawChildren() to render on screen.
663 // Draw the box and background first.
664 CellAttributes border
= getBorder();
665 CellAttributes background
= getBackground();
666 int borderType
= getBorderType();
668 getScreen().drawBox(0, 0, getWidth(), getHeight(), border
,
669 background
, borderType
, true);
672 int titleLeft
= (getWidth() - title
.length() - 2) / 2;
673 putCharXY(titleLeft
, 0, ' ', border
);
674 putStringXY(titleLeft
+ 1, 0, title
);
675 putCharXY(titleLeft
+ title
.length() + 1, 0, ' ', border
);
679 // Draw the close button
680 if ((flags
& NOCLOSEBOX
) == 0) {
681 putCharXY(2, 0, '[', border
);
682 putCharXY(4, 0, ']', border
);
683 if (mouseOnClose() && mouse
.isMouse1()) {
684 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
686 ?
getTheme().getColor("twindow.border.windowmove")
687 : getTheme().getColor("twindow.border.modal.windowmove"));
689 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
691 ?
getTheme().getColor("twindow.border.windowmove")
692 : getTheme().getColor("twindow.border.modal.windowmove"));
696 // Draw the maximize button
699 putCharXY(getWidth() - 5, 0, '[', border
);
700 putCharXY(getWidth() - 3, 0, ']', border
);
701 if (mouseOnMaximize() && mouse
.isMouse1()) {
702 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
703 getTheme().getColor("twindow.border.windowmove"));
706 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
707 getTheme().getColor("twindow.border.windowmove"));
709 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
710 getTheme().getColor("twindow.border.windowmove"));
714 // Draw the resize corner
715 if ((flags
& RESIZABLE
) != 0) {
716 putCharXY(getWidth() - 2, getHeight() - 1,
717 GraphicsChars
.SINGLE_BAR
,
718 getTheme().getColor("twindow.border.windowmove"));
719 putCharXY(getWidth() - 1, getHeight() - 1,
720 GraphicsChars
.LRCORNER
,
721 getTheme().getColor("twindow.border.windowmove"));
727 // ------------------------------------------------------------------------
728 // Event handlers ---------------------------------------------------------
729 // ------------------------------------------------------------------------
732 * Returns true if the mouse is currently on the close button.
734 * @return true if mouse is currently on the close button
736 protected boolean mouseOnClose() {
737 if ((flags
& NOCLOSEBOX
) != 0) {
741 && (mouse
.getAbsoluteY() == getY())
742 && (mouse
.getAbsoluteX() == getX() + 3)
750 * Returns true if the mouse is currently on the maximize/restore button.
752 * @return true if the mouse is currently on the maximize/restore button
754 protected boolean mouseOnMaximize() {
757 && (mouse
.getAbsoluteY() == getY())
758 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
766 * Returns true if the mouse is currently on the resizable lower right
769 * @return true if the mouse is currently on the resizable lower right
772 protected boolean mouseOnResize() {
773 if (((flags
& RESIZABLE
) != 0)
776 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
777 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
778 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
786 * Subclasses should override this method to cleanup resources. This is
787 * called by application.closeWindow().
789 public void onClose() {
790 // Default: do nothing
794 * Called by application.switchWindow() when this window gets the
795 * focus, and also by application.addWindow().
797 public void onFocus() {
798 // Default: do nothing
802 * Called by application.switchWindow() when another window gets the
805 public void onUnfocus() {
806 // Default: do nothing
810 * Called by application.hideWindow().
812 public void onHide() {
813 // Default: do nothing
817 * Called by application.showWindow().
819 public void onShow() {
820 // Default: do nothing
824 * Handle mouse button presses.
826 * @param mouse mouse button event
829 public void onMouseDown(final TMouseEvent mouse
) {
832 inKeyboardResize
= false;
834 if ((mouse
.getAbsoluteY() == getY())
836 && (getX() <= mouse
.getAbsoluteX())
837 && (mouse
.getAbsoluteX() < getX() + getWidth())
839 && !mouseOnMaximize()
841 // Begin moving window
843 moveWindowMouseX
= mouse
.getAbsoluteX();
844 moveWindowMouseY
= mouse
.getAbsoluteY();
852 if (mouseOnResize()) {
853 // Begin window resize
854 inWindowResize
= true;
855 moveWindowMouseX
= mouse
.getAbsoluteX();
856 moveWindowMouseY
= mouse
.getAbsoluteY();
857 resizeWindowWidth
= getWidth();
858 resizeWindowHeight
= getHeight();
865 // Give the shortcut bar a shot at this.
866 if (statusBar
!= null) {
867 if (statusBar
.statusBarMouseDown(mouse
)) {
872 // I didn't take it, pass it on to my children
873 super.onMouseDown(mouse
);
877 * Handle mouse button releases.
879 * @param mouse mouse button release event
882 public void onMouseUp(final TMouseEvent mouse
) {
885 if ((inWindowMove
) && (mouse
.isMouse1())) {
886 // Stop moving window
887 inWindowMove
= false;
891 if ((inWindowResize
) && (mouse
.isMouse1())) {
892 // Stop resizing window
893 inWindowResize
= false;
897 if (mouse
.isMouse1() && mouseOnClose()) {
899 application
.closeWindow(this);
903 if ((mouse
.getAbsoluteY() == getY())
905 && mouseOnMaximize()) {
913 // Pass a resize event to my children
914 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
915 getWidth(), getHeight()));
919 // Give the shortcut bar a shot at this.
920 if (statusBar
!= null) {
921 if (statusBar
.statusBarMouseUp(mouse
)) {
926 // I didn't take it, pass it on to my children
927 super.onMouseUp(mouse
);
931 * Handle mouse movements.
933 * @param mouse mouse motion event
936 public void onMouseMotion(final TMouseEvent mouse
) {
941 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
942 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
943 // Don't cover up the menu bar
944 if (getY() < application
.getDesktopTop()) {
945 setY(application
.getDesktopTop());
947 // Don't go below the status bar
948 if (getY() >= application
.getDesktopBottom()) {
949 setY(application
.getDesktopBottom() - 1);
954 if (inWindowResize
) {
955 // Do not permit resizing below the status line
956 if (mouse
.getAbsoluteY() == application
.getDesktopBottom()) {
957 inWindowResize
= false;
962 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
963 - moveWindowMouseX
));
964 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
965 - moveWindowMouseY
));
966 if (getX() + getWidth() > getScreen().getWidth()) {
967 setWidth(getScreen().getWidth() - getX());
969 if (getY() + getHeight() > application
.getDesktopBottom()) {
970 setY(application
.getDesktopBottom() - getHeight() + 1);
972 // Don't cover up the menu bar
973 if (getY() < application
.getDesktopTop()) {
974 setY(application
.getDesktopTop());
977 // Keep within min/max bounds
978 if (getWidth() < minimumWindowWidth
) {
979 setWidth(minimumWindowWidth
);
980 inWindowResize
= false;
982 if (getHeight() < minimumWindowHeight
) {
983 setHeight(minimumWindowHeight
);
984 inWindowResize
= false;
986 if ((maximumWindowWidth
> 0)
987 && (getWidth() > maximumWindowWidth
)
989 setWidth(maximumWindowWidth
);
990 inWindowResize
= false;
992 if ((maximumWindowHeight
> 0)
993 && (getHeight() > maximumWindowHeight
)
995 setHeight(maximumWindowHeight
);
996 inWindowResize
= false;
999 // Pass a resize event to my children
1000 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1001 getWidth(), getHeight()));
1005 // Give the shortcut bar a shot at this.
1006 if (statusBar
!= null) {
1007 statusBar
.statusBarMouseMotion(mouse
);
1010 // I didn't take it, pass it on to my children
1011 super.onMouseMotion(mouse
);
1015 * Handle keystrokes.
1017 * @param keypress keystroke event
1020 public void onKeypress(final TKeypressEvent keypress
) {
1022 if (inKeyboardResize
) {
1024 // ESC or ENTER - Exit size/move
1025 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
1026 inKeyboardResize
= false;
1029 if (keypress
.equals(kbLeft
)) {
1034 if (keypress
.equals(kbRight
)) {
1035 if (getX() < getScreen().getWidth() - 1) {
1039 if (keypress
.equals(kbDown
)) {
1040 if (getY() < application
.getDesktopBottom() - 1) {
1044 if (keypress
.equals(kbUp
)) {
1051 * Only permit keyboard resizing if the window was RESIZABLE.
1053 if ((flags
& RESIZABLE
) != 0) {
1055 if (keypress
.equals(kbShiftLeft
)) {
1056 if ((getWidth() > minimumWindowWidth
)
1057 || (minimumWindowWidth
<= 0)
1059 setWidth(getWidth() - 1);
1062 if (keypress
.equals(kbShiftRight
)) {
1063 if ((getWidth() < maximumWindowWidth
)
1064 || (maximumWindowWidth
<= 0)
1066 setWidth(getWidth() + 1);
1069 if (keypress
.equals(kbShiftUp
)) {
1070 if ((getHeight() > minimumWindowHeight
)
1071 || (minimumWindowHeight
<= 0)
1073 setHeight(getHeight() - 1);
1076 if (keypress
.equals(kbShiftDown
)) {
1077 if ((getHeight() < maximumWindowHeight
)
1078 || (maximumWindowHeight
<= 0)
1080 setHeight(getHeight() + 1);
1084 // Pass a resize event to my children
1085 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1086 getWidth(), getHeight()));
1088 } // if ((flags & RESIZABLE) != 0)
1093 // Give the shortcut bar a shot at this.
1094 if (statusBar
!= null) {
1095 if (statusBar
.statusBarKeypress(keypress
)) {
1100 // These keystrokes will typically not be seen unless a subclass
1101 // overrides onMenu() due to how TApplication dispatches
1104 if (!(this instanceof TDesktop
)) {
1106 // Ctrl-W - close window
1107 if (keypress
.equals(kbCtrlW
)) {
1108 if ((flags
& NOCLOSEBOX
) == 0) {
1109 application
.closeWindow(this);
1114 // F6 - behave like Alt-TAB
1115 if (keypress
.equals(kbF6
)) {
1116 application
.switchWindow(true);
1120 // Shift-F6 - behave like Shift-Alt-TAB
1121 if (keypress
.equals(kbShiftF6
)) {
1122 application
.switchWindow(false);
1127 if (keypress
.equals(kbF5
)) {
1135 // Ctrl-F5 - size/move
1136 if (keypress
.equals(kbCtrlF5
)) {
1137 inKeyboardResize
= !inKeyboardResize
;
1140 } // if (!(this instanceof TDesktop))
1142 // I didn't take it, pass it on to my children
1143 super.onKeypress(keypress
);
1147 * Handle posted command events.
1149 * @param command command event
1152 public void onCommand(final TCommandEvent command
) {
1154 // These commands will typically not be seen unless a subclass
1155 // overrides onMenu() due to how TApplication dispatches
1158 if (!(this instanceof TDesktop
)) {
1160 if (command
.equals(cmWindowClose
)) {
1161 if ((flags
& NOCLOSEBOX
) == 0) {
1162 application
.closeWindow(this);
1167 if (command
.equals(cmWindowNext
)) {
1168 application
.switchWindow(true);
1172 if (command
.equals(cmWindowPrevious
)) {
1173 application
.switchWindow(false);
1177 if (command
.equals(cmWindowMove
)) {
1178 inKeyboardResize
= true;
1182 if (command
.equals(cmWindowZoom
)) {
1190 } // if (!(this instanceof TDesktop))
1192 // I didn't take it, pass it on to my children
1193 super.onCommand(command
);
1197 * Handle posted menu events.
1199 * @param menu menu event
1202 public void onMenu(final TMenuEvent menu
) {
1204 if (!(this instanceof TDesktop
)) {
1206 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
1207 if ((flags
& NOCLOSEBOX
) == 0) {
1208 application
.closeWindow(this);
1213 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
1214 application
.switchWindow(true);
1218 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
1219 application
.switchWindow(false);
1223 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
1224 inKeyboardResize
= true;
1228 if (menu
.getId() == TMenu
.MID_WINDOW_ZOOM
) {
1237 } // if (!(this instanceof TDesktop))
1239 // I didn't take it, pass it on to my children
1243 // ------------------------------------------------------------------------
1244 // Passthru for Screen functions ------------------------------------------
1245 // ------------------------------------------------------------------------
1248 * Get the attributes at one location.
1250 * @param x column coordinate. 0 is the left-most column.
1251 * @param y row coordinate. 0 is the top-most row.
1252 * @return attributes at (x, y)
1254 public final CellAttributes
getAttrXY(final int x
, final int y
) {
1255 return getScreen().getAttrXY(x
, y
);
1259 * Set the attributes at one location.
1261 * @param x column coordinate. 0 is the left-most column.
1262 * @param y row coordinate. 0 is the top-most row.
1263 * @param attr attributes to use (bold, foreColor, backColor)
1265 public final void putAttrXY(final int x
, final int y
,
1266 final CellAttributes attr
) {
1268 getScreen().putAttrXY(x
, y
, attr
);
1272 * Set the attributes at one location.
1274 * @param x column coordinate. 0 is the left-most column.
1275 * @param y row coordinate. 0 is the top-most row.
1276 * @param attr attributes to use (bold, foreColor, backColor)
1277 * @param clip if true, honor clipping/offset
1279 public final void putAttrXY(final int x
, final int y
,
1280 final CellAttributes attr
, final boolean clip
) {
1282 getScreen().putAttrXY(x
, y
, attr
, clip
);
1286 * Fill the entire screen with one character with attributes.
1288 * @param ch character to draw
1289 * @param attr attributes to use (bold, foreColor, backColor)
1291 public final void putAll(final char ch
, final CellAttributes attr
) {
1292 getScreen().putAll(ch
, attr
);
1296 * Render one character with attributes.
1298 * @param x column coordinate. 0 is the left-most column.
1299 * @param y row coordinate. 0 is the top-most row.
1300 * @param ch character + attributes to draw
1302 public final void putCharXY(final int x
, final int y
, final Cell ch
) {
1303 getScreen().putCharXY(x
, y
, ch
);
1307 * Render one character with attributes.
1309 * @param x column coordinate. 0 is the left-most column.
1310 * @param y row coordinate. 0 is the top-most row.
1311 * @param ch character to draw
1312 * @param attr attributes to use (bold, foreColor, backColor)
1314 public final void putCharXY(final int x
, final int y
, final char ch
,
1315 final CellAttributes attr
) {
1317 getScreen().putCharXY(x
, y
, ch
, attr
);
1321 * Render one character without changing the underlying attributes.
1323 * @param x column coordinate. 0 is the left-most column.
1324 * @param y row coordinate. 0 is the top-most row.
1325 * @param ch character to draw
1327 public final void putCharXY(final int x
, final int y
, final char ch
) {
1328 getScreen().putCharXY(x
, y
, ch
);
1332 * Render a string. Does not wrap if the string exceeds the line.
1334 * @param x column coordinate. 0 is the left-most column.
1335 * @param y row coordinate. 0 is the top-most row.
1336 * @param str string to draw
1337 * @param attr attributes to use (bold, foreColor, backColor)
1339 public final void putStringXY(final int x
, final int y
, final String str
,
1340 final CellAttributes attr
) {
1342 getScreen().putStringXY(x
, y
, str
, attr
);
1346 * Render a string without changing the underlying attribute. Does not
1347 * wrap if the string exceeds the line.
1349 * @param x column coordinate. 0 is the left-most column.
1350 * @param y row coordinate. 0 is the top-most row.
1351 * @param str string to draw
1353 public final void putStringXY(final int x
, final int y
, final String str
) {
1354 getScreen().putStringXY(x
, y
, str
);
1358 * Draw a vertical line from (x, y) to (x, y + n).
1360 * @param x column coordinate. 0 is the left-most column.
1361 * @param y row coordinate. 0 is the top-most row.
1362 * @param n number of characters to draw
1363 * @param ch character to draw
1364 * @param attr attributes to use (bold, foreColor, backColor)
1366 public final void vLineXY(final int x
, final int y
, final int n
,
1367 final char ch
, final CellAttributes attr
) {
1369 getScreen().vLineXY(x
, y
, n
, ch
, attr
);
1373 * Draw a horizontal line from (x, y) to (x + n, y).
1375 * @param x column coordinate. 0 is the left-most column.
1376 * @param y row coordinate. 0 is the top-most row.
1377 * @param n number of characters to draw
1378 * @param ch character to draw
1379 * @param attr attributes to use (bold, foreColor, backColor)
1381 public final void hLineXY(final int x
, final int y
, final int n
,
1382 final char ch
, final CellAttributes attr
) {
1384 getScreen().hLineXY(x
, y
, n
, ch
, attr
);