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 (inWindowMove
|| inWindowResize
) {
612 // ESC or ENTER - Exit size/move
613 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
614 inWindowMove
= false;
615 inWindowResize
= false;
620 if (inKeyboardResize
) {
622 // ESC or ENTER - Exit size/move
623 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
624 inKeyboardResize
= false;
627 if (keypress
.equals(kbLeft
)) {
632 if (keypress
.equals(kbRight
)) {
633 if (getX() < getScreen().getWidth() - 1) {
637 if (keypress
.equals(kbDown
)) {
638 if (getY() < application
.getDesktopBottom() - 1) {
642 if (keypress
.equals(kbUp
)) {
649 * Only permit keyboard resizing if the window was RESIZABLE.
651 if ((flags
& RESIZABLE
) != 0) {
653 if (keypress
.equals(kbShiftLeft
)) {
654 if ((getWidth() > minimumWindowWidth
)
655 || (minimumWindowWidth
<= 0)
657 setWidth(getWidth() - 1);
660 if (keypress
.equals(kbShiftRight
)) {
661 if ((getWidth() < maximumWindowWidth
)
662 || (maximumWindowWidth
<= 0)
664 setWidth(getWidth() + 1);
667 if (keypress
.equals(kbShiftUp
)) {
668 if ((getHeight() > minimumWindowHeight
)
669 || (minimumWindowHeight
<= 0)
671 setHeight(getHeight() - 1);
674 if (keypress
.equals(kbShiftDown
)) {
675 if ((getHeight() < maximumWindowHeight
)
676 || (maximumWindowHeight
<= 0)
678 setHeight(getHeight() + 1);
682 // Pass a resize event to my children
683 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
684 getWidth(), getHeight()));
686 } // if ((flags & RESIZABLE) != 0)
691 // Give the shortcut bar a shot at this.
692 if (statusBar
!= null) {
693 if (statusBar
.statusBarKeypress(keypress
)) {
698 // These keystrokes will typically not be seen unless a subclass
699 // overrides onMenu() due to how TApplication dispatches
702 if (!(this instanceof TDesktop
)) {
704 // Ctrl-W - close window
705 if (keypress
.equals(kbCtrlW
)) {
706 if ((flags
& NOCLOSEBOX
) == 0) {
707 if ((flags
& HIDEONCLOSE
) == 0) {
709 application
.closeWindow(this);
712 application
.hideWindow(this);
718 // F6 - behave like Alt-TAB
719 if (keypress
.equals(kbF6
)) {
720 application
.switchWindow(true);
724 // Shift-F6 - behave like Shift-Alt-TAB
725 if (keypress
.equals(kbShiftF6
)) {
726 application
.switchWindow(false);
731 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
739 // Ctrl-F5 - size/move
740 if (keypress
.equals(kbCtrlF5
)) {
741 inKeyboardResize
= !inKeyboardResize
;
744 } // if (!(this instanceof TDesktop))
746 // I didn't take it, pass it on to my children
747 super.onKeypress(keypress
);
751 * Handle posted command events.
753 * @param command command event
756 public void onCommand(final TCommandEvent command
) {
758 // These commands will typically not be seen unless a subclass
759 // overrides onMenu() due to how TApplication dispatches
762 if (!(this instanceof TDesktop
)) {
764 if (command
.equals(cmWindowClose
)) {
765 if ((flags
& NOCLOSEBOX
) == 0) {
766 if ((flags
& HIDEONCLOSE
) == 0) {
768 application
.closeWindow(this);
771 application
.hideWindow(this);
777 if (command
.equals(cmWindowNext
)) {
778 application
.switchWindow(true);
782 if (command
.equals(cmWindowPrevious
)) {
783 application
.switchWindow(false);
787 if (command
.equals(cmWindowMove
)) {
788 inKeyboardResize
= true;
792 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
800 } // if (!(this instanceof TDesktop))
802 // I didn't take it, pass it on to my children
803 super.onCommand(command
);
807 * Handle posted menu events.
809 * @param menu menu event
812 public void onMenu(final TMenuEvent menu
) {
814 if (!(this instanceof TDesktop
)) {
816 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
817 if ((flags
& NOCLOSEBOX
) == 0) {
818 if ((flags
& HIDEONCLOSE
) == 0) {
820 application
.closeWindow(this);
823 application
.hideWindow(this);
829 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
830 application
.switchWindow(true);
834 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
835 application
.switchWindow(false);
839 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
840 inKeyboardResize
= true;
844 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
845 && ((flags
& NOZOOMBOX
) == 0)
855 } // if (!(this instanceof TDesktop))
857 // I didn't take it, pass it on to my children
862 * Method that subclasses can override to handle window/screen resize
865 * @param resize resize event
868 public void onResize(final TResizeEvent resize
) {
869 if (resize
.getType() == TResizeEvent
.Type
.WIDGET
) {
870 if (getChildren().size() == 1) {
871 TWidget child
= getChildren().get(0);
872 if ((child
instanceof TSplitPane
)
873 || (child
instanceof TPanel
)
875 if (this instanceof TDesktop
) {
876 child
.onResize(new TResizeEvent(
877 TResizeEvent
.Type
.WIDGET
,
878 resize
.getWidth(), resize
.getHeight()));
880 child
.onResize(new TResizeEvent(
881 TResizeEvent
.Type
.WIDGET
,
882 resize
.getWidth() - 2, resize
.getHeight() - 2));
889 // Pass on to TWidget.
890 super.onResize(resize
);
893 // ------------------------------------------------------------------------
894 // TWidget ----------------------------------------------------------------
895 // ------------------------------------------------------------------------
898 * Get this TWindow's parent TApplication.
900 * @return this TWindow's parent TApplication
903 public final TApplication
getApplication() {
913 public final Screen
getScreen() {
914 return application
.getScreen();
918 * Called by TApplication.drawChildren() to render on screen.
922 // Draw the box and background first.
923 CellAttributes border
= getBorder();
924 CellAttributes background
= getBackground();
925 int borderType
= getBorderType();
927 drawBox(0, 0, getWidth(), getHeight(), border
, background
, borderType
,
931 int titleLength
= StringUtils
.width(title
);
932 int titleLeft
= (getWidth() - titleLength
- 2) / 2;
933 putCharXY(titleLeft
, 0, ' ', border
);
934 putStringXY(titleLeft
+ 1, 0, title
, border
);
935 putCharXY(titleLeft
+ titleLength
+ 1, 0, ' ', border
);
939 // Draw the close button
940 if ((flags
& NOCLOSEBOX
) == 0) {
941 putCharXY(2, 0, '[', border
);
942 putCharXY(4, 0, ']', border
);
943 if (mouseOnClose() && mouse
.isMouse1()) {
944 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
945 getBorderControls());
947 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
948 getBorderControls());
952 // Draw the maximize button
953 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
955 putCharXY(getWidth() - 5, 0, '[', border
);
956 putCharXY(getWidth() - 3, 0, ']', border
);
957 if (mouseOnMaximize() && mouse
.isMouse1()) {
958 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
959 getBorderControls());
962 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
963 getBorderControls());
965 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
966 getBorderControls());
970 // Draw the resize corner
971 if ((flags
& RESIZABLE
) != 0) {
972 putCharXY(getWidth() - 2, getHeight() - 1,
973 GraphicsChars
.SINGLE_BAR
, getBorderControls());
974 putCharXY(getWidth() - 1, getHeight() - 1,
975 GraphicsChars
.LRCORNER
, getBorderControls());
981 // ------------------------------------------------------------------------
982 // TWindow ----------------------------------------------------------------
983 // ------------------------------------------------------------------------
988 * @return window title
990 public final String
getTitle() {
997 * @param title new window title
999 public final void setTitle(final String title
) {
1004 * Get Z order. Lower number means more in-front.
1006 * @return Z value. Lower number means more in-front.
1008 public final int getZ() {
1013 * Set Z order. Lower number means more in-front.
1015 * @param z the new Z value. Lower number means more in-front.
1017 public final void setZ(final int z
) {
1022 * Add a keypress to be overridden for this window.
1024 * @param key the key to start taking control of
1026 protected void addShortcutKeypress(final TKeypress key
) {
1027 keyboardShortcuts
.add(key
);
1031 * Remove a keypress to be overridden for this window.
1033 * @param key the key to stop taking control of
1035 protected void removeShortcutKeypress(final TKeypress key
) {
1036 keyboardShortcuts
.remove(key
);
1040 * Remove all keypresses to be overridden for this window.
1042 protected void clearShortcutKeypresses() {
1043 keyboardShortcuts
.clear();
1047 * Determine if a keypress is overridden for this window.
1049 * @param key the key to check
1050 * @return true if this window wants to process this key on its own
1052 public boolean isShortcutKeypress(final TKeypress key
) {
1053 return keyboardShortcuts
.contains(key
);
1057 * Get the window's status bar, or null if it does not have one.
1059 * @return the status bar, or null
1061 public TStatusBar
getStatusBar() {
1066 * Set the window's status bar to a new one.
1068 * @param text the status bar text
1069 * @return the status bar
1071 public TStatusBar
newStatusBar(final String text
) {
1072 statusBar
= new TStatusBar(this, text
);
1077 * Set the maximum width for this window.
1079 * @param maximumWindowWidth new maximum width
1081 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
1082 if ((maximumWindowWidth
!= -1)
1083 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
1085 throw new IllegalArgumentException("Maximum window width cannot " +
1086 "be smaller than minimum window width + 1");
1088 this.maximumWindowWidth
= maximumWindowWidth
;
1092 * Set the minimum width for this window.
1094 * @param minimumWindowWidth new minimum width
1096 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
1097 if ((maximumWindowWidth
!= -1)
1098 && (minimumWindowWidth
> maximumWindowWidth
- 1)
1100 throw new IllegalArgumentException("Minimum window width cannot " +
1101 "be larger than maximum window width - 1");
1103 this.minimumWindowWidth
= minimumWindowWidth
;
1107 * Set the maximum height for this window.
1109 * @param maximumWindowHeight new maximum height
1111 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
1112 if ((maximumWindowHeight
!= -1)
1113 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
1115 throw new IllegalArgumentException("Maximum window height cannot " +
1116 "be smaller than minimum window height + 1");
1118 this.maximumWindowHeight
= maximumWindowHeight
;
1122 * Set the minimum height for this window.
1124 * @param minimumWindowHeight new minimum height
1126 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
1127 if ((maximumWindowHeight
!= -1)
1128 && (minimumWindowHeight
> maximumWindowHeight
- 1)
1130 throw new IllegalArgumentException("Minimum window height cannot " +
1131 "be larger than maximum window height - 1");
1133 this.minimumWindowHeight
= minimumWindowHeight
;
1137 * Recenter the window on-screen.
1139 public final void center() {
1140 if ((flags
& CENTERED
) != 0) {
1141 if (getWidth() < getScreen().getWidth()) {
1142 setX((getScreen().getWidth() - getWidth()) / 2);
1146 setY(((application
.getDesktopBottom()
1147 - application
.getDesktopTop()) - getHeight()) / 2);
1151 setY(getY() + application
.getDesktopTop());
1158 public void maximize() {
1163 restoreWindowWidth
= getWidth();
1164 restoreWindowHeight
= getHeight();
1165 restoreWindowX
= getX();
1166 restoreWindowY
= getY();
1167 setWidth(getScreen().getWidth());
1168 setHeight(application
.getDesktopBottom() - application
.getDesktopTop());
1170 setY(application
.getDesktopTop());
1173 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1178 * Restore (unmaximize) window.
1180 public void restore() {
1185 setWidth(restoreWindowWidth
);
1186 setHeight(restoreWindowHeight
);
1187 setX(restoreWindowX
);
1188 setY(restoreWindowY
);
1191 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1196 * Returns true if this window is hidden.
1198 * @return true if this window is hidden, false if the window is shown
1200 public final boolean isHidden() {
1205 * Returns true if this window is shown.
1207 * @return true if this window is shown, false if the window is hidden
1209 public final boolean isShown() {
1214 * Hide window. A hidden window will still have its onIdle() called, and
1215 * will also have onClose() called at application exit. Hidden windows
1216 * will not receive any other events.
1218 public void hide() {
1219 application
.hideWindow(this);
1225 public void show() {
1226 application
.showWindow(this);
1230 * Activate window (bring to top and receive events).
1233 public void activate() {
1234 application
.activateWindow(this);
1238 * Close window. Note that windows without a close box can still be
1239 * closed by calling the close() method.
1242 public void close() {
1243 application
.closeWindow(this);
1247 * See if this window is undergoing any movement/resize/etc.
1249 * @return true if the window is moving
1251 public boolean inMovements() {
1252 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
1259 * Stop any pending movement/resize/etc.
1261 public void stopMovements() {
1262 inWindowResize
= false;
1263 inWindowMove
= false;
1264 inKeyboardResize
= false;
1268 * Returns true if this window is modal.
1270 * @return true if this window is modal
1272 public final boolean isModal() {
1273 if ((flags
& MODAL
) == 0) {
1280 * Returns true if this window has a close box.
1282 * @return true if this window has a close box
1284 public final boolean hasCloseBox() {
1285 if ((flags
& NOCLOSEBOX
) != 0) {
1292 * Returns true if this window has a maximize/zoom box.
1294 * @return true if this window has a maximize/zoom box
1296 public final boolean hasZoomBox() {
1297 if ((flags
& NOZOOMBOX
) != 0) {
1304 * Returns true if this window does not want menus to work while it is
1307 * @return true if this window does not want menus to work while it is
1310 public final boolean hasOverriddenMenu() {
1311 if ((flags
& OVERRIDEMENU
) != 0) {
1318 * Retrieve the background color.
1320 * @return the background color
1322 public CellAttributes
getBackground() {
1324 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1326 assert (isActive());
1327 return getTheme().getColor("twindow.background.windowmove");
1328 } else if (isModal() && inWindowMove
) {
1329 assert (isActive());
1330 return getTheme().getColor("twindow.background.modal");
1331 } else if (isModal()) {
1333 return getTheme().getColor("twindow.background.modal");
1335 return getTheme().getColor("twindow.background.modal.inactive");
1336 } else if (isActive()) {
1337 assert (!isModal());
1338 return getTheme().getColor("twindow.background");
1340 assert (!isModal());
1341 return getTheme().getColor("twindow.background.inactive");
1346 * Retrieve the border color.
1348 * @return the border color
1350 public CellAttributes
getBorder() {
1352 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1355 // The user's terminal never passed a mouse up event, and now
1356 // another window is active but we never finished a drag.
1357 inWindowMove
= false;
1358 inWindowResize
= false;
1359 inKeyboardResize
= false;
1360 return getTheme().getColor("twindow.border.inactive");
1363 return getTheme().getColor("twindow.border.windowmove");
1364 } else if (isModal() && inWindowMove
) {
1365 assert (isActive());
1366 return getTheme().getColor("twindow.border.modal.windowmove");
1367 } else if (isModal()) {
1369 return getTheme().getColor("twindow.border.modal");
1371 return getTheme().getColor("twindow.border.modal.inactive");
1373 } else if (isActive()) {
1374 assert (!isModal());
1375 return getTheme().getColor("twindow.border");
1377 assert (!isModal());
1378 return getTheme().getColor("twindow.border.inactive");
1383 * Retrieve the color used by the window movement/sizing controls.
1385 * @return the color used by the zoom box, resize bar, and close box
1387 public CellAttributes
getBorderControls() {
1389 return getTheme().getColor("twindow.border.modal.windowmove");
1391 return getTheme().getColor("twindow.border.windowmove");
1395 * Retrieve the border line type.
1397 * @return the border line type
1399 private int getBorderType() {
1401 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1403 assert (isActive());
1405 } else if (isModal() && inWindowMove
) {
1406 assert (isActive());
1408 } else if (isModal()) {
1414 } else if (isActive()) {
1422 * Returns true if this window does not want the application-wide mouse
1423 * cursor drawn over it.
1425 * @return true if this window does not want the application-wide mouse
1426 * cursor drawn over it
1428 public boolean hasHiddenMouse() {
1433 * Set request to prevent the application-wide mouse cursor from being
1434 * drawn over this window.
1436 * @param hideMouse if true, this window does not want the
1437 * application-wide mouse cursor drawn over it
1439 public final void setHiddenMouse(final boolean hideMouse
) {
1440 this.hideMouse
= hideMouse
;
1444 * Generate a human-readable string for this window.
1446 * @return a human-readable string
1449 public String
toString() {
1450 return String
.format("%s(%8x) \'%s\' position (%d, %d) geometry %dx%d" +
1451 " hidden %s modal %s", getClass().getName(), hashCode(), title
,
1452 getX(), getY(), getWidth(), getHeight(), hidden
, isModal());