2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 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
.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 // 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;
82 * Window is placed at absolute position (no smart placement) (default
85 public static final int ABSOLUTEXY
= 0x20;
88 * Hitting the closebox with the mouse calls TApplication.hideWindow()
89 * rather than TApplication.closeWindow() (default no).
91 public static final int HIDEONCLOSE
= 0x40;
94 * Menus cannot be used when this window is active (default no).
96 public static final int OVERRIDEMENU
= 0x80;
98 // ------------------------------------------------------------------------
99 // Variables --------------------------------------------------------------
100 // ------------------------------------------------------------------------
103 * Window flags. Note package private access.
105 int flags
= RESIZABLE
;
110 private String title
= "";
113 * Window's parent TApplication.
115 private TApplication application
;
118 * Z order. Lower number means more in-front.
123 * Window's keyboard shortcuts. Any key in this set will be passed to
124 * the window directly rather than processed through the menu
127 private Set
<TKeypress
> keyboardShortcuts
= new HashSet
<TKeypress
>();
130 * If true, then the user clicked on the title bar and is moving the
133 protected boolean inWindowMove
= false;
136 * If true, then the user clicked on the bottom right corner and is
137 * resizing the window.
139 protected boolean inWindowResize
= false;
142 * If true, then the user selected "Size/Move" (or hit Ctrl-F5) and is
143 * resizing/moving the window via the keyboard.
145 protected boolean inKeyboardResize
= false;
148 * If true, this window is maximized.
150 private boolean maximized
= false;
153 * Remember mouse state.
155 protected TMouseEvent mouse
;
157 // For moving the window. resizing also uses moveWindowMouseX/Y
158 private int moveWindowMouseX
;
159 private int moveWindowMouseY
;
160 private int oldWindowX
;
161 private int oldWindowY
;
164 private int resizeWindowWidth
;
165 private int resizeWindowHeight
;
166 private int minimumWindowWidth
= 10;
167 private int minimumWindowHeight
= 2;
168 private int maximumWindowWidth
= -1;
169 private int maximumWindowHeight
= -1;
171 // For maximize/restore
172 private int restoreWindowWidth
;
173 private int restoreWindowHeight
;
174 private int restoreWindowX
;
175 private int restoreWindowY
;
178 * Hidden flag. A hidden window will still have its onIdle() called, and
179 * will also have onClose() called at application exit. Note package
180 * private access: TApplication will force hidden false if a modal window
183 boolean hidden
= false;
186 * A window may have a status bar associated with it. TApplication will
187 * draw this status bar last, and will also route events to it first
190 protected TStatusBar statusBar
= null;
193 * A window may request that TApplication NOT draw the mouse cursor over
194 * it by setting this to true. This is currently only used within Jexer
195 * by TTerminalWindow so that only the bottom-most instance of nested
196 * Jexer's draws the mouse within its application window. But perhaps
197 * other applications can use it, so public getter/setter is provided.
199 private boolean hideMouse
= false;
201 // ------------------------------------------------------------------------
202 // Constructors -----------------------------------------------------------
203 // ------------------------------------------------------------------------
206 * Public constructor. Window will be located at (0, 0).
208 * @param application TApplication that manages this window
209 * @param title window title, will be centered along the top border
210 * @param width width of window
211 * @param height height of window
213 public TWindow(final TApplication application
, final String title
,
214 final int width
, final int height
) {
216 this(application
, title
, 0, 0, width
, height
, RESIZABLE
);
220 * Public constructor. Window will be located at (0, 0).
222 * @param application TApplication that manages this window
223 * @param title window title, will be centered along the top border
224 * @param width width of window
225 * @param height height of window
226 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
228 public TWindow(final TApplication application
, final String title
,
229 final int width
, final int height
, final int flags
) {
231 this(application
, title
, 0, 0, width
, height
, flags
);
235 * Public constructor.
237 * @param application TApplication that manages this window
238 * @param title window title, will be centered along the top border
239 * @param x column relative to parent
240 * @param y row relative to parent
241 * @param width width of window
242 * @param height height of window
244 public TWindow(final TApplication application
, final String title
,
245 final int x
, final int y
, final int width
, final int height
) {
247 this(application
, title
, x
, y
, width
, height
, RESIZABLE
);
251 * Public constructor.
253 * @param application TApplication that manages this window
254 * @param title window title, will be centered along the top border
255 * @param x column relative to parent
256 * @param y row relative to parent
257 * @param width width of window
258 * @param height height of window
259 * @param flags mask of RESIZABLE, CENTERED, or MODAL
261 public TWindow(final TApplication application
, final String title
,
262 final int x
, final int y
, final int width
, final int height
,
267 // I am my own window and parent
268 setupForTWindow(this, x
, y
+ application
.getDesktopTop(),
273 this.application
= application
;
276 // Minimum width/height are 10 and 2
277 assert (width
>= 10);
278 assert (getHeight() >= 2);
280 // MODAL implies CENTERED
282 this.flags
|= CENTERED
;
285 // Center window if specified
288 // Add me to the application
289 application
.addWindowToApplication(this);
292 // ------------------------------------------------------------------------
293 // Event handlers ---------------------------------------------------------
294 // ------------------------------------------------------------------------
297 * Returns true if the mouse is currently on the close button.
299 * @return true if mouse is currently on the close button
301 protected boolean mouseOnClose() {
302 if ((flags
& NOCLOSEBOX
) != 0) {
306 && (mouse
.getAbsoluteY() == getY())
307 && (mouse
.getAbsoluteX() == getX() + 3)
315 * Returns true if the mouse is currently on the maximize/restore button.
317 * @return true if the mouse is currently on the maximize/restore button
319 protected boolean mouseOnMaximize() {
320 if ((flags
& NOZOOMBOX
) != 0) {
325 && (mouse
.getAbsoluteY() == getY())
326 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
334 * Returns true if the mouse is currently on the resizable lower right
337 * @return true if the mouse is currently on the resizable lower right
340 protected boolean mouseOnResize() {
341 if (((flags
& RESIZABLE
) != 0)
344 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
345 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
346 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
354 * Subclasses should override this method to perform any user prompting
355 * before they are offscreen. Note that unlike other windowing toolkits,
356 * windows can NOT use this function in some manner to avoid being
357 * closed. This is called by application.closeWindow().
359 protected void onPreClose() {
360 // Default: do nothing.
364 * Subclasses should override this method to cleanup resources. This is
365 * called by application.closeWindow().
367 protected void onClose() {
368 // Default: perform widget-specific cleanup.
369 for (TWidget w
: getChildren()) {
375 * Called by application.switchWindow() when this window gets the
376 * focus, and also by application.addWindow().
378 protected void onFocus() {
379 // Default: do nothing
383 * Called by application.switchWindow() when another window gets the
386 protected void onUnfocus() {
387 // Default: do nothing
391 * Called by application.hideWindow().
393 protected void onHide() {
394 // Default: do nothing
398 * Called by application.showWindow().
400 protected void onShow() {
401 // Default: do nothing
405 * Handle mouse button presses.
407 * @param mouse mouse button event
410 public void onMouseDown(final TMouseEvent mouse
) {
413 inKeyboardResize
= false;
414 inWindowMove
= false;
415 inWindowResize
= false;
417 if ((mouse
.getAbsoluteY() == getY())
419 && (getX() <= mouse
.getAbsoluteX())
420 && (mouse
.getAbsoluteX() < getX() + getWidth())
422 && !mouseOnMaximize()
424 // Begin moving window
426 moveWindowMouseX
= mouse
.getAbsoluteX();
427 moveWindowMouseY
= mouse
.getAbsoluteY();
435 if (mouseOnResize()) {
436 // Begin window resize
437 inWindowResize
= true;
438 moveWindowMouseX
= mouse
.getAbsoluteX();
439 moveWindowMouseY
= mouse
.getAbsoluteY();
440 resizeWindowWidth
= getWidth();
441 resizeWindowHeight
= getHeight();
448 // Give the shortcut bar a shot at this.
449 if (statusBar
!= null) {
450 if (statusBar
.statusBarMouseDown(mouse
)) {
455 // I didn't take it, pass it on to my children
456 super.onMouseDown(mouse
);
460 * Handle mouse button releases.
462 * @param mouse mouse button release event
465 public void onMouseUp(final TMouseEvent mouse
) {
468 if ((inWindowMove
) && (mouse
.isMouse1())) {
469 // Stop moving window
470 inWindowMove
= false;
474 if ((inWindowResize
) && (mouse
.isMouse1())) {
475 // Stop resizing window
476 inWindowResize
= false;
480 if (mouse
.isMouse1() && mouseOnClose()) {
481 if ((flags
& HIDEONCLOSE
) == 0) {
483 application
.closeWindow(this);
486 application
.hideWindow(this);
491 if ((mouse
.getAbsoluteY() == getY())
493 && mouseOnMaximize()) {
501 // Pass a resize event to my children
502 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
503 getWidth(), getHeight()));
507 // Give the shortcut bar a shot at this.
508 if (statusBar
!= null) {
509 if (statusBar
.statusBarMouseUp(mouse
)) {
514 // I didn't take it, pass it on to my children
515 super.onMouseUp(mouse
);
519 * Handle mouse movements.
521 * @param mouse mouse motion event
524 public void onMouseMotion(final TMouseEvent mouse
) {
529 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
530 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
531 // Don't cover up the menu bar
532 if (getY() < application
.getDesktopTop()) {
533 setY(application
.getDesktopTop());
535 // Don't go below the status bar
536 if (getY() >= application
.getDesktopBottom()) {
537 setY(application
.getDesktopBottom() - 1);
542 if (inWindowResize
) {
543 // Do not permit resizing below the status line
544 if (mouse
.getAbsoluteY() == application
.getDesktopBottom()) {
545 inWindowResize
= false;
550 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
551 - moveWindowMouseX
));
552 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
553 - moveWindowMouseY
));
554 if (getX() + getWidth() > getScreen().getWidth()) {
555 setWidth(getScreen().getWidth() - getX());
557 if (getY() + getHeight() > application
.getDesktopBottom()) {
558 setY(application
.getDesktopBottom() - getHeight() + 1);
560 // Don't cover up the menu bar
561 if (getY() < application
.getDesktopTop()) {
562 setY(application
.getDesktopTop());
565 // Keep within min/max bounds
566 if (getWidth() < minimumWindowWidth
) {
567 setWidth(minimumWindowWidth
);
568 inWindowResize
= false;
570 if (getHeight() < minimumWindowHeight
) {
571 setHeight(minimumWindowHeight
);
572 inWindowResize
= false;
574 if ((maximumWindowWidth
> 0)
575 && (getWidth() > maximumWindowWidth
)
577 setWidth(maximumWindowWidth
);
578 inWindowResize
= false;
580 if ((maximumWindowHeight
> 0)
581 && (getHeight() > maximumWindowHeight
)
583 setHeight(maximumWindowHeight
);
584 inWindowResize
= false;
587 // Pass a resize event to my children
588 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
589 getWidth(), getHeight()));
593 // Give the shortcut bar a shot at this.
594 if (statusBar
!= null) {
595 statusBar
.statusBarMouseMotion(mouse
);
598 // I didn't take it, pass it on to my children
599 super.onMouseMotion(mouse
);
605 * @param keypress keystroke event
608 public void onKeypress(final TKeypressEvent keypress
) {
610 if (inKeyboardResize
) {
612 // ESC or ENTER - Exit size/move
613 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
614 inKeyboardResize
= false;
617 if (keypress
.equals(kbLeft
)) {
622 if (keypress
.equals(kbRight
)) {
623 if (getX() < getScreen().getWidth() - 1) {
627 if (keypress
.equals(kbDown
)) {
628 if (getY() < application
.getDesktopBottom() - 1) {
632 if (keypress
.equals(kbUp
)) {
639 * Only permit keyboard resizing if the window was RESIZABLE.
641 if ((flags
& RESIZABLE
) != 0) {
643 if (keypress
.equals(kbShiftLeft
)) {
644 if ((getWidth() > minimumWindowWidth
)
645 || (minimumWindowWidth
<= 0)
647 setWidth(getWidth() - 1);
650 if (keypress
.equals(kbShiftRight
)) {
651 if ((getWidth() < maximumWindowWidth
)
652 || (maximumWindowWidth
<= 0)
654 setWidth(getWidth() + 1);
657 if (keypress
.equals(kbShiftUp
)) {
658 if ((getHeight() > minimumWindowHeight
)
659 || (minimumWindowHeight
<= 0)
661 setHeight(getHeight() - 1);
664 if (keypress
.equals(kbShiftDown
)) {
665 if ((getHeight() < maximumWindowHeight
)
666 || (maximumWindowHeight
<= 0)
668 setHeight(getHeight() + 1);
672 // Pass a resize event to my children
673 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
674 getWidth(), getHeight()));
676 } // if ((flags & RESIZABLE) != 0)
681 // Give the shortcut bar a shot at this.
682 if (statusBar
!= null) {
683 if (statusBar
.statusBarKeypress(keypress
)) {
688 // These keystrokes will typically not be seen unless a subclass
689 // overrides onMenu() due to how TApplication dispatches
692 if (!(this instanceof TDesktop
)) {
694 // Ctrl-W - close window
695 if (keypress
.equals(kbCtrlW
)) {
696 if ((flags
& NOCLOSEBOX
) == 0) {
697 if ((flags
& HIDEONCLOSE
) == 0) {
699 application
.closeWindow(this);
702 application
.hideWindow(this);
708 // F6 - behave like Alt-TAB
709 if (keypress
.equals(kbF6
)) {
710 application
.switchWindow(true);
714 // Shift-F6 - behave like Shift-Alt-TAB
715 if (keypress
.equals(kbShiftF6
)) {
716 application
.switchWindow(false);
721 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
729 // Ctrl-F5 - size/move
730 if (keypress
.equals(kbCtrlF5
)) {
731 inKeyboardResize
= !inKeyboardResize
;
734 } // if (!(this instanceof TDesktop))
736 // I didn't take it, pass it on to my children
737 super.onKeypress(keypress
);
741 * Handle posted command events.
743 * @param command command event
746 public void onCommand(final TCommandEvent command
) {
748 // These commands will typically not be seen unless a subclass
749 // overrides onMenu() due to how TApplication dispatches
752 if (!(this instanceof TDesktop
)) {
754 if (command
.equals(cmWindowClose
)) {
755 if ((flags
& NOCLOSEBOX
) == 0) {
756 if ((flags
& HIDEONCLOSE
) == 0) {
758 application
.closeWindow(this);
761 application
.hideWindow(this);
767 if (command
.equals(cmWindowNext
)) {
768 application
.switchWindow(true);
772 if (command
.equals(cmWindowPrevious
)) {
773 application
.switchWindow(false);
777 if (command
.equals(cmWindowMove
)) {
778 inKeyboardResize
= true;
782 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
790 } // if (!(this instanceof TDesktop))
792 // I didn't take it, pass it on to my children
793 super.onCommand(command
);
797 * Handle posted menu events.
799 * @param menu menu event
802 public void onMenu(final TMenuEvent menu
) {
804 if (!(this instanceof TDesktop
)) {
806 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
807 if ((flags
& NOCLOSEBOX
) == 0) {
808 if ((flags
& HIDEONCLOSE
) == 0) {
810 application
.closeWindow(this);
813 application
.hideWindow(this);
819 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
820 application
.switchWindow(true);
824 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
825 application
.switchWindow(false);
829 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
830 inKeyboardResize
= true;
834 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
835 && ((flags
& NOZOOMBOX
) == 0)
845 } // if (!(this instanceof TDesktop))
847 // I didn't take it, pass it on to my children
851 // ------------------------------------------------------------------------
852 // TWidget ----------------------------------------------------------------
853 // ------------------------------------------------------------------------
856 * Get this TWindow's parent TApplication.
858 * @return this TWindow's parent TApplication
861 public final TApplication
getApplication() {
871 public final Screen
getScreen() {
872 return application
.getScreen();
876 * Called by TApplication.drawChildren() to render on screen.
880 // Draw the box and background first.
881 CellAttributes border
= getBorder();
882 CellAttributes background
= getBackground();
883 int borderType
= getBorderType();
885 drawBox(0, 0, getWidth(), getHeight(), border
, background
, borderType
,
889 int titleLeft
= (getWidth() - title
.length() - 2) / 2;
890 putCharXY(titleLeft
, 0, ' ', border
);
891 putStringXY(titleLeft
+ 1, 0, title
);
892 putCharXY(titleLeft
+ title
.length() + 1, 0, ' ', border
);
896 // Draw the close button
897 if ((flags
& NOCLOSEBOX
) == 0) {
898 putCharXY(2, 0, '[', border
);
899 putCharXY(4, 0, ']', border
);
900 if (mouseOnClose() && mouse
.isMouse1()) {
901 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
902 getBorderControls());
904 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
905 getBorderControls());
909 // Draw the maximize button
910 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
912 putCharXY(getWidth() - 5, 0, '[', border
);
913 putCharXY(getWidth() - 3, 0, ']', border
);
914 if (mouseOnMaximize() && mouse
.isMouse1()) {
915 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
916 getBorderControls());
919 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
920 getBorderControls());
922 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
923 getBorderControls());
927 // Draw the resize corner
928 if ((flags
& RESIZABLE
) != 0) {
929 putCharXY(getWidth() - 2, getHeight() - 1,
930 GraphicsChars
.SINGLE_BAR
, getBorderControls());
931 putCharXY(getWidth() - 1, getHeight() - 1,
932 GraphicsChars
.LRCORNER
, getBorderControls());
938 // ------------------------------------------------------------------------
939 // TWindow ----------------------------------------------------------------
940 // ------------------------------------------------------------------------
945 * @return window title
947 public final String
getTitle() {
954 * @param title new window title
956 public final void setTitle(final String title
) {
961 * Get Z order. Lower number means more in-front.
963 * @return Z value. Lower number means more in-front.
965 public final int getZ() {
970 * Set Z order. Lower number means more in-front.
972 * @param z the new Z value. Lower number means more in-front.
974 public final void setZ(final int z
) {
979 * Add a keypress to be overridden for this window.
981 * @param key the key to start taking control of
983 protected void addShortcutKeypress(final TKeypress key
) {
984 keyboardShortcuts
.add(key
);
988 * Remove a keypress to be overridden for this window.
990 * @param key the key to stop taking control of
992 protected void removeShortcutKeypress(final TKeypress key
) {
993 keyboardShortcuts
.remove(key
);
997 * Remove all keypresses to be overridden for this window.
999 protected void clearShortcutKeypresses() {
1000 keyboardShortcuts
.clear();
1004 * Determine if a keypress is overridden for this window.
1006 * @param key the key to check
1007 * @return true if this window wants to process this key on its own
1009 public boolean isShortcutKeypress(final TKeypress key
) {
1010 return keyboardShortcuts
.contains(key
);
1014 * Get the window's status bar, or null if it does not have one.
1016 * @return the status bar, or null
1018 public TStatusBar
getStatusBar() {
1023 * Set the window's status bar to a new one.
1025 * @param text the status bar text
1026 * @return the status bar
1028 public TStatusBar
newStatusBar(final String text
) {
1029 statusBar
= new TStatusBar(this, text
);
1034 * Set the maximum width for this window.
1036 * @param maximumWindowWidth new maximum width
1038 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
1039 if ((maximumWindowWidth
!= -1)
1040 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
1042 throw new IllegalArgumentException("Maximum window width cannot " +
1043 "be smaller than minimum window width + 1");
1045 this.maximumWindowWidth
= maximumWindowWidth
;
1049 * Set the minimum width for this window.
1051 * @param minimumWindowWidth new minimum width
1053 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
1054 if ((maximumWindowWidth
!= -1)
1055 && (minimumWindowWidth
> maximumWindowWidth
- 1)
1057 throw new IllegalArgumentException("Minimum window width cannot " +
1058 "be larger than maximum window width - 1");
1060 this.minimumWindowWidth
= minimumWindowWidth
;
1064 * Set the maximum height for this window.
1066 * @param maximumWindowHeight new maximum height
1068 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
1069 if ((maximumWindowHeight
!= -1)
1070 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
1072 throw new IllegalArgumentException("Maximum window height cannot " +
1073 "be smaller than minimum window height + 1");
1075 this.maximumWindowHeight
= maximumWindowHeight
;
1079 * Set the minimum height for this window.
1081 * @param minimumWindowHeight new minimum height
1083 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
1084 if ((maximumWindowHeight
!= -1)
1085 && (minimumWindowHeight
> maximumWindowHeight
- 1)
1087 throw new IllegalArgumentException("Minimum window height cannot " +
1088 "be larger than maximum window height - 1");
1090 this.minimumWindowHeight
= minimumWindowHeight
;
1094 * Recenter the window on-screen.
1096 public final void center() {
1097 if ((flags
& CENTERED
) != 0) {
1098 if (getWidth() < getScreen().getWidth()) {
1099 setX((getScreen().getWidth() - getWidth()) / 2);
1103 setY(((application
.getDesktopBottom()
1104 - application
.getDesktopTop()) - getHeight()) / 2);
1108 setY(getY() + application
.getDesktopTop());
1115 public void maximize() {
1120 restoreWindowWidth
= getWidth();
1121 restoreWindowHeight
= getHeight();
1122 restoreWindowX
= getX();
1123 restoreWindowY
= getY();
1124 setWidth(getScreen().getWidth());
1125 setHeight(application
.getDesktopBottom() - 1);
1130 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1135 * Restore (unmaximize) window.
1137 public void restore() {
1142 setWidth(restoreWindowWidth
);
1143 setHeight(restoreWindowHeight
);
1144 setX(restoreWindowX
);
1145 setY(restoreWindowY
);
1148 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1153 * Returns true if this window is hidden.
1155 * @return true if this window is hidden, false if the window is shown
1157 public final boolean isHidden() {
1162 * Returns true if this window is shown.
1164 * @return true if this window is shown, false if the window is hidden
1166 public final boolean isShown() {
1171 * Hide window. A hidden window will still have its onIdle() called, and
1172 * will also have onClose() called at application exit. Hidden windows
1173 * will not receive any other events.
1175 public void hide() {
1176 application
.hideWindow(this);
1182 public void show() {
1183 application
.showWindow(this);
1187 * Activate window (bring to top and receive events).
1190 public void activate() {
1191 application
.activateWindow(this);
1195 * Close window. Note that windows without a close box can still be
1196 * closed by calling the close() method.
1199 public void close() {
1200 application
.closeWindow(this);
1204 * See if this window is undergoing any movement/resize/etc.
1206 * @return true if the window is moving
1208 public boolean inMovements() {
1209 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
1216 * Stop any pending movement/resize/etc.
1218 public void stopMovements() {
1219 inWindowResize
= false;
1220 inWindowMove
= false;
1221 inKeyboardResize
= false;
1225 * Returns true if this window is modal.
1227 * @return true if this window is modal
1229 public final boolean isModal() {
1230 if ((flags
& MODAL
) == 0) {
1237 * Returns true if this window has a close box.
1239 * @return true if this window has a close box
1241 public final boolean hasCloseBox() {
1242 if ((flags
& NOCLOSEBOX
) != 0) {
1249 * Returns true if this window has a maximize/zoom box.
1251 * @return true if this window has a maximize/zoom box
1253 public final boolean hasZoomBox() {
1254 if ((flags
& NOZOOMBOX
) != 0) {
1261 * Returns true if this window does not want menus to work while it is
1264 * @return true if this window does not want menus to work while it is
1267 public final boolean hasOverriddenMenu() {
1268 if ((flags
& OVERRIDEMENU
) != 0) {
1275 * Retrieve the background color.
1277 * @return the background color
1279 public CellAttributes
getBackground() {
1281 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1283 assert (isActive());
1284 return getTheme().getColor("twindow.background.windowmove");
1285 } else if (isModal() && inWindowMove
) {
1286 assert (isActive());
1287 return getTheme().getColor("twindow.background.modal");
1288 } else if (isModal()) {
1290 return getTheme().getColor("twindow.background.modal");
1292 return getTheme().getColor("twindow.background.modal.inactive");
1293 } else if (isActive()) {
1294 assert (!isModal());
1295 return getTheme().getColor("twindow.background");
1297 assert (!isModal());
1298 return getTheme().getColor("twindow.background.inactive");
1303 * Retrieve the border color.
1305 * @return the border color
1307 public CellAttributes
getBorder() {
1309 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1312 // The user's terminal never passed a mouse up event, and now
1313 // another window is active but we never finished a drag.
1314 inWindowMove
= false;
1315 inWindowResize
= false;
1316 inKeyboardResize
= false;
1317 return getTheme().getColor("twindow.border.inactive");
1320 return getTheme().getColor("twindow.border.windowmove");
1321 } else if (isModal() && inWindowMove
) {
1322 assert (isActive());
1323 return getTheme().getColor("twindow.border.modal.windowmove");
1324 } else if (isModal()) {
1326 return getTheme().getColor("twindow.border.modal");
1328 return getTheme().getColor("twindow.border.modal.inactive");
1330 } else if (isActive()) {
1331 assert (!isModal());
1332 return getTheme().getColor("twindow.border");
1334 assert (!isModal());
1335 return getTheme().getColor("twindow.border.inactive");
1340 * Retrieve the color used by the window movement/sizing controls.
1342 * @return the color used by the zoom box, resize bar, and close box
1344 public CellAttributes
getBorderControls() {
1346 return getTheme().getColor("twindow.border.modal.windowmove");
1348 return getTheme().getColor("twindow.border.windowmove");
1352 * Retrieve the border line type.
1354 * @return the border line type
1356 private int getBorderType() {
1358 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1360 assert (isActive());
1362 } else if (isModal() && inWindowMove
) {
1363 assert (isActive());
1365 } else if (isModal()) {
1371 } else if (isActive()) {
1379 * Returns true if this window does not want the application-wide mouse
1380 * cursor drawn over it.
1382 * @return true if this window does not want the application-wide mouse
1383 * cursor drawn over it
1385 public final boolean hasHiddenMouse() {
1390 * Set request to prevent the application-wide mouse cursor from being
1391 * drawn over this window.
1393 * @param hideMouse if true, this window does not want the
1394 * application-wide mouse cursor drawn over it
1396 public final void setHiddenMouse(final boolean hideMouse
) {
1397 this.hideMouse
= hideMouse
;