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
;
34 import jexer
.backend
.Screen
;
35 import jexer
.bits
.Cell
;
36 import jexer
.bits
.CellAttributes
;
37 import jexer
.bits
.GraphicsChars
;
38 import jexer
.event
.TCommandEvent
;
39 import jexer
.event
.TKeypressEvent
;
40 import jexer
.event
.TMenuEvent
;
41 import jexer
.event
.TMouseEvent
;
42 import jexer
.event
.TResizeEvent
;
43 import jexer
.menu
.TMenu
;
44 import static jexer
.TCommand
.*;
45 import static jexer
.TKeypress
.*;
48 * TWindow is the top-level container and drawing surface for other widgets.
50 public class TWindow
extends TWidget
{
52 // ------------------------------------------------------------------------
53 // Constants --------------------------------------------------------------
54 // ------------------------------------------------------------------------
57 * Window is resizable (default yes).
59 public static final int RESIZABLE
= 0x01;
62 * Window is modal (default no).
64 public static final int MODAL
= 0x02;
67 * Window is centered (default no).
69 public static final int CENTERED
= 0x04;
72 * Window has no close box (default no). Window can still be closed via
73 * TApplication.closeWindow() and TWindow.close().
75 public static final int NOCLOSEBOX
= 0x08;
78 * Window has no maximize box (default no).
80 public static final int NOZOOMBOX
= 0x10;
83 * Window is placed at absolute position (no smart placement) (default
86 public static final int ABSOLUTEXY
= 0x20;
89 * Hitting the closebox with the mouse calls TApplication.hideWindow()
90 * rather than TApplication.closeWindow() (default no).
92 public static final int HIDEONCLOSE
= 0x40;
94 // ------------------------------------------------------------------------
95 // Variables --------------------------------------------------------------
96 // ------------------------------------------------------------------------
99 * Window flags. Note package private access.
101 int flags
= RESIZABLE
;
106 private String title
= "";
109 * Window's parent TApplication.
111 private TApplication application
;
114 * Z order. Lower number means more in-front.
119 * Window's keyboard shortcuts. Any key in this set will be passed to
120 * the window directly rather than processed through the menu
123 private Set
<TKeypress
> keyboardShortcuts
= new HashSet
<TKeypress
>();
126 * If true, then the user clicked on the title bar and is moving the
129 protected boolean inWindowMove
= false;
132 * If true, then the user clicked on the bottom right corner and is
133 * resizing the window.
135 protected boolean inWindowResize
= false;
138 * If true, then the user selected "Size/Move" (or hit Ctrl-F5) and is
139 * resizing/moving the window via the keyboard.
141 protected boolean inKeyboardResize
= false;
144 * If true, this window is maximized.
146 private boolean maximized
= false;
149 * Remember mouse state.
151 protected TMouseEvent mouse
;
153 // For moving the window. resizing also uses moveWindowMouseX/Y
154 private int moveWindowMouseX
;
155 private int moveWindowMouseY
;
156 private int oldWindowX
;
157 private int oldWindowY
;
160 private int resizeWindowWidth
;
161 private int resizeWindowHeight
;
162 private int minimumWindowWidth
= 10;
163 private int minimumWindowHeight
= 2;
164 private int maximumWindowWidth
= -1;
165 private int maximumWindowHeight
= -1;
167 // For maximize/restore
168 private int restoreWindowWidth
;
169 private int restoreWindowHeight
;
170 private int restoreWindowX
;
171 private int restoreWindowY
;
174 * Hidden flag. A hidden window will still have its onIdle() called, and
175 * will also have onClose() called at application exit. Note package
176 * private access: TApplication will force hidden false if a modal window
179 boolean hidden
= false;
182 * A window may have a status bar associated with it. TApplication will
183 * draw this status bar last, and will also route events to it first
186 protected TStatusBar statusBar
= null;
188 // ------------------------------------------------------------------------
189 // Constructors -----------------------------------------------------------
190 // ------------------------------------------------------------------------
193 * Public constructor. Window will be located at (0, 0).
195 * @param application TApplication that manages this window
196 * @param title window title, will be centered along the top border
197 * @param width width of window
198 * @param height height of window
200 public TWindow(final TApplication application
, final String title
,
201 final int width
, final int height
) {
203 this(application
, title
, 0, 0, width
, height
, RESIZABLE
);
207 * Public constructor. Window will be located at (0, 0).
209 * @param application TApplication that manages this window
210 * @param title window title, will be centered along the top border
211 * @param width width of window
212 * @param height height of window
213 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
215 public TWindow(final TApplication application
, final String title
,
216 final int width
, final int height
, final int flags
) {
218 this(application
, title
, 0, 0, width
, height
, flags
);
222 * Public constructor.
224 * @param application TApplication that manages this window
225 * @param title window title, will be centered along the top border
226 * @param x column relative to parent
227 * @param y row relative to parent
228 * @param width width of window
229 * @param height height of window
231 public TWindow(final TApplication application
, final String title
,
232 final int x
, final int y
, final int width
, final int height
) {
234 this(application
, title
, x
, y
, width
, height
, RESIZABLE
);
238 * Public constructor.
240 * @param application TApplication that manages this window
241 * @param title window title, will be centered along the top border
242 * @param x column relative to parent
243 * @param y row relative to parent
244 * @param width width of window
245 * @param height height of window
246 * @param flags mask of RESIZABLE, CENTERED, or MODAL
248 public TWindow(final TApplication application
, final String title
,
249 final int x
, final int y
, final int width
, final int height
,
254 // I am my own window and parent
255 setupForTWindow(this, x
, y
+ application
.getDesktopTop(),
260 this.application
= application
;
263 // Minimum width/height are 10 and 2
264 assert (width
>= 10);
265 assert (getHeight() >= 2);
267 // MODAL implies CENTERED
269 this.flags
|= CENTERED
;
272 // Center window if specified
275 // Add me to the application
276 application
.addWindowToApplication(this);
279 // ------------------------------------------------------------------------
280 // Event handlers ---------------------------------------------------------
281 // ------------------------------------------------------------------------
284 * Returns true if the mouse is currently on the close button.
286 * @return true if mouse is currently on the close button
288 protected boolean mouseOnClose() {
289 if ((flags
& NOCLOSEBOX
) != 0) {
293 && (mouse
.getAbsoluteY() == getY())
294 && (mouse
.getAbsoluteX() == getX() + 3)
302 * Returns true if the mouse is currently on the maximize/restore button.
304 * @return true if the mouse is currently on the maximize/restore button
306 protected boolean mouseOnMaximize() {
307 if ((flags
& NOZOOMBOX
) != 0) {
312 && (mouse
.getAbsoluteY() == getY())
313 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
321 * Returns true if the mouse is currently on the resizable lower right
324 * @return true if the mouse is currently on the resizable lower right
327 protected boolean mouseOnResize() {
328 if (((flags
& RESIZABLE
) != 0)
331 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
332 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
333 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
341 * Subclasses should override this method to cleanup resources. This is
342 * called by application.closeWindow().
344 public void onClose() {
345 // Default: do nothing
349 * Called by application.switchWindow() when this window gets the
350 * focus, and also by application.addWindow().
352 public void onFocus() {
353 // Default: do nothing
357 * Called by application.switchWindow() when another window gets the
360 public void onUnfocus() {
361 // Default: do nothing
365 * Called by application.hideWindow().
367 public void onHide() {
368 // Default: do nothing
372 * Called by application.showWindow().
374 public void onShow() {
375 // Default: do nothing
379 * Handle mouse button presses.
381 * @param mouse mouse button event
384 public void onMouseDown(final TMouseEvent mouse
) {
387 inKeyboardResize
= false;
389 if ((mouse
.getAbsoluteY() == getY())
391 && (getX() <= mouse
.getAbsoluteX())
392 && (mouse
.getAbsoluteX() < getX() + getWidth())
394 && !mouseOnMaximize()
396 // Begin moving window
398 moveWindowMouseX
= mouse
.getAbsoluteX();
399 moveWindowMouseY
= mouse
.getAbsoluteY();
407 if (mouseOnResize()) {
408 // Begin window resize
409 inWindowResize
= true;
410 moveWindowMouseX
= mouse
.getAbsoluteX();
411 moveWindowMouseY
= mouse
.getAbsoluteY();
412 resizeWindowWidth
= getWidth();
413 resizeWindowHeight
= getHeight();
420 // Give the shortcut bar a shot at this.
421 if (statusBar
!= null) {
422 if (statusBar
.statusBarMouseDown(mouse
)) {
427 // I didn't take it, pass it on to my children
428 super.onMouseDown(mouse
);
432 * Handle mouse button releases.
434 * @param mouse mouse button release event
437 public void onMouseUp(final TMouseEvent mouse
) {
440 if ((inWindowMove
) && (mouse
.isMouse1())) {
441 // Stop moving window
442 inWindowMove
= false;
446 if ((inWindowResize
) && (mouse
.isMouse1())) {
447 // Stop resizing window
448 inWindowResize
= false;
452 if (mouse
.isMouse1() && mouseOnClose()) {
453 if ((flags
& HIDEONCLOSE
) == 0) {
455 application
.closeWindow(this);
458 application
.hideWindow(this);
463 if ((mouse
.getAbsoluteY() == getY())
465 && mouseOnMaximize()) {
473 // Pass a resize event to my children
474 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
475 getWidth(), getHeight()));
479 // Give the shortcut bar a shot at this.
480 if (statusBar
!= null) {
481 if (statusBar
.statusBarMouseUp(mouse
)) {
486 // I didn't take it, pass it on to my children
487 super.onMouseUp(mouse
);
491 * Handle mouse movements.
493 * @param mouse mouse motion event
496 public void onMouseMotion(final TMouseEvent mouse
) {
501 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
502 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
503 // Don't cover up the menu bar
504 if (getY() < application
.getDesktopTop()) {
505 setY(application
.getDesktopTop());
507 // Don't go below the status bar
508 if (getY() >= application
.getDesktopBottom()) {
509 setY(application
.getDesktopBottom() - 1);
514 if (inWindowResize
) {
515 // Do not permit resizing below the status line
516 if (mouse
.getAbsoluteY() == application
.getDesktopBottom()) {
517 inWindowResize
= false;
522 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
523 - moveWindowMouseX
));
524 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
525 - moveWindowMouseY
));
526 if (getX() + getWidth() > getScreen().getWidth()) {
527 setWidth(getScreen().getWidth() - getX());
529 if (getY() + getHeight() > application
.getDesktopBottom()) {
530 setY(application
.getDesktopBottom() - getHeight() + 1);
532 // Don't cover up the menu bar
533 if (getY() < application
.getDesktopTop()) {
534 setY(application
.getDesktopTop());
537 // Keep within min/max bounds
538 if (getWidth() < minimumWindowWidth
) {
539 setWidth(minimumWindowWidth
);
540 inWindowResize
= false;
542 if (getHeight() < minimumWindowHeight
) {
543 setHeight(minimumWindowHeight
);
544 inWindowResize
= false;
546 if ((maximumWindowWidth
> 0)
547 && (getWidth() > maximumWindowWidth
)
549 setWidth(maximumWindowWidth
);
550 inWindowResize
= false;
552 if ((maximumWindowHeight
> 0)
553 && (getHeight() > maximumWindowHeight
)
555 setHeight(maximumWindowHeight
);
556 inWindowResize
= false;
559 // Pass a resize event to my children
560 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
561 getWidth(), getHeight()));
565 // Give the shortcut bar a shot at this.
566 if (statusBar
!= null) {
567 statusBar
.statusBarMouseMotion(mouse
);
570 // I didn't take it, pass it on to my children
571 super.onMouseMotion(mouse
);
577 * @param keypress keystroke event
580 public void onKeypress(final TKeypressEvent keypress
) {
582 if (inKeyboardResize
) {
584 // ESC or ENTER - Exit size/move
585 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
586 inKeyboardResize
= false;
589 if (keypress
.equals(kbLeft
)) {
594 if (keypress
.equals(kbRight
)) {
595 if (getX() < getScreen().getWidth() - 1) {
599 if (keypress
.equals(kbDown
)) {
600 if (getY() < application
.getDesktopBottom() - 1) {
604 if (keypress
.equals(kbUp
)) {
611 * Only permit keyboard resizing if the window was RESIZABLE.
613 if ((flags
& RESIZABLE
) != 0) {
615 if (keypress
.equals(kbShiftLeft
)) {
616 if ((getWidth() > minimumWindowWidth
)
617 || (minimumWindowWidth
<= 0)
619 setWidth(getWidth() - 1);
622 if (keypress
.equals(kbShiftRight
)) {
623 if ((getWidth() < maximumWindowWidth
)
624 || (maximumWindowWidth
<= 0)
626 setWidth(getWidth() + 1);
629 if (keypress
.equals(kbShiftUp
)) {
630 if ((getHeight() > minimumWindowHeight
)
631 || (minimumWindowHeight
<= 0)
633 setHeight(getHeight() - 1);
636 if (keypress
.equals(kbShiftDown
)) {
637 if ((getHeight() < maximumWindowHeight
)
638 || (maximumWindowHeight
<= 0)
640 setHeight(getHeight() + 1);
644 // Pass a resize event to my children
645 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
646 getWidth(), getHeight()));
648 } // if ((flags & RESIZABLE) != 0)
653 // Give the shortcut bar a shot at this.
654 if (statusBar
!= null) {
655 if (statusBar
.statusBarKeypress(keypress
)) {
660 // These keystrokes will typically not be seen unless a subclass
661 // overrides onMenu() due to how TApplication dispatches
664 if (!(this instanceof TDesktop
)) {
666 // Ctrl-W - close window
667 if (keypress
.equals(kbCtrlW
)) {
668 if ((flags
& NOCLOSEBOX
) == 0) {
669 if ((flags
& HIDEONCLOSE
) == 0) {
671 application
.closeWindow(this);
674 application
.hideWindow(this);
680 // F6 - behave like Alt-TAB
681 if (keypress
.equals(kbF6
)) {
682 application
.switchWindow(true);
686 // Shift-F6 - behave like Shift-Alt-TAB
687 if (keypress
.equals(kbShiftF6
)) {
688 application
.switchWindow(false);
693 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
701 // Ctrl-F5 - size/move
702 if (keypress
.equals(kbCtrlF5
)) {
703 inKeyboardResize
= !inKeyboardResize
;
706 } // if (!(this instanceof TDesktop))
708 // I didn't take it, pass it on to my children
709 super.onKeypress(keypress
);
713 * Handle posted command events.
715 * @param command command event
718 public void onCommand(final TCommandEvent command
) {
720 // These commands will typically not be seen unless a subclass
721 // overrides onMenu() due to how TApplication dispatches
724 if (!(this instanceof TDesktop
)) {
726 if (command
.equals(cmWindowClose
)) {
727 if ((flags
& NOCLOSEBOX
) == 0) {
728 if ((flags
& HIDEONCLOSE
) == 0) {
730 application
.closeWindow(this);
733 application
.hideWindow(this);
739 if (command
.equals(cmWindowNext
)) {
740 application
.switchWindow(true);
744 if (command
.equals(cmWindowPrevious
)) {
745 application
.switchWindow(false);
749 if (command
.equals(cmWindowMove
)) {
750 inKeyboardResize
= true;
754 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
762 } // if (!(this instanceof TDesktop))
764 // I didn't take it, pass it on to my children
765 super.onCommand(command
);
769 * Handle posted menu events.
771 * @param menu menu event
774 public void onMenu(final TMenuEvent menu
) {
776 if (!(this instanceof TDesktop
)) {
778 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
779 if ((flags
& NOCLOSEBOX
) == 0) {
780 if ((flags
& HIDEONCLOSE
) == 0) {
782 application
.closeWindow(this);
785 application
.hideWindow(this);
791 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
792 application
.switchWindow(true);
796 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
797 application
.switchWindow(false);
801 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
802 inKeyboardResize
= true;
806 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
807 && ((flags
& NOZOOMBOX
) == 0)
817 } // if (!(this instanceof TDesktop))
819 // I didn't take it, pass it on to my children
823 // ------------------------------------------------------------------------
824 // TWidget ----------------------------------------------------------------
825 // ------------------------------------------------------------------------
828 * Get this TWindow's parent TApplication.
830 * @return this TWindow's parent TApplication
833 public final TApplication
getApplication() {
843 public final Screen
getScreen() {
844 return application
.getScreen();
848 * Called by TApplication.drawChildren() to render on screen.
852 // Draw the box and background first.
853 CellAttributes border
= getBorder();
854 CellAttributes background
= getBackground();
855 int borderType
= getBorderType();
857 getScreen().drawBox(0, 0, getWidth(), getHeight(), border
,
858 background
, borderType
, true);
861 int titleLeft
= (getWidth() - title
.length() - 2) / 2;
862 putCharXY(titleLeft
, 0, ' ', border
);
863 putStringXY(titleLeft
+ 1, 0, title
);
864 putCharXY(titleLeft
+ title
.length() + 1, 0, ' ', border
);
868 // Draw the close button
869 if ((flags
& NOCLOSEBOX
) == 0) {
870 putCharXY(2, 0, '[', border
);
871 putCharXY(4, 0, ']', border
);
872 if (mouseOnClose() && mouse
.isMouse1()) {
873 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
874 getBorderControls());
876 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
877 getBorderControls());
881 // Draw the maximize button
882 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
884 putCharXY(getWidth() - 5, 0, '[', border
);
885 putCharXY(getWidth() - 3, 0, ']', border
);
886 if (mouseOnMaximize() && mouse
.isMouse1()) {
887 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
888 getBorderControls());
891 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
892 getBorderControls());
894 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
895 getBorderControls());
899 // Draw the resize corner
900 if ((flags
& RESIZABLE
) != 0) {
901 putCharXY(getWidth() - 2, getHeight() - 1,
902 GraphicsChars
.SINGLE_BAR
, getBorderControls());
903 putCharXY(getWidth() - 1, getHeight() - 1,
904 GraphicsChars
.LRCORNER
, getBorderControls());
910 // ------------------------------------------------------------------------
911 // TWindow ----------------------------------------------------------------
912 // ------------------------------------------------------------------------
917 * @return window title
919 public final String
getTitle() {
926 * @param title new window title
928 public final void setTitle(final String title
) {
933 * Get Z order. Lower number means more in-front.
935 * @return Z value. Lower number means more in-front.
937 public final int getZ() {
942 * Set Z order. Lower number means more in-front.
944 * @param z the new Z value. Lower number means more in-front.
946 public final void setZ(final int z
) {
951 * Add a keypress to be overridden for this window.
953 * @param key the key to start taking control of
955 protected void addShortcutKeypress(final TKeypress key
) {
956 keyboardShortcuts
.add(key
);
960 * Remove a keypress to be overridden for this window.
962 * @param key the key to stop taking control of
964 protected void removeShortcutKeypress(final TKeypress key
) {
965 keyboardShortcuts
.remove(key
);
969 * Remove all keypresses to be overridden for this window.
971 protected void clearShortcutKeypresses() {
972 keyboardShortcuts
.clear();
976 * Determine if a keypress is overridden for this window.
978 * @param key the key to check
979 * @return true if this window wants to process this key on its own
981 public boolean isShortcutKeypress(final TKeypress key
) {
982 return keyboardShortcuts
.contains(key
);
986 * Get the window's status bar, or null if it does not have one.
988 * @return the status bar, or null
990 public TStatusBar
getStatusBar() {
995 * Set the window's status bar to a new one.
997 * @param text the status bar text
998 * @return the status bar
1000 public TStatusBar
newStatusBar(final String text
) {
1001 statusBar
= new TStatusBar(this, text
);
1006 * Set the maximum width for this window.
1008 * @param maximumWindowWidth new maximum width
1010 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
1011 if ((maximumWindowWidth
!= -1)
1012 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
1014 throw new IllegalArgumentException("Maximum window width cannot " +
1015 "be smaller than minimum window width + 1");
1017 this.maximumWindowWidth
= maximumWindowWidth
;
1021 * Set the minimum width for this window.
1023 * @param minimumWindowWidth new minimum width
1025 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
1026 if ((maximumWindowWidth
!= -1)
1027 && (minimumWindowWidth
> maximumWindowWidth
- 1)
1029 throw new IllegalArgumentException("Minimum window width cannot " +
1030 "be larger than maximum window width - 1");
1032 this.minimumWindowWidth
= minimumWindowWidth
;
1036 * Set the maximum height for this window.
1038 * @param maximumWindowHeight new maximum height
1040 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
1041 if ((maximumWindowHeight
!= -1)
1042 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
1044 throw new IllegalArgumentException("Maximum window height cannot " +
1045 "be smaller than minimum window height + 1");
1047 this.maximumWindowHeight
= maximumWindowHeight
;
1051 * Set the minimum height for this window.
1053 * @param minimumWindowHeight new minimum height
1055 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
1056 if ((maximumWindowHeight
!= -1)
1057 && (minimumWindowHeight
> maximumWindowHeight
- 1)
1059 throw new IllegalArgumentException("Minimum window height cannot " +
1060 "be larger than maximum window height - 1");
1062 this.minimumWindowHeight
= minimumWindowHeight
;
1066 * Recenter the window on-screen.
1068 public final void center() {
1069 if ((flags
& CENTERED
) != 0) {
1070 if (getWidth() < getScreen().getWidth()) {
1071 setX((getScreen().getWidth() - getWidth()) / 2);
1075 setY(((application
.getDesktopBottom()
1076 - application
.getDesktopTop()) - getHeight()) / 2);
1080 setY(getY() + application
.getDesktopTop());
1087 public void maximize() {
1092 restoreWindowWidth
= getWidth();
1093 restoreWindowHeight
= getHeight();
1094 restoreWindowX
= getX();
1095 restoreWindowY
= getY();
1096 setWidth(getScreen().getWidth());
1097 setHeight(application
.getDesktopBottom() - 1);
1102 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1107 * Restore (unmaximize) window.
1109 public void restore() {
1114 setWidth(restoreWindowWidth
);
1115 setHeight(restoreWindowHeight
);
1116 setX(restoreWindowX
);
1117 setY(restoreWindowY
);
1120 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1125 * Returns true if this window is hidden.
1127 * @return true if this window is hidden, false if the window is shown
1129 public final boolean isHidden() {
1134 * Returns true if this window is shown.
1136 * @return true if this window is shown, false if the window is hidden
1138 public final boolean isShown() {
1143 * Hide window. A hidden window will still have its onIdle() called, and
1144 * will also have onClose() called at application exit. Hidden windows
1145 * will not receive any other events.
1147 public void hide() {
1148 application
.hideWindow(this);
1154 public void show() {
1155 application
.showWindow(this);
1159 * Activate window (bring to top and receive events).
1161 public void activate() {
1162 application
.activateWindow(this);
1166 * Close window. Note that windows without a close box can still be
1167 * closed by calling the close() method.
1169 public void close() {
1170 application
.closeWindow(this);
1174 * See if this window is undergoing any movement/resize/etc.
1176 * @return true if the window is moving
1178 public boolean inMovements() {
1179 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
1186 * Stop any pending movement/resize/etc.
1188 public void stopMovements() {
1189 inWindowResize
= false;
1190 inWindowMove
= false;
1191 inKeyboardResize
= false;
1195 * Returns true if this window is modal.
1197 * @return true if this window is modal
1199 public final boolean isModal() {
1200 if ((flags
& MODAL
) == 0) {
1207 * Returns true if this window has a close box.
1209 * @return true if this window has a close box
1211 public final boolean hasCloseBox() {
1212 if ((flags
& NOCLOSEBOX
) != 0) {
1219 * Returns true if this window has a maximize/zoom box.
1221 * @return true if this window has a maximize/zoom box
1223 public final boolean hasZoomBox() {
1224 if ((flags
& NOZOOMBOX
) != 0) {
1231 * Retrieve the background color.
1233 * @return the background color
1235 public CellAttributes
getBackground() {
1237 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1239 assert (isActive());
1240 return getTheme().getColor("twindow.background.windowmove");
1241 } else if (isModal() && inWindowMove
) {
1242 assert (isActive());
1243 return getTheme().getColor("twindow.background.modal");
1244 } else if (isModal()) {
1246 return getTheme().getColor("twindow.background.modal");
1248 return getTheme().getColor("twindow.background.modal.inactive");
1249 } else if (isActive()) {
1250 assert (!isModal());
1251 return getTheme().getColor("twindow.background");
1253 assert (!isModal());
1254 return getTheme().getColor("twindow.background.inactive");
1259 * Retrieve the border color.
1261 * @return the border color
1263 public CellAttributes
getBorder() {
1265 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1267 assert (isActive());
1268 return getTheme().getColor("twindow.border.windowmove");
1269 } else if (isModal() && inWindowMove
) {
1270 assert (isActive());
1271 return getTheme().getColor("twindow.border.modal.windowmove");
1272 } else if (isModal()) {
1274 return getTheme().getColor("twindow.border.modal");
1276 return getTheme().getColor("twindow.border.modal.inactive");
1278 } else if (isActive()) {
1279 assert (!isModal());
1280 return getTheme().getColor("twindow.border");
1282 assert (!isModal());
1283 return getTheme().getColor("twindow.border.inactive");
1288 * Retrieve the color used by the window movement/sizing controls.
1290 * @return the color used by the zoom box, resize bar, and close box
1292 public CellAttributes
getBorderControls() {
1294 return getTheme().getColor("twindow.border.modal.windowmove");
1296 return getTheme().getColor("twindow.border.windowmove");
1300 * Retrieve the border line type.
1302 * @return the border line type
1304 private int getBorderType() {
1306 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1308 assert (isActive());
1310 } else if (isModal() && inWindowMove
) {
1311 assert (isActive());
1313 } else if (isModal()) {
1319 } else if (isActive()) {
1326 // ------------------------------------------------------------------------
1327 // Passthru for Screen functions ------------------------------------------
1328 // ------------------------------------------------------------------------
1331 * Get the attributes at one location.
1333 * @param x column coordinate. 0 is the left-most column.
1334 * @param y row coordinate. 0 is the top-most row.
1335 * @return attributes at (x, y)
1337 public final CellAttributes
getAttrXY(final int x
, final int y
) {
1338 return getScreen().getAttrXY(x
, y
);
1342 * Set the attributes at one location.
1344 * @param x column coordinate. 0 is the left-most column.
1345 * @param y row coordinate. 0 is the top-most row.
1346 * @param attr attributes to use (bold, foreColor, backColor)
1348 public final void putAttrXY(final int x
, final int y
,
1349 final CellAttributes attr
) {
1351 getScreen().putAttrXY(x
, y
, attr
);
1355 * Set the attributes at one location.
1357 * @param x column coordinate. 0 is the left-most column.
1358 * @param y row coordinate. 0 is the top-most row.
1359 * @param attr attributes to use (bold, foreColor, backColor)
1360 * @param clip if true, honor clipping/offset
1362 public final void putAttrXY(final int x
, final int y
,
1363 final CellAttributes attr
, final boolean clip
) {
1365 getScreen().putAttrXY(x
, y
, attr
, clip
);
1369 * Fill the entire screen with one character with attributes.
1371 * @param ch character to draw
1372 * @param attr attributes to use (bold, foreColor, backColor)
1374 public final void putAll(final char ch
, final CellAttributes attr
) {
1375 getScreen().putAll(ch
, attr
);
1379 * Render one character with attributes.
1381 * @param x column coordinate. 0 is the left-most column.
1382 * @param y row coordinate. 0 is the top-most row.
1383 * @param ch character + attributes to draw
1385 public final void putCharXY(final int x
, final int y
, final Cell ch
) {
1386 getScreen().putCharXY(x
, y
, ch
);
1390 * Render one character with attributes.
1392 * @param x column coordinate. 0 is the left-most column.
1393 * @param y row coordinate. 0 is the top-most row.
1394 * @param ch character to draw
1395 * @param attr attributes to use (bold, foreColor, backColor)
1397 public final void putCharXY(final int x
, final int y
, final char ch
,
1398 final CellAttributes attr
) {
1400 getScreen().putCharXY(x
, y
, ch
, attr
);
1404 * Render one character without changing the underlying attributes.
1406 * @param x column coordinate. 0 is the left-most column.
1407 * @param y row coordinate. 0 is the top-most row.
1408 * @param ch character to draw
1410 public final void putCharXY(final int x
, final int y
, final char ch
) {
1411 getScreen().putCharXY(x
, y
, ch
);
1415 * Render a string. Does not wrap if the string exceeds the line.
1417 * @param x column coordinate. 0 is the left-most column.
1418 * @param y row coordinate. 0 is the top-most row.
1419 * @param str string to draw
1420 * @param attr attributes to use (bold, foreColor, backColor)
1422 public final void putStringXY(final int x
, final int y
, final String str
,
1423 final CellAttributes attr
) {
1425 getScreen().putStringXY(x
, y
, str
, attr
);
1429 * Render a string without changing the underlying attribute. Does not
1430 * wrap if the string exceeds the line.
1432 * @param x column coordinate. 0 is the left-most column.
1433 * @param y row coordinate. 0 is the top-most row.
1434 * @param str string to draw
1436 public final void putStringXY(final int x
, final int y
, final String str
) {
1437 getScreen().putStringXY(x
, y
, str
);
1441 * Draw a vertical line from (x, y) to (x, y + n).
1443 * @param x column coordinate. 0 is the left-most column.
1444 * @param y row coordinate. 0 is the top-most row.
1445 * @param n number of characters to draw
1446 * @param ch character to draw
1447 * @param attr attributes to use (bold, foreColor, backColor)
1449 public final void vLineXY(final int x
, final int y
, final int n
,
1450 final char ch
, final CellAttributes attr
) {
1452 getScreen().vLineXY(x
, y
, n
, ch
, attr
);
1456 * Draw a horizontal line from (x, y) to (x + n, y).
1458 * @param x column coordinate. 0 is the left-most column.
1459 * @param y row coordinate. 0 is the top-most row.
1460 * @param n number of characters to draw
1461 * @param ch character to draw
1462 * @param attr attributes to use (bold, foreColor, backColor)
1464 public final void hLineXY(final int x
, final int y
, final int n
,
1465 final char ch
, final CellAttributes attr
) {
1467 getScreen().hLineXY(x
, y
, n
, ch
, attr
);