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
) {
545 setWidth(resizeWindowWidth
+ (mouse
.getAbsoluteX()
546 - moveWindowMouseX
));
547 setHeight(resizeWindowHeight
+ (mouse
.getAbsoluteY()
548 - moveWindowMouseY
));
549 if (getX() + getWidth() > getScreen().getWidth()) {
550 setWidth(getScreen().getWidth() - getX());
552 if (getY() + getHeight() > application
.getDesktopBottom()) {
553 setY(application
.getDesktopBottom() - getHeight() + 1);
555 // Don't cover up the menu bar
556 if (getY() < application
.getDesktopTop()) {
557 setY(application
.getDesktopTop());
560 // Keep within min/max bounds
561 if (getWidth() < minimumWindowWidth
) {
562 setWidth(minimumWindowWidth
);
564 if (getHeight() < minimumWindowHeight
) {
565 setHeight(minimumWindowHeight
);
567 if ((maximumWindowWidth
> 0)
568 && (getWidth() > maximumWindowWidth
)
570 setWidth(maximumWindowWidth
);
572 if ((maximumWindowHeight
> 0)
573 && (getHeight() > maximumWindowHeight
)
575 setHeight(maximumWindowHeight
);
577 if (getHeight() + getY() >= getApplication().getDesktopBottom()) {
578 setHeight(getApplication().getDesktopBottom() - getY());
581 // Pass a resize event to my children
582 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
583 getWidth(), getHeight()));
587 // Give the shortcut bar a shot at this.
588 if (statusBar
!= null) {
589 statusBar
.statusBarMouseMotion(mouse
);
592 // I didn't take it, pass it on to my children
593 super.onMouseMotion(mouse
);
599 * @param keypress keystroke event
602 public void onKeypress(final TKeypressEvent keypress
) {
604 if (inWindowMove
|| inWindowResize
) {
605 // ESC or ENTER - Exit size/move
606 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
607 inWindowMove
= false;
608 inWindowResize
= false;
613 if (inKeyboardResize
) {
615 // ESC or ENTER - Exit size/move
616 if (keypress
.equals(kbEsc
) || keypress
.equals(kbEnter
)) {
617 inKeyboardResize
= false;
620 if (keypress
.equals(kbLeft
)) {
625 if (keypress
.equals(kbRight
)) {
626 if (getX() < getScreen().getWidth() - 1) {
630 if (keypress
.equals(kbDown
)) {
631 if (getY() < application
.getDesktopBottom() - 1) {
635 if (keypress
.equals(kbUp
)) {
642 * Only permit keyboard resizing if the window was RESIZABLE.
644 if ((flags
& RESIZABLE
) != 0) {
646 if (keypress
.equals(kbShiftLeft
)) {
647 if ((getWidth() > minimumWindowWidth
)
648 || (minimumWindowWidth
<= 0)
650 setWidth(getWidth() - 1);
653 if (keypress
.equals(kbShiftRight
)) {
654 if ((getWidth() < maximumWindowWidth
)
655 || (maximumWindowWidth
<= 0)
657 setWidth(getWidth() + 1);
660 if (keypress
.equals(kbShiftUp
)) {
661 if ((getHeight() > minimumWindowHeight
)
662 || (minimumWindowHeight
<= 0)
664 setHeight(getHeight() - 1);
667 if (keypress
.equals(kbShiftDown
)) {
668 if ((getHeight() < maximumWindowHeight
)
669 || (maximumWindowHeight
<= 0)
671 setHeight(getHeight() + 1);
675 // Pass a resize event to my children
676 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
677 getWidth(), getHeight()));
679 } // if ((flags & RESIZABLE) != 0)
684 // Give the shortcut bar a shot at this.
685 if (statusBar
!= null) {
686 if (statusBar
.statusBarKeypress(keypress
)) {
691 // These keystrokes will typically not be seen unless a subclass
692 // overrides onMenu() due to how TApplication dispatches
695 if (!(this instanceof TDesktop
)) {
697 // Ctrl-W - close window
698 if (keypress
.equals(kbCtrlW
)) {
699 if ((flags
& NOCLOSEBOX
) == 0) {
700 if ((flags
& HIDEONCLOSE
) == 0) {
702 application
.closeWindow(this);
705 application
.hideWindow(this);
711 // F6 - behave like Alt-TAB
712 if (keypress
.equals(kbF6
)) {
713 application
.switchWindow(true);
717 // Shift-F6 - behave like Shift-Alt-TAB
718 if (keypress
.equals(kbShiftF6
)) {
719 application
.switchWindow(false);
724 if (keypress
.equals(kbF5
) && ((flags
& NOZOOMBOX
) == 0)) {
732 // Ctrl-F5 - size/move
733 if (keypress
.equals(kbCtrlF5
)) {
734 inKeyboardResize
= !inKeyboardResize
;
737 } // if (!(this instanceof TDesktop))
739 // I didn't take it, pass it on to my children
740 super.onKeypress(keypress
);
744 * Handle posted command events.
746 * @param command command event
749 public void onCommand(final TCommandEvent command
) {
751 // These commands will typically not be seen unless a subclass
752 // overrides onMenu() due to how TApplication dispatches
755 if (!(this instanceof TDesktop
)) {
757 if (command
.equals(cmWindowClose
)) {
758 if ((flags
& NOCLOSEBOX
) == 0) {
759 if ((flags
& HIDEONCLOSE
) == 0) {
761 application
.closeWindow(this);
764 application
.hideWindow(this);
770 if (command
.equals(cmWindowNext
)) {
771 application
.switchWindow(true);
775 if (command
.equals(cmWindowPrevious
)) {
776 application
.switchWindow(false);
780 if (command
.equals(cmWindowMove
)) {
781 inKeyboardResize
= true;
785 if (command
.equals(cmWindowZoom
) && ((flags
& NOZOOMBOX
) == 0)) {
793 } // if (!(this instanceof TDesktop))
795 // I didn't take it, pass it on to my children
796 super.onCommand(command
);
800 * Handle posted menu events.
802 * @param menu menu event
805 public void onMenu(final TMenuEvent menu
) {
807 if (!(this instanceof TDesktop
)) {
809 if (menu
.getId() == TMenu
.MID_WINDOW_CLOSE
) {
810 if ((flags
& NOCLOSEBOX
) == 0) {
811 if ((flags
& HIDEONCLOSE
) == 0) {
813 application
.closeWindow(this);
816 application
.hideWindow(this);
822 if (menu
.getId() == TMenu
.MID_WINDOW_NEXT
) {
823 application
.switchWindow(true);
827 if (menu
.getId() == TMenu
.MID_WINDOW_PREVIOUS
) {
828 application
.switchWindow(false);
832 if (menu
.getId() == TMenu
.MID_WINDOW_MOVE
) {
833 inKeyboardResize
= true;
837 if ((menu
.getId() == TMenu
.MID_WINDOW_ZOOM
)
838 && ((flags
& NOZOOMBOX
) == 0)
848 } // if (!(this instanceof TDesktop))
850 // I didn't take it, pass it on to my children
855 * Method that subclasses can override to handle window/screen resize
858 * @param resize resize event
861 public void onResize(final TResizeEvent resize
) {
862 if (resize
.getType() == TResizeEvent
.Type
.WIDGET
) {
863 if (getChildren().size() == 1) {
864 TWidget child
= getChildren().get(0);
865 if ((child
instanceof TSplitPane
)
866 || (child
instanceof TPanel
)
868 if (this instanceof TDesktop
) {
869 child
.onResize(new TResizeEvent(
870 TResizeEvent
.Type
.WIDGET
,
871 resize
.getWidth(), resize
.getHeight()));
873 child
.onResize(new TResizeEvent(
874 TResizeEvent
.Type
.WIDGET
,
875 resize
.getWidth() - 2, resize
.getHeight() - 2));
882 // Pass on to TWidget.
883 super.onResize(resize
);
886 // ------------------------------------------------------------------------
887 // TWidget ----------------------------------------------------------------
888 // ------------------------------------------------------------------------
891 * Get this TWindow's parent TApplication.
893 * @return this TWindow's parent TApplication
896 public final TApplication
getApplication() {
906 public final Screen
getScreen() {
907 return application
.getScreen();
911 * Called by TApplication.drawChildren() to render on screen.
915 // Draw the box and background first.
916 CellAttributes border
= getBorder();
917 CellAttributes background
= getBackground();
918 int borderType
= getBorderType();
920 drawBox(0, 0, getWidth(), getHeight(), border
, background
, borderType
,
924 int titleLength
= StringUtils
.width(title
);
925 int titleLeft
= (getWidth() - titleLength
- 2) / 2;
926 putCharXY(titleLeft
, 0, ' ', border
);
927 putStringXY(titleLeft
+ 1, 0, title
, border
);
928 putCharXY(titleLeft
+ titleLength
+ 1, 0, ' ', border
);
932 // Draw the close button
933 if ((flags
& NOCLOSEBOX
) == 0) {
934 putCharXY(2, 0, '[', border
);
935 putCharXY(4, 0, ']', border
);
936 if (mouseOnClose() && mouse
.isMouse1()) {
937 putCharXY(3, 0, GraphicsChars
.CP437
[0x0F],
938 getBorderControls());
940 putCharXY(3, 0, GraphicsChars
.CP437
[0xFE],
941 getBorderControls());
945 // Draw the maximize button
946 if (!isModal() && ((flags
& NOZOOMBOX
) == 0)) {
948 putCharXY(getWidth() - 5, 0, '[', border
);
949 putCharXY(getWidth() - 3, 0, ']', border
);
950 if (mouseOnMaximize() && mouse
.isMouse1()) {
951 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x0F],
952 getBorderControls());
955 putCharXY(getWidth() - 4, 0, GraphicsChars
.CP437
[0x12],
956 getBorderControls());
958 putCharXY(getWidth() - 4, 0, GraphicsChars
.UPARROW
,
959 getBorderControls());
963 // Draw the resize corner
964 if ((flags
& RESIZABLE
) != 0) {
965 putCharXY(getWidth() - 2, getHeight() - 1,
966 GraphicsChars
.SINGLE_BAR
, getBorderControls());
967 putCharXY(getWidth() - 1, getHeight() - 1,
968 GraphicsChars
.LRCORNER
, getBorderControls());
974 // ------------------------------------------------------------------------
975 // TWindow ----------------------------------------------------------------
976 // ------------------------------------------------------------------------
981 * @return window title
983 public final String
getTitle() {
990 * @param title new window title
992 public final void setTitle(final String title
) {
997 * Get Z order. Lower number means more in-front.
999 * @return Z value. Lower number means more in-front.
1001 public final int getZ() {
1006 * Set Z order. Lower number means more in-front.
1008 * @param z the new Z value. Lower number means more in-front.
1010 public final void setZ(final int z
) {
1015 * Add a keypress to be overridden for this window.
1017 * @param key the key to start taking control of
1019 protected void addShortcutKeypress(final TKeypress key
) {
1020 keyboardShortcuts
.add(key
);
1024 * Remove a keypress to be overridden for this window.
1026 * @param key the key to stop taking control of
1028 protected void removeShortcutKeypress(final TKeypress key
) {
1029 keyboardShortcuts
.remove(key
);
1033 * Remove all keypresses to be overridden for this window.
1035 protected void clearShortcutKeypresses() {
1036 keyboardShortcuts
.clear();
1040 * Determine if a keypress is overridden for this window.
1042 * @param key the key to check
1043 * @return true if this window wants to process this key on its own
1045 public boolean isShortcutKeypress(final TKeypress key
) {
1046 return keyboardShortcuts
.contains(key
);
1050 * Get the window's status bar, or null if it does not have one.
1052 * @return the status bar, or null
1054 public TStatusBar
getStatusBar() {
1059 * Set the window's status bar to a new one.
1061 * @param text the status bar text
1062 * @return the status bar
1064 public TStatusBar
newStatusBar(final String text
) {
1065 statusBar
= new TStatusBar(this, text
);
1070 * Set the maximum width for this window.
1072 * @param maximumWindowWidth new maximum width
1074 public final void setMaximumWindowWidth(final int maximumWindowWidth
) {
1075 if ((maximumWindowWidth
!= -1)
1076 && (maximumWindowWidth
< minimumWindowWidth
+ 1)
1078 throw new IllegalArgumentException("Maximum window width cannot " +
1079 "be smaller than minimum window width + 1");
1081 this.maximumWindowWidth
= maximumWindowWidth
;
1085 * Set the minimum width for this window.
1087 * @param minimumWindowWidth new minimum width
1089 public final void setMinimumWindowWidth(final int minimumWindowWidth
) {
1090 if ((maximumWindowWidth
!= -1)
1091 && (minimumWindowWidth
> maximumWindowWidth
- 1)
1093 throw new IllegalArgumentException("Minimum window width cannot " +
1094 "be larger than maximum window width - 1");
1096 this.minimumWindowWidth
= minimumWindowWidth
;
1100 * Set the maximum height for this window.
1102 * @param maximumWindowHeight new maximum height
1104 public final void setMaximumWindowHeight(final int maximumWindowHeight
) {
1105 if ((maximumWindowHeight
!= -1)
1106 && (maximumWindowHeight
< minimumWindowHeight
+ 1)
1108 throw new IllegalArgumentException("Maximum window height cannot " +
1109 "be smaller than minimum window height + 1");
1111 this.maximumWindowHeight
= maximumWindowHeight
;
1115 * Set the minimum height for this window.
1117 * @param minimumWindowHeight new minimum height
1119 public final void setMinimumWindowHeight(final int minimumWindowHeight
) {
1120 if ((maximumWindowHeight
!= -1)
1121 && (minimumWindowHeight
> maximumWindowHeight
- 1)
1123 throw new IllegalArgumentException("Minimum window height cannot " +
1124 "be larger than maximum window height - 1");
1126 this.minimumWindowHeight
= minimumWindowHeight
;
1130 * Recenter the window on-screen.
1132 public final void center() {
1133 if ((flags
& CENTERED
) != 0) {
1134 if (getWidth() < getScreen().getWidth()) {
1135 setX((getScreen().getWidth() - getWidth()) / 2);
1139 setY(((application
.getDesktopBottom()
1140 - application
.getDesktopTop()) - getHeight()) / 2);
1144 setY(getY() + application
.getDesktopTop());
1151 public void maximize() {
1156 restoreWindowWidth
= getWidth();
1157 restoreWindowHeight
= getHeight();
1158 restoreWindowX
= getX();
1159 restoreWindowY
= getY();
1160 setWidth(getScreen().getWidth());
1161 setHeight(application
.getDesktopBottom() - application
.getDesktopTop());
1163 setY(application
.getDesktopTop());
1166 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1171 * Restore (unmaximize) window.
1173 public void restore() {
1178 setWidth(restoreWindowWidth
);
1179 setHeight(restoreWindowHeight
);
1180 setX(restoreWindowX
);
1181 setY(restoreWindowY
);
1184 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
1189 * Returns true if this window is hidden.
1191 * @return true if this window is hidden, false if the window is shown
1193 public final boolean isHidden() {
1198 * Returns true if this window is shown.
1200 * @return true if this window is shown, false if the window is hidden
1202 public final boolean isShown() {
1207 * Hide window. A hidden window will still have its onIdle() called, and
1208 * will also have onClose() called at application exit. Hidden windows
1209 * will not receive any other events.
1211 public void hide() {
1212 application
.hideWindow(this);
1218 public void show() {
1219 application
.showWindow(this);
1223 * Activate window (bring to top and receive events).
1226 public void activate() {
1227 application
.activateWindow(this);
1231 * Close window. Note that windows without a close box can still be
1232 * closed by calling the close() method.
1235 public void close() {
1236 application
.closeWindow(this);
1240 * See if this window is undergoing any movement/resize/etc.
1242 * @return true if the window is moving
1244 public boolean inMovements() {
1245 if (inWindowResize
|| inWindowMove
|| inKeyboardResize
) {
1252 * Stop any pending movement/resize/etc.
1254 public void stopMovements() {
1255 inWindowResize
= false;
1256 inWindowMove
= false;
1257 inKeyboardResize
= false;
1261 * Returns true if this window is modal.
1263 * @return true if this window is modal
1265 public final boolean isModal() {
1266 if ((flags
& MODAL
) == 0) {
1273 * Returns true if this window has a close box.
1275 * @return true if this window has a close box
1277 public final boolean hasCloseBox() {
1278 if ((flags
& NOCLOSEBOX
) != 0) {
1285 * Returns true if this window has a maximize/zoom box.
1287 * @return true if this window has a maximize/zoom box
1289 public final boolean hasZoomBox() {
1290 if ((flags
& NOZOOMBOX
) != 0) {
1297 * Returns true if this window does not want menus to work while it is
1300 * @return true if this window does not want menus to work while it is
1303 public final boolean hasOverriddenMenu() {
1304 if ((flags
& OVERRIDEMENU
) != 0) {
1311 * Retrieve the background color.
1313 * @return the background color
1315 public CellAttributes
getBackground() {
1317 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1319 assert (isActive());
1320 return getTheme().getColor("twindow.background.windowmove");
1321 } else if (isModal() && inWindowMove
) {
1322 assert (isActive());
1323 return getTheme().getColor("twindow.background.modal");
1324 } else if (isModal()) {
1326 return getTheme().getColor("twindow.background.modal");
1328 return getTheme().getColor("twindow.background.modal.inactive");
1329 } else if (isActive()) {
1330 assert (!isModal());
1331 return getTheme().getColor("twindow.background");
1333 assert (!isModal());
1334 return getTheme().getColor("twindow.background.inactive");
1339 * Retrieve the border color.
1341 * @return the border color
1343 public CellAttributes
getBorder() {
1345 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1348 // The user's terminal never passed a mouse up event, and now
1349 // another window is active but we never finished a drag.
1350 inWindowMove
= false;
1351 inWindowResize
= false;
1352 inKeyboardResize
= false;
1353 return getTheme().getColor("twindow.border.inactive");
1356 return getTheme().getColor("twindow.border.windowmove");
1357 } else if (isModal() && inWindowMove
) {
1358 assert (isActive());
1359 return getTheme().getColor("twindow.border.modal.windowmove");
1360 } else if (isModal()) {
1362 return getTheme().getColor("twindow.border.modal");
1364 return getTheme().getColor("twindow.border.modal.inactive");
1366 } else if (isActive()) {
1367 assert (!isModal());
1368 return getTheme().getColor("twindow.border");
1370 assert (!isModal());
1371 return getTheme().getColor("twindow.border.inactive");
1376 * Retrieve the color used by the window movement/sizing controls.
1378 * @return the color used by the zoom box, resize bar, and close box
1380 public CellAttributes
getBorderControls() {
1382 return getTheme().getColor("twindow.border.modal.windowmove");
1384 return getTheme().getColor("twindow.border.windowmove");
1388 * Retrieve the border line type.
1390 * @return the border line type
1392 private int getBorderType() {
1394 && (inWindowMove
|| inWindowResize
|| inKeyboardResize
)
1396 assert (isActive());
1398 } else if (isModal() && inWindowMove
) {
1399 assert (isActive());
1401 } else if (isModal()) {
1407 } else if (isActive()) {
1415 * Returns true if this window does not want the application-wide mouse
1416 * cursor drawn over it.
1418 * @return true if this window does not want the application-wide mouse
1419 * cursor drawn over it
1421 public boolean hasHiddenMouse() {
1426 * Set request to prevent the application-wide mouse cursor from being
1427 * drawn over this window.
1429 * @param hideMouse if true, this window does not want the
1430 * application-wide mouse cursor drawn over it
1432 public final void setHiddenMouse(final boolean hideMouse
) {
1433 this.hideMouse
= hideMouse
;
1437 * Generate a human-readable string for this window.
1439 * @return a human-readable string
1442 public String
toString() {
1443 return String
.format("%s(%8x) \'%s\' position (%d, %d) geometry %dx%d" +
1444 " hidden %s modal %s", getClass().getName(), hashCode(), title
,
1445 getX(), getY(), getWidth(), getHeight(), hidden
, isModal());