TButton and TLabel
[fanfix.git] / src / jexer / TWindow.java
CommitLineData
48e27807
KL
1/**
2 * Jexer - Java Text User Interface
3 *
4 * License: LGPLv3 or later
5 *
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
9 *
10 * Copyright (C) 2015 Kevin Lamonte
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * 02110-1301 USA
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
30 */
31package jexer;
32
33import jexer.bits.Cell;
34import jexer.bits.CellAttributes;
35import jexer.bits.GraphicsChars;
36import jexer.event.TCommandEvent;
37import jexer.event.TKeypressEvent;
38import jexer.event.TMenuEvent;
39import jexer.event.TMouseEvent;
40import jexer.event.TResizeEvent;
41import jexer.io.Screen;
928811d8 42import jexer.menu.TMenu;
48e27807
KL
43import static jexer.TCommand.*;
44import static jexer.TKeypress.*;
45
46/**
47 * TWindow is the top-level container and drawing surface for other widgets.
48 */
a06459bd 49public class TWindow extends TWidget implements Comparable<TWindow> {
48e27807
KL
50
51 /**
52 * Window's parent TApplication.
53 */
fca67db0 54 private TApplication application;
48e27807
KL
55
56 /**
57 * Get this TWindow's parent TApplication.
58 *
59 * @return this TWindow's parent TApplication
60 */
928811d8 61 @Override
48e27807
KL
62 public final TApplication getApplication() {
63 return application;
64 }
65
66 /**
67 * Get the Screen.
68 *
69 * @return the Screen
70 */
928811d8 71 @Override
48e27807
KL
72 public final Screen getScreen() {
73 return application.getScreen();
74 }
75
76 /**
77 * Window title.
78 */
fca67db0
KL
79 private String title = "";
80
81 /**
82 * Get window title.
83 *
84 * @return window title
85 */
86 public final String getTitle() {
87 return title;
88 }
89
90 /**
91 * Set window title.
92 *
93 * @param title new window title
94 */
95 public final void setTitle(final String title) {
96 this.title = title;
97 }
48e27807
KL
98
99 /**
100 * Window is resizable (default yes).
101 */
102 public static final int RESIZABLE = 0x01;
103
104 /**
105 * Window is modal (default no).
106 */
107 public static final int MODAL = 0x02;
108
109 /**
110 * Window is centered (default no).
111 */
112 public static final int CENTERED = 0x04;
113
114 /**
115 * Window flags.
116 */
117 private int flags = RESIZABLE;
118
119 /**
120 * Z order. Lower number means more in-front.
121 */
122 private int z = 0;
123
a06459bd
KL
124 /**
125 * Get Z order. Lower number means more in-front.
126 *
127 * @return Z value. Lower number means more in-front.
128 */
129 public final int getZ() {
130 return z;
131 }
132
133 /**
134 * Set Z order. Lower number means more in-front.
135 *
136 * @param z the new Z value. Lower number means more in-front.
137 */
138 public final void setZ(final int z) {
139 this.z = z;
140 }
141
48e27807
KL
142 /**
143 * If true, then the user clicked on the title bar and is moving the
144 * window.
145 */
146 private boolean inWindowMove = false;
147
148 /**
149 * If true, then the user clicked on the bottom right corner and is
150 * resizing the window.
151 */
152 private boolean inWindowResize = false;
153
154 /**
155 * If true, then the user selected "Size/Move" (or hit Ctrl-F5) and is
156 * resizing/moving the window via the keyboard.
157 */
158 private boolean inKeyboardResize = false;
159
160 /**
161 * If true, this window is maximized.
162 */
163 private boolean maximized = false;
164
165 /**
166 * Remember mouse state.
167 */
928811d8 168 protected TMouseEvent mouse;
48e27807
KL
169
170 // For moving the window. resizing also uses moveWindowMouseX/Y
171 private int moveWindowMouseX;
172 private int moveWindowMouseY;
173 private int oldWindowX;
174 private int oldWindowY;
175
176 // Resizing
177 private int resizeWindowWidth;
178 private int resizeWindowHeight;
179 private int minimumWindowWidth = 10;
180 private int minimumWindowHeight = 2;
181 private int maximumWindowWidth = -1;
182 private int maximumWindowHeight = -1;
183
184 // For maximize/restore
185 private int restoreWindowWidth;
186 private int restoreWindowHeight;
187 private int restoreWindowX;
188 private int restoreWindowY;
189
190 /**
191 * Public constructor. Window will be located at (0, 0).
192 *
193 * @param application TApplication that manages this window
194 * @param title window title, will be centered along the top border
195 * @param width width of window
196 * @param height height of window
197 */
198 public TWindow(final TApplication application, final String title,
199 final int width, final int height) {
200
201 this(application, title, 0, 0, width, height, RESIZABLE);
202 }
203
204 /**
205 * Public constructor. Window will be located at (0, 0).
206 *
207 * @param application TApplication that manages this window
208 * @param title window title, will be centered along the top border
209 * @param width width of window
210 * @param height height of window
211 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
212 */
213 public TWindow(final TApplication application, final String title,
214 final int width, final int height, final int flags) {
215
216 this(application, title, 0, 0, width, height, flags);
217 }
218
219 /**
220 * Public constructor.
221 *
222 * @param application TApplication that manages this window
223 * @param title window title, will be centered along the top border
224 * @param x column relative to parent
225 * @param y row relative to parent
226 * @param width width of window
227 * @param height height of window
228 */
229 public TWindow(final TApplication application, final String title,
230 final int x, final int y, final int width, final int height) {
231
232 this(application, title, x, y, width, height, RESIZABLE);
233 }
234
235 /**
236 * Public constructor.
237 *
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
244 * @param flags mask of RESIZABLE, CENTERED, or MODAL
245 */
246 public TWindow(final TApplication application, final String title,
247 final int x, final int y, final int width, final int height,
248 final int flags) {
249
fca67db0
KL
250 super();
251
48e27807 252 // I am my own window and parent
fca67db0
KL
253 setupForTWindow(this, x, y + application.getDesktopTop(),
254 width, height);
48e27807
KL
255
256 // Save fields
257 this.title = title;
258 this.application = application;
48e27807
KL
259 this.flags = flags;
260
261 // Minimum width/height are 10 and 2
262 assert (width >= 10);
fca67db0 263 assert (getHeight() >= 2);
48e27807
KL
264
265 // MODAL implies CENTERED
266 if (isModal()) {
267 this.flags |= CENTERED;
268 }
269
270 // Center window if specified
271 center();
272
273 // Add me to the application
274 application.addWindow(this);
275 }
276
277 /**
278 * Recenter the window on-screen.
279 */
280 public final void center() {
281 if ((flags & CENTERED) != 0) {
fca67db0
KL
282 if (getWidth() < getScreen().getWidth()) {
283 setX((getScreen().getWidth() - getWidth()) / 2);
48e27807 284 } else {
fca67db0 285 setX(0);
48e27807 286 }
fca67db0
KL
287 setY(((application.getDesktopBottom()
288 - application.getDesktopTop()) - getHeight()) / 2);
289 if (getY() < 0) {
290 setY(0);
48e27807 291 }
fca67db0 292 setY(getY() + application.getDesktopTop());
48e27807
KL
293 }
294 }
295
296 /**
297 * Returns true if this window is modal.
298 *
299 * @return true if this window is modal
300 */
301 public final boolean isModal() {
302 if ((flags & MODAL) == 0) {
303 return false;
304 }
305 return true;
306 }
307
308 /**
309 * Comparison operator sorts on z.
310 *
311 * @param that another TWindow instance
312 * @return difference between this.z and that.z
313 */
a06459bd
KL
314 @Override
315 public final int compareTo(final TWindow that) {
316 return (this.z - that.z);
48e27807
KL
317 }
318
319 /**
320 * Returns true if the mouse is currently on the close button.
321 *
322 * @return true if mouse is currently on the close button
323 */
324 private boolean mouseOnClose() {
325 if ((mouse != null)
fca67db0
KL
326 && (mouse.getAbsoluteY() == getY())
327 && (mouse.getAbsoluteX() == getX() + 3)
48e27807
KL
328 ) {
329 return true;
330 }
331 return false;
332 }
333
334 /**
335 * Returns true if the mouse is currently on the maximize/restore button.
336 *
337 * @return true if the mouse is currently on the maximize/restore button
338 */
339 private boolean mouseOnMaximize() {
340 if ((mouse != null)
341 && !isModal()
fca67db0
KL
342 && (mouse.getAbsoluteY() == getY())
343 && (mouse.getAbsoluteX() == getX() + getWidth() - 4)
48e27807
KL
344 ) {
345 return true;
346 }
347 return false;
348 }
349
350 /**
351 * Returns true if the mouse is currently on the resizable lower right
352 * corner.
353 *
354 * @return true if the mouse is currently on the resizable lower right
355 * corner
356 */
357 private boolean mouseOnResize() {
358 if (((flags & RESIZABLE) != 0)
359 && !isModal()
360 && (mouse != null)
fca67db0
KL
361 && (mouse.getAbsoluteY() == getY() + getHeight() - 1)
362 && ((mouse.getAbsoluteX() == getX() + getWidth() - 1)
363 || (mouse.getAbsoluteX() == getX() + getWidth() - 2))
48e27807
KL
364 ) {
365 return true;
366 }
367 return false;
368 }
369
370 /**
371 * Retrieve the background color.
372 *
373 * @return the background color
374 */
30d336cc 375 public final CellAttributes getBackground() {
48e27807
KL
376 if (!isModal()
377 && (inWindowMove || inWindowResize || inKeyboardResize)
378 ) {
fca67db0 379 assert (getActive());
928811d8 380 return getTheme().getColor("twindow.background.windowmove");
48e27807 381 } else if (isModal() && inWindowMove) {
fca67db0 382 assert (getActive());
928811d8 383 return getTheme().getColor("twindow.background.modal");
48e27807 384 } else if (isModal()) {
fca67db0 385 if (getActive()) {
928811d8 386 return getTheme().getColor("twindow.background.modal");
48e27807 387 }
928811d8 388 return getTheme().getColor("twindow.background.modal.inactive");
fca67db0 389 } else if (getActive()) {
48e27807 390 assert (!isModal());
928811d8 391 return getTheme().getColor("twindow.background");
48e27807
KL
392 } else {
393 assert (!isModal());
928811d8 394 return getTheme().getColor("twindow.background.inactive");
48e27807
KL
395 }
396 }
397
398 /**
399 * Retrieve the border color.
400 *
401 * @return the border color
402 */
928811d8 403 private CellAttributes getBorder() {
48e27807
KL
404 if (!isModal()
405 && (inWindowMove || inWindowResize || inKeyboardResize)
406 ) {
fca67db0 407 assert (getActive());
928811d8 408 return getTheme().getColor("twindow.border.windowmove");
48e27807 409 } else if (isModal() && inWindowMove) {
fca67db0 410 assert (getActive());
928811d8 411 return getTheme().getColor("twindow.border.modal.windowmove");
48e27807 412 } else if (isModal()) {
fca67db0 413 if (getActive()) {
928811d8 414 return getTheme().getColor("twindow.border.modal");
48e27807 415 } else {
928811d8 416 return getTheme().getColor("twindow.border.modal.inactive");
48e27807 417 }
fca67db0 418 } else if (getActive()) {
48e27807 419 assert (!isModal());
928811d8 420 return getTheme().getColor("twindow.border");
48e27807
KL
421 } else {
422 assert (!isModal());
928811d8 423 return getTheme().getColor("twindow.border.inactive");
48e27807
KL
424 }
425 }
426
427 /**
428 * Retrieve the border line type.
429 *
430 * @return the border line type
431 */
928811d8 432 private int getBorderType() {
48e27807
KL
433 if (!isModal()
434 && (inWindowMove || inWindowResize || inKeyboardResize)
435 ) {
fca67db0 436 assert (getActive());
48e27807
KL
437 return 1;
438 } else if (isModal() && inWindowMove) {
fca67db0 439 assert (getActive());
48e27807
KL
440 return 1;
441 } else if (isModal()) {
fca67db0 442 if (getActive()) {
48e27807
KL
443 return 2;
444 } else {
445 return 1;
446 }
fca67db0 447 } else if (getActive()) {
48e27807
KL
448 return 2;
449 } else {
450 return 1;
451 }
452 }
453
454 /**
455 * Subclasses should override this method to cleanup resources. This is
456 * called by application.closeWindow().
457 */
458 public void onClose() {
459 // Default: do nothing
460 }
461
462 /**
463 * Called by TApplication.drawChildren() to render on screen.
464 */
465 @Override
466 public void draw() {
467 // Draw the box and background first.
468 CellAttributes border = getBorder();
469 CellAttributes background = getBackground();
470 int borderType = getBorderType();
471
fca67db0 472 getScreen().drawBox(0, 0, getWidth(), getHeight(), border,
48e27807
KL
473 background, borderType, true);
474
475 // Draw the title
fca67db0 476 int titleLeft = (getWidth() - title.length() - 2) / 2;
48e27807
KL
477 putCharXY(titleLeft, 0, ' ', border);
478 putStrXY(titleLeft + 1, 0, title);
479 putCharXY(titleLeft + title.length() + 1, 0, ' ', border);
480
fca67db0 481 if (getActive()) {
48e27807
KL
482
483 // Draw the close button
484 putCharXY(2, 0, '[', border);
485 putCharXY(4, 0, ']', border);
486 if (mouseOnClose() && mouse.getMouse1()) {
487 putCharXY(3, 0, GraphicsChars.CP437[0x0F],
488 !isModal()
928811d8
KL
489 ? getTheme().getColor("twindow.border.windowmove")
490 : getTheme().getColor("twindow.border.modal.windowmove"));
48e27807
KL
491 } else {
492 putCharXY(3, 0, GraphicsChars.CP437[0xFE],
493 !isModal()
928811d8
KL
494 ? getTheme().getColor("twindow.border.windowmove")
495 : getTheme().getColor("twindow.border.modal.windowmove"));
48e27807
KL
496 }
497
498 // Draw the maximize button
499 if (!isModal()) {
500
fca67db0
KL
501 putCharXY(getWidth() - 5, 0, '[', border);
502 putCharXY(getWidth() - 3, 0, ']', border);
48e27807 503 if (mouseOnMaximize() && mouse.getMouse1()) {
fca67db0 504 putCharXY(getWidth() - 4, 0, GraphicsChars.CP437[0x0F],
928811d8 505 getTheme().getColor("twindow.border.windowmove"));
48e27807
KL
506 } else {
507 if (maximized) {
fca67db0 508 putCharXY(getWidth() - 4, 0, GraphicsChars.CP437[0x12],
928811d8 509 getTheme().getColor("twindow.border.windowmove"));
48e27807 510 } else {
fca67db0 511 putCharXY(getWidth() - 4, 0, GraphicsChars.UPARROW,
928811d8 512 getTheme().getColor("twindow.border.windowmove"));
48e27807
KL
513 }
514 }
515
516 // Draw the resize corner
517 if ((flags & RESIZABLE) != 0) {
928811d8
KL
518 putCharXY(getWidth() - 2, getHeight() - 1,
519 GraphicsChars.SINGLE_BAR,
520 getTheme().getColor("twindow.border.windowmove"));
521 putCharXY(getWidth() - 1, getHeight() - 1,
522 GraphicsChars.LRCORNER,
523 getTheme().getColor("twindow.border.windowmove"));
48e27807
KL
524 }
525 }
526 }
527 }
528
529 /**
530 * Handle mouse button presses.
531 *
532 * @param mouse mouse button event
533 */
534 @Override
535 public void onMouseDown(final TMouseEvent mouse) {
536 this.mouse = mouse;
537 application.setRepaint();
538
539 inKeyboardResize = false;
540
fca67db0 541 if ((mouse.getAbsoluteY() == getY())
48e27807 542 && mouse.getMouse1()
fca67db0
KL
543 && (getX() <= mouse.getAbsoluteX())
544 && (mouse.getAbsoluteX() < getX() + getWidth())
48e27807
KL
545 && !mouseOnClose()
546 && !mouseOnMaximize()
547 ) {
548 // Begin moving window
549 inWindowMove = true;
550 moveWindowMouseX = mouse.getAbsoluteX();
551 moveWindowMouseY = mouse.getAbsoluteY();
fca67db0
KL
552 oldWindowX = getX();
553 oldWindowY = getY();
48e27807
KL
554 if (maximized) {
555 maximized = false;
556 }
557 return;
558 }
559 if (mouseOnResize()) {
560 // Begin window resize
561 inWindowResize = true;
562 moveWindowMouseX = mouse.getAbsoluteX();
563 moveWindowMouseY = mouse.getAbsoluteY();
fca67db0
KL
564 resizeWindowWidth = getWidth();
565 resizeWindowHeight = getHeight();
48e27807
KL
566 if (maximized) {
567 maximized = false;
568 }
569 return;
570 }
571
572 // I didn't take it, pass it on to my children
573 super.onMouseDown(mouse);
574 }
575
576 /**
577 * Maximize window.
578 */
579 private void maximize() {
fca67db0
KL
580 restoreWindowWidth = getWidth();
581 restoreWindowHeight = getHeight();
582 restoreWindowX = getX();
583 restoreWindowY = getY();
584 setWidth(getScreen().getWidth());
585 setHeight(application.getDesktopBottom() - 1);
586 setX(0);
587 setY(1);
48e27807
KL
588 maximized = true;
589 }
590
591 /**
592 * Restote (unmaximize) window.
593 */
594 private void restore() {
fca67db0
KL
595 setWidth(restoreWindowWidth);
596 setHeight(restoreWindowHeight);
597 setX(restoreWindowX);
598 setY(restoreWindowY);
48e27807
KL
599 maximized = false;
600 }
601
602 /**
603 * Handle mouse button releases.
604 *
605 * @param mouse mouse button release event
606 */
607 @Override
608 public void onMouseUp(final TMouseEvent mouse) {
609 this.mouse = mouse;
610 application.setRepaint();
611
612 if ((inWindowMove) && (mouse.getMouse1())) {
613 // Stop moving window
614 inWindowMove = false;
615 return;
616 }
617
618 if ((inWindowResize) && (mouse.getMouse1())) {
619 // Stop resizing window
620 inWindowResize = false;
621 return;
622 }
623
624 if (mouse.getMouse1() && mouseOnClose()) {
625 // Close window
626 application.closeWindow(this);
627 return;
628 }
629
fca67db0
KL
630 if ((mouse.getAbsoluteY() == getY())
631 && mouse.getMouse1()
48e27807
KL
632 && mouseOnMaximize()) {
633 if (maximized) {
634 // Restore
635 restore();
636 } else {
637 // Maximize
638 maximize();
639 }
640 // Pass a resize event to my children
fca67db0
KL
641 onResize(new TResizeEvent(TResizeEvent.Type.WIDGET,
642 getWidth(), getHeight()));
48e27807
KL
643 return;
644 }
645
646 // I didn't take it, pass it on to my children
647 super.onMouseUp(mouse);
648 }
649
650 /**
651 * Handle mouse movements.
652 *
653 * @param mouse mouse motion event
654 */
655 @Override
656 public void onMouseMotion(final TMouseEvent mouse) {
657 this.mouse = mouse;
658 application.setRepaint();
659
660 if (inWindowMove) {
661 // Move window over
fca67db0
KL
662 setX(oldWindowX + (mouse.getAbsoluteX() - moveWindowMouseX));
663 setY(oldWindowY + (mouse.getAbsoluteY() - moveWindowMouseY));
48e27807 664 // Don't cover up the menu bar
fca67db0
KL
665 if (getY() < application.getDesktopTop()) {
666 setY(application.getDesktopTop());
48e27807
KL
667 }
668 return;
669 }
670
671 if (inWindowResize) {
672 // Move window over
fca67db0
KL
673 setWidth(resizeWindowWidth + (mouse.getAbsoluteX()
674 - moveWindowMouseX));
675 setHeight(resizeWindowHeight + (mouse.getAbsoluteY()
676 - moveWindowMouseY));
677 if (getX() + getWidth() > getScreen().getWidth()) {
678 setWidth(getScreen().getWidth() - getX());
48e27807 679 }
fca67db0
KL
680 if (getY() + getHeight() > application.getDesktopBottom()) {
681 setY(application.getDesktopBottom() - getHeight() + 1);
48e27807
KL
682 }
683 // Don't cover up the menu bar
fca67db0
KL
684 if (getY() < application.getDesktopTop()) {
685 setY(application.getDesktopTop());
48e27807
KL
686 }
687
688 // Keep within min/max bounds
fca67db0
KL
689 if (getWidth() < minimumWindowWidth) {
690 setWidth(minimumWindowWidth);
48e27807
KL
691 inWindowResize = false;
692 }
fca67db0
KL
693 if (getHeight() < minimumWindowHeight) {
694 setHeight(minimumWindowHeight);
48e27807
KL
695 inWindowResize = false;
696 }
fca67db0
KL
697 if ((maximumWindowWidth > 0)
698 && (getWidth() > maximumWindowWidth)
699 ) {
700 setWidth(maximumWindowWidth);
48e27807
KL
701 inWindowResize = false;
702 }
fca67db0
KL
703 if ((maximumWindowHeight > 0)
704 && (getHeight() > maximumWindowHeight)
705 ) {
706 setHeight(maximumWindowHeight);
48e27807
KL
707 inWindowResize = false;
708 }
709
710 // Pass a resize event to my children
fca67db0
KL
711 onResize(new TResizeEvent(TResizeEvent.Type.WIDGET,
712 getWidth(), getHeight()));
48e27807
KL
713 return;
714 }
715
716 // I didn't take it, pass it on to my children
717 super.onMouseMotion(mouse);
718 }
719
720 /**
721 * Handle keystrokes.
722 *
723 * @param keypress keystroke event
724 */
725 @Override
726 public void onKeypress(final TKeypressEvent keypress) {
727
728 if (inKeyboardResize) {
729
730 // ESC - Exit size/move
731 if (keypress.equals(kbEsc)) {
732 inKeyboardResize = false;
733 }
734
735 if (keypress.equals(kbLeft)) {
fca67db0
KL
736 if (getX() > 0) {
737 setX(getX() - 1);
48e27807
KL
738 }
739 }
740 if (keypress.equals(kbRight)) {
fca67db0
KL
741 if (getX() < getScreen().getWidth() - 1) {
742 setX(getX() + 1);
48e27807
KL
743 }
744 }
745 if (keypress.equals(kbDown)) {
fca67db0
KL
746 if (getY() < application.getDesktopBottom() - 1) {
747 setY(getY() + 1);
48e27807
KL
748 }
749 }
750 if (keypress.equals(kbUp)) {
fca67db0
KL
751 if (getY() > 1) {
752 setY(getY() - 1);
48e27807
KL
753 }
754 }
755 if (keypress.equals(kbShiftLeft)) {
fca67db0
KL
756 if (getWidth() > minimumWindowWidth) {
757 setWidth(getWidth() - 1);
48e27807
KL
758 }
759 }
760 if (keypress.equals(kbShiftRight)) {
fca67db0
KL
761 if (getWidth() < maximumWindowWidth) {
762 setWidth(getWidth() + 1);
48e27807
KL
763 }
764 }
765 if (keypress.equals(kbShiftUp)) {
fca67db0
KL
766 if (getHeight() > minimumWindowHeight) {
767 setHeight(getHeight() - 1);
48e27807
KL
768 }
769 }
770 if (keypress.equals(kbShiftDown)) {
fca67db0
KL
771 if (getHeight() < maximumWindowHeight) {
772 setHeight(getHeight() + 1);
48e27807
KL
773 }
774 }
775
776 return;
777 }
778
779 // These keystrokes will typically not be seen unless a subclass
780 // overrides onMenu() due to how TApplication dispatches
781 // accelerators.
782
783 // Ctrl-W - close window
784 if (keypress.equals(kbCtrlW)) {
785 application.closeWindow(this);
786 return;
787 }
788
789 // F6 - behave like Alt-TAB
790 if (keypress.equals(kbF6)) {
791 application.switchWindow(true);
792 return;
793 }
794
795 // Shift-F6 - behave like Shift-Alt-TAB
796 if (keypress.equals(kbShiftF6)) {
797 application.switchWindow(false);
798 return;
799 }
800
801 // F5 - zoom
802 if (keypress.equals(kbF5)) {
803 if (maximized) {
804 restore();
805 } else {
806 maximize();
807 }
808 }
809
810 // Ctrl-F5 - size/move
811 if (keypress.equals(kbCtrlF5)) {
812 inKeyboardResize = !inKeyboardResize;
813 }
814
815 // I didn't take it, pass it on to my children
816 super.onKeypress(keypress);
817 }
818
819 /**
820 * Handle posted command events.
821 *
822 * @param command command event
823 */
824 @Override
825 public void onCommand(final TCommandEvent command) {
826
827 // These commands will typically not be seen unless a subclass
828 // overrides onMenu() due to how TApplication dispatches
829 // accelerators.
830
831 if (command.equals(cmWindowClose)) {
832 application.closeWindow(this);
833 return;
834 }
835
836 if (command.equals(cmWindowNext)) {
837 application.switchWindow(true);
838 return;
839 }
840
841 if (command.equals(cmWindowPrevious)) {
842 application.switchWindow(false);
843 return;
844 }
845
846 if (command.equals(cmWindowMove)) {
847 inKeyboardResize = true;
848 return;
849 }
850
851 if (command.equals(cmWindowZoom)) {
852 if (maximized) {
853 restore();
854 } else {
855 maximize();
856 }
857 }
858
859 // I didn't take it, pass it on to my children
860 super.onCommand(command);
861 }
862
863 /**
864 * Handle posted menu events.
865 *
866 * @param menu menu event
867 */
868 @Override
869 public void onMenu(final TMenuEvent menu) {
870 if (menu.getId() == TMenu.MID_WINDOW_CLOSE) {
871 application.closeWindow(this);
872 return;
873 }
874
875 if (menu.getId() == TMenu.MID_WINDOW_NEXT) {
876 application.switchWindow(true);
877 return;
878 }
879
880 if (menu.getId() == TMenu.MID_WINDOW_PREVIOUS) {
881 application.switchWindow(false);
882 return;
883 }
884
885 if (menu.getId() == TMenu.MID_WINDOW_MOVE) {
886 inKeyboardResize = true;
887 return;
888 }
889
890 if (menu.getId() == TMenu.MID_WINDOW_ZOOM) {
891 if (maximized) {
892 restore();
893 } else {
894 maximize();
895 }
896 return;
897 }
898
899 // I didn't take it, pass it on to my children
900 super.onMenu(menu);
901 }
902
903 // ------------------------------------------------------------------------
904 // Passthru for Screen functions ------------------------------------------
905 // ------------------------------------------------------------------------
906
907 /**
908 * Get the attributes at one location.
909 *
910 * @param x column coordinate. 0 is the left-most column.
911 * @param y row coordinate. 0 is the top-most row.
912 * @return attributes at (x, y)
913 */
914 public final CellAttributes getAttrXY(final int x, final int y) {
915 return getScreen().getAttrXY(x, y);
916 }
917
918 /**
919 * Set the attributes at one location.
920 *
921 * @param x column coordinate. 0 is the left-most column.
922 * @param y row coordinate. 0 is the top-most row.
923 * @param attr attributes to use (bold, foreColor, backColor)
924 */
925 public final void putAttrXY(final int x, final int y,
926 final CellAttributes attr) {
927
928 getScreen().putAttrXY(x, y, attr);
929 }
930
931 /**
932 * Set the attributes at one location.
933 *
934 * @param x column coordinate. 0 is the left-most column.
935 * @param y row coordinate. 0 is the top-most row.
936 * @param attr attributes to use (bold, foreColor, backColor)
937 * @param clip if true, honor clipping/offset
938 */
939 public final void putAttrXY(final int x, final int y,
940 final CellAttributes attr, final boolean clip) {
941
942 getScreen().putAttrXY(x, y, attr, clip);
943 }
944
945 /**
946 * Fill the entire screen with one character with attributes.
947 *
948 * @param ch character to draw
949 * @param attr attributes to use (bold, foreColor, backColor)
950 */
951 public final void putAll(final char ch, final CellAttributes attr) {
952 getScreen().putAll(ch, attr);
953 }
954
955 /**
956 * Render one character with attributes.
957 *
958 * @param x column coordinate. 0 is the left-most column.
959 * @param y row coordinate. 0 is the top-most row.
960 * @param ch character + attributes to draw
961 */
962 public final void putCharXY(final int x, final int y, final Cell ch) {
963 getScreen().putCharXY(x, y, ch);
964 }
965
966 /**
967 * Render one character with attributes.
968 *
969 * @param x column coordinate. 0 is the left-most column.
970 * @param y row coordinate. 0 is the top-most row.
971 * @param ch character to draw
972 * @param attr attributes to use (bold, foreColor, backColor)
973 */
974 public final void putCharXY(final int x, final int y, final char ch,
975 final CellAttributes attr) {
976
977 getScreen().putCharXY(x, y, ch, attr);
978 }
979
980 /**
981 * Render one character without changing the underlying attributes.
982 *
983 * @param x column coordinate. 0 is the left-most column.
984 * @param y row coordinate. 0 is the top-most row.
985 * @param ch character to draw
986 */
987 public final void putCharXY(final int x, final int y, final char ch) {
988 getScreen().putCharXY(x, y, ch);
989 }
990
991 /**
992 * Render a string. Does not wrap if the string exceeds the line.
993 *
994 * @param x column coordinate. 0 is the left-most column.
995 * @param y row coordinate. 0 is the top-most row.
996 * @param str string to draw
997 * @param attr attributes to use (bold, foreColor, backColor)
998 */
999 public final void putStrXY(final int x, final int y, final String str,
1000 final CellAttributes attr) {
1001
1002 getScreen().putStrXY(x, y, str, attr);
1003 }
1004
1005 /**
1006 * Render a string without changing the underlying attribute. Does not
1007 * wrap if the string exceeds the line.
1008 *
1009 * @param x column coordinate. 0 is the left-most column.
1010 * @param y row coordinate. 0 is the top-most row.
1011 * @param str string to draw
1012 */
1013 public final void putStrXY(final int x, final int y, final String str) {
1014 getScreen().putStrXY(x, y, str);
1015 }
1016
1017 /**
1018 * Draw a vertical line from (x, y) to (x, y + n).
1019 *
1020 * @param x column coordinate. 0 is the left-most column.
1021 * @param y row coordinate. 0 is the top-most row.
1022 * @param n number of characters to draw
1023 * @param ch character to draw
1024 * @param attr attributes to use (bold, foreColor, backColor)
1025 */
1026 public final void vLineXY(final int x, final int y, final int n,
1027 final char ch, final CellAttributes attr) {
1028
1029 getScreen().vLineXY(x, y, n, ch, attr);
1030 }
1031
1032 /**
1033 * Draw a horizontal line from (x, y) to (x + n, y).
1034 *
1035 * @param x column coordinate. 0 is the left-most column.
1036 * @param y row coordinate. 0 is the top-most row.
1037 * @param n number of characters to draw
1038 * @param ch character to draw
1039 * @param attr attributes to use (bold, foreColor, backColor)
1040 */
1041 public final void hLineXY(final int x, final int y, final int n,
1042 final char ch, final CellAttributes attr) {
1043
1044 getScreen().hLineXY(x, y, n, ch, attr);
1045 }
1046
1047
1048}