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;
203 * The help topic for this window.
205 protected String helpTopic
= "Help";
207 // ------------------------------------------------------------------------
208 // Constructors -----------------------------------------------------------
209 // ------------------------------------------------------------------------
212 * Public constructor. Window will be located at (0, 0).
214 * @param application TApplication that manages this window
215 * @param title window title, will be centered along the top border
216 * @param width width of window
217 * @param height height of window
219 public TWindow(final TApplication application
, final String title
,
220 final int width
, final int height
) {
222 this(application
, title
, 0, 0, width
, height
, RESIZABLE
);
226 * Public constructor. Window will be located at (0, 0).
228 * @param application TApplication that manages this window
229 * @param title window title, will be centered along the top border
230 * @param width width of window
231 * @param height height of window
232 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
234 public TWindow(final TApplication application
, final String title
,
235 final int width
, final int height
, final int flags
) {
237 this(application
, title
, 0, 0, width
, height
, flags
);
241 * Public constructor.
243 * @param application TApplication that manages this window
244 * @param title window title, will be centered along the top border
245 * @param x column relative to parent
246 * @param y row relative to parent
247 * @param width width of window
248 * @param height height of window
250 public TWindow(final TApplication application
, final String title
,
251 final int x
, final int y
, final int width
, final int height
) {
253 this(application
, title
, x
, y
, width
, height
, RESIZABLE
);
257 * Public constructor.
259 * @param application TApplication that manages this window
260 * @param title window title, will be centered along the top border
261 * @param x column relative to parent
262 * @param y row relative to parent
263 * @param width width of window
264 * @param height height of window
265 * @param flags mask of RESIZABLE, CENTERED, or MODAL
267 public TWindow(final TApplication application
, final String title
,
268 final int x
, final int y
, final int width
, final int height
,
273 // I am my own window and parent
274 setupForTWindow(this, x
, y
+ application
.getDesktopTop(),
279 this.application
= application
;
282 // Minimum width/height are 10 and 2
283 assert (width
>= 10);
284 assert (getHeight() >= 2);
286 // MODAL implies CENTERED
288 this.flags
|= CENTERED
;
291 // Center window if specified
294 // Add me to the application
295 application
.addWindowToApplication(this);
298 // ------------------------------------------------------------------------
299 // Event handlers ---------------------------------------------------------
300 // ------------------------------------------------------------------------
303 * Returns true if the mouse is currently on the close button.
305 * @return true if mouse is currently on the close button
307 protected boolean mouseOnClose() {
308 if ((flags
& NOCLOSEBOX
) != 0) {
312 && (mouse
.getAbsoluteY() == getY())
313 && (mouse
.getAbsoluteX() == getX() + 3)
321 * Returns true if the mouse is currently on the maximize/restore button.
323 * @return true if the mouse is currently on the maximize/restore button
325 protected boolean mouseOnMaximize() {
326 if ((flags
& NOZOOMBOX
) != 0) {
331 && (mouse
.getAbsoluteY() == getY())
332 && (mouse
.getAbsoluteX() == getX() + getWidth() - 4)
340 * Returns true if the mouse is currently on the resizable lower right
343 * @return true if the mouse is currently on the resizable lower right
346 protected boolean mouseOnResize() {
347 if (((flags
& RESIZABLE
) != 0)
350 && (mouse
.getAbsoluteY() == getY() + getHeight() - 1)
351 && ((mouse
.getAbsoluteX() == getX() + getWidth() - 1)
352 || (mouse
.getAbsoluteX() == getX() + getWidth() - 2))
360 * Subclasses should override this method to perform any user prompting
361 * before they are offscreen. Note that unlike other windowing toolkits,
362 * windows can NOT use this function in some manner to avoid being
363 * closed. This is called by application.closeWindow().
365 protected void onPreClose() {
366 // Default: do nothing.
370 * Subclasses should override this method to cleanup resources. This is
371 * called by application.closeWindow().
373 protected void onClose() {
374 // Default: perform widget-specific cleanup.
375 for (TWidget w
: getChildren()) {
381 * Called by application.switchWindow() when this window gets the
382 * focus, and also by application.addWindow().
384 protected void onFocus() {
385 // Default: do nothing
389 * Called by application.switchWindow() when another window gets the
392 protected void onUnfocus() {
393 // Default: do nothing
397 * Called by application.hideWindow().
399 protected void onHide() {
400 // Default: do nothing
404 * Called by application.showWindow().
406 protected void onShow() {
407 // Default: do nothing
411 * Handle mouse button presses.
413 * @param mouse mouse button event
416 public void onMouseDown(final TMouseEvent mouse
) {
419 inKeyboardResize
= false;
420 inWindowMove
= false;
421 inWindowResize
= false;
423 if ((mouse
.getAbsoluteY() == getY())
425 && (getX() <= mouse
.getAbsoluteX())
426 && (mouse
.getAbsoluteX() < getX() + getWidth())
428 && !mouseOnMaximize()
430 // Begin moving window
432 moveWindowMouseX
= mouse
.getAbsoluteX();
433 moveWindowMouseY
= mouse
.getAbsoluteY();
441 if (mouseOnResize()) {
442 // Begin window resize
443 inWindowResize
= true;
444 moveWindowMouseX
= mouse
.getAbsoluteX();
445 moveWindowMouseY
= mouse
.getAbsoluteY();
446 resizeWindowWidth
= getWidth();
447 resizeWindowHeight
= getHeight();
454 // Give the shortcut bar a shot at this.
455 if (statusBar
!= null) {
456 if (statusBar
.statusBarMouseDown(mouse
)) {
461 // I didn't take it, pass it on to my children
462 super.onMouseDown(mouse
);
466 * Handle mouse button releases.
468 * @param mouse mouse button release event
471 public void onMouseUp(final TMouseEvent mouse
) {
474 if ((inWindowMove
) && (mouse
.isMouse1())) {
475 // Stop moving window
476 inWindowMove
= false;
480 if ((inWindowResize
) && (mouse
.isMouse1())) {
481 // Stop resizing window
482 inWindowResize
= false;
486 if (mouse
.isMouse1() && mouseOnClose()) {
487 if ((flags
& HIDEONCLOSE
) == 0) {
489 application
.closeWindow(this);
492 application
.hideWindow(this);
497 if ((mouse
.getAbsoluteY() == getY())
499 && mouseOnMaximize()) {
507 // Pass a resize event to my children
508 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
509 getWidth(), getHeight()));
513 // Give the shortcut bar a shot at this.
514 if (statusBar
!= null) {
515 if (statusBar
.statusBarMouseUp(mouse
)) {
520 // I didn't take it, pass it on to my children
521 super.onMouseUp(mouse
);
525 * Handle mouse movements.
527 * @param mouse mouse motion event
530 public void onMouseMotion(final TMouseEvent mouse
) {
535 setX(oldWindowX
+ (mouse
.getAbsoluteX() - moveWindowMouseX
));
536 setY(oldWindowY
+ (mouse
.getAbsoluteY() - moveWindowMouseY
));
537 // Don't cover up the menu bar
538 if (getY() < application
.getDesktopTop()) {
539 setY(application
.getDesktopTop());
541 // Don't go below the status bar
542 if (getY() >= application
.getDesktopBottom()) {
543 setY(application
.getDesktopBottom() - 1);
548 if (inWindowResize
) {
550 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
551 - moveWindowMouseX
));
552 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
553 - moveWindowMouseY
));
554 if (getX() + getWidth() > getScreen().getWidth()) {
555 setWidth(getScreen().getWidth() - getX());
557 if (getY() + getHeight() > application
.getDesktopBottom()) {
558 setY(application
.getDesktopBottom() - getHeight() + 1);
560 // Don't cover up the menu bar
561 if (getY() < application
.getDesktopTop()) {
562 setY(application
.getDesktopTop());
565 // Keep within min/max bounds
566 if (getWidth() < minimumWindowWidth
) {
567 setWidth(minimumWindowWidth
);
569 if (getHeight() < minimumWindowHeight
) {
570 setHeight(minimumWindowHeight
);
572 if ((maximumWindowWidth
> 0)
573 && (getWidth() > maximumWindowWidth
)
575 setWidth(maximumWindowWidth
);
577 if ((maximumWindowHeight
> 0)
578 && (getHeight() > maximumWindowHeight
)
580 setHeight(maximumWindowHeight
);
582 if (getHeight() + getY() >= getApplication().getDesktopBottom()) {
583 setHeight(getApplication().getDesktopBottom() - getY());
586 // Pass a resize event to my children
587 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
588 getWidth(), getHeight()));
592 // Give the shortcut bar a shot at this.
593 if (statusBar
!= null) {
594 statusBar
.statusBarMouseMotion(mouse
);
597 // I didn't take it, pass it on to my children
598 super.onMouseMotion(mouse
);
604 * @param keypress keystroke event
607 public void onKeypress(final TKeypressEvent keypress
) {
609 if (inWindowMove
|| inWindowResize
) {
610 // ESC or ENTER - Exit size/move
611 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
612 inWindowMove
= false;
613 inWindowResize
= false;
618 if (inKeyboardResize
) {
620 // ESC or ENTER - Exit size/move
621 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
622 inKeyboardResize
= false;
625 if (keypress
.equals(kbLeft
)) {
630 if (keypress
.equals(kbRight
)) {
631 if (getX() < getScreen().getWidth() - 1) {
635 if (keypress
.equals(kbDown
)) {
636 if (getY() < application
.getDesktopBottom() - 1) {
640 if (keypress
.equals(kbUp
)) {
647 * Only permit keyboard resizing if the window was RESIZABLE.
649 if ((flags
& RESIZABLE
) != 0) {
651 if (keypress
.equals(kbShiftLeft
)) {
652 if ((getWidth() > minimumWindowWidth
)
653 || (minimumWindowWidth
<= 0)
655 setWidth(getWidth() - 1);
658 if (keypress
.equals(kbShiftRight
)) {
659 if ((getWidth() < maximumWindowWidth
)
660 || (maximumWindowWidth
<= 0)
662 setWidth(getWidth() + 1);
665 if (keypress
.equals(kbShiftUp
)) {
666 if ((getHeight() > minimumWindowHeight
)
667 || (minimumWindowHeight
<= 0)
669 setHeight(getHeight() - 1);
672 if (keypress
.equals(kbShiftDown
)) {
673 if ((getHeight() < maximumWindowHeight
)
674 || (maximumWindowHeight
<= 0)
676 setHeight(getHeight() + 1);
680 // Pass a resize event to my children
681 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
682 getWidth(), getHeight()));
684 } // if ((flags & RESIZABLE) != 0)
689 // Give the shortcut bar a shot at this.
690 if (statusBar
!= null) {
691 if (statusBar
.statusBarKeypress(keypress
)) {
696 // These keystrokes will typically not be seen unless a subclass
697 // overrides onMenu() due to how TApplication dispatches
700 if (!(this instanceof TDesktop
)) {
702 // Ctrl-W - close window
703 if (keypress
.equals(kbCtrlW
)) {
704 if ((flags
& NOCLOSEBOX
) == 0) {
705 if ((flags
& HIDEONCLOSE
) == 0) {
707 application
.closeWindow(this);
710 application
.hideWindow(this);
716 // F6 - behave like Alt-TAB
717 if (keypress
.equals(kbF6
)) {
718 application
.switchWindow(true);
722 // Shift-F6 - behave like Shift-Alt-TAB
723 if (keypress
.equals(kbShiftF6
)) {
724 application
.switchWindow(false);
729 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
737 // Ctrl-F5 - size/move
738 if (keypress
.equals(kbCtrlF5
)) {
739 inKeyboardResize
= !inKeyboardResize
;
742 } // if (!(this instanceof TDesktop))
744 // I didn't take it, pass it on to my children
745 super.onKeypress(keypress
);
749 * Handle posted command events.
751 * @param command command event
754 public void onCommand(final TCommandEvent command
) {
756 // These commands will typically not be seen unless a subclass
757 // overrides onMenu() due to how TApplication dispatches
760 if (!(this instanceof TDesktop
)) {
762 if (command
.equals(cmWindowClose
)) {
763 if ((flags
& NOCLOSEBOX
) == 0) {
764 if ((flags
& HIDEONCLOSE
) == 0) {
766 application
.closeWindow(this);
769 application
.hideWindow(this);
775 if (command
.equals(cmWindowNext
)) {
776 application
.switchWindow(true);
780 if (command
.equals(cmWindowPrevious
)) {
781 application
.switchWindow(false);
785 if (command
.equals(cmWindowMove
)) {
786 inKeyboardResize
= true;
790 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
798 } // if (!(this instanceof TDesktop))
800 // I didn't take it, pass it on to my children
801 super.onCommand(command
);
805 * Handle posted menu events.
807 * @param menu menu event
810 public void onMenu(final TMenuEvent menu
) {
812 if (!(this instanceof TDesktop
)) {
814 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
815 if ((flags
& NOCLOSEBOX
) == 0) {
816 if ((flags
& HIDEONCLOSE
) == 0) {
818 application
.closeWindow(this);
821 application
.hideWindow(this);
827 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
828 application
.switchWindow(true);
832 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
833 application
.switchWindow(false);
837 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
838 inKeyboardResize
= true;
842 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
843 && ((flags
& NOZOOMBOX
) == 0)
853 } // if (!(this instanceof TDesktop))
855 // I didn't take it, pass it on to my children
860 * Method that subclasses can override to handle window/screen resize
863 * @param resize resize event
866 public void onResize(final TResizeEvent resize
) {
867 if (resize
.getType() == TResizeEvent
.Type
.WIDGET
) {
868 if (getChildren().size() == 1) {
869 TWidget child
= getChildren().get(0);
870 if ((child
instanceof TSplitPane
)
871 || (child
instanceof TPanel
)
873 if (this instanceof TDesktop
) {
874 child
.onResize(new TResizeEvent(
875 TResizeEvent
.Type
.WIDGET
,
876 resize
.getWidth(), resize
.getHeight()));
878 child
.onResize(new TResizeEvent(
879 TResizeEvent
.Type
.WIDGET
,
880 resize
.getWidth() - 2, resize
.getHeight() - 2));
887 // Pass on to TWidget.
888 super.onResize(resize
);
891 // ------------------------------------------------------------------------
892 // TWidget ----------------------------------------------------------------
893 // ------------------------------------------------------------------------
896 * Get this TWindow's parent TApplication.
898 * @return this TWindow's parent TApplication
901 public final TApplication
getApplication() {
911 public final Screen
getScreen() {
912 return application
.getScreen();
916 * Called by TApplication.drawChildren() to render on screen.
920 // Draw the box and background first.
921 CellAttributes border
= getBorder();
922 CellAttributes background
= getBackground();
923 int borderType
= getBorderType();
925 drawBox(0, 0, getWidth(), getHeight(), border
, background
, borderType
,
929 int titleLength
= StringUtils
.width(title
);
930 int titleLeft
= (getWidth() - titleLength
- 2) / 2;
931 putCharXY(titleLeft
, 0, ' ', border
);
932 putStringXY(titleLeft
+ 1, 0, title
, border
);
933 putCharXY(titleLeft
+ titleLength
+ 1, 0, ' ', border
);
937 // Draw the close button
938 if ((flags
& NOCLOSEBOX
) == 0) {
939 putCharXY(2, 0, '[', border
);
940 putCharXY(4, 0, ']', border
);
941 if (mouseOnClose() && mouse
.isMouse1()) {
942 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
943 getBorderControls());
945 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
946 getBorderControls());
950 // Draw the maximize button
951 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
953 putCharXY(getWidth() - 5, 0, '[', border
);
954 putCharXY(getWidth() - 3, 0, ']', border
);
955 if (mouseOnMaximize() && mouse
.isMouse1()) {
956 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
957 getBorderControls());
960 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
961 getBorderControls());
963 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
964 getBorderControls());
968 // Draw the resize corner
969 if ((flags
& RESIZABLE
) != 0) {
970 putCharXY(getWidth() - 2, getHeight() - 1,
971 GraphicsChars
.SINGLE_BAR
, getBorderControls());
972 putCharXY(getWidth() - 1, getHeight() - 1,
973 GraphicsChars
.LRCORNER
, getBorderControls());
979 // ------------------------------------------------------------------------
980 // TWindow ----------------------------------------------------------------
981 // ------------------------------------------------------------------------
986 * @return window title
988 public final String
getTitle() {
995 * @param title new window title
997 public final void setTitle(final String title
) {
1002 * Get Z order. Lower number means more in-front.
1004 * @return Z value. Lower number means more in-front.
1006 public final int getZ() {
1011 * Set Z order. Lower number means more in-front.
1013 * @param z the new Z value. Lower number means more in-front.
1015 public final void setZ(final int z
) {
1020 * Add a keypress to be overridden for this window.
1022 * @param key the key to start taking control of
1024 protected void addShortcutKeypress(final TKeypress key
) {
1025 keyboardShortcuts
.add(key
);
1029 * Remove a keypress to be overridden for this window.
1031 * @param key the key to stop taking control of
1033 protected void removeShortcutKeypress(final TKeypress key
) {
1034 keyboardShortcuts
.remove(key
);
1038 * Remove all keypresses to be overridden for this window.
1040 protected void clearShortcutKeypresses() {
1041 keyboardShortcuts
.clear();
1045 * Determine if a keypress is overridden for this window.
1047 * @param key the key to check
1048 * @return true if this window wants to process this key on its own
1050 public boolean isShortcutKeypress(final TKeypress key
) {
1051 return keyboardShortcuts
.contains(key
);
1055 * Get the window's status bar, or null if it does not have one.
1057 * @return the status bar, or null
1059 public TStatusBar
getStatusBar() {
1064 * Set the window's status bar to a new one.
1066 * @param text the status bar text
1067 * @return the status bar
1069 public TStatusBar
newStatusBar(final String text
) {
1070 statusBar
= new TStatusBar(this, text
);
1075 * Set the maximum width for this window.
1077 * @param maximumWindowWidth new maximum width
1079 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
1080 if ((maximumWindowWidth
!= -1)
1081 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
1083 throw new IllegalArgumentException("Maximum window width cannot " +
1084 "be smaller than minimum window width + 1");
1086 this.maximumWindowWidth
= maximumWindowWidth
;
1090 * Set the minimum width for this window.
1092 * @param minimumWindowWidth new minimum width
1094 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
1095 if ((maximumWindowWidth
!= -1)
1096 && (minimumWindowWidth
> maximumWindowWidth
- 1)
1098 throw new IllegalArgumentException("Minimum window width cannot " +
1099 "be larger than maximum window width - 1");
1101 this.minimumWindowWidth
= minimumWindowWidth
;
1105 * Set the maximum height for this window.
1107 * @param maximumWindowHeight new maximum height
1109 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
1110 if ((maximumWindowHeight
!= -1)
1111 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
1113 throw new IllegalArgumentException("Maximum window height cannot " +
1114 "be smaller than minimum window height + 1");
1116 this.maximumWindowHeight
= maximumWindowHeight
;
1120 * Set the minimum height for this window.
1122 * @param minimumWindowHeight new minimum height
1124 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
1125 if ((maximumWindowHeight
!= -1)
1126 && (minimumWindowHeight
> maximumWindowHeight
- 1)
1128 throw new IllegalArgumentException("Minimum window height cannot " +
1129 "be larger than maximum window height - 1");
1131 this.minimumWindowHeight
= minimumWindowHeight
;
1135 * Recenter the window on-screen.
1137 public final void center() {
1138 if ((flags
& CENTERED
) != 0) {
1139 if (getWidth() < getScreen().getWidth()) {
1140 setX((getScreen().getWidth() - getWidth()) / 2);
1144 setY(((application
.getDesktopBottom()
1145 - application
.getDesktopTop()) - getHeight()) / 2);
1149 setY(getY() + application
.getDesktopTop());
1156 public void maximize() {
1161 restoreWindowWidth
= getWidth();
1162 restoreWindowHeight
= getHeight();
1163 restoreWindowX
= getX();
1164 restoreWindowY
= getY();
1165 setWidth(getScreen().getWidth());
1166 setHeight(application
.getDesktopBottom() - application
.getDesktopTop());
1168 setY(application
.getDesktopTop());
1171 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1176 * Restore (unmaximize) window.
1178 public void restore() {
1183 setWidth(restoreWindowWidth
);
1184 setHeight(restoreWindowHeight
);
1185 setX(restoreWindowX
);
1186 setY(restoreWindowY
);
1189 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1194 * Returns true if this window is hidden.
1196 * @return true if this window is hidden, false if the window is shown
1198 public final boolean isHidden() {
1203 * Returns true if this window is shown.
1205 * @return true if this window is shown, false if the window is hidden
1207 public final boolean isShown() {
1212 * Hide window. A hidden window will still have its onIdle() called, and
1213 * will also have onClose() called at application exit. Hidden windows
1214 * will not receive any other events.
1216 public void hide() {
1217 application
.hideWindow(this);
1223 public void show() {
1224 application
.showWindow(this);
1228 * Activate window (bring to top and receive events).
1231 public void activate() {
1232 application
.activateWindow(this);
1236 * Close window. Note that windows without a close box can still be
1237 * closed by calling the close() method.
1240 public void close() {
1241 application
.closeWindow(this);
1245 * See if this window is undergoing any movement/resize/etc.
1247 * @return true if the window is moving
1249 public boolean inMovements() {
1250 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
1257 * Stop any pending movement/resize/etc.
1259 public void stopMovements() {
1260 inWindowResize
= false;
1261 inWindowMove
= false;
1262 inKeyboardResize
= false;
1266 * Returns true if this window is modal.
1268 * @return true if this window is modal
1270 public final boolean isModal() {
1271 if ((flags
& MODAL
) == 0) {
1278 * Returns true if this window has a close box.
1280 * @return true if this window has a close box
1282 public final boolean hasCloseBox() {
1283 if ((flags
& NOCLOSEBOX
) != 0) {
1290 * Returns true if this window has a maximize/zoom box.
1292 * @return true if this window has a maximize/zoom box
1294 public final boolean hasZoomBox() {
1295 if ((flags
& NOZOOMBOX
) != 0) {
1302 * Returns true if this window does not want menus to work while it is
1305 * @return true if this window does not want menus to work while it is
1308 public final boolean hasOverriddenMenu() {
1309 if ((flags
& OVERRIDEMENU
) != 0) {
1316 * Retrieve the background color.
1318 * @return the background color
1320 public CellAttributes
getBackground() {
1322 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1324 assert (isActive());
1325 return getTheme().getColor("twindow.background.windowmove");
1326 } else if (isModal() && inWindowMove
) {
1327 assert (isActive());
1328 return getTheme().getColor("twindow.background.modal");
1329 } else if (isModal()) {
1331 return getTheme().getColor("twindow.background.modal");
1333 return getTheme().getColor("twindow.background.modal.inactive");
1334 } else if (isActive()) {
1335 assert (!isModal());
1336 return getTheme().getColor("twindow.background");
1338 assert (!isModal());
1339 return getTheme().getColor("twindow.background.inactive");
1344 * Retrieve the border color.
1346 * @return the border color
1348 public CellAttributes
getBorder() {
1350 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1353 // The user's terminal never passed a mouse up event, and now
1354 // another window is active but we never finished a drag.
1355 inWindowMove
= false;
1356 inWindowResize
= false;
1357 inKeyboardResize
= false;
1358 return getTheme().getColor("twindow.border.inactive");
1361 return getTheme().getColor("twindow.border.windowmove");
1362 } else if (isModal() && inWindowMove
) {
1363 assert (isActive());
1364 return getTheme().getColor("twindow.border.modal.windowmove");
1365 } else if (isModal()) {
1367 return getTheme().getColor("twindow.border.modal");
1369 return getTheme().getColor("twindow.border.modal.inactive");
1371 } else if (isActive()) {
1372 assert (!isModal());
1373 return getTheme().getColor("twindow.border");
1375 assert (!isModal());
1376 return getTheme().getColor("twindow.border.inactive");
1381 * Retrieve the color used by the window movement/sizing controls.
1383 * @return the color used by the zoom box, resize bar, and close box
1385 public CellAttributes
getBorderControls() {
1387 return getTheme().getColor("twindow.border.modal.windowmove");
1389 return getTheme().getColor("twindow.border.windowmove");
1393 * Retrieve the border line type.
1395 * @return the border line type
1397 private int getBorderType() {
1399 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1401 assert (isActive());
1403 } else if (isModal() && inWindowMove
) {
1404 assert (isActive());
1406 } else if (isModal()) {
1412 } else if (isActive()) {
1420 * Returns true if this window does not want the application-wide mouse
1421 * cursor drawn over it.
1423 * @return true if this window does not want the application-wide mouse
1424 * cursor drawn over it
1426 public boolean hasHiddenMouse() {
1431 * Set request to prevent the application-wide mouse cursor from being
1432 * drawn over this window.
1434 * @param hideMouse if true, this window does not want the
1435 * application-wide mouse cursor drawn over it
1437 public final void setHiddenMouse(final boolean hideMouse
) {
1438 this.hideMouse
= hideMouse
;
1442 * Get this window's help topic to load.
1444 * @return the topic name
1446 public String
getHelpTopic() {
1451 * Generate a human-readable string for this window.
1453 * @return a human-readable string
1456 public String
toString() {
1457 return String
.format("%s(%8x) \'%s\' Z %d position (%d, %d) " +
1458 "geometry %dx%d hidden %s modal %s",
1459 getClass().getName(), hashCode(), title
, getZ(),
1460 getX(), getY(), getWidth(), getHeight(), hidden
, isModal());