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 * See if this window is undergoing any movement/resize/etc.
553 * @return true if the window is moving
555 public boolean inMovements() {
556 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
563 * Stop any pending movement/resize/etc.
565 public void stopMovements() {
566 inWindowResize
= false;
567 inWindowMove
= false;
568 inKeyboardResize
= false;
572 * Returns true if this window is modal.
574 * @return true if this window is modal
576 public final boolean isModal() {
577 if ((flags
& MODAL
) == 0) {
584 * Returns true if this window has a close box.
586 * @return true if this window has a close box
588 public final boolean hasCloseBox() {
589 if ((flags
& NOCLOSEBOX
) != 0) {
596 * Retrieve the background color.
598 * @return the background color
600 public final CellAttributes
getBackground() {
602 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
605 return getTheme().getColor("twindow.background.windowmove");
606 } else if (isModal() && inWindowMove
) {
608 return getTheme().getColor("twindow.background.modal");
609 } else if (isModal()) {
611 return getTheme().getColor("twindow.background.modal");
613 return getTheme().getColor("twindow.background.modal.inactive");
614 } else if (isActive()) {
616 return getTheme().getColor("twindow.background");
619 return getTheme().getColor("twindow.background.inactive");
624 * Retrieve the border color.
626 * @return the border color
628 public CellAttributes
getBorder() {
630 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
633 return getTheme().getColor("twindow.border.windowmove");
634 } else if (isModal() && inWindowMove
) {
636 return getTheme().getColor("twindow.border.modal.windowmove");
637 } else if (isModal()) {
639 return getTheme().getColor("twindow.border.modal");
641 return getTheme().getColor("twindow.border.modal.inactive");
643 } else if (isActive()) {
645 return getTheme().getColor("twindow.border");
648 return getTheme().getColor("twindow.border.inactive");
653 * Retrieve the border line type.
655 * @return the border line type
657 private int getBorderType() {
659 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
663 } else if (isModal() && inWindowMove
) {
666 } else if (isModal()) {
672 } else if (isActive()) {
680 * Called by TApplication.drawChildren() to render on screen.
684 // Draw the box and background first.
685 CellAttributes border
= getBorder();
686 CellAttributes background
= getBackground();
687 int borderType
= getBorderType();
689 getScreen().drawBox(0, 0, getWidth(), getHeight(), border
,
690 background
, borderType
, true);
693 int titleLeft
= (getWidth() - title
.length() - 2) / 2;
694 putCharXY(titleLeft
, 0, ' ', border
);
695 putStringXY(titleLeft
+ 1, 0, title
);
696 putCharXY(titleLeft
+ title
.length() + 1, 0, ' ', border
);
700 // Draw the close button
701 if ((flags
& NOCLOSEBOX
) == 0) {
702 putCharXY(2, 0, '[', border
);
703 putCharXY(4, 0, ']', border
);
704 if (mouseOnClose() && mouse
.isMouse1()) {
705 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
707 ?
getTheme().getColor("twindow.border.windowmove")
708 : getTheme().getColor("twindow.border.modal.windowmove"));
710 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
712 ?
getTheme().getColor("twindow.border.windowmove")
713 : getTheme().getColor("twindow.border.modal.windowmove"));
717 // Draw the maximize button
720 putCharXY(getWidth() - 5, 0, '[', border
);
721 putCharXY(getWidth() - 3, 0, ']', border
);
722 if (mouseOnMaximize() && mouse
.isMouse1()) {
723 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
724 getTheme().getColor("twindow.border.windowmove"));
727 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
728 getTheme().getColor("twindow.border.windowmove"));
730 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
731 getTheme().getColor("twindow.border.windowmove"));
735 // Draw the resize corner
736 if ((flags
& RESIZABLE
) != 0) {
737 putCharXY(getWidth() - 2, getHeight() - 1,
738 GraphicsChars
.SINGLE_BAR
,
739 getTheme().getColor("twindow.border.windowmove"));
740 putCharXY(getWidth() - 1, getHeight() - 1,
741 GraphicsChars
.LRCORNER
,
742 getTheme().getColor("twindow.border.windowmove"));
748 // ------------------------------------------------------------------------
749 // Event handlers ---------------------------------------------------------
750 // ------------------------------------------------------------------------
753 * Returns true if the mouse is currently on the close button.
755 * @return true if mouse is currently on the close button
757 protected boolean mouseOnClose() {
758 if ((flags
& NOCLOSEBOX
) != 0) {
762 && (mouse
.getAbsoluteY() == getY())
763 && (mouse
.getAbsoluteX() == getX() + 3)
771 * Returns true if the mouse is currently on the maximize/restore button.
773 * @return true if the mouse is currently on the maximize/restore button
775 protected boolean mouseOnMaximize() {
778 && (mouse
.getAbsoluteY() == getY())
779 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
787 * Returns true if the mouse is currently on the resizable lower right
790 * @return true if the mouse is currently on the resizable lower right
793 protected boolean mouseOnResize() {
794 if (((flags
& RESIZABLE
) != 0)
797 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
798 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
799 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
807 * Subclasses should override this method to cleanup resources. This is
808 * called by application.closeWindow().
810 public void onClose() {
811 // Default: do nothing
815 * Called by application.switchWindow() when this window gets the
816 * focus, and also by application.addWindow().
818 public void onFocus() {
819 // Default: do nothing
823 * Called by application.switchWindow() when another window gets the
826 public void onUnfocus() {
827 // Default: do nothing
831 * Called by application.hideWindow().
833 public void onHide() {
834 // Default: do nothing
838 * Called by application.showWindow().
840 public void onShow() {
841 // Default: do nothing
845 * Handle mouse button presses.
847 * @param mouse mouse button event
850 public void onMouseDown(final TMouseEvent mouse
) {
853 inKeyboardResize
= false;
855 if ((mouse
.getAbsoluteY() == getY())
857 && (getX() <= mouse
.getAbsoluteX())
858 && (mouse
.getAbsoluteX() < getX() + getWidth())
860 && !mouseOnMaximize()
862 // Begin moving window
864 moveWindowMouseX
= mouse
.getAbsoluteX();
865 moveWindowMouseY
= mouse
.getAbsoluteY();
873 if (mouseOnResize()) {
874 // Begin window resize
875 inWindowResize
= true;
876 moveWindowMouseX
= mouse
.getAbsoluteX();
877 moveWindowMouseY
= mouse
.getAbsoluteY();
878 resizeWindowWidth
= getWidth();
879 resizeWindowHeight
= getHeight();
886 // Give the shortcut bar a shot at this.
887 if (statusBar
!= null) {
888 if (statusBar
.statusBarMouseDown(mouse
)) {
893 // I didn't take it, pass it on to my children
894 super.onMouseDown(mouse
);
898 * Handle mouse button releases.
900 * @param mouse mouse button release event
903 public void onMouseUp(final TMouseEvent mouse
) {
906 if ((inWindowMove
) && (mouse
.isMouse1())) {
907 // Stop moving window
908 inWindowMove
= false;
912 if ((inWindowResize
) && (mouse
.isMouse1())) {
913 // Stop resizing window
914 inWindowResize
= false;
918 if (mouse
.isMouse1() && mouseOnClose()) {
920 application
.closeWindow(this);
924 if ((mouse
.getAbsoluteY() == getY())
926 && mouseOnMaximize()) {
934 // Pass a resize event to my children
935 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
936 getWidth(), getHeight()));
940 // Give the shortcut bar a shot at this.
941 if (statusBar
!= null) {
942 if (statusBar
.statusBarMouseUp(mouse
)) {
947 // I didn't take it, pass it on to my children
948 super.onMouseUp(mouse
);
952 * Handle mouse movements.
954 * @param mouse mouse motion event
957 public void onMouseMotion(final TMouseEvent mouse
) {
962 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
963 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
964 // Don't cover up the menu bar
965 if (getY() < application
.getDesktopTop()) {
966 setY(application
.getDesktopTop());
968 // Don't go below the status bar
969 if (getY() >= application
.getDesktopBottom()) {
970 setY(application
.getDesktopBottom() - 1);
975 if (inWindowResize
) {
976 // Do not permit resizing below the status line
977 if (mouse
.getAbsoluteY() == application
.getDesktopBottom()) {
978 inWindowResize
= false;
983 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
984 - moveWindowMouseX
));
985 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
986 - moveWindowMouseY
));
987 if (getX() + getWidth() > getScreen().getWidth()) {
988 setWidth(getScreen().getWidth() - getX());
990 if (getY() + getHeight() > application
.getDesktopBottom()) {
991 setY(application
.getDesktopBottom() - getHeight() + 1);
993 // Don't cover up the menu bar
994 if (getY() < application
.getDesktopTop()) {
995 setY(application
.getDesktopTop());
998 // Keep within min/max bounds
999 if (getWidth() < minimumWindowWidth
) {
1000 setWidth(minimumWindowWidth
);
1001 inWindowResize
= false;
1003 if (getHeight() < minimumWindowHeight
) {
1004 setHeight(minimumWindowHeight
);
1005 inWindowResize
= false;
1007 if ((maximumWindowWidth
> 0)
1008 && (getWidth() > maximumWindowWidth
)
1010 setWidth(maximumWindowWidth
);
1011 inWindowResize
= false;
1013 if ((maximumWindowHeight
> 0)
1014 && (getHeight() > maximumWindowHeight
)
1016 setHeight(maximumWindowHeight
);
1017 inWindowResize
= false;
1020 // Pass a resize event to my children
1021 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1022 getWidth(), getHeight()));
1026 // Give the shortcut bar a shot at this.
1027 if (statusBar
!= null) {
1028 statusBar
.statusBarMouseMotion(mouse
);
1031 // I didn't take it, pass it on to my children
1032 super.onMouseMotion(mouse
);
1036 * Handle keystrokes.
1038 * @param keypress keystroke event
1041 public void onKeypress(final TKeypressEvent keypress
) {
1043 if (inKeyboardResize
) {
1045 // ESC or ENTER - Exit size/move
1046 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
1047 inKeyboardResize
= false;
1050 if (keypress
.equals(kbLeft
)) {
1055 if (keypress
.equals(kbRight
)) {
1056 if (getX() < getScreen().getWidth() - 1) {
1060 if (keypress
.equals(kbDown
)) {
1061 if (getY() < application
.getDesktopBottom() - 1) {
1065 if (keypress
.equals(kbUp
)) {
1072 * Only permit keyboard resizing if the window was RESIZABLE.
1074 if ((flags
& RESIZABLE
) != 0) {
1076 if (keypress
.equals(kbShiftLeft
)) {
1077 if ((getWidth() > minimumWindowWidth
)
1078 || (minimumWindowWidth
<= 0)
1080 setWidth(getWidth() - 1);
1083 if (keypress
.equals(kbShiftRight
)) {
1084 if ((getWidth() < maximumWindowWidth
)
1085 || (maximumWindowWidth
<= 0)
1087 setWidth(getWidth() + 1);
1090 if (keypress
.equals(kbShiftUp
)) {
1091 if ((getHeight() > minimumWindowHeight
)
1092 || (minimumWindowHeight
<= 0)
1094 setHeight(getHeight() - 1);
1097 if (keypress
.equals(kbShiftDown
)) {
1098 if ((getHeight() < maximumWindowHeight
)
1099 || (maximumWindowHeight
<= 0)
1101 setHeight(getHeight() + 1);
1105 // Pass a resize event to my children
1106 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1107 getWidth(), getHeight()));
1109 } // if ((flags & RESIZABLE) != 0)
1114 // Give the shortcut bar a shot at this.
1115 if (statusBar
!= null) {
1116 if (statusBar
.statusBarKeypress(keypress
)) {
1121 // These keystrokes will typically not be seen unless a subclass
1122 // overrides onMenu() due to how TApplication dispatches
1125 if (!(this instanceof TDesktop
)) {
1127 // Ctrl-W - close window
1128 if (keypress
.equals(kbCtrlW
)) {
1129 if ((flags
& NOCLOSEBOX
) == 0) {
1130 application
.closeWindow(this);
1135 // F6 - behave like Alt-TAB
1136 if (keypress
.equals(kbF6
)) {
1137 application
.switchWindow(true);
1141 // Shift-F6 - behave like Shift-Alt-TAB
1142 if (keypress
.equals(kbShiftF6
)) {
1143 application
.switchWindow(false);
1148 if (keypress
.equals(kbF5
)) {
1156 // Ctrl-F5 - size/move
1157 if (keypress
.equals(kbCtrlF5
)) {
1158 inKeyboardResize
= !inKeyboardResize
;
1161 } // if (!(this instanceof TDesktop))
1163 // I didn't take it, pass it on to my children
1164 super.onKeypress(keypress
);
1168 * Handle posted command events.
1170 * @param command command event
1173 public void onCommand(final TCommandEvent command
) {
1175 // These commands will typically not be seen unless a subclass
1176 // overrides onMenu() due to how TApplication dispatches
1179 if (!(this instanceof TDesktop
)) {
1181 if (command
.equals(cmWindowClose
)) {
1182 if ((flags
& NOCLOSEBOX
) == 0) {
1183 application
.closeWindow(this);
1188 if (command
.equals(cmWindowNext
)) {
1189 application
.switchWindow(true);
1193 if (command
.equals(cmWindowPrevious
)) {
1194 application
.switchWindow(false);
1198 if (command
.equals(cmWindowMove
)) {
1199 inKeyboardResize
= true;
1203 if (command
.equals(cmWindowZoom
)) {
1211 } // if (!(this instanceof TDesktop))
1213 // I didn't take it, pass it on to my children
1214 super.onCommand(command
);
1218 * Handle posted menu events.
1220 * @param menu menu event
1223 public void onMenu(final TMenuEvent menu
) {
1225 if (!(this instanceof TDesktop
)) {
1227 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
1228 if ((flags
& NOCLOSEBOX
) == 0) {
1229 application
.closeWindow(this);
1234 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
1235 application
.switchWindow(true);
1239 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
1240 application
.switchWindow(false);
1244 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
1245 inKeyboardResize
= true;
1249 if (menu
.getId() == TMenu
.MID_WINDOW_ZOOM
) {
1258 } // if (!(this instanceof TDesktop))
1260 // I didn't take it, pass it on to my children
1264 // ------------------------------------------------------------------------
1265 // Passthru for Screen functions ------------------------------------------
1266 // ------------------------------------------------------------------------
1269 * Get the attributes at one location.
1271 * @param x column coordinate. 0 is the left-most column.
1272 * @param y row coordinate. 0 is the top-most row.
1273 * @return attributes at (x, y)
1275 public final CellAttributes
getAttrXY(final int x
, final int y
) {
1276 return getScreen().getAttrXY(x
, y
);
1280 * Set the attributes at one location.
1282 * @param x column coordinate. 0 is the left-most column.
1283 * @param y row coordinate. 0 is the top-most row.
1284 * @param attr attributes to use (bold, foreColor, backColor)
1286 public final void putAttrXY(final int x
, final int y
,
1287 final CellAttributes attr
) {
1289 getScreen().putAttrXY(x
, y
, attr
);
1293 * Set the attributes at one location.
1295 * @param x column coordinate. 0 is the left-most column.
1296 * @param y row coordinate. 0 is the top-most row.
1297 * @param attr attributes to use (bold, foreColor, backColor)
1298 * @param clip if true, honor clipping/offset
1300 public final void putAttrXY(final int x
, final int y
,
1301 final CellAttributes attr
, final boolean clip
) {
1303 getScreen().putAttrXY(x
, y
, attr
, clip
);
1307 * Fill the entire screen with one character with attributes.
1309 * @param ch character to draw
1310 * @param attr attributes to use (bold, foreColor, backColor)
1312 public final void putAll(final char ch
, final CellAttributes attr
) {
1313 getScreen().putAll(ch
, attr
);
1317 * Render one character with attributes.
1319 * @param x column coordinate. 0 is the left-most column.
1320 * @param y row coordinate. 0 is the top-most row.
1321 * @param ch character + attributes to draw
1323 public final void putCharXY(final int x
, final int y
, final Cell ch
) {
1324 getScreen().putCharXY(x
, y
, ch
);
1328 * Render one character with attributes.
1330 * @param x column coordinate. 0 is the left-most column.
1331 * @param y row coordinate. 0 is the top-most row.
1332 * @param ch character to draw
1333 * @param attr attributes to use (bold, foreColor, backColor)
1335 public final void putCharXY(final int x
, final int y
, final char ch
,
1336 final CellAttributes attr
) {
1338 getScreen().putCharXY(x
, y
, ch
, attr
);
1342 * Render one character without changing the underlying attributes.
1344 * @param x column coordinate. 0 is the left-most column.
1345 * @param y row coordinate. 0 is the top-most row.
1346 * @param ch character to draw
1348 public final void putCharXY(final int x
, final int y
, final char ch
) {
1349 getScreen().putCharXY(x
, y
, ch
);
1353 * Render a string. Does not wrap if the string exceeds the line.
1355 * @param x column coordinate. 0 is the left-most column.
1356 * @param y row coordinate. 0 is the top-most row.
1357 * @param str string to draw
1358 * @param attr attributes to use (bold, foreColor, backColor)
1360 public final void putStringXY(final int x
, final int y
, final String str
,
1361 final CellAttributes attr
) {
1363 getScreen().putStringXY(x
, y
, str
, attr
);
1367 * Render a string without changing the underlying attribute. Does not
1368 * wrap if the string exceeds the line.
1370 * @param x column coordinate. 0 is the left-most column.
1371 * @param y row coordinate. 0 is the top-most row.
1372 * @param str string to draw
1374 public final void putStringXY(final int x
, final int y
, final String str
) {
1375 getScreen().putStringXY(x
, y
, str
);
1379 * Draw a vertical line from (x, y) to (x, y + n).
1381 * @param x column coordinate. 0 is the left-most column.
1382 * @param y row coordinate. 0 is the top-most row.
1383 * @param n number of characters to draw
1384 * @param ch character to draw
1385 * @param attr attributes to use (bold, foreColor, backColor)
1387 public final void vLineXY(final int x
, final int y
, final int n
,
1388 final char ch
, final CellAttributes attr
) {
1390 getScreen().vLineXY(x
, y
, n
, ch
, attr
);
1394 * Draw a horizontal line from (x, y) to (x + n, y).
1396 * @param x column coordinate. 0 is the left-most column.
1397 * @param y row coordinate. 0 is the top-most row.
1398 * @param n number of characters to draw
1399 * @param ch character to draw
1400 * @param attr attributes to use (bold, foreColor, backColor)
1402 public final void hLineXY(final int x
, final int y
, final int n
,
1403 final char ch
, final CellAttributes attr
) {
1405 getScreen().hLineXY(x
, y
, n
, ch
, attr
);