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;
189 * A window may request that TApplication NOT draw the mouse cursor over
190 * it by setting this to true. This is currently only used within Jexer
191 * by TTerminalWindow so that only the bottom-most instance of nested
192 * Jexer's draws the mouse within its application window. But perhaps
193 * other applications can use it, so public getter/setter is provided.
195 private boolean hideMouse
= false;
197 // ------------------------------------------------------------------------
198 // Constructors -----------------------------------------------------------
199 // ------------------------------------------------------------------------
202 * Public constructor. Window will be located at (0, 0).
204 * @param application TApplication that manages this window
205 * @param title window title, will be centered along the top border
206 * @param width width of window
207 * @param height height of window
209 public TWindow(final TApplication application
, final String title
,
210 final int width
, final int height
) {
212 this(application
, title
, 0, 0, width
, height
, RESIZABLE
);
216 * Public constructor. Window will be located at (0, 0).
218 * @param application TApplication that manages this window
219 * @param title window title, will be centered along the top border
220 * @param width width of window
221 * @param height height of window
222 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
224 public TWindow(final TApplication application
, final String title
,
225 final int width
, final int height
, final int flags
) {
227 this(application
, title
, 0, 0, width
, height
, flags
);
231 * Public constructor.
233 * @param application TApplication that manages this window
234 * @param title window title, will be centered along the top border
235 * @param x column relative to parent
236 * @param y row relative to parent
237 * @param width width of window
238 * @param height height of window
240 public TWindow(final TApplication application
, final String title
,
241 final int x
, final int y
, final int width
, final int height
) {
243 this(application
, title
, x
, y
, width
, height
, RESIZABLE
);
247 * Public constructor.
249 * @param application TApplication that manages this window
250 * @param title window title, will be centered along the top border
251 * @param x column relative to parent
252 * @param y row relative to parent
253 * @param width width of window
254 * @param height height of window
255 * @param flags mask of RESIZABLE, CENTERED, or MODAL
257 public TWindow(final TApplication application
, final String title
,
258 final int x
, final int y
, final int width
, final int height
,
263 // I am my own window and parent
264 setupForTWindow(this, x
, y
+ application
.getDesktopTop(),
269 this.application
= application
;
272 // Minimum width/height are 10 and 2
273 assert (width
>= 10);
274 assert (getHeight() >= 2);
276 // MODAL implies CENTERED
278 this.flags
|= CENTERED
;
281 // Center window if specified
284 // Add me to the application
285 application
.addWindowToApplication(this);
288 // ------------------------------------------------------------------------
289 // Event handlers ---------------------------------------------------------
290 // ------------------------------------------------------------------------
293 * Returns true if the mouse is currently on the close button.
295 * @return true if mouse is currently on the close button
297 protected boolean mouseOnClose() {
298 if ((flags
& NOCLOSEBOX
) != 0) {
302 && (mouse
.getAbsoluteY() == getY())
303 && (mouse
.getAbsoluteX() == getX() + 3)
311 * Returns true if the mouse is currently on the maximize/restore button.
313 * @return true if the mouse is currently on the maximize/restore button
315 protected boolean mouseOnMaximize() {
316 if ((flags
& NOZOOMBOX
) != 0) {
321 && (mouse
.getAbsoluteY() == getY())
322 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
330 * Returns true if the mouse is currently on the resizable lower right
333 * @return true if the mouse is currently on the resizable lower right
336 protected boolean mouseOnResize() {
337 if (((flags
& RESIZABLE
) != 0)
340 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
341 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
342 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
350 * Subclasses should override this method to perform any user prompting
351 * before they are offscreen. Note that unlike other windowing toolkits,
352 * windows can NOT use this function in some manner to avoid being
353 * closed. This is called by application.closeWindow().
355 protected void onPreClose() {
356 // Default: do nothing.
360 * Subclasses should override this method to cleanup resources. This is
361 * called by application.closeWindow().
363 protected void onClose() {
364 // Default: perform widget-specific cleanup.
365 for (TWidget w
: getChildren()) {
371 * Called by application.switchWindow() when this window gets the
372 * focus, and also by application.addWindow().
374 protected void onFocus() {
375 // Default: do nothing
379 * Called by application.switchWindow() when another window gets the
382 protected void onUnfocus() {
383 // Default: do nothing
387 * Called by application.hideWindow().
389 protected void onHide() {
390 // Default: do nothing
394 * Called by application.showWindow().
396 protected void onShow() {
397 // Default: do nothing
401 * Handle mouse button presses.
403 * @param mouse mouse button event
406 public void onMouseDown(final TMouseEvent mouse
) {
409 inKeyboardResize
= false;
410 inWindowMove
= false;
411 inWindowResize
= false;
413 if ((mouse
.getAbsoluteY() == getY())
415 && (getX() <= mouse
.getAbsoluteX())
416 && (mouse
.getAbsoluteX() < getX() + getWidth())
418 && !mouseOnMaximize()
420 // Begin moving window
422 moveWindowMouseX
= mouse
.getAbsoluteX();
423 moveWindowMouseY
= mouse
.getAbsoluteY();
431 if (mouseOnResize()) {
432 // Begin window resize
433 inWindowResize
= true;
434 moveWindowMouseX
= mouse
.getAbsoluteX();
435 moveWindowMouseY
= mouse
.getAbsoluteY();
436 resizeWindowWidth
= getWidth();
437 resizeWindowHeight
= getHeight();
444 // Give the shortcut bar a shot at this.
445 if (statusBar
!= null) {
446 if (statusBar
.statusBarMouseDown(mouse
)) {
451 // I didn't take it, pass it on to my children
452 super.onMouseDown(mouse
);
456 * Handle mouse button releases.
458 * @param mouse mouse button release event
461 public void onMouseUp(final TMouseEvent mouse
) {
464 if ((inWindowMove
) && (mouse
.isMouse1())) {
465 // Stop moving window
466 inWindowMove
= false;
470 if ((inWindowResize
) && (mouse
.isMouse1())) {
471 // Stop resizing window
472 inWindowResize
= false;
476 if (mouse
.isMouse1() && mouseOnClose()) {
477 if ((flags
& HIDEONCLOSE
) == 0) {
479 application
.closeWindow(this);
482 application
.hideWindow(this);
487 if ((mouse
.getAbsoluteY() == getY())
489 && mouseOnMaximize()) {
497 // Pass a resize event to my children
498 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
499 getWidth(), getHeight()));
503 // Give the shortcut bar a shot at this.
504 if (statusBar
!= null) {
505 if (statusBar
.statusBarMouseUp(mouse
)) {
510 // I didn't take it, pass it on to my children
511 super.onMouseUp(mouse
);
515 * Handle mouse movements.
517 * @param mouse mouse motion event
520 public void onMouseMotion(final TMouseEvent mouse
) {
525 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
526 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
527 // Don't cover up the menu bar
528 if (getY() < application
.getDesktopTop()) {
529 setY(application
.getDesktopTop());
531 // Don't go below the status bar
532 if (getY() >= application
.getDesktopBottom()) {
533 setY(application
.getDesktopBottom() - 1);
538 if (inWindowResize
) {
539 // Do not permit resizing below the status line
540 if (mouse
.getAbsoluteY() == application
.getDesktopBottom()) {
541 inWindowResize
= false;
546 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
547 - moveWindowMouseX
));
548 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
549 - moveWindowMouseY
));
550 if (getX() + getWidth() > getScreen().getWidth()) {
551 setWidth(getScreen().getWidth() - getX());
553 if (getY() + getHeight() > application
.getDesktopBottom()) {
554 setY(application
.getDesktopBottom() - getHeight() + 1);
556 // Don't cover up the menu bar
557 if (getY() < application
.getDesktopTop()) {
558 setY(application
.getDesktopTop());
561 // Keep within min/max bounds
562 if (getWidth() < minimumWindowWidth
) {
563 setWidth(minimumWindowWidth
);
564 inWindowResize
= false;
566 if (getHeight() < minimumWindowHeight
) {
567 setHeight(minimumWindowHeight
);
568 inWindowResize
= false;
570 if ((maximumWindowWidth
> 0)
571 && (getWidth() > maximumWindowWidth
)
573 setWidth(maximumWindowWidth
);
574 inWindowResize
= false;
576 if ((maximumWindowHeight
> 0)
577 && (getHeight() > maximumWindowHeight
)
579 setHeight(maximumWindowHeight
);
580 inWindowResize
= false;
583 // Pass a resize event to my children
584 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
585 getWidth(), getHeight()));
589 // Give the shortcut bar a shot at this.
590 if (statusBar
!= null) {
591 statusBar
.statusBarMouseMotion(mouse
);
594 // I didn't take it, pass it on to my children
595 super.onMouseMotion(mouse
);
601 * @param keypress keystroke event
604 public void onKeypress(final TKeypressEvent keypress
) {
606 if (inKeyboardResize
) {
608 // ESC or ENTER - Exit size/move
609 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
610 inKeyboardResize
= false;
613 if (keypress
.equals(kbLeft
)) {
618 if (keypress
.equals(kbRight
)) {
619 if (getX() < getScreen().getWidth() - 1) {
623 if (keypress
.equals(kbDown
)) {
624 if (getY() < application
.getDesktopBottom() - 1) {
628 if (keypress
.equals(kbUp
)) {
635 * Only permit keyboard resizing if the window was RESIZABLE.
637 if ((flags
& RESIZABLE
) != 0) {
639 if (keypress
.equals(kbShiftLeft
)) {
640 if ((getWidth() > minimumWindowWidth
)
641 || (minimumWindowWidth
<= 0)
643 setWidth(getWidth() - 1);
646 if (keypress
.equals(kbShiftRight
)) {
647 if ((getWidth() < maximumWindowWidth
)
648 || (maximumWindowWidth
<= 0)
650 setWidth(getWidth() + 1);
653 if (keypress
.equals(kbShiftUp
)) {
654 if ((getHeight() > minimumWindowHeight
)
655 || (minimumWindowHeight
<= 0)
657 setHeight(getHeight() - 1);
660 if (keypress
.equals(kbShiftDown
)) {
661 if ((getHeight() < maximumWindowHeight
)
662 || (maximumWindowHeight
<= 0)
664 setHeight(getHeight() + 1);
668 // Pass a resize event to my children
669 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
670 getWidth(), getHeight()));
672 } // if ((flags & RESIZABLE) != 0)
677 // Give the shortcut bar a shot at this.
678 if (statusBar
!= null) {
679 if (statusBar
.statusBarKeypress(keypress
)) {
684 // These keystrokes will typically not be seen unless a subclass
685 // overrides onMenu() due to how TApplication dispatches
688 if (!(this instanceof TDesktop
)) {
690 // Ctrl-W - close window
691 if (keypress
.equals(kbCtrlW
)) {
692 if ((flags
& NOCLOSEBOX
) == 0) {
693 if ((flags
& HIDEONCLOSE
) == 0) {
695 application
.closeWindow(this);
698 application
.hideWindow(this);
704 // F6 - behave like Alt-TAB
705 if (keypress
.equals(kbF6
)) {
706 application
.switchWindow(true);
710 // Shift-F6 - behave like Shift-Alt-TAB
711 if (keypress
.equals(kbShiftF6
)) {
712 application
.switchWindow(false);
717 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
725 // Ctrl-F5 - size/move
726 if (keypress
.equals(kbCtrlF5
)) {
727 inKeyboardResize
= !inKeyboardResize
;
730 } // if (!(this instanceof TDesktop))
732 // I didn't take it, pass it on to my children
733 super.onKeypress(keypress
);
737 * Handle posted command events.
739 * @param command command event
742 public void onCommand(final TCommandEvent command
) {
744 // These commands will typically not be seen unless a subclass
745 // overrides onMenu() due to how TApplication dispatches
748 if (!(this instanceof TDesktop
)) {
750 if (command
.equals(cmWindowClose
)) {
751 if ((flags
& NOCLOSEBOX
) == 0) {
752 if ((flags
& HIDEONCLOSE
) == 0) {
754 application
.closeWindow(this);
757 application
.hideWindow(this);
763 if (command
.equals(cmWindowNext
)) {
764 application
.switchWindow(true);
768 if (command
.equals(cmWindowPrevious
)) {
769 application
.switchWindow(false);
773 if (command
.equals(cmWindowMove
)) {
774 inKeyboardResize
= true;
778 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
786 } // if (!(this instanceof TDesktop))
788 // I didn't take it, pass it on to my children
789 super.onCommand(command
);
793 * Handle posted menu events.
795 * @param menu menu event
798 public void onMenu(final TMenuEvent menu
) {
800 if (!(this instanceof TDesktop
)) {
802 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
803 if ((flags
& NOCLOSEBOX
) == 0) {
804 if ((flags
& HIDEONCLOSE
) == 0) {
806 application
.closeWindow(this);
809 application
.hideWindow(this);
815 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
816 application
.switchWindow(true);
820 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
821 application
.switchWindow(false);
825 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
826 inKeyboardResize
= true;
830 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
831 && ((flags
& NOZOOMBOX
) == 0)
841 } // if (!(this instanceof TDesktop))
843 // I didn't take it, pass it on to my children
847 // ------------------------------------------------------------------------
848 // TWidget ----------------------------------------------------------------
849 // ------------------------------------------------------------------------
852 * Get this TWindow's parent TApplication.
854 * @return this TWindow's parent TApplication
857 public final TApplication
getApplication() {
867 public final Screen
getScreen() {
868 return application
.getScreen();
872 * Called by TApplication.drawChildren() to render on screen.
876 // Draw the box and background first.
877 CellAttributes border
= getBorder();
878 CellAttributes background
= getBackground();
879 int borderType
= getBorderType();
881 drawBox(0, 0, getWidth(), getHeight(), border
, background
, borderType
,
885 int titleLeft
= (getWidth() - title
.length() - 2) / 2;
886 putCharXY(titleLeft
, 0, ' ', border
);
887 putStringXY(titleLeft
+ 1, 0, title
);
888 putCharXY(titleLeft
+ title
.length() + 1, 0, ' ', border
);
892 // Draw the close button
893 if ((flags
& NOCLOSEBOX
) == 0) {
894 putCharXY(2, 0, '[', border
);
895 putCharXY(4, 0, ']', border
);
896 if (mouseOnClose() && mouse
.isMouse1()) {
897 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
898 getBorderControls());
900 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
901 getBorderControls());
905 // Draw the maximize button
906 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
908 putCharXY(getWidth() - 5, 0, '[', border
);
909 putCharXY(getWidth() - 3, 0, ']', border
);
910 if (mouseOnMaximize() && mouse
.isMouse1()) {
911 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
912 getBorderControls());
915 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
916 getBorderControls());
918 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
919 getBorderControls());
923 // Draw the resize corner
924 if ((flags
& RESIZABLE
) != 0) {
925 putCharXY(getWidth() - 2, getHeight() - 1,
926 GraphicsChars
.SINGLE_BAR
, getBorderControls());
927 putCharXY(getWidth() - 1, getHeight() - 1,
928 GraphicsChars
.LRCORNER
, getBorderControls());
934 // ------------------------------------------------------------------------
935 // TWindow ----------------------------------------------------------------
936 // ------------------------------------------------------------------------
941 * @return window title
943 public final String
getTitle() {
950 * @param title new window title
952 public final void setTitle(final String title
) {
957 * Get Z order. Lower number means more in-front.
959 * @return Z value. Lower number means more in-front.
961 public final int getZ() {
966 * Set Z order. Lower number means more in-front.
968 * @param z the new Z value. Lower number means more in-front.
970 public final void setZ(final int z
) {
975 * Add a keypress to be overridden for this window.
977 * @param key the key to start taking control of
979 protected void addShortcutKeypress(final TKeypress key
) {
980 keyboardShortcuts
.add(key
);
984 * Remove a keypress to be overridden for this window.
986 * @param key the key to stop taking control of
988 protected void removeShortcutKeypress(final TKeypress key
) {
989 keyboardShortcuts
.remove(key
);
993 * Remove all keypresses to be overridden for this window.
995 protected void clearShortcutKeypresses() {
996 keyboardShortcuts
.clear();
1000 * Determine if a keypress is overridden for this window.
1002 * @param key the key to check
1003 * @return true if this window wants to process this key on its own
1005 public boolean isShortcutKeypress(final TKeypress key
) {
1006 return keyboardShortcuts
.contains(key
);
1010 * Get the window's status bar, or null if it does not have one.
1012 * @return the status bar, or null
1014 public TStatusBar
getStatusBar() {
1019 * Set the window's status bar to a new one.
1021 * @param text the status bar text
1022 * @return the status bar
1024 public TStatusBar
newStatusBar(final String text
) {
1025 statusBar
= new TStatusBar(this, text
);
1030 * Set the maximum width for this window.
1032 * @param maximumWindowWidth new maximum width
1034 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
1035 if ((maximumWindowWidth
!= -1)
1036 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
1038 throw new IllegalArgumentException("Maximum window width cannot " +
1039 "be smaller than minimum window width + 1");
1041 this.maximumWindowWidth
= maximumWindowWidth
;
1045 * Set the minimum width for this window.
1047 * @param minimumWindowWidth new minimum width
1049 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
1050 if ((maximumWindowWidth
!= -1)
1051 && (minimumWindowWidth
> maximumWindowWidth
- 1)
1053 throw new IllegalArgumentException("Minimum window width cannot " +
1054 "be larger than maximum window width - 1");
1056 this.minimumWindowWidth
= minimumWindowWidth
;
1060 * Set the maximum height for this window.
1062 * @param maximumWindowHeight new maximum height
1064 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
1065 if ((maximumWindowHeight
!= -1)
1066 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
1068 throw new IllegalArgumentException("Maximum window height cannot " +
1069 "be smaller than minimum window height + 1");
1071 this.maximumWindowHeight
= maximumWindowHeight
;
1075 * Set the minimum height for this window.
1077 * @param minimumWindowHeight new minimum height
1079 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
1080 if ((maximumWindowHeight
!= -1)
1081 && (minimumWindowHeight
> maximumWindowHeight
- 1)
1083 throw new IllegalArgumentException("Minimum window height cannot " +
1084 "be larger than maximum window height - 1");
1086 this.minimumWindowHeight
= minimumWindowHeight
;
1090 * Recenter the window on-screen.
1092 public final void center() {
1093 if ((flags
& CENTERED
) != 0) {
1094 if (getWidth() < getScreen().getWidth()) {
1095 setX((getScreen().getWidth() - getWidth()) / 2);
1099 setY(((application
.getDesktopBottom()
1100 - application
.getDesktopTop()) - getHeight()) / 2);
1104 setY(getY() + application
.getDesktopTop());
1111 public void maximize() {
1116 restoreWindowWidth
= getWidth();
1117 restoreWindowHeight
= getHeight();
1118 restoreWindowX
= getX();
1119 restoreWindowY
= getY();
1120 setWidth(getScreen().getWidth());
1121 setHeight(application
.getDesktopBottom() - 1);
1126 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1131 * Restore (unmaximize) window.
1133 public void restore() {
1138 setWidth(restoreWindowWidth
);
1139 setHeight(restoreWindowHeight
);
1140 setX(restoreWindowX
);
1141 setY(restoreWindowY
);
1144 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1149 * Returns true if this window is hidden.
1151 * @return true if this window is hidden, false if the window is shown
1153 public final boolean isHidden() {
1158 * Returns true if this window is shown.
1160 * @return true if this window is shown, false if the window is hidden
1162 public final boolean isShown() {
1167 * Hide window. A hidden window will still have its onIdle() called, and
1168 * will also have onClose() called at application exit. Hidden windows
1169 * will not receive any other events.
1171 public void hide() {
1172 application
.hideWindow(this);
1178 public void show() {
1179 application
.showWindow(this);
1183 * Activate window (bring to top and receive events).
1185 public void activate() {
1186 application
.activateWindow(this);
1190 * Close window. Note that windows without a close box can still be
1191 * closed by calling the close() method.
1193 public void close() {
1194 application
.closeWindow(this);
1198 * See if this window is undergoing any movement/resize/etc.
1200 * @return true if the window is moving
1202 public boolean inMovements() {
1203 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
1210 * Stop any pending movement/resize/etc.
1212 public void stopMovements() {
1213 inWindowResize
= false;
1214 inWindowMove
= false;
1215 inKeyboardResize
= false;
1219 * Returns true if this window is modal.
1221 * @return true if this window is modal
1223 public final boolean isModal() {
1224 if ((flags
& MODAL
) == 0) {
1231 * Returns true if this window has a close box.
1233 * @return true if this window has a close box
1235 public final boolean hasCloseBox() {
1236 if ((flags
& NOCLOSEBOX
) != 0) {
1243 * Returns true if this window has a maximize/zoom box.
1245 * @return true if this window has a maximize/zoom box
1247 public final boolean hasZoomBox() {
1248 if ((flags
& NOZOOMBOX
) != 0) {
1255 * Retrieve the background color.
1257 * @return the background color
1259 public CellAttributes
getBackground() {
1261 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1263 assert (isActive());
1264 return getTheme().getColor("twindow.background.windowmove");
1265 } else if (isModal() && inWindowMove
) {
1266 assert (isActive());
1267 return getTheme().getColor("twindow.background.modal");
1268 } else if (isModal()) {
1270 return getTheme().getColor("twindow.background.modal");
1272 return getTheme().getColor("twindow.background.modal.inactive");
1273 } else if (isActive()) {
1274 assert (!isModal());
1275 return getTheme().getColor("twindow.background");
1277 assert (!isModal());
1278 return getTheme().getColor("twindow.background.inactive");
1283 * Retrieve the border color.
1285 * @return the border color
1287 public CellAttributes
getBorder() {
1289 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1292 // The user's terminal never passed a mouse up event, and now
1293 // another window is active but we never finished a drag.
1294 inWindowMove
= false;
1295 inWindowResize
= false;
1296 inKeyboardResize
= false;
1297 return getTheme().getColor("twindow.border.inactive");
1300 return getTheme().getColor("twindow.border.windowmove");
1301 } else if (isModal() && inWindowMove
) {
1302 assert (isActive());
1303 return getTheme().getColor("twindow.border.modal.windowmove");
1304 } else if (isModal()) {
1306 return getTheme().getColor("twindow.border.modal");
1308 return getTheme().getColor("twindow.border.modal.inactive");
1310 } else if (isActive()) {
1311 assert (!isModal());
1312 return getTheme().getColor("twindow.border");
1314 assert (!isModal());
1315 return getTheme().getColor("twindow.border.inactive");
1320 * Retrieve the color used by the window movement/sizing controls.
1322 * @return the color used by the zoom box, resize bar, and close box
1324 public CellAttributes
getBorderControls() {
1326 return getTheme().getColor("twindow.border.modal.windowmove");
1328 return getTheme().getColor("twindow.border.windowmove");
1332 * Retrieve the border line type.
1334 * @return the border line type
1336 private int getBorderType() {
1338 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1340 assert (isActive());
1342 } else if (isModal() && inWindowMove
) {
1343 assert (isActive());
1345 } else if (isModal()) {
1351 } else if (isActive()) {
1359 * Returns true if this window does not want the application-wide mouse
1360 * cursor drawn over it.
1362 * @return true if this window does not want the application-wide mouse
1363 * cursor drawn over it
1365 public final boolean hasHiddenMouse() {
1370 * Set request to prevent the application-wide mouse cursor from being
1371 * drawn over this window.
1373 * @param hideMouse if true, this window does not want the
1374 * application-wide mouse cursor drawn over it
1376 public final void setHiddenMouse(final boolean hideMouse
) {
1377 this.hideMouse
= hideMouse
;