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
.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 perform any user prompting
342 * before they are offscreen. Note that unlike other windowing toolkits,
343 * windows can NOT use this function in some manner to avoid being
344 * closed. This is called by application.closeWindow().
346 protected void onPreClose() {
347 // Default: do nothing.
351 * Subclasses should override this method to cleanup resources. This is
352 * called by application.closeWindow().
354 protected void onClose() {
355 // Default: perform widget-specific cleanup.
356 for (TWidget w
: getChildren()) {
362 * Called by application.switchWindow() when this window gets the
363 * focus, and also by application.addWindow().
365 protected void onFocus() {
366 // Default: do nothing
370 * Called by application.switchWindow() when another window gets the
373 protected void onUnfocus() {
374 // Default: do nothing
378 * Called by application.hideWindow().
380 protected void onHide() {
381 // Default: do nothing
385 * Called by application.showWindow().
387 protected void onShow() {
388 // Default: do nothing
392 * Handle mouse button presses.
394 * @param mouse mouse button event
397 public void onMouseDown(final TMouseEvent mouse
) {
400 inKeyboardResize
= false;
401 inWindowMove
= false;
402 inWindowResize
= false;
404 if ((mouse
.getAbsoluteY() == getY())
406 && (getX() <= mouse
.getAbsoluteX())
407 && (mouse
.getAbsoluteX() < getX() + getWidth())
409 && !mouseOnMaximize()
411 // Begin moving window
413 moveWindowMouseX
= mouse
.getAbsoluteX();
414 moveWindowMouseY
= mouse
.getAbsoluteY();
422 if (mouseOnResize()) {
423 // Begin window resize
424 inWindowResize
= true;
425 moveWindowMouseX
= mouse
.getAbsoluteX();
426 moveWindowMouseY
= mouse
.getAbsoluteY();
427 resizeWindowWidth
= getWidth();
428 resizeWindowHeight
= getHeight();
435 // Give the shortcut bar a shot at this.
436 if (statusBar
!= null) {
437 if (statusBar
.statusBarMouseDown(mouse
)) {
442 // I didn't take it, pass it on to my children
443 super.onMouseDown(mouse
);
447 * Handle mouse button releases.
449 * @param mouse mouse button release event
452 public void onMouseUp(final TMouseEvent mouse
) {
455 if ((inWindowMove
) && (mouse
.isMouse1())) {
456 // Stop moving window
457 inWindowMove
= false;
461 if ((inWindowResize
) && (mouse
.isMouse1())) {
462 // Stop resizing window
463 inWindowResize
= false;
467 if (mouse
.isMouse1() && mouseOnClose()) {
468 if ((flags
& HIDEONCLOSE
) == 0) {
470 application
.closeWindow(this);
473 application
.hideWindow(this);
478 if ((mouse
.getAbsoluteY() == getY())
480 && mouseOnMaximize()) {
488 // Pass a resize event to my children
489 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
490 getWidth(), getHeight()));
494 // Give the shortcut bar a shot at this.
495 if (statusBar
!= null) {
496 if (statusBar
.statusBarMouseUp(mouse
)) {
501 // I didn't take it, pass it on to my children
502 super.onMouseUp(mouse
);
506 * Handle mouse movements.
508 * @param mouse mouse motion event
511 public void onMouseMotion(final TMouseEvent mouse
) {
516 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
517 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
518 // Don't cover up the menu bar
519 if (getY() < application
.getDesktopTop()) {
520 setY(application
.getDesktopTop());
522 // Don't go below the status bar
523 if (getY() >= application
.getDesktopBottom()) {
524 setY(application
.getDesktopBottom() - 1);
529 if (inWindowResize
) {
530 // Do not permit resizing below the status line
531 if (mouse
.getAbsoluteY() == application
.getDesktopBottom()) {
532 inWindowResize
= false;
537 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
538 - moveWindowMouseX
));
539 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
540 - moveWindowMouseY
));
541 if (getX() + getWidth() > getScreen().getWidth()) {
542 setWidth(getScreen().getWidth() - getX());
544 if (getY() + getHeight() > application
.getDesktopBottom()) {
545 setY(application
.getDesktopBottom() - getHeight() + 1);
547 // Don't cover up the menu bar
548 if (getY() < application
.getDesktopTop()) {
549 setY(application
.getDesktopTop());
552 // Keep within min/max bounds
553 if (getWidth() < minimumWindowWidth
) {
554 setWidth(minimumWindowWidth
);
555 inWindowResize
= false;
557 if (getHeight() < minimumWindowHeight
) {
558 setHeight(minimumWindowHeight
);
559 inWindowResize
= false;
561 if ((maximumWindowWidth
> 0)
562 && (getWidth() > maximumWindowWidth
)
564 setWidth(maximumWindowWidth
);
565 inWindowResize
= false;
567 if ((maximumWindowHeight
> 0)
568 && (getHeight() > maximumWindowHeight
)
570 setHeight(maximumWindowHeight
);
571 inWindowResize
= false;
574 // Pass a resize event to my children
575 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
576 getWidth(), getHeight()));
580 // Give the shortcut bar a shot at this.
581 if (statusBar
!= null) {
582 statusBar
.statusBarMouseMotion(mouse
);
585 // I didn't take it, pass it on to my children
586 super.onMouseMotion(mouse
);
592 * @param keypress keystroke event
595 public void onKeypress(final TKeypressEvent keypress
) {
597 if (inKeyboardResize
) {
599 // ESC or ENTER - Exit size/move
600 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
601 inKeyboardResize
= false;
604 if (keypress
.equals(kbLeft
)) {
609 if (keypress
.equals(kbRight
)) {
610 if (getX() < getScreen().getWidth() - 1) {
614 if (keypress
.equals(kbDown
)) {
615 if (getY() < application
.getDesktopBottom() - 1) {
619 if (keypress
.equals(kbUp
)) {
626 * Only permit keyboard resizing if the window was RESIZABLE.
628 if ((flags
& RESIZABLE
) != 0) {
630 if (keypress
.equals(kbShiftLeft
)) {
631 if ((getWidth() > minimumWindowWidth
)
632 || (minimumWindowWidth
<= 0)
634 setWidth(getWidth() - 1);
637 if (keypress
.equals(kbShiftRight
)) {
638 if ((getWidth() < maximumWindowWidth
)
639 || (maximumWindowWidth
<= 0)
641 setWidth(getWidth() + 1);
644 if (keypress
.equals(kbShiftUp
)) {
645 if ((getHeight() > minimumWindowHeight
)
646 || (minimumWindowHeight
<= 0)
648 setHeight(getHeight() - 1);
651 if (keypress
.equals(kbShiftDown
)) {
652 if ((getHeight() < maximumWindowHeight
)
653 || (maximumWindowHeight
<= 0)
655 setHeight(getHeight() + 1);
659 // Pass a resize event to my children
660 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
661 getWidth(), getHeight()));
663 } // if ((flags & RESIZABLE) != 0)
668 // Give the shortcut bar a shot at this.
669 if (statusBar
!= null) {
670 if (statusBar
.statusBarKeypress(keypress
)) {
675 // These keystrokes will typically not be seen unless a subclass
676 // overrides onMenu() due to how TApplication dispatches
679 if (!(this instanceof TDesktop
)) {
681 // Ctrl-W - close window
682 if (keypress
.equals(kbCtrlW
)) {
683 if ((flags
& NOCLOSEBOX
) == 0) {
684 if ((flags
& HIDEONCLOSE
) == 0) {
686 application
.closeWindow(this);
689 application
.hideWindow(this);
695 // F6 - behave like Alt-TAB
696 if (keypress
.equals(kbF6
)) {
697 application
.switchWindow(true);
701 // Shift-F6 - behave like Shift-Alt-TAB
702 if (keypress
.equals(kbShiftF6
)) {
703 application
.switchWindow(false);
708 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
716 // Ctrl-F5 - size/move
717 if (keypress
.equals(kbCtrlF5
)) {
718 inKeyboardResize
= !inKeyboardResize
;
721 } // if (!(this instanceof TDesktop))
723 // I didn't take it, pass it on to my children
724 super.onKeypress(keypress
);
728 * Handle posted command events.
730 * @param command command event
733 public void onCommand(final TCommandEvent command
) {
735 // These commands will typically not be seen unless a subclass
736 // overrides onMenu() due to how TApplication dispatches
739 if (!(this instanceof TDesktop
)) {
741 if (command
.equals(cmWindowClose
)) {
742 if ((flags
& NOCLOSEBOX
) == 0) {
743 if ((flags
& HIDEONCLOSE
) == 0) {
745 application
.closeWindow(this);
748 application
.hideWindow(this);
754 if (command
.equals(cmWindowNext
)) {
755 application
.switchWindow(true);
759 if (command
.equals(cmWindowPrevious
)) {
760 application
.switchWindow(false);
764 if (command
.equals(cmWindowMove
)) {
765 inKeyboardResize
= true;
769 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
777 } // if (!(this instanceof TDesktop))
779 // I didn't take it, pass it on to my children
780 super.onCommand(command
);
784 * Handle posted menu events.
786 * @param menu menu event
789 public void onMenu(final TMenuEvent menu
) {
791 if (!(this instanceof TDesktop
)) {
793 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
794 if ((flags
& NOCLOSEBOX
) == 0) {
795 if ((flags
& HIDEONCLOSE
) == 0) {
797 application
.closeWindow(this);
800 application
.hideWindow(this);
806 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
807 application
.switchWindow(true);
811 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
812 application
.switchWindow(false);
816 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
817 inKeyboardResize
= true;
821 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
822 && ((flags
& NOZOOMBOX
) == 0)
832 } // if (!(this instanceof TDesktop))
834 // I didn't take it, pass it on to my children
838 // ------------------------------------------------------------------------
839 // TWidget ----------------------------------------------------------------
840 // ------------------------------------------------------------------------
843 * Get this TWindow's parent TApplication.
845 * @return this TWindow's parent TApplication
848 public final TApplication
getApplication() {
858 public final Screen
getScreen() {
859 return application
.getScreen();
863 * Called by TApplication.drawChildren() to render on screen.
867 // Draw the box and background first.
868 CellAttributes border
= getBorder();
869 CellAttributes background
= getBackground();
870 int borderType
= getBorderType();
872 drawBox(0, 0, getWidth(), getHeight(), border
, background
, borderType
,
876 int titleLeft
= (getWidth() - title
.length() - 2) / 2;
877 putCharXY(titleLeft
, 0, ' ', border
);
878 putStringXY(titleLeft
+ 1, 0, title
);
879 putCharXY(titleLeft
+ title
.length() + 1, 0, ' ', border
);
883 // Draw the close button
884 if ((flags
& NOCLOSEBOX
) == 0) {
885 putCharXY(2, 0, '[', border
);
886 putCharXY(4, 0, ']', border
);
887 if (mouseOnClose() && mouse
.isMouse1()) {
888 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
889 getBorderControls());
891 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
892 getBorderControls());
896 // Draw the maximize button
897 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
899 putCharXY(getWidth() - 5, 0, '[', border
);
900 putCharXY(getWidth() - 3, 0, ']', border
);
901 if (mouseOnMaximize() && mouse
.isMouse1()) {
902 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
903 getBorderControls());
906 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
907 getBorderControls());
909 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
910 getBorderControls());
914 // Draw the resize corner
915 if ((flags
& RESIZABLE
) != 0) {
916 putCharXY(getWidth() - 2, getHeight() - 1,
917 GraphicsChars
.SINGLE_BAR
, getBorderControls());
918 putCharXY(getWidth() - 1, getHeight() - 1,
919 GraphicsChars
.LRCORNER
, getBorderControls());
925 // ------------------------------------------------------------------------
926 // TWindow ----------------------------------------------------------------
927 // ------------------------------------------------------------------------
932 * @return window title
934 public final String
getTitle() {
941 * @param title new window title
943 public final void setTitle(final String title
) {
948 * Get Z order. Lower number means more in-front.
950 * @return Z value. Lower number means more in-front.
952 public final int getZ() {
957 * Set Z order. Lower number means more in-front.
959 * @param z the new Z value. Lower number means more in-front.
961 public final void setZ(final int z
) {
966 * Add a keypress to be overridden for this window.
968 * @param key the key to start taking control of
970 protected void addShortcutKeypress(final TKeypress key
) {
971 keyboardShortcuts
.add(key
);
975 * Remove a keypress to be overridden for this window.
977 * @param key the key to stop taking control of
979 protected void removeShortcutKeypress(final TKeypress key
) {
980 keyboardShortcuts
.remove(key
);
984 * Remove all keypresses to be overridden for this window.
986 protected void clearShortcutKeypresses() {
987 keyboardShortcuts
.clear();
991 * Determine if a keypress is overridden for this window.
993 * @param key the key to check
994 * @return true if this window wants to process this key on its own
996 public boolean isShortcutKeypress(final TKeypress key
) {
997 return keyboardShortcuts
.contains(key
);
1001 * Get the window's status bar, or null if it does not have one.
1003 * @return the status bar, or null
1005 public TStatusBar
getStatusBar() {
1010 * Set the window's status bar to a new one.
1012 * @param text the status bar text
1013 * @return the status bar
1015 public TStatusBar
newStatusBar(final String text
) {
1016 statusBar
= new TStatusBar(this, text
);
1021 * Set the maximum width for this window.
1023 * @param maximumWindowWidth new maximum width
1025 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
1026 if ((maximumWindowWidth
!= -1)
1027 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
1029 throw new IllegalArgumentException("Maximum window width cannot " +
1030 "be smaller than minimum window width + 1");
1032 this.maximumWindowWidth
= maximumWindowWidth
;
1036 * Set the minimum width for this window.
1038 * @param minimumWindowWidth new minimum width
1040 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
1041 if ((maximumWindowWidth
!= -1)
1042 && (minimumWindowWidth
> maximumWindowWidth
- 1)
1044 throw new IllegalArgumentException("Minimum window width cannot " +
1045 "be larger than maximum window width - 1");
1047 this.minimumWindowWidth
= minimumWindowWidth
;
1051 * Set the maximum height for this window.
1053 * @param maximumWindowHeight new maximum height
1055 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
1056 if ((maximumWindowHeight
!= -1)
1057 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
1059 throw new IllegalArgumentException("Maximum window height cannot " +
1060 "be smaller than minimum window height + 1");
1062 this.maximumWindowHeight
= maximumWindowHeight
;
1066 * Set the minimum height for this window.
1068 * @param minimumWindowHeight new minimum height
1070 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
1071 if ((maximumWindowHeight
!= -1)
1072 && (minimumWindowHeight
> maximumWindowHeight
- 1)
1074 throw new IllegalArgumentException("Minimum window height cannot " +
1075 "be larger than maximum window height - 1");
1077 this.minimumWindowHeight
= minimumWindowHeight
;
1081 * Recenter the window on-screen.
1083 public final void center() {
1084 if ((flags
& CENTERED
) != 0) {
1085 if (getWidth() < getScreen().getWidth()) {
1086 setX((getScreen().getWidth() - getWidth()) / 2);
1090 setY(((application
.getDesktopBottom()
1091 - application
.getDesktopTop()) - getHeight()) / 2);
1095 setY(getY() + application
.getDesktopTop());
1102 public void maximize() {
1107 restoreWindowWidth
= getWidth();
1108 restoreWindowHeight
= getHeight();
1109 restoreWindowX
= getX();
1110 restoreWindowY
= getY();
1111 setWidth(getScreen().getWidth());
1112 setHeight(application
.getDesktopBottom() - 1);
1117 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1122 * Restore (unmaximize) window.
1124 public void restore() {
1129 setWidth(restoreWindowWidth
);
1130 setHeight(restoreWindowHeight
);
1131 setX(restoreWindowX
);
1132 setY(restoreWindowY
);
1135 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1140 * Returns true if this window is hidden.
1142 * @return true if this window is hidden, false if the window is shown
1144 public final boolean isHidden() {
1149 * Returns true if this window is shown.
1151 * @return true if this window is shown, false if the window is hidden
1153 public final boolean isShown() {
1158 * Hide window. A hidden window will still have its onIdle() called, and
1159 * will also have onClose() called at application exit. Hidden windows
1160 * will not receive any other events.
1162 public void hide() {
1163 application
.hideWindow(this);
1169 public void show() {
1170 application
.showWindow(this);
1174 * Activate window (bring to top and receive events).
1176 public void activate() {
1177 application
.activateWindow(this);
1181 * Close window. Note that windows without a close box can still be
1182 * closed by calling the close() method.
1184 public void close() {
1185 application
.closeWindow(this);
1189 * See if this window is undergoing any movement/resize/etc.
1191 * @return true if the window is moving
1193 public boolean inMovements() {
1194 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
1201 * Stop any pending movement/resize/etc.
1203 public void stopMovements() {
1204 inWindowResize
= false;
1205 inWindowMove
= false;
1206 inKeyboardResize
= false;
1210 * Returns true if this window is modal.
1212 * @return true if this window is modal
1214 public final boolean isModal() {
1215 if ((flags
& MODAL
) == 0) {
1222 * Returns true if this window has a close box.
1224 * @return true if this window has a close box
1226 public final boolean hasCloseBox() {
1227 if ((flags
& NOCLOSEBOX
) != 0) {
1234 * Returns true if this window has a maximize/zoom box.
1236 * @return true if this window has a maximize/zoom box
1238 public final boolean hasZoomBox() {
1239 if ((flags
& NOZOOMBOX
) != 0) {
1246 * Retrieve the background color.
1248 * @return the background color
1250 public CellAttributes
getBackground() {
1252 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1254 assert (isActive());
1255 return getTheme().getColor("twindow.background.windowmove");
1256 } else if (isModal() && inWindowMove
) {
1257 assert (isActive());
1258 return getTheme().getColor("twindow.background.modal");
1259 } else if (isModal()) {
1261 return getTheme().getColor("twindow.background.modal");
1263 return getTheme().getColor("twindow.background.modal.inactive");
1264 } else if (isActive()) {
1265 assert (!isModal());
1266 return getTheme().getColor("twindow.background");
1268 assert (!isModal());
1269 return getTheme().getColor("twindow.background.inactive");
1274 * Retrieve the border color.
1276 * @return the border color
1278 public CellAttributes
getBorder() {
1280 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1283 // The user's terminal never passed a mouse up event, and now
1284 // another window is active but we never finished a drag.
1285 inWindowMove
= false;
1286 inWindowResize
= false;
1287 inKeyboardResize
= false;
1288 return getTheme().getColor("twindow.border.inactive");
1291 return getTheme().getColor("twindow.border.windowmove");
1292 } else if (isModal() && inWindowMove
) {
1293 assert (isActive());
1294 return getTheme().getColor("twindow.border.modal.windowmove");
1295 } else if (isModal()) {
1297 return getTheme().getColor("twindow.border.modal");
1299 return getTheme().getColor("twindow.border.modal.inactive");
1301 } else if (isActive()) {
1302 assert (!isModal());
1303 return getTheme().getColor("twindow.border");
1305 assert (!isModal());
1306 return getTheme().getColor("twindow.border.inactive");
1311 * Retrieve the color used by the window movement/sizing controls.
1313 * @return the color used by the zoom box, resize bar, and close box
1315 public CellAttributes
getBorderControls() {
1317 return getTheme().getColor("twindow.border.modal.windowmove");
1319 return getTheme().getColor("twindow.border.windowmove");
1323 * Retrieve the border line type.
1325 * @return the border line type
1327 private int getBorderType() {
1329 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1331 assert (isActive());
1333 } else if (isModal() && inWindowMove
) {
1334 assert (isActive());
1336 } else if (isModal()) {
1342 } else if (isActive()) {