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
.bits
.StringUtils
;
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;
95 * Menus cannot be used when this window is active (default no).
97 public static final int OVERRIDEMENU
= 0x80;
99 // ------------------------------------------------------------------------
100 // Variables --------------------------------------------------------------
101 // ------------------------------------------------------------------------
104 * Window flags. Note package private access.
106 int flags
= RESIZABLE
;
111 private String title
= "";
114 * Window's parent TApplication.
116 private TApplication application
;
119 * Z order. Lower number means more in-front.
124 * Window's keyboard shortcuts. Any key in this set will be passed to
125 * the window directly rather than processed through the menu
128 private Set
<TKeypress
> keyboardShortcuts
= new HashSet
<TKeypress
>();
131 * If true, then the user clicked on the title bar and is moving the
134 protected boolean inWindowMove
= false;
137 * If true, then the user clicked on the bottom right corner and is
138 * resizing the window.
140 protected boolean inWindowResize
= false;
143 * If true, then the user selected "Size/Move" (or hit Ctrl-F5) and is
144 * resizing/moving the window via the keyboard.
146 protected boolean inKeyboardResize
= false;
149 * If true, this window is maximized.
151 private boolean maximized
= false;
154 * Remember mouse state.
156 protected TMouseEvent mouse
;
158 // For moving the window. resizing also uses moveWindowMouseX/Y
159 private int moveWindowMouseX
;
160 private int moveWindowMouseY
;
161 private int oldWindowX
;
162 private int oldWindowY
;
165 private int resizeWindowWidth
;
166 private int resizeWindowHeight
;
167 private int minimumWindowWidth
= 10;
168 private int minimumWindowHeight
= 2;
169 private int maximumWindowWidth
= -1;
170 private int maximumWindowHeight
= -1;
172 // For maximize/restore
173 private int restoreWindowWidth
;
174 private int restoreWindowHeight
;
175 private int restoreWindowX
;
176 private int restoreWindowY
;
179 * Hidden flag. A hidden window will still have its onIdle() called, and
180 * will also have onClose() called at application exit. Note package
181 * private access: TApplication will force hidden false if a modal window
184 boolean hidden
= false;
187 * A window may have a status bar associated with it. TApplication will
188 * draw this status bar last, and will also route events to it first
191 protected TStatusBar statusBar
= null;
194 * A window may request that TApplication NOT draw the mouse cursor over
195 * it by setting this to true. This is currently only used within Jexer
196 * by TTerminalWindow so that only the bottom-most instance of nested
197 * Jexer's draws the mouse within its application window. But perhaps
198 * other applications can use it, so public getter/setter is provided.
200 private boolean hideMouse
= false;
202 // ------------------------------------------------------------------------
203 // Constructors -----------------------------------------------------------
204 // ------------------------------------------------------------------------
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
214 public TWindow(final TApplication application
, final String title
,
215 final int width
, final int height
) {
217 this(application
, title
, 0, 0, width
, height
, RESIZABLE
);
221 * Public constructor. Window will be located at (0, 0).
223 * @param application TApplication that manages this window
224 * @param title window title, will be centered along the top border
225 * @param width width of window
226 * @param height height of window
227 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
229 public TWindow(final TApplication application
, final String title
,
230 final int width
, final int height
, final int flags
) {
232 this(application
, title
, 0, 0, width
, height
, flags
);
236 * Public constructor.
238 * @param application TApplication that manages this window
239 * @param title window title, will be centered along the top border
240 * @param x column relative to parent
241 * @param y row relative to parent
242 * @param width width of window
243 * @param height height of window
245 public TWindow(final TApplication application
, final String title
,
246 final int x
, final int y
, final int width
, final int height
) {
248 this(application
, title
, x
, y
, width
, height
, RESIZABLE
);
252 * Public constructor.
254 * @param application TApplication that manages this window
255 * @param title window title, will be centered along the top border
256 * @param x column relative to parent
257 * @param y row relative to parent
258 * @param width width of window
259 * @param height height of window
260 * @param flags mask of RESIZABLE, CENTERED, or MODAL
262 public TWindow(final TApplication application
, final String title
,
263 final int x
, final int y
, final int width
, final int height
,
268 // I am my own window and parent
269 setupForTWindow(this, x
, y
+ application
.getDesktopTop(),
274 this.application
= application
;
277 // Minimum width/height are 10 and 2
278 assert (width
>= 10);
279 assert (getHeight() >= 2);
281 // MODAL implies CENTERED
283 this.flags
|= CENTERED
;
286 // Center window if specified
289 // Add me to the application
290 application
.addWindowToApplication(this);
293 // ------------------------------------------------------------------------
294 // Event handlers ---------------------------------------------------------
295 // ------------------------------------------------------------------------
298 * Returns true if the mouse is currently on the close button.
300 * @return true if mouse is currently on the close button
302 protected boolean mouseOnClose() {
303 if ((flags
& NOCLOSEBOX
) != 0) {
307 && (mouse
.getAbsoluteY() == getY())
308 && (mouse
.getAbsoluteX() == getX() + 3)
316 * Returns true if the mouse is currently on the maximize/restore button.
318 * @return true if the mouse is currently on the maximize/restore button
320 protected boolean mouseOnMaximize() {
321 if ((flags
& NOZOOMBOX
) != 0) {
326 && (mouse
.getAbsoluteY() == getY())
327 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
335 * Returns true if the mouse is currently on the resizable lower right
338 * @return true if the mouse is currently on the resizable lower right
341 protected boolean mouseOnResize() {
342 if (((flags
& RESIZABLE
) != 0)
345 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
346 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
347 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
355 * Subclasses should override this method to perform any user prompting
356 * before they are offscreen. Note that unlike other windowing toolkits,
357 * windows can NOT use this function in some manner to avoid being
358 * closed. This is called by application.closeWindow().
360 protected void onPreClose() {
361 // Default: do nothing.
365 * Subclasses should override this method to cleanup resources. This is
366 * called by application.closeWindow().
368 protected void onClose() {
369 // Default: perform widget-specific cleanup.
370 for (TWidget w
: getChildren()) {
376 * Called by application.switchWindow() when this window gets the
377 * focus, and also by application.addWindow().
379 protected void onFocus() {
380 // Default: do nothing
384 * Called by application.switchWindow() when another window gets the
387 protected void onUnfocus() {
388 // Default: do nothing
392 * Called by application.hideWindow().
394 protected void onHide() {
395 // Default: do nothing
399 * Called by application.showWindow().
401 protected void onShow() {
402 // Default: do nothing
406 * Handle mouse button presses.
408 * @param mouse mouse button event
411 public void onMouseDown(final TMouseEvent mouse
) {
414 inKeyboardResize
= false;
415 inWindowMove
= false;
416 inWindowResize
= false;
418 if ((mouse
.getAbsoluteY() == getY())
420 && (getX() <= mouse
.getAbsoluteX())
421 && (mouse
.getAbsoluteX() < getX() + getWidth())
423 && !mouseOnMaximize()
425 // Begin moving window
427 moveWindowMouseX
= mouse
.getAbsoluteX();
428 moveWindowMouseY
= mouse
.getAbsoluteY();
436 if (mouseOnResize()) {
437 // Begin window resize
438 inWindowResize
= true;
439 moveWindowMouseX
= mouse
.getAbsoluteX();
440 moveWindowMouseY
= mouse
.getAbsoluteY();
441 resizeWindowWidth
= getWidth();
442 resizeWindowHeight
= getHeight();
449 // Give the shortcut bar a shot at this.
450 if (statusBar
!= null) {
451 if (statusBar
.statusBarMouseDown(mouse
)) {
456 // I didn't take it, pass it on to my children
457 super.onMouseDown(mouse
);
461 * Handle mouse button releases.
463 * @param mouse mouse button release event
466 public void onMouseUp(final TMouseEvent mouse
) {
469 if ((inWindowMove
) && (mouse
.isMouse1())) {
470 // Stop moving window
471 inWindowMove
= false;
475 if ((inWindowResize
) && (mouse
.isMouse1())) {
476 // Stop resizing window
477 inWindowResize
= false;
481 if (mouse
.isMouse1() && mouseOnClose()) {
482 if ((flags
& HIDEONCLOSE
) == 0) {
484 application
.closeWindow(this);
487 application
.hideWindow(this);
492 if ((mouse
.getAbsoluteY() == getY())
494 && mouseOnMaximize()) {
502 // Pass a resize event to my children
503 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
504 getWidth(), getHeight()));
508 // Give the shortcut bar a shot at this.
509 if (statusBar
!= null) {
510 if (statusBar
.statusBarMouseUp(mouse
)) {
515 // I didn't take it, pass it on to my children
516 super.onMouseUp(mouse
);
520 * Handle mouse movements.
522 * @param mouse mouse motion event
525 public void onMouseMotion(final TMouseEvent mouse
) {
530 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
531 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
532 // Don't cover up the menu bar
533 if (getY() < application
.getDesktopTop()) {
534 setY(application
.getDesktopTop());
536 // Don't go below the status bar
537 if (getY() >= application
.getDesktopBottom()) {
538 setY(application
.getDesktopBottom() - 1);
543 if (inWindowResize
) {
544 // Do not permit resizing below the status line
545 if (mouse
.getAbsoluteY() == application
.getDesktopBottom()) {
546 inWindowResize
= false;
551 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
552 - moveWindowMouseX
));
553 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
554 - moveWindowMouseY
));
555 if (getX() + getWidth() > getScreen().getWidth()) {
556 setWidth(getScreen().getWidth() - getX());
558 if (getY() + getHeight() > application
.getDesktopBottom()) {
559 setY(application
.getDesktopBottom() - getHeight() + 1);
561 // Don't cover up the menu bar
562 if (getY() < application
.getDesktopTop()) {
563 setY(application
.getDesktopTop());
566 // Keep within min/max bounds
567 if (getWidth() < minimumWindowWidth
) {
568 setWidth(minimumWindowWidth
);
569 inWindowResize
= false;
571 if (getHeight() < minimumWindowHeight
) {
572 setHeight(minimumWindowHeight
);
573 inWindowResize
= false;
575 if ((maximumWindowWidth
> 0)
576 && (getWidth() > maximumWindowWidth
)
578 setWidth(maximumWindowWidth
);
579 inWindowResize
= false;
581 if ((maximumWindowHeight
> 0)
582 && (getHeight() > maximumWindowHeight
)
584 setHeight(maximumWindowHeight
);
585 inWindowResize
= false;
588 // Pass a resize event to my children
589 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
590 getWidth(), getHeight()));
594 // Give the shortcut bar a shot at this.
595 if (statusBar
!= null) {
596 statusBar
.statusBarMouseMotion(mouse
);
599 // I didn't take it, pass it on to my children
600 super.onMouseMotion(mouse
);
606 * @param keypress keystroke event
609 public void onKeypress(final TKeypressEvent keypress
) {
611 if (inKeyboardResize
) {
613 // ESC or ENTER - Exit size/move
614 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
615 inKeyboardResize
= false;
618 if (keypress
.equals(kbLeft
)) {
623 if (keypress
.equals(kbRight
)) {
624 if (getX() < getScreen().getWidth() - 1) {
628 if (keypress
.equals(kbDown
)) {
629 if (getY() < application
.getDesktopBottom() - 1) {
633 if (keypress
.equals(kbUp
)) {
640 * Only permit keyboard resizing if the window was RESIZABLE.
642 if ((flags
& RESIZABLE
) != 0) {
644 if (keypress
.equals(kbShiftLeft
)) {
645 if ((getWidth() > minimumWindowWidth
)
646 || (minimumWindowWidth
<= 0)
648 setWidth(getWidth() - 1);
651 if (keypress
.equals(kbShiftRight
)) {
652 if ((getWidth() < maximumWindowWidth
)
653 || (maximumWindowWidth
<= 0)
655 setWidth(getWidth() + 1);
658 if (keypress
.equals(kbShiftUp
)) {
659 if ((getHeight() > minimumWindowHeight
)
660 || (minimumWindowHeight
<= 0)
662 setHeight(getHeight() - 1);
665 if (keypress
.equals(kbShiftDown
)) {
666 if ((getHeight() < maximumWindowHeight
)
667 || (maximumWindowHeight
<= 0)
669 setHeight(getHeight() + 1);
673 // Pass a resize event to my children
674 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
675 getWidth(), getHeight()));
677 } // if ((flags & RESIZABLE) != 0)
682 // Give the shortcut bar a shot at this.
683 if (statusBar
!= null) {
684 if (statusBar
.statusBarKeypress(keypress
)) {
689 // These keystrokes will typically not be seen unless a subclass
690 // overrides onMenu() due to how TApplication dispatches
693 if (!(this instanceof TDesktop
)) {
695 // Ctrl-W - close window
696 if (keypress
.equals(kbCtrlW
)) {
697 if ((flags
& NOCLOSEBOX
) == 0) {
698 if ((flags
& HIDEONCLOSE
) == 0) {
700 application
.closeWindow(this);
703 application
.hideWindow(this);
709 // F6 - behave like Alt-TAB
710 if (keypress
.equals(kbF6
)) {
711 application
.switchWindow(true);
715 // Shift-F6 - behave like Shift-Alt-TAB
716 if (keypress
.equals(kbShiftF6
)) {
717 application
.switchWindow(false);
722 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
730 // Ctrl-F5 - size/move
731 if (keypress
.equals(kbCtrlF5
)) {
732 inKeyboardResize
= !inKeyboardResize
;
735 } // if (!(this instanceof TDesktop))
737 // I didn't take it, pass it on to my children
738 super.onKeypress(keypress
);
742 * Handle posted command events.
744 * @param command command event
747 public void onCommand(final TCommandEvent command
) {
749 // These commands will typically not be seen unless a subclass
750 // overrides onMenu() due to how TApplication dispatches
753 if (!(this instanceof TDesktop
)) {
755 if (command
.equals(cmWindowClose
)) {
756 if ((flags
& NOCLOSEBOX
) == 0) {
757 if ((flags
& HIDEONCLOSE
) == 0) {
759 application
.closeWindow(this);
762 application
.hideWindow(this);
768 if (command
.equals(cmWindowNext
)) {
769 application
.switchWindow(true);
773 if (command
.equals(cmWindowPrevious
)) {
774 application
.switchWindow(false);
778 if (command
.equals(cmWindowMove
)) {
779 inKeyboardResize
= true;
783 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
791 } // if (!(this instanceof TDesktop))
793 // I didn't take it, pass it on to my children
794 super.onCommand(command
);
798 * Handle posted menu events.
800 * @param menu menu event
803 public void onMenu(final TMenuEvent menu
) {
805 if (!(this instanceof TDesktop
)) {
807 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
808 if ((flags
& NOCLOSEBOX
) == 0) {
809 if ((flags
& HIDEONCLOSE
) == 0) {
811 application
.closeWindow(this);
814 application
.hideWindow(this);
820 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
821 application
.switchWindow(true);
825 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
826 application
.switchWindow(false);
830 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
831 inKeyboardResize
= true;
835 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
836 && ((flags
& NOZOOMBOX
) == 0)
846 } // if (!(this instanceof TDesktop))
848 // I didn't take it, pass it on to my children
852 // ------------------------------------------------------------------------
853 // TWidget ----------------------------------------------------------------
854 // ------------------------------------------------------------------------
857 * Get this TWindow's parent TApplication.
859 * @return this TWindow's parent TApplication
862 public final TApplication
getApplication() {
872 public final Screen
getScreen() {
873 return application
.getScreen();
877 * Called by TApplication.drawChildren() to render on screen.
881 // Draw the box and background first.
882 CellAttributes border
= getBorder();
883 CellAttributes background
= getBackground();
884 int borderType
= getBorderType();
886 drawBox(0, 0, getWidth(), getHeight(), border
, background
, borderType
,
890 int titleLength
= StringUtils
.width(title
);
891 int titleLeft
= (getWidth() - titleLength
- 2) / 2;
892 putCharXY(titleLeft
, 0, ' ', border
);
893 putStringXY(titleLeft
+ 1, 0, title
, border
);
894 putCharXY(titleLeft
+ titleLength
+ 1, 0, ' ', border
);
898 // Draw the close button
899 if ((flags
& NOCLOSEBOX
) == 0) {
900 putCharXY(2, 0, '[', border
);
901 putCharXY(4, 0, ']', border
);
902 if (mouseOnClose() && mouse
.isMouse1()) {
903 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
904 getBorderControls());
906 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
907 getBorderControls());
911 // Draw the maximize button
912 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
914 putCharXY(getWidth() - 5, 0, '[', border
);
915 putCharXY(getWidth() - 3, 0, ']', border
);
916 if (mouseOnMaximize() && mouse
.isMouse1()) {
917 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
918 getBorderControls());
921 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
922 getBorderControls());
924 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
925 getBorderControls());
929 // Draw the resize corner
930 if ((flags
& RESIZABLE
) != 0) {
931 putCharXY(getWidth() - 2, getHeight() - 1,
932 GraphicsChars
.SINGLE_BAR
, getBorderControls());
933 putCharXY(getWidth() - 1, getHeight() - 1,
934 GraphicsChars
.LRCORNER
, getBorderControls());
940 // ------------------------------------------------------------------------
941 // TWindow ----------------------------------------------------------------
942 // ------------------------------------------------------------------------
947 * @return window title
949 public final String
getTitle() {
956 * @param title new window title
958 public final void setTitle(final String title
) {
963 * Get Z order. Lower number means more in-front.
965 * @return Z value. Lower number means more in-front.
967 public final int getZ() {
972 * Set Z order. Lower number means more in-front.
974 * @param z the new Z value. Lower number means more in-front.
976 public final void setZ(final int z
) {
981 * Add a keypress to be overridden for this window.
983 * @param key the key to start taking control of
985 protected void addShortcutKeypress(final TKeypress key
) {
986 keyboardShortcuts
.add(key
);
990 * Remove a keypress to be overridden for this window.
992 * @param key the key to stop taking control of
994 protected void removeShortcutKeypress(final TKeypress key
) {
995 keyboardShortcuts
.remove(key
);
999 * Remove all keypresses to be overridden for this window.
1001 protected void clearShortcutKeypresses() {
1002 keyboardShortcuts
.clear();
1006 * Determine if a keypress is overridden for this window.
1008 * @param key the key to check
1009 * @return true if this window wants to process this key on its own
1011 public boolean isShortcutKeypress(final TKeypress key
) {
1012 return keyboardShortcuts
.contains(key
);
1016 * Get the window's status bar, or null if it does not have one.
1018 * @return the status bar, or null
1020 public TStatusBar
getStatusBar() {
1025 * Set the window's status bar to a new one.
1027 * @param text the status bar text
1028 * @return the status bar
1030 public TStatusBar
newStatusBar(final String text
) {
1031 statusBar
= new TStatusBar(this, text
);
1036 * Set the maximum width for this window.
1038 * @param maximumWindowWidth new maximum width
1040 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
1041 if ((maximumWindowWidth
!= -1)
1042 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
1044 throw new IllegalArgumentException("Maximum window width cannot " +
1045 "be smaller than minimum window width + 1");
1047 this.maximumWindowWidth
= maximumWindowWidth
;
1051 * Set the minimum width for this window.
1053 * @param minimumWindowWidth new minimum width
1055 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
1056 if ((maximumWindowWidth
!= -1)
1057 && (minimumWindowWidth
> maximumWindowWidth
- 1)
1059 throw new IllegalArgumentException("Minimum window width cannot " +
1060 "be larger than maximum window width - 1");
1062 this.minimumWindowWidth
= minimumWindowWidth
;
1066 * Set the maximum height for this window.
1068 * @param maximumWindowHeight new maximum height
1070 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
1071 if ((maximumWindowHeight
!= -1)
1072 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
1074 throw new IllegalArgumentException("Maximum window height cannot " +
1075 "be smaller than minimum window height + 1");
1077 this.maximumWindowHeight
= maximumWindowHeight
;
1081 * Set the minimum height for this window.
1083 * @param minimumWindowHeight new minimum height
1085 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
1086 if ((maximumWindowHeight
!= -1)
1087 && (minimumWindowHeight
> maximumWindowHeight
- 1)
1089 throw new IllegalArgumentException("Minimum window height cannot " +
1090 "be larger than maximum window height - 1");
1092 this.minimumWindowHeight
= minimumWindowHeight
;
1096 * Recenter the window on-screen.
1098 public final void center() {
1099 if ((flags
& CENTERED
) != 0) {
1100 if (getWidth() < getScreen().getWidth()) {
1101 setX((getScreen().getWidth() - getWidth()) / 2);
1105 setY(((application
.getDesktopBottom()
1106 - application
.getDesktopTop()) - getHeight()) / 2);
1110 setY(getY() + application
.getDesktopTop());
1117 public void maximize() {
1122 restoreWindowWidth
= getWidth();
1123 restoreWindowHeight
= getHeight();
1124 restoreWindowX
= getX();
1125 restoreWindowY
= getY();
1126 setWidth(getScreen().getWidth());
1127 setHeight(application
.getDesktopBottom() - 1);
1132 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1137 * Restore (unmaximize) window.
1139 public void restore() {
1144 setWidth(restoreWindowWidth
);
1145 setHeight(restoreWindowHeight
);
1146 setX(restoreWindowX
);
1147 setY(restoreWindowY
);
1150 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1155 * Returns true if this window is hidden.
1157 * @return true if this window is hidden, false if the window is shown
1159 public final boolean isHidden() {
1164 * Returns true if this window is shown.
1166 * @return true if this window is shown, false if the window is hidden
1168 public final boolean isShown() {
1173 * Hide window. A hidden window will still have its onIdle() called, and
1174 * will also have onClose() called at application exit. Hidden windows
1175 * will not receive any other events.
1177 public void hide() {
1178 application
.hideWindow(this);
1184 public void show() {
1185 application
.showWindow(this);
1189 * Activate window (bring to top and receive events).
1192 public void activate() {
1193 application
.activateWindow(this);
1197 * Close window. Note that windows without a close box can still be
1198 * closed by calling the close() method.
1201 public void close() {
1202 application
.closeWindow(this);
1206 * See if this window is undergoing any movement/resize/etc.
1208 * @return true if the window is moving
1210 public boolean inMovements() {
1211 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
1218 * Stop any pending movement/resize/etc.
1220 public void stopMovements() {
1221 inWindowResize
= false;
1222 inWindowMove
= false;
1223 inKeyboardResize
= false;
1227 * Returns true if this window is modal.
1229 * @return true if this window is modal
1231 public final boolean isModal() {
1232 if ((flags
& MODAL
) == 0) {
1239 * Returns true if this window has a close box.
1241 * @return true if this window has a close box
1243 public final boolean hasCloseBox() {
1244 if ((flags
& NOCLOSEBOX
) != 0) {
1251 * Returns true if this window has a maximize/zoom box.
1253 * @return true if this window has a maximize/zoom box
1255 public final boolean hasZoomBox() {
1256 if ((flags
& NOZOOMBOX
) != 0) {
1263 * Returns true if this window does not want menus to work while it is
1266 * @return true if this window does not want menus to work while it is
1269 public final boolean hasOverriddenMenu() {
1270 if ((flags
& OVERRIDEMENU
) != 0) {
1277 * Retrieve the background color.
1279 * @return the background color
1281 public CellAttributes
getBackground() {
1283 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1285 assert (isActive());
1286 return getTheme().getColor("twindow.background.windowmove");
1287 } else if (isModal() && inWindowMove
) {
1288 assert (isActive());
1289 return getTheme().getColor("twindow.background.modal");
1290 } else if (isModal()) {
1292 return getTheme().getColor("twindow.background.modal");
1294 return getTheme().getColor("twindow.background.modal.inactive");
1295 } else if (isActive()) {
1296 assert (!isModal());
1297 return getTheme().getColor("twindow.background");
1299 assert (!isModal());
1300 return getTheme().getColor("twindow.background.inactive");
1305 * Retrieve the border color.
1307 * @return the border color
1309 public CellAttributes
getBorder() {
1311 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1314 // The user's terminal never passed a mouse up event, and now
1315 // another window is active but we never finished a drag.
1316 inWindowMove
= false;
1317 inWindowResize
= false;
1318 inKeyboardResize
= false;
1319 return getTheme().getColor("twindow.border.inactive");
1322 return getTheme().getColor("twindow.border.windowmove");
1323 } else if (isModal() && inWindowMove
) {
1324 assert (isActive());
1325 return getTheme().getColor("twindow.border.modal.windowmove");
1326 } else if (isModal()) {
1328 return getTheme().getColor("twindow.border.modal");
1330 return getTheme().getColor("twindow.border.modal.inactive");
1332 } else if (isActive()) {
1333 assert (!isModal());
1334 return getTheme().getColor("twindow.border");
1336 assert (!isModal());
1337 return getTheme().getColor("twindow.border.inactive");
1342 * Retrieve the color used by the window movement/sizing controls.
1344 * @return the color used by the zoom box, resize bar, and close box
1346 public CellAttributes
getBorderControls() {
1348 return getTheme().getColor("twindow.border.modal.windowmove");
1350 return getTheme().getColor("twindow.border.windowmove");
1354 * Retrieve the border line type.
1356 * @return the border line type
1358 private int getBorderType() {
1360 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1362 assert (isActive());
1364 } else if (isModal() && inWindowMove
) {
1365 assert (isActive());
1367 } else if (isModal()) {
1373 } else if (isActive()) {
1381 * Returns true if this window does not want the application-wide mouse
1382 * cursor drawn over it.
1384 * @return true if this window does not want the application-wide mouse
1385 * cursor drawn over it
1387 public final boolean hasHiddenMouse() {
1392 * Set request to prevent the application-wide mouse cursor from being
1393 * drawn over this window.
1395 * @param hideMouse if true, this window does not want the
1396 * application-wide mouse cursor drawn over it
1398 public final void setHiddenMouse(final boolean hideMouse
) {
1399 this.hideMouse
= hideMouse
;