d6864db746316659ef5d3ed4fed3cc76b0934d6a
2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
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.
10 * Copyright (C) 2015 Kevin Lamonte
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.
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.
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
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import java
.util
.List
;
34 import java
.util
.LinkedList
;
36 import jexer
.bits
.ColorTheme
;
37 import jexer
.event
.TCommandEvent
;
38 import jexer
.event
.TInputEvent
;
39 import jexer
.event
.TKeypressEvent
;
40 import jexer
.event
.TMenuEvent
;
41 import jexer
.event
.TMouseEvent
;
42 import jexer
.event
.TResizeEvent
;
43 import jexer
.io
.Screen
;
44 import jexer
.menu
.TMenu
;
45 import static jexer
.TKeypress
.*;
48 * TWidget is the base class of all objects that can be drawn on screen or
49 * handle user input events.
51 public abstract class TWidget
implements Comparable
<TWidget
> {
54 * Every widget has a parent widget that it may be "contained" in. For
55 * example, a TWindow might contain several TTextFields, or a TComboBox
56 * may contain a TScrollBar.
58 private TWidget parent
= null;
63 * @return parent widget
65 public final TWidget
getParent() {
70 * Backdoor access for TWindow's constructor. ONLY TWindow USES THIS.
72 * @param window the top-level window
73 * @param x column relative to parent
74 * @param y row relative to parent
75 * @param width width of window
76 * @param height height of window
78 protected final void setupForTWindow(final TWindow window
,
79 final int x
, final int y
, final int width
, final int height
) {
90 * Request full repaint on next screen refresh.
92 protected final void setRepaint() {
93 window
.getApplication().setRepaint();
97 * Get this TWidget's parent TApplication.
99 * @return the parent TApplication
101 public TApplication
getApplication() {
102 return window
.getApplication();
110 public Screen
getScreen() {
111 return window
.getScreen();
115 * Child widgets that this widget contains.
117 private List
<TWidget
> children
;
120 * Get the list of child widgets that this widget contains.
122 * @return the list of child widgets
124 public List
<TWidget
> getChildren() {
129 * The currently active child widget that will receive keypress events.
131 private TWidget activeChild
= null;
134 * If true, this widget will receive events.
136 private boolean active
= false;
141 * @return if true, this widget will receive events
143 public final boolean getActive() {
150 * @param active if true, this widget will receive events
152 public final void setActive(final boolean active
) {
153 this.active
= active
;
157 * The window that this widget draws to.
159 private TWindow window
= null;
162 * Get the window this widget is on.
166 public final TWindow
getWindow() {
171 * Absolute X position of the top-left corner.
178 * @return absolute X position of the top-left corner
180 public final int getX() {
187 * @param x absolute X position of the top-left corner
189 public final void setX(final int x
) {
194 * Absolute Y position of the top-left corner.
201 * @return absolute Y position of the top-left corner
203 public final int getY() {
210 * @param y absolute Y position of the top-left corner
212 public final void setY(final int y
) {
219 private int width
= 0;
224 * @return widget width
226 public final int getWidth() {
233 * @param width new widget width
235 public final void setWidth(final int width
) {
242 private int height
= 0;
247 * @return widget height
249 public final int getHeight() {
256 * @param height new widget height
258 public final void setHeight(final int height
) {
259 this.height
= height
;
263 * My tab order inside a window or containing widget.
265 private int tabOrder
= 0;
268 * If true, this widget can be tabbed to or receive events.
270 private boolean enabled
= true;
275 * @return if true, this widget can be tabbed to or receive events
277 public final boolean getEnabled() {
284 * @param enabled if true, this widget can be tabbed to or receive events
286 public final void setEnabled(final boolean enabled
) {
287 this.enabled
= enabled
;
290 // See if there are any active siblings to switch to
291 boolean foundSibling
= false;
292 if (parent
!= null) {
293 for (TWidget w
: parent
.children
) {
295 && !(this instanceof THScroller
)
296 && !(this instanceof TVScroller
)
304 parent
.activeChild
= null;
311 * If true, this widget has a cursor.
313 private boolean hasCursor
= false;
316 * Set visible cursor flag.
318 * @param hasCursor if true, this widget has a cursor
320 public final void setHasCursor(final boolean hasCursor
) {
321 this.hasCursor
= hasCursor
;
325 * See if this widget has a visible cursor.
327 * @return if true, this widget has a visible cursor
329 public final boolean visibleCursor() {
334 * Cursor column position in relative coordinates.
336 private int cursorX
= 0;
339 * Get cursor X value.
341 * @return cursor column position in relative coordinates
343 public final int getCursorX() {
348 * Set cursor X value.
350 * @param cursorX column position in relative coordinates
352 public final void setCursorX(final int cursorX
) {
353 this.cursorX
= cursorX
;
357 * Cursor row position in relative coordinates.
359 private int cursorY
= 0;
362 * Get cursor Y value.
364 * @return cursor row position in relative coordinates
366 public final int getCursorY() {
371 * Set cursor Y value.
373 * @param cursorY row position in relative coordinates
375 public final void setCursorY(final int cursorY
) {
376 this.cursorY
= cursorY
;
380 * Comparison operator sorts on tabOrder for TWidgets and z for TWindows.
382 * @param that another TWidget or TWindow instance
383 * @return difference between this.tabOrder and that.tabOrder, or
384 * difference between this.z and that.z
387 public final int compareTo(final TWidget that
) {
388 if ((this instanceof TWindow
)
389 && (that
instanceof TWindow
)
391 return (((TWindow
) this).getZ() - ((TWindow
) that
).getZ());
393 return (this.tabOrder
- that
.tabOrder
);
397 * See if this widget should render with the active color.
399 * @return true if this widget is active and all of its parents are
402 public final boolean getAbsoluteActive() {
403 if (parent
== this) {
406 return (active
&& parent
.getAbsoluteActive());
410 * Returns the cursor X position.
412 * @return absolute screen column number for the cursor's X position
414 public final int getCursorAbsoluteX() {
416 return getAbsoluteX() + cursorX
;
420 * Returns the cursor Y position.
422 * @return absolute screen row number for the cursor's Y position
424 public final int getCursorAbsoluteY() {
426 return getAbsoluteY() + cursorY
;
430 * Compute my absolute X position as the sum of my X plus all my parent's
433 * @return absolute screen column number for my X position
435 public final int getAbsoluteX() {
436 assert (parent
!= null);
437 if (parent
== this) {
440 if ((parent
instanceof TWindow
) && !(parent
instanceof TMenu
)) {
441 // Widgets on a TWindow have (0,0) as their top-left, but this is
442 // actually the TWindow's (1,1).
443 return parent
.getAbsoluteX() + x
+ 1;
445 return parent
.getAbsoluteX() + x
;
449 * Compute my absolute Y position as the sum of my Y plus all my parent's
452 * @return absolute screen row number for my Y position
454 public final int getAbsoluteY() {
455 assert (parent
!= null);
456 if (parent
== this) {
459 if ((parent
instanceof TWindow
) && !(parent
instanceof TMenu
)) {
460 // Widgets on a TWindow have (0,0) as their top-left, but this is
461 // actually the TWindow's (1,1).
462 return parent
.getAbsoluteY() + y
+ 1;
464 return parent
.getAbsoluteY() + y
;
468 * Get the global color theme.
470 * @return the ColorTheme
472 public final ColorTheme
getTheme() {
473 return window
.getApplication().getTheme();
477 * Draw my specific widget. When called, the screen rectangle I draw
478 * into is already setup (offset and clipping).
481 // Default widget draws nothing.
485 * Called by parent to render to TWindow.
487 public final void drawChildren() {
488 // Set my clipping rectangle
489 assert (window
!= null);
490 assert (window
.getScreen() != null);
491 Screen screen
= window
.getScreen();
493 screen
.setClipRight(width
);
494 screen
.setClipBottom(height
);
496 int absoluteRightEdge
= window
.getAbsoluteX() + screen
.getWidth();
497 int absoluteBottomEdge
= window
.getAbsoluteY() + screen
.getHeight();
498 if (!(this instanceof TWindow
) && !(this instanceof TVScroller
)) {
499 absoluteRightEdge
-= 1;
501 if (!(this instanceof TWindow
) && !(this instanceof THScroller
)) {
502 absoluteBottomEdge
-= 1;
504 int myRightEdge
= getAbsoluteX() + width
;
505 int myBottomEdge
= getAbsoluteY() + height
;
506 if (getAbsoluteX() > absoluteRightEdge
) {
508 screen
.setClipRight(0);
509 } else if (myRightEdge
> absoluteRightEdge
) {
510 screen
.setClipRight(screen
.getClipRight()
511 - myRightEdge
- absoluteRightEdge
);
513 if (getAbsoluteY() > absoluteBottomEdge
) {
515 screen
.setClipBottom(0);
516 } else if (myBottomEdge
> absoluteBottomEdge
) {
517 screen
.setClipBottom(screen
.getClipBottom()
518 - myBottomEdge
- absoluteBottomEdge
);
522 screen
.setOffsetX(getAbsoluteX());
523 screen
.setOffsetY(getAbsoluteY());
528 // Continue down the chain
529 for (TWidget widget
: children
) {
530 widget
.drawChildren();
535 * Default constructor for subclasses.
537 protected TWidget() {
538 children
= new LinkedList
<TWidget
>();
542 * Protected constructor.
544 * @param parent parent widget
546 protected TWidget(final TWidget parent
) {
551 * Protected constructor.
553 * @param parent parent widget
554 * @param x column relative to parent
555 * @param y row relative to parent
556 * @param width width of widget
557 * @param height height of widget
559 protected TWidget(final TWidget parent
, final int x
, final int y
,
560 final int width
, final int height
) {
562 this(parent
, true, x
, y
, width
, height
);
566 * Protected constructor used by subclasses that are disabled by default.
568 * @param parent parent widget
569 * @param enabled if true assume enabled
571 protected TWidget(final TWidget parent
, final boolean enabled
) {
572 this.enabled
= enabled
;
573 this.parent
= parent
;
574 this.window
= parent
.window
;
575 children
= new LinkedList
<TWidget
>();
576 parent
.addChild(this);
580 * Protected constructor used by subclasses that are disabled by default.
582 * @param parent parent widget
583 * @param enabled if true assume enabled
584 * @param x column relative to parent
585 * @param y row relative to parent
586 * @param width width of widget
587 * @param height height of widget
589 protected TWidget(final TWidget parent
, final boolean enabled
,
590 final int x
, final int y
, final int width
, final int height
) {
592 this.enabled
= enabled
;
593 this.parent
= parent
;
594 this.window
= parent
.window
;
595 children
= new LinkedList
<TWidget
>();
596 parent
.addChild(this);
601 this.height
= height
;
605 * Add a child widget to my list of children. We set its tabOrder to 0
606 * and increment the tabOrder of all other children.
608 * @param child TWidget to add
610 private void addChild(final TWidget child
) {
614 && !(child
instanceof THScroller
)
615 && !(child
instanceof TVScroller
)
617 for (TWidget widget
: children
) {
618 widget
.active
= false;
623 for (int i
= 0; i
< children
.size(); i
++) {
624 children
.get(i
).tabOrder
= i
;
629 * Switch the active child.
631 * @param child TWidget to activate
633 public final void activate(final TWidget child
) {
634 assert (child
.enabled
);
635 if ((child
instanceof THScroller
)
636 || (child
instanceof TVScroller
)
641 if (child
!= activeChild
) {
642 if (activeChild
!= null) {
643 activeChild
.active
= false;
651 * Switch the active child.
653 * @param tabOrder tabOrder of the child to activate. If that child
654 * isn't enabled, then the next enabled child will be activated.
656 public final void activate(final int tabOrder
) {
657 if (activeChild
== null) {
660 TWidget child
= null;
661 for (TWidget widget
: children
) {
663 && !(widget
instanceof THScroller
)
664 && !(widget
instanceof TVScroller
)
665 && (widget
.tabOrder
>= tabOrder
)
671 if ((child
!= null) && (child
!= activeChild
)) {
672 activeChild
.active
= false;
673 assert (child
.enabled
);
680 * Switch the active widget with the next in the tab order.
682 * @param forward if true, then switch to the next enabled widget in the
683 * list, otherwise switch to the previous enabled widget in the list
685 public final void switchWidget(final boolean forward
) {
687 // Only switch if there are multiple enabled widgets
688 if ((children
.size() < 2) || (activeChild
== null)) {
692 int tabOrder
= activeChild
.tabOrder
;
701 // If at the end, pass the switch to my parent.
702 if ((!forward
) && (parent
!= this)) {
703 parent
.switchWidget(forward
);
707 tabOrder
= children
.size() - 1;
708 } else if (tabOrder
== children
.size()) {
709 // If at the end, pass the switch to my parent.
710 if ((forward
) && (parent
!= this)) {
711 parent
.switchWidget(forward
);
717 if (activeChild
.tabOrder
== tabOrder
) {
721 } while ((!children
.get(tabOrder
).enabled
)
722 && !(children
.get(tabOrder
) instanceof THScroller
)
723 && !(children
.get(tabOrder
) instanceof TVScroller
));
725 assert (children
.get(tabOrder
).enabled
);
727 activeChild
.active
= false;
728 children
.get(tabOrder
).active
= true;
729 activeChild
= children
.get(tabOrder
);
732 window
.getApplication().setRepaint();
736 * Returns my active widget.
738 * @return widget that is active, or this if no children
740 public TWidget
getActiveChild() {
741 if ((this instanceof THScroller
)
742 || (this instanceof TVScroller
)
747 for (TWidget widget
: children
) {
749 return widget
.getActiveChild();
752 // No active children, return me
757 * Method that subclasses can override to handle keystrokes.
759 * @param keypress keystroke event
761 public void onKeypress(final TKeypressEvent keypress
) {
763 if ((children
.size() == 0)
765 // || (cast(TTreeView)this)
766 || (this instanceof TText
)
770 // tab / shift-tab - switch to next/previous widget
771 // right-arrow or down-arrow: same as tab
772 // left-arrow or up-arrow: same as shift-tab
773 if ((keypress
.equals(kbTab
))
774 || (keypress
.equals(kbRight
))
775 || (keypress
.equals(kbDown
))
777 parent
.switchWidget(true);
779 } else if ((keypress
.equals(kbShiftTab
))
780 || (keypress
.equals(kbBackTab
))
781 || (keypress
.equals(kbLeft
))
782 || (keypress
.equals(kbUp
))
784 parent
.switchWidget(false);
789 // If I have any buttons on me AND this is an Alt-key that matches
790 // its mnemonic, send it an Enter keystroke
791 for (TWidget widget
: children
) {
795 if (TButton button = cast(TButton)w) {
796 if (button.enabled &&
797 !keypress.key.isKey &&
799 !keypress.key.ctrl &&
800 (toLowercase(button.mnemonic.shortcut) == toLowercase(keypress.key.ch))) {
802 w.handleEvent(new TKeypressEvent(kbEnter));
809 // Dispatch the keypress to an active widget
810 for (TWidget widget
: children
) {
812 window
.getApplication().setRepaint();
813 widget
.handleEvent(keypress
);
820 * Method that subclasses can override to handle mouse button presses.
822 * @param mouse mouse button event
824 public void onMouseDown(final TMouseEvent mouse
) {
825 // Default: do nothing, pass to children instead
826 for (TWidget widget
: children
) {
827 if (widget
.mouseWouldHit(mouse
)) {
828 // Dispatch to this child, also activate it
831 // Set x and y relative to the child's coordinates
832 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
833 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
834 widget
.handleEvent(mouse
);
841 * Method that subclasses can override to handle mouse button releases.
843 * @param mouse mouse button event
845 public void onMouseUp(final TMouseEvent mouse
) {
846 // Default: do nothing, pass to children instead
847 for (TWidget widget
: children
) {
848 if (widget
.mouseWouldHit(mouse
)) {
849 // Dispatch to this child, also activate it
852 // Set x and y relative to the child's coordinates
853 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
854 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
855 widget
.handleEvent(mouse
);
862 * Method that subclasses can override to handle mouse movements.
864 * @param mouse mouse motion event
866 public void onMouseMotion(final TMouseEvent mouse
) {
867 // Default: do nothing, pass it on to ALL of my children. This way
868 // the children can see the mouse "leaving" their area.
869 for (TWidget widget
: children
) {
870 // Set x and y relative to the child's coordinates
871 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
872 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
873 widget
.handleEvent(mouse
);
878 * Method that subclasses can override to handle window/screen resize
881 * @param resize resize event
883 public void onResize(final TResizeEvent resize
) {
884 // Default: do nothing, pass to children instead
885 for (TWidget widget
: children
) {
886 widget
.onResize(resize
);
891 * Method that subclasses can override to handle posted command events.
893 * @param command command event
895 public void onCommand(final TCommandEvent command
) {
896 // Default: do nothing, pass to children instead
897 for (TWidget widget
: children
) {
898 widget
.onCommand(command
);
903 * Method that subclasses can override to handle menu or posted menu
906 * @param menu menu event
908 public void onMenu(final TMenuEvent menu
) {
909 // Default: do nothing, pass to children instead
910 for (TWidget widget
: children
) {
916 * Method that subclasses can override to do processing when the UI is
919 public void onIdle() {
920 // Default: do nothing, pass to children instead
921 for (TWidget widget
: children
) {
927 * Consume event. Subclasses that want to intercept all events in one go
928 * can override this method.
930 * @param event keyboard, mouse, resize, command, or menu event
932 public void handleEvent(final TInputEvent event
) {
933 // System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(),
938 // System.err.println(" -- discard --");
942 if (event
instanceof TKeypressEvent
) {
943 onKeypress((TKeypressEvent
) event
);
944 } else if (event
instanceof TMouseEvent
) {
946 TMouseEvent mouse
= (TMouseEvent
) event
;
948 switch (mouse
.getType()) {
959 onMouseMotion(mouse
);
963 throw new IllegalArgumentException("Invalid mouse event type: "
966 } else if (event
instanceof TResizeEvent
) {
967 onResize((TResizeEvent
) event
);
968 } else if (event
instanceof TCommandEvent
) {
969 onCommand((TCommandEvent
) event
);
970 } else if (event
instanceof TMenuEvent
) {
971 onMenu((TMenuEvent
) event
);
979 * Check if a mouse press/release event coordinate is contained in this
982 * @param mouse a mouse-based event
983 * @return whether or not a mouse click would be sent to this widget
985 public final boolean mouseWouldHit(final TMouseEvent mouse
) {
991 if ((mouse
.getAbsoluteX() >= getAbsoluteX())
992 && (mouse
.getAbsoluteX() < getAbsoluteX() + width
)
993 && (mouse
.getAbsoluteY() >= getAbsoluteY())
994 && (mouse
.getAbsoluteY() < getAbsoluteY() + height
)
1002 * Convenience function to add a label to this container/window.
1005 * @param x column relative to parent
1006 * @param y row relative to parent
1007 * @return the new label
1009 public final TLabel
addLabel(final String text
, final int x
, final int y
) {
1010 return addLabel(text
, x
, y
, "tlabel");
1014 * Convenience function to add a label to this container/window.
1017 * @param x column relative to parent
1018 * @param y row relative to parent
1019 * @param colorKey ColorTheme key color to use for foreground text.
1020 * Default is "tlabel"
1021 * @return the new label
1023 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1024 final String colorKey
) {
1026 return new TLabel(this, text
, x
, y
, colorKey
);
1030 * Convenience function to add a button to this container/window.
1032 * @param text label on the button
1033 * @param x column relative to parent
1034 * @param y row relative to parent
1035 * @param action to call when button is pressed
1036 * @return the new button
1038 public final TButton
addButton(final String text
, final int x
, final int y
,
1039 final TAction action
) {
1041 return new TButton(this, text
, x
, y
, action
);
1045 * Convenience function to add a checkbox to this container/window.
1047 * @param x column relative to parent
1048 * @param y row relative to parent
1049 * @param label label to display next to (right of) the checkbox
1050 * @param checked initial check state
1051 * @return the new checkbox
1053 public final TCheckbox
addCheckbox(final int x
, final int y
,
1054 final String label
, final boolean checked
) {
1056 return new TCheckbox(this, x
, y
, label
, checked
);
1060 * Convenience function to add a progress bar to this container/window.
1062 * @param x column relative to parent
1063 * @param y row relative to parent
1064 * @param width width of progress bar
1065 * @param value initial value of percent complete
1066 * @return the new progress bar
1068 public final TProgressBar
addProgressBar(final int x
, final int y
,
1069 final int width
, final int value
) {
1071 return new TProgressBar(this, x
, y
, width
, value
);
1075 * Convenience function to add a radio button group to this
1078 * @param x column relative to parent
1079 * @param y row relative to parent
1080 * @param label label to display on the group box
1081 * @return the new radio button group
1083 public final TRadioGroup
addRadioGroup(final int x
, final int y
,
1084 final String label
) {
1086 return new TRadioGroup(this, x
, y
, label
);
1090 * Convenience function to add a text field to this container/window.
1092 * @param x column relative to parent
1093 * @param y row relative to parent
1094 * @param width visible text width
1095 * @param fixed if true, the text cannot exceed the display width
1096 * @return the new text field
1098 public final TField
addField(final int x
, final int y
,
1099 final int width
, final boolean fixed
) {
1101 return new TField(this, x
, y
, width
, fixed
);
1105 * Convenience function to add a text field to this container/window.
1107 * @param x column relative to parent
1108 * @param y row relative to parent
1109 * @param width visible text width
1110 * @param fixed if true, the text cannot exceed the display width
1111 * @param text initial text, default is empty string
1112 * @return the new text field
1114 public final TField
addField(final int x
, final int y
,
1115 final int width
, final boolean fixed
, final String text
) {
1117 return new TField(this, x
, y
, width
, fixed
, text
);
1121 * Convenience function to add a text field to this container/window.
1123 * @param x column relative to parent
1124 * @param y row relative to parent
1125 * @param width visible text width
1126 * @param fixed if true, the text cannot exceed the display width
1127 * @param text initial text, default is empty string
1128 * @param enterAction function to call when enter key is pressed
1129 * @param updateAction function to call when the text is updated
1130 * @return the new text field
1132 public final TField
addField(final int x
, final int y
,
1133 final int width
, final boolean fixed
, final String text
,
1134 final TAction enterAction
, final TAction updateAction
) {
1136 return new TField(this, x
, y
, width
, fixed
, text
, enterAction
,
1141 * Convenience function to add a scrollable text box to this
1144 * @param text text on the screen
1145 * @param x column relative to parent
1146 * @param y row relative to parent
1147 * @param width width of text area
1148 * @param height height of text area
1149 * @param colorKey ColorTheme key color to use for foreground text
1150 * @return the new text box
1152 public final TText
addText(final String text
, final int x
,
1153 final int y
, final int width
, final int height
, final String colorKey
) {
1155 return new TText(this, text
, x
, y
, width
, height
, colorKey
);
1159 * Convenience function to add a scrollable text box to this
1162 * @param text text on the screen
1163 * @param x column relative to parent
1164 * @param y row relative to parent
1165 * @param width width of text area
1166 * @param height height of text area
1167 * @return the new text box
1169 public final TText
addText(final String text
, final int x
, final int y
,
1170 final int width
, final int height
) {
1172 return new TText(this, text
, x
, y
, width
, height
, "ttext");
1176 * Convenience function to spawn a message box.
1178 * @param title window title, will be centered along the top border
1179 * @param caption message to display. Use embedded newlines to get a
1181 * @return the new message box
1183 public final TMessageBox
messageBox(final String title
,
1184 final String caption
) {
1186 return getApplication().messageBox(title
, caption
, TMessageBox
.Type
.OK
);
1190 * Convenience function to spawn a message box.
1192 * @param title window title, will be centered along the top border
1193 * @param caption message to display. Use embedded newlines to get a
1195 * @param type one of the TMessageBox.Type constants. Default is
1197 * @return the new message box
1199 public final TMessageBox
messageBox(final String title
,
1200 final String caption
, final TMessageBox
.Type type
) {
1202 return getApplication().messageBox(title
, caption
, type
);
1206 * Convenience function to spawn an input box.
1208 * @param title window title, will be centered along the top border
1209 * @param caption message to display. Use embedded newlines to get a
1211 * @return the new input box
1213 public final TInputBox
inputBox(final String title
, final String caption
) {
1215 return getApplication().inputBox(title
, caption
);
1219 * Convenience function to spawn an input box.
1221 * @param title window title, will be centered along the top border
1222 * @param caption message to display. Use embedded newlines to get a
1224 * @param text initial text to seed the field with
1225 * @return the new input box
1227 public final TInputBox
inputBox(final String title
, final String caption
,
1228 final String text
) {
1230 return getApplication().inputBox(title
, caption
, text
);
1234 * Convenience function to add a password text field to this
1237 * @param x column relative to parent
1238 * @param y row relative to parent
1239 * @param width visible text width
1240 * @param fixed if true, the text cannot exceed the display width
1241 * @return the new text field
1243 public final TPasswordField
addPasswordField(final int x
, final int y
,
1244 final int width
, final boolean fixed
) {
1246 return new TPasswordField(this, x
, y
, width
, fixed
);
1250 * Convenience function to add a password text field to this
1253 * @param x column relative to parent
1254 * @param y row relative to parent
1255 * @param width visible text width
1256 * @param fixed if true, the text cannot exceed the display width
1257 * @param text initial text, default is empty string
1258 * @return the new text field
1260 public final TPasswordField
addPasswordField(final int x
, final int y
,
1261 final int width
, final boolean fixed
, final String text
) {
1263 return new TPasswordField(this, x
, y
, width
, fixed
, text
);
1267 * Convenience function to add a password text field to this
1270 * @param x column relative to parent
1271 * @param y row relative to parent
1272 * @param width visible text width
1273 * @param fixed if true, the text cannot exceed the display width
1274 * @param text initial text, default is empty string
1275 * @param enterAction function to call when enter key is pressed
1276 * @param updateAction function to call when the text is updated
1277 * @return the new text field
1279 public final TPasswordField
addPasswordField(final int x
, final int y
,
1280 final int width
, final boolean fixed
, final String text
,
1281 final TAction enterAction
, final TAction updateAction
) {
1283 return new TPasswordField(this, x
, y
, width
, fixed
, text
, enterAction
,