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;
77 * Window has no maximize box (default no).
79 public static final int NOZOOMBOX
= 0x10;
81 // ------------------------------------------------------------------------
82 // Common window attributes -----------------------------------------------
83 // ------------------------------------------------------------------------
86 * Window flags. Note package private access.
88 int flags
= RESIZABLE
;
93 private String title
= "";
98 * @return window title
100 public final String
getTitle() {
107 * @param title new window title
109 public final void setTitle(final String title
) {
113 // ------------------------------------------------------------------------
114 // TApplication integration -----------------------------------------------
115 // ------------------------------------------------------------------------
118 * Window's parent TApplication.
120 private TApplication application
;
123 * Get this TWindow's parent TApplication.
125 * @return this TWindow's parent TApplication
128 public final TApplication
getApplication() {
138 public final Screen
getScreen() {
139 return application
.getScreen();
143 * Z order. Lower number means more in-front.
148 * Get Z order. Lower number means more in-front.
150 * @return Z value. Lower number means more in-front.
152 public final int getZ() {
157 * Set Z order. Lower number means more in-front.
159 * @param z the new Z value. Lower number means more in-front.
161 public final void setZ(final int z
) {
166 * Window's keyboard shortcuts. Any key in this set will be passed to
167 * the window directly rather than processed through the menu
170 private HashSet
<TKeypress
> keyboardShortcuts
= new HashSet
<TKeypress
>();
173 * Add a keypress to be overridden for this window.
175 * @param key the key to start taking control of
177 protected void addShortcutKeypress(final TKeypress key
) {
178 keyboardShortcuts
.add(key
);
182 * Remove a keypress to be overridden for this window.
184 * @param key the key to stop taking control of
186 protected void removeShortcutKeypress(final TKeypress key
) {
187 keyboardShortcuts
.remove(key
);
191 * Remove all keypresses to be overridden for this window.
193 protected void clearShortcutKeypresses() {
194 keyboardShortcuts
.clear();
198 * Determine if a keypress is overridden for this window.
200 * @param key the key to check
201 * @return true if this window wants to process this key on its own
203 public boolean isShortcutKeypress(final TKeypress key
) {
204 return keyboardShortcuts
.contains(key
);
208 * A window may have a status bar associated with it. TApplication will
209 * draw this status bar last, and will also route events to it first
212 protected TStatusBar statusBar
= null;
215 * Get the window's status bar, or null if it does not have one.
217 * @return the status bar, or null
219 public TStatusBar
getStatusBar() {
224 * Set the window's status bar to a new one.
226 * @param text the status bar text
227 * @return the status bar
229 public TStatusBar
newStatusBar(final String text
) {
230 statusBar
= new TStatusBar(this, text
);
234 // ------------------------------------------------------------------------
235 // Window movement/resizing support ---------------------------------------
236 // ------------------------------------------------------------------------
239 * If true, then the user clicked on the title bar and is moving the
242 protected boolean inWindowMove
= false;
245 * If true, then the user clicked on the bottom right corner and is
246 * resizing the window.
248 protected boolean inWindowResize
= false;
251 * If true, then the user selected "Size/Move" (or hit Ctrl-F5) and is
252 * resizing/moving the window via the keyboard.
254 private boolean inKeyboardResize
= false;
257 * If true, this window is maximized.
259 private boolean maximized
= false;
262 * Remember mouse state.
264 protected TMouseEvent mouse
;
266 // For moving the window. resizing also uses moveWindowMouseX/Y
267 private int moveWindowMouseX
;
268 private int moveWindowMouseY
;
269 private int oldWindowX
;
270 private int oldWindowY
;
273 private int resizeWindowWidth
;
274 private int resizeWindowHeight
;
275 private int minimumWindowWidth
= 10;
276 private int minimumWindowHeight
= 2;
277 private int maximumWindowWidth
= -1;
278 private int maximumWindowHeight
= -1;
280 // For maximize/restore
281 private int restoreWindowWidth
;
282 private int restoreWindowHeight
;
283 private int restoreWindowX
;
284 private int restoreWindowY
;
287 * Set the maximum width for this window.
289 * @param maximumWindowWidth new maximum width
291 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
292 if ((maximumWindowWidth
!= -1)
293 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
295 throw new IllegalArgumentException("Maximum window width cannot " +
296 "be smaller than minimum window width + 1");
298 this.maximumWindowWidth
= maximumWindowWidth
;
302 * Set the minimum width for this window.
304 * @param minimumWindowWidth new minimum width
306 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
307 if ((maximumWindowWidth
!= -1)
308 && (minimumWindowWidth
> maximumWindowWidth
- 1)
310 throw new IllegalArgumentException("Minimum window width cannot " +
311 "be larger than maximum window width - 1");
313 this.minimumWindowWidth
= minimumWindowWidth
;
317 * Set the maximum height for this window.
319 * @param maximumWindowHeight new maximum height
321 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
322 if ((maximumWindowHeight
!= -1)
323 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
325 throw new IllegalArgumentException("Maximum window height cannot " +
326 "be smaller than minimum window height + 1");
328 this.maximumWindowHeight
= maximumWindowHeight
;
332 * Set the minimum height for this window.
334 * @param minimumWindowHeight new minimum height
336 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
337 if ((maximumWindowHeight
!= -1)
338 && (minimumWindowHeight
> maximumWindowHeight
- 1)
340 throw new IllegalArgumentException("Minimum window height cannot " +
341 "be larger than maximum window height - 1");
343 this.minimumWindowHeight
= minimumWindowHeight
;
347 * Recenter the window on-screen.
349 public final void center() {
350 if ((flags
& CENTERED
) != 0) {
351 if (getWidth() < getScreen().getWidth()) {
352 setX((getScreen().getWidth() - getWidth()) / 2);
356 setY(((application
.getDesktopBottom()
357 - application
.getDesktopTop()) - getHeight()) / 2);
361 setY(getY() + application
.getDesktopTop());
368 public void maximize() {
373 restoreWindowWidth
= getWidth();
374 restoreWindowHeight
= getHeight();
375 restoreWindowX
= getX();
376 restoreWindowY
= getY();
377 setWidth(getScreen().getWidth());
378 setHeight(application
.getDesktopBottom() - 1);
385 * Restore (unmaximize) window.
387 public void restore() {
392 setWidth(restoreWindowWidth
);
393 setHeight(restoreWindowHeight
);
394 setX(restoreWindowX
);
395 setY(restoreWindowY
);
399 // ------------------------------------------------------------------------
400 // Window visibility ------------------------------------------------------
401 // ------------------------------------------------------------------------
404 * Hidden flag. A hidden window will still have its onIdle() called, and
405 * will also have onClose() called at application exit. Note package
406 * private access: TApplication will force hidden false if a modal window
409 boolean hidden
= false;
412 * Returns true if this window is hidden.
414 * @return true if this window is hidden, false if the window is shown
416 public final boolean isHidden() {
421 * Returns true if this window is shown.
423 * @return true if this window is shown, false if the window is hidden
425 public final boolean isShown() {
430 * Hide window. A hidden window will still have its onIdle() called, and
431 * will also have onClose() called at application exit. Hidden windows
432 * will not receive any other events.
435 application
.hideWindow(this);
442 application
.showWindow(this);
446 * Activate window (bring to top and receive events).
448 public void activate() {
449 application
.activateWindow(this);
453 * Close window. Note that windows without a close box can still be
454 * closed by calling the close() method.
456 public void close() {
457 application
.closeWindow(this);
460 // ------------------------------------------------------------------------
461 // Constructors -----------------------------------------------------------
462 // ------------------------------------------------------------------------
465 * Public constructor. Window will be located at (0, 0).
467 * @param application TApplication that manages this window
468 * @param title window title, will be centered along the top border
469 * @param width width of window
470 * @param height height of window
472 public TWindow(final TApplication application
, final String title
,
473 final int width
, final int height
) {
475 this(application
, title
, 0, 0, width
, height
, RESIZABLE
);
479 * Public constructor. Window will be located at (0, 0).
481 * @param application TApplication that manages this window
482 * @param title window title, will be centered along the top border
483 * @param width width of window
484 * @param height height of window
485 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
487 public TWindow(final TApplication application
, final String title
,
488 final int width
, final int height
, final int flags
) {
490 this(application
, title
, 0, 0, width
, height
, flags
);
494 * Public constructor.
496 * @param application TApplication that manages this window
497 * @param title window title, will be centered along the top border
498 * @param x column relative to parent
499 * @param y row relative to parent
500 * @param width width of window
501 * @param height height of window
503 public TWindow(final TApplication application
, final String title
,
504 final int x
, final int y
, final int width
, final int height
) {
506 this(application
, title
, x
, y
, width
, height
, RESIZABLE
);
510 * Public constructor.
512 * @param application TApplication that manages this window
513 * @param title window title, will be centered along the top border
514 * @param x column relative to parent
515 * @param y row relative to parent
516 * @param width width of window
517 * @param height height of window
518 * @param flags mask of RESIZABLE, CENTERED, or MODAL
520 public TWindow(final TApplication application
, final String title
,
521 final int x
, final int y
, final int width
, final int height
,
526 // I am my own window and parent
527 setupForTWindow(this, x
, y
+ application
.getDesktopTop(),
532 this.application
= application
;
535 // Minimum width/height are 10 and 2
536 assert (width
>= 10);
537 assert (getHeight() >= 2);
539 // MODAL implies CENTERED
541 this.flags
|= CENTERED
;
544 // Center window if specified
547 // Add me to the application
548 application
.addWindow(this);
551 // ------------------------------------------------------------------------
552 // General behavior -------------------------------------------------------
553 // ------------------------------------------------------------------------
556 * See if this window is undergoing any movement/resize/etc.
558 * @return true if the window is moving
560 public boolean inMovements() {
561 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
568 * Stop any pending movement/resize/etc.
570 public void stopMovements() {
571 inWindowResize
= false;
572 inWindowMove
= false;
573 inKeyboardResize
= false;
577 * Returns true if this window is modal.
579 * @return true if this window is modal
581 public final boolean isModal() {
582 if ((flags
& MODAL
) == 0) {
589 * Returns true if this window has a close box.
591 * @return true if this window has a close box
593 public final boolean hasCloseBox() {
594 if ((flags
& NOCLOSEBOX
) != 0) {
601 * Returns true if this window has a maximize/zoom box.
603 * @return true if this window has a maximize/zoom box
605 public final boolean hasZoomBox() {
606 if ((flags
& NOZOOMBOX
) != 0) {
613 * Retrieve the background color.
615 * @return the background color
617 public CellAttributes
getBackground() {
619 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
622 return getTheme().getColor("twindow.background.windowmove");
623 } else if (isModal() && inWindowMove
) {
625 return getTheme().getColor("twindow.background.modal");
626 } else if (isModal()) {
628 return getTheme().getColor("twindow.background.modal");
630 return getTheme().getColor("twindow.background.modal.inactive");
631 } else if (isActive()) {
633 return getTheme().getColor("twindow.background");
636 return getTheme().getColor("twindow.background.inactive");
641 * Retrieve the border color.
643 * @return the border color
645 public CellAttributes
getBorder() {
647 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
650 return getTheme().getColor("twindow.border.windowmove");
651 } else if (isModal() && inWindowMove
) {
653 return getTheme().getColor("twindow.border.modal.windowmove");
654 } else if (isModal()) {
656 return getTheme().getColor("twindow.border.modal");
658 return getTheme().getColor("twindow.border.modal.inactive");
660 } else if (isActive()) {
662 return getTheme().getColor("twindow.border");
665 return getTheme().getColor("twindow.border.inactive");
670 * Retrieve the border line type.
672 * @return the border line type
674 private int getBorderType() {
676 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
680 } else if (isModal() && inWindowMove
) {
683 } else if (isModal()) {
689 } else if (isActive()) {
697 * Called by TApplication.drawChildren() to render on screen.
701 // Draw the box and background first.
702 CellAttributes border
= getBorder();
703 CellAttributes background
= getBackground();
704 int borderType
= getBorderType();
706 getScreen().drawBox(0, 0, getWidth(), getHeight(), border
,
707 background
, borderType
, true);
710 int titleLeft
= (getWidth() - title
.length() - 2) / 2;
711 putCharXY(titleLeft
, 0, ' ', border
);
712 putStringXY(titleLeft
+ 1, 0, title
);
713 putCharXY(titleLeft
+ title
.length() + 1, 0, ' ', border
);
717 // Draw the close button
718 if ((flags
& NOCLOSEBOX
) == 0) {
719 putCharXY(2, 0, '[', border
);
720 putCharXY(4, 0, ']', border
);
721 if (mouseOnClose() && mouse
.isMouse1()) {
722 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
724 ?
getTheme().getColor("twindow.border.windowmove")
725 : getTheme().getColor("twindow.border.modal.windowmove"));
727 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
729 ?
getTheme().getColor("twindow.border.windowmove")
730 : getTheme().getColor("twindow.border.modal.windowmove"));
734 // Draw the maximize button
735 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
737 putCharXY(getWidth() - 5, 0, '[', border
);
738 putCharXY(getWidth() - 3, 0, ']', border
);
739 if (mouseOnMaximize() && mouse
.isMouse1()) {
740 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
741 getTheme().getColor("twindow.border.windowmove"));
744 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
745 getTheme().getColor("twindow.border.windowmove"));
747 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
748 getTheme().getColor("twindow.border.windowmove"));
752 // Draw the resize corner
753 if ((flags
& RESIZABLE
) != 0) {
754 putCharXY(getWidth() - 2, getHeight() - 1,
755 GraphicsChars
.SINGLE_BAR
,
756 getTheme().getColor("twindow.border.windowmove"));
757 putCharXY(getWidth() - 1, getHeight() - 1,
758 GraphicsChars
.LRCORNER
,
759 getTheme().getColor("twindow.border.windowmove"));
765 // ------------------------------------------------------------------------
766 // Event handlers ---------------------------------------------------------
767 // ------------------------------------------------------------------------
770 * Returns true if the mouse is currently on the close button.
772 * @return true if mouse is currently on the close button
774 protected boolean mouseOnClose() {
775 if ((flags
& NOCLOSEBOX
) != 0) {
779 && (mouse
.getAbsoluteY() == getY())
780 && (mouse
.getAbsoluteX() == getX() + 3)
788 * Returns true if the mouse is currently on the maximize/restore button.
790 * @return true if the mouse is currently on the maximize/restore button
792 protected boolean mouseOnMaximize() {
793 if ((flags
& NOZOOMBOX
) != 0) {
798 && (mouse
.getAbsoluteY() == getY())
799 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
807 * Returns true if the mouse is currently on the resizable lower right
810 * @return true if the mouse is currently on the resizable lower right
813 protected boolean mouseOnResize() {
814 if (((flags
& RESIZABLE
) != 0)
817 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
818 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
819 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
827 * Subclasses should override this method to cleanup resources. This is
828 * called by application.closeWindow().
830 public void onClose() {
831 // Default: do nothing
835 * Called by application.switchWindow() when this window gets the
836 * focus, and also by application.addWindow().
838 public void onFocus() {
839 // Default: do nothing
843 * Called by application.switchWindow() when another window gets the
846 public void onUnfocus() {
847 // Default: do nothing
851 * Called by application.hideWindow().
853 public void onHide() {
854 // Default: do nothing
858 * Called by application.showWindow().
860 public void onShow() {
861 // Default: do nothing
865 * Handle mouse button presses.
867 * @param mouse mouse button event
870 public void onMouseDown(final TMouseEvent mouse
) {
873 inKeyboardResize
= false;
875 if ((mouse
.getAbsoluteY() == getY())
877 && (getX() <= mouse
.getAbsoluteX())
878 && (mouse
.getAbsoluteX() < getX() + getWidth())
880 && !mouseOnMaximize()
882 // Begin moving window
884 moveWindowMouseX
= mouse
.getAbsoluteX();
885 moveWindowMouseY
= mouse
.getAbsoluteY();
893 if (mouseOnResize()) {
894 // Begin window resize
895 inWindowResize
= true;
896 moveWindowMouseX
= mouse
.getAbsoluteX();
897 moveWindowMouseY
= mouse
.getAbsoluteY();
898 resizeWindowWidth
= getWidth();
899 resizeWindowHeight
= getHeight();
906 // Give the shortcut bar a shot at this.
907 if (statusBar
!= null) {
908 if (statusBar
.statusBarMouseDown(mouse
)) {
913 // I didn't take it, pass it on to my children
914 super.onMouseDown(mouse
);
918 * Handle mouse button releases.
920 * @param mouse mouse button release event
923 public void onMouseUp(final TMouseEvent mouse
) {
926 if ((inWindowMove
) && (mouse
.isMouse1())) {
927 // Stop moving window
928 inWindowMove
= false;
932 if ((inWindowResize
) && (mouse
.isMouse1())) {
933 // Stop resizing window
934 inWindowResize
= false;
938 if (mouse
.isMouse1() && mouseOnClose()) {
940 application
.closeWindow(this);
944 if ((mouse
.getAbsoluteY() == getY())
946 && mouseOnMaximize()) {
954 // Pass a resize event to my children
955 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
956 getWidth(), getHeight()));
960 // Give the shortcut bar a shot at this.
961 if (statusBar
!= null) {
962 if (statusBar
.statusBarMouseUp(mouse
)) {
967 // I didn't take it, pass it on to my children
968 super.onMouseUp(mouse
);
972 * Handle mouse movements.
974 * @param mouse mouse motion event
977 public void onMouseMotion(final TMouseEvent mouse
) {
982 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
983 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
984 // Don't cover up the menu bar
985 if (getY() < application
.getDesktopTop()) {
986 setY(application
.getDesktopTop());
988 // Don't go below the status bar
989 if (getY() >= application
.getDesktopBottom()) {
990 setY(application
.getDesktopBottom() - 1);
995 if (inWindowResize
) {
996 // Do not permit resizing below the status line
997 if (mouse
.getAbsoluteY() == application
.getDesktopBottom()) {
998 inWindowResize
= false;
1003 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
1004 - moveWindowMouseX
));
1005 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
1006 - moveWindowMouseY
));
1007 if (getX() + getWidth() > getScreen().getWidth()) {
1008 setWidth(getScreen().getWidth() - getX());
1010 if (getY() + getHeight() > application
.getDesktopBottom()) {
1011 setY(application
.getDesktopBottom() - getHeight() + 1);
1013 // Don't cover up the menu bar
1014 if (getY() < application
.getDesktopTop()) {
1015 setY(application
.getDesktopTop());
1018 // Keep within min/max bounds
1019 if (getWidth() < minimumWindowWidth
) {
1020 setWidth(minimumWindowWidth
);
1021 inWindowResize
= false;
1023 if (getHeight() < minimumWindowHeight
) {
1024 setHeight(minimumWindowHeight
);
1025 inWindowResize
= false;
1027 if ((maximumWindowWidth
> 0)
1028 && (getWidth() > maximumWindowWidth
)
1030 setWidth(maximumWindowWidth
);
1031 inWindowResize
= false;
1033 if ((maximumWindowHeight
> 0)
1034 && (getHeight() > maximumWindowHeight
)
1036 setHeight(maximumWindowHeight
);
1037 inWindowResize
= false;
1040 // Pass a resize event to my children
1041 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1042 getWidth(), getHeight()));
1046 // Give the shortcut bar a shot at this.
1047 if (statusBar
!= null) {
1048 statusBar
.statusBarMouseMotion(mouse
);
1051 // I didn't take it, pass it on to my children
1052 super.onMouseMotion(mouse
);
1056 * Handle keystrokes.
1058 * @param keypress keystroke event
1061 public void onKeypress(final TKeypressEvent keypress
) {
1063 if (inKeyboardResize
) {
1065 // ESC or ENTER - Exit size/move
1066 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
1067 inKeyboardResize
= false;
1070 if (keypress
.equals(kbLeft
)) {
1075 if (keypress
.equals(kbRight
)) {
1076 if (getX() < getScreen().getWidth() - 1) {
1080 if (keypress
.equals(kbDown
)) {
1081 if (getY() < application
.getDesktopBottom() - 1) {
1085 if (keypress
.equals(kbUp
)) {
1092 * Only permit keyboard resizing if the window was RESIZABLE.
1094 if ((flags
& RESIZABLE
) != 0) {
1096 if (keypress
.equals(kbShiftLeft
)) {
1097 if ((getWidth() > minimumWindowWidth
)
1098 || (minimumWindowWidth
<= 0)
1100 setWidth(getWidth() - 1);
1103 if (keypress
.equals(kbShiftRight
)) {
1104 if ((getWidth() < maximumWindowWidth
)
1105 || (maximumWindowWidth
<= 0)
1107 setWidth(getWidth() + 1);
1110 if (keypress
.equals(kbShiftUp
)) {
1111 if ((getHeight() > minimumWindowHeight
)
1112 || (minimumWindowHeight
<= 0)
1114 setHeight(getHeight() - 1);
1117 if (keypress
.equals(kbShiftDown
)) {
1118 if ((getHeight() < maximumWindowHeight
)
1119 || (maximumWindowHeight
<= 0)
1121 setHeight(getHeight() + 1);
1125 // Pass a resize event to my children
1126 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1127 getWidth(), getHeight()));
1129 } // if ((flags & RESIZABLE) != 0)
1134 // Give the shortcut bar a shot at this.
1135 if (statusBar
!= null) {
1136 if (statusBar
.statusBarKeypress(keypress
)) {
1141 // These keystrokes will typically not be seen unless a subclass
1142 // overrides onMenu() due to how TApplication dispatches
1145 if (!(this instanceof TDesktop
)) {
1147 // Ctrl-W - close window
1148 if (keypress
.equals(kbCtrlW
)) {
1149 if ((flags
& NOCLOSEBOX
) == 0) {
1150 application
.closeWindow(this);
1155 // F6 - behave like Alt-TAB
1156 if (keypress
.equals(kbF6
)) {
1157 application
.switchWindow(true);
1161 // Shift-F6 - behave like Shift-Alt-TAB
1162 if (keypress
.equals(kbShiftF6
)) {
1163 application
.switchWindow(false);
1168 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
1176 // Ctrl-F5 - size/move
1177 if (keypress
.equals(kbCtrlF5
)) {
1178 inKeyboardResize
= !inKeyboardResize
;
1181 } // if (!(this instanceof TDesktop))
1183 // I didn't take it, pass it on to my children
1184 super.onKeypress(keypress
);
1188 * Handle posted command events.
1190 * @param command command event
1193 public void onCommand(final TCommandEvent command
) {
1195 // These commands will typically not be seen unless a subclass
1196 // overrides onMenu() due to how TApplication dispatches
1199 if (!(this instanceof TDesktop
)) {
1201 if (command
.equals(cmWindowClose
)) {
1202 if ((flags
& NOCLOSEBOX
) == 0) {
1203 application
.closeWindow(this);
1208 if (command
.equals(cmWindowNext
)) {
1209 application
.switchWindow(true);
1213 if (command
.equals(cmWindowPrevious
)) {
1214 application
.switchWindow(false);
1218 if (command
.equals(cmWindowMove
)) {
1219 inKeyboardResize
= true;
1223 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
1231 } // if (!(this instanceof TDesktop))
1233 // I didn't take it, pass it on to my children
1234 super.onCommand(command
);
1238 * Handle posted menu events.
1240 * @param menu menu event
1243 public void onMenu(final TMenuEvent menu
) {
1245 if (!(this instanceof TDesktop
)) {
1247 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
1248 if ((flags
& NOCLOSEBOX
) == 0) {
1249 application
.closeWindow(this);
1254 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
1255 application
.switchWindow(true);
1259 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
1260 application
.switchWindow(false);
1264 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
1265 inKeyboardResize
= true;
1269 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
1270 && ((flags
& NOZOOMBOX
) == 0)
1280 } // if (!(this instanceof TDesktop))
1282 // I didn't take it, pass it on to my children
1286 // ------------------------------------------------------------------------
1287 // Passthru for Screen functions ------------------------------------------
1288 // ------------------------------------------------------------------------
1291 * Get the attributes at one location.
1293 * @param x column coordinate. 0 is the left-most column.
1294 * @param y row coordinate. 0 is the top-most row.
1295 * @return attributes at (x, y)
1297 public final CellAttributes
getAttrXY(final int x
, final int y
) {
1298 return getScreen().getAttrXY(x
, y
);
1302 * Set the attributes at one location.
1304 * @param x column coordinate. 0 is the left-most column.
1305 * @param y row coordinate. 0 is the top-most row.
1306 * @param attr attributes to use (bold, foreColor, backColor)
1308 public final void putAttrXY(final int x
, final int y
,
1309 final CellAttributes attr
) {
1311 getScreen().putAttrXY(x
, y
, attr
);
1315 * Set the attributes at one location.
1317 * @param x column coordinate. 0 is the left-most column.
1318 * @param y row coordinate. 0 is the top-most row.
1319 * @param attr attributes to use (bold, foreColor, backColor)
1320 * @param clip if true, honor clipping/offset
1322 public final void putAttrXY(final int x
, final int y
,
1323 final CellAttributes attr
, final boolean clip
) {
1325 getScreen().putAttrXY(x
, y
, attr
, clip
);
1329 * Fill the entire screen with one character with attributes.
1331 * @param ch character to draw
1332 * @param attr attributes to use (bold, foreColor, backColor)
1334 public final void putAll(final char ch
, final CellAttributes attr
) {
1335 getScreen().putAll(ch
, attr
);
1339 * Render one character with attributes.
1341 * @param x column coordinate. 0 is the left-most column.
1342 * @param y row coordinate. 0 is the top-most row.
1343 * @param ch character + attributes to draw
1345 public final void putCharXY(final int x
, final int y
, final Cell ch
) {
1346 getScreen().putCharXY(x
, y
, ch
);
1350 * Render one character with attributes.
1352 * @param x column coordinate. 0 is the left-most column.
1353 * @param y row coordinate. 0 is the top-most row.
1354 * @param ch character to draw
1355 * @param attr attributes to use (bold, foreColor, backColor)
1357 public final void putCharXY(final int x
, final int y
, final char ch
,
1358 final CellAttributes attr
) {
1360 getScreen().putCharXY(x
, y
, ch
, attr
);
1364 * Render one character without changing the underlying attributes.
1366 * @param x column coordinate. 0 is the left-most column.
1367 * @param y row coordinate. 0 is the top-most row.
1368 * @param ch character to draw
1370 public final void putCharXY(final int x
, final int y
, final char ch
) {
1371 getScreen().putCharXY(x
, y
, ch
);
1375 * Render a string. Does not wrap if the string exceeds the line.
1377 * @param x column coordinate. 0 is the left-most column.
1378 * @param y row coordinate. 0 is the top-most row.
1379 * @param str string to draw
1380 * @param attr attributes to use (bold, foreColor, backColor)
1382 public final void putStringXY(final int x
, final int y
, final String str
,
1383 final CellAttributes attr
) {
1385 getScreen().putStringXY(x
, y
, str
, attr
);
1389 * Render a string without changing the underlying attribute. Does not
1390 * wrap if the string exceeds the line.
1392 * @param x column coordinate. 0 is the left-most column.
1393 * @param y row coordinate. 0 is the top-most row.
1394 * @param str string to draw
1396 public final void putStringXY(final int x
, final int y
, final String str
) {
1397 getScreen().putStringXY(x
, y
, str
);
1401 * Draw a vertical line from (x, y) to (x, y + n).
1403 * @param x column coordinate. 0 is the left-most column.
1404 * @param y row coordinate. 0 is the top-most row.
1405 * @param n number of characters to draw
1406 * @param ch character to draw
1407 * @param attr attributes to use (bold, foreColor, backColor)
1409 public final void vLineXY(final int x
, final int y
, final int n
,
1410 final char ch
, final CellAttributes attr
) {
1412 getScreen().vLineXY(x
, y
, n
, ch
, attr
);
1416 * Draw a horizontal line from (x, y) to (x + n, y).
1418 * @param x column coordinate. 0 is the left-most column.
1419 * @param y row coordinate. 0 is the top-most row.
1420 * @param n number of characters to draw
1421 * @param ch character to draw
1422 * @param attr attributes to use (bold, foreColor, backColor)
1424 public final void hLineXY(final int x
, final int y
, final int n
,
1425 final char ch
, final CellAttributes attr
) {
1427 getScreen().hLineXY(x
, y
, n
, ch
, attr
);