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 * Get this TWidget's parent TApplication.
92 * @return the parent TApplication
94 public TApplication
getApplication() {
95 return window
.getApplication();
103 public Screen
getScreen() {
104 return window
.getScreen();
108 * Child widgets that this widget contains.
110 private List
<TWidget
> children
;
113 * Get the list of child widgets that this widget contains.
115 * @return the list of child widgets
117 public List
<TWidget
> getChildren() {
122 * The currently active child widget that will receive keypress events.
124 private TWidget activeChild
= null;
127 * If true, this widget will receive events.
129 private boolean active
= false;
134 * @return if true, this widget will receive events
136 public final boolean isActive() {
143 * @param active if true, this widget will receive events
145 public final void setActive(final boolean active
) {
146 this.active
= active
;
150 * The window that this widget draws to.
152 private TWindow window
= null;
155 * Get the window this widget is on.
159 public final TWindow
getWindow() {
164 * Absolute X position of the top-left corner.
171 * @return absolute X position of the top-left corner
173 public final int getX() {
180 * @param x absolute X position of the top-left corner
182 public final void setX(final int x
) {
187 * Absolute Y position of the top-left corner.
194 * @return absolute Y position of the top-left corner
196 public final int getY() {
203 * @param y absolute Y position of the top-left corner
205 public final void setY(final int y
) {
212 private int width
= 0;
217 * @return widget width
219 public final int getWidth() {
226 * @param width new widget width
228 public final void setWidth(final int width
) {
235 private int height
= 0;
240 * @return widget height
242 public final int getHeight() {
249 * @param height new widget height
251 public final void setHeight(final int height
) {
252 this.height
= height
;
256 * My tab order inside a window or containing widget.
258 private int tabOrder
= 0;
261 * If true, this widget can be tabbed to or receive events.
263 private boolean enabled
= true;
268 * @return if true, this widget can be tabbed to or receive events
270 public final boolean isEnabled() {
277 * @param enabled if true, this widget can be tabbed to or receive events
279 public final void setEnabled(final boolean enabled
) {
280 this.enabled
= enabled
;
283 // See if there are any active siblings to switch to
284 boolean foundSibling
= false;
285 if (parent
!= null) {
286 for (TWidget w
: parent
.children
) {
288 && !(this instanceof THScroller
)
289 && !(this instanceof TVScroller
)
297 parent
.activeChild
= null;
304 * If true, this widget has a cursor.
306 private boolean cursorVisible
= false;
309 * Set visible cursor flag.
311 * @param cursorVisible if true, this widget has a cursor
313 public final void setCursorVisible(final boolean cursorVisible
) {
314 this.cursorVisible
= cursorVisible
;
318 * See if this widget has a visible cursor.
320 * @return if true, this widget has a visible cursor
322 public final boolean isCursorVisible() {
323 return cursorVisible
;
327 * Cursor column position in relative coordinates.
329 private int cursorX
= 0;
332 * Get cursor X value.
334 * @return cursor column position in relative coordinates
336 public final int getCursorX() {
341 * Set cursor X value.
343 * @param cursorX column position in relative coordinates
345 public final void setCursorX(final int cursorX
) {
346 this.cursorX
= cursorX
;
350 * Cursor row position in relative coordinates.
352 private int cursorY
= 0;
355 * Get cursor Y value.
357 * @return cursor row position in relative coordinates
359 public final int getCursorY() {
364 * Set cursor Y value.
366 * @param cursorY row position in relative coordinates
368 public final void setCursorY(final int cursorY
) {
369 this.cursorY
= cursorY
;
373 * Comparison operator sorts on tabOrder for TWidgets and z for TWindows.
375 * @param that another TWidget or TWindow instance
376 * @return difference between this.tabOrder and that.tabOrder, or
377 * difference between this.z and that.z
380 public final int compareTo(final TWidget that
) {
381 if ((this instanceof TWindow
)
382 && (that
instanceof TWindow
)
384 return (((TWindow
) this).getZ() - ((TWindow
) that
).getZ());
386 return (this.tabOrder
- that
.tabOrder
);
390 * See if this widget should render with the active color.
392 * @return true if this widget is active and all of its parents are
395 public final boolean isAbsoluteActive() {
396 if (parent
== this) {
399 return (active
&& parent
.isAbsoluteActive());
403 * Returns the cursor X position.
405 * @return absolute screen column number for the cursor's X position
407 public final int getCursorAbsoluteX() {
408 assert (cursorVisible
);
409 return getAbsoluteX() + cursorX
;
413 * Returns the cursor Y position.
415 * @return absolute screen row number for the cursor's Y position
417 public final int getCursorAbsoluteY() {
418 assert (cursorVisible
);
419 return getAbsoluteY() + cursorY
;
423 * Compute my absolute X position as the sum of my X plus all my parent's
426 * @return absolute screen column number for my X position
428 public final int getAbsoluteX() {
429 assert (parent
!= null);
430 if (parent
== this) {
433 if ((parent
instanceof TWindow
) && !(parent
instanceof TMenu
)) {
434 // Widgets on a TWindow have (0,0) as their top-left, but this is
435 // actually the TWindow's (1,1).
436 return parent
.getAbsoluteX() + x
+ 1;
438 return parent
.getAbsoluteX() + x
;
442 * Compute my absolute Y position as the sum of my Y plus all my parent's
445 * @return absolute screen row number for my Y position
447 public final int getAbsoluteY() {
448 assert (parent
!= null);
449 if (parent
== this) {
452 if ((parent
instanceof TWindow
) && !(parent
instanceof TMenu
)) {
453 // Widgets on a TWindow have (0,0) as their top-left, but this is
454 // actually the TWindow's (1,1).
455 return parent
.getAbsoluteY() + y
+ 1;
457 return parent
.getAbsoluteY() + y
;
461 * Get the global color theme.
463 * @return the ColorTheme
465 public final ColorTheme
getTheme() {
466 return window
.getApplication().getTheme();
470 * Draw my specific widget. When called, the screen rectangle I draw
471 * into is already setup (offset and clipping).
474 // Default widget draws nothing.
478 * Called by parent to render to TWindow.
480 public final void drawChildren() {
481 // Set my clipping rectangle
482 assert (window
!= null);
483 assert (getScreen() != null);
484 Screen screen
= getScreen();
486 screen
.setClipRight(width
);
487 screen
.setClipBottom(height
);
489 int absoluteRightEdge
= window
.getAbsoluteX() + window
.getWidth();
490 int absoluteBottomEdge
= window
.getAbsoluteY() + window
.getHeight();
491 if (!(this instanceof TWindow
) && !(this instanceof TVScroller
)) {
492 absoluteRightEdge
-= 1;
494 if (!(this instanceof TWindow
) && !(this instanceof THScroller
)) {
495 absoluteBottomEdge
-= 1;
497 int myRightEdge
= getAbsoluteX() + width
;
498 int myBottomEdge
= getAbsoluteY() + height
;
499 if (getAbsoluteX() > absoluteRightEdge
) {
501 screen
.setClipRight(0);
502 } else if (myRightEdge
> absoluteRightEdge
) {
503 screen
.setClipRight(screen
.getClipRight()
504 - (myRightEdge
- absoluteRightEdge
));
506 if (getAbsoluteY() > absoluteBottomEdge
) {
508 screen
.setClipBottom(0);
509 } else if (myBottomEdge
> absoluteBottomEdge
) {
510 screen
.setClipBottom(screen
.getClipBottom()
511 - (myBottomEdge
- absoluteBottomEdge
));
515 screen
.setOffsetX(getAbsoluteX());
516 screen
.setOffsetY(getAbsoluteY());
521 // Continue down the chain
522 for (TWidget widget
: children
) {
523 widget
.drawChildren();
528 * Default constructor for subclasses.
530 protected TWidget() {
531 children
= new LinkedList
<TWidget
>();
535 * Protected constructor.
537 * @param parent parent widget
539 protected TWidget(final TWidget parent
) {
544 * Protected constructor.
546 * @param parent parent widget
547 * @param x column relative to parent
548 * @param y row relative to parent
549 * @param width width of widget
550 * @param height height of widget
552 protected TWidget(final TWidget parent
, final int x
, final int y
,
553 final int width
, final int height
) {
555 this(parent
, true, x
, y
, width
, height
);
559 * Protected constructor used by subclasses that are disabled by default.
561 * @param parent parent widget
562 * @param enabled if true assume enabled
564 protected TWidget(final TWidget parent
, final boolean enabled
) {
565 this.enabled
= enabled
;
566 this.parent
= parent
;
567 this.window
= parent
.window
;
568 children
= new LinkedList
<TWidget
>();
569 parent
.addChild(this);
573 * Protected constructor used by subclasses that are disabled by default.
575 * @param parent parent widget
576 * @param enabled if true assume enabled
577 * @param x column relative to parent
578 * @param y row relative to parent
579 * @param width width of widget
580 * @param height height of widget
582 protected TWidget(final TWidget parent
, final boolean enabled
,
583 final int x
, final int y
, final int width
, final int height
) {
585 this.enabled
= enabled
;
586 this.parent
= parent
;
587 this.window
= parent
.window
;
588 children
= new LinkedList
<TWidget
>();
589 parent
.addChild(this);
594 this.height
= height
;
598 * Add a child widget to my list of children. We set its tabOrder to 0
599 * and increment the tabOrder of all other children.
601 * @param child TWidget to add
603 private void addChild(final TWidget child
) {
607 && !(child
instanceof THScroller
)
608 && !(child
instanceof TVScroller
)
610 for (TWidget widget
: children
) {
611 widget
.active
= false;
616 for (int i
= 0; i
< children
.size(); i
++) {
617 children
.get(i
).tabOrder
= i
;
622 * Switch the active child.
624 * @param child TWidget to activate
626 public final void activate(final TWidget child
) {
627 assert (child
.enabled
);
628 if ((child
instanceof THScroller
)
629 || (child
instanceof TVScroller
)
634 if (child
!= activeChild
) {
635 if (activeChild
!= null) {
636 activeChild
.active
= false;
644 * Switch the active child.
646 * @param tabOrder tabOrder of the child to activate. If that child
647 * isn't enabled, then the next enabled child will be activated.
649 public final void activate(final int tabOrder
) {
650 if (activeChild
== null) {
653 TWidget child
= null;
654 for (TWidget widget
: children
) {
656 && !(widget
instanceof THScroller
)
657 && !(widget
instanceof TVScroller
)
658 && (widget
.tabOrder
>= tabOrder
)
664 if ((child
!= null) && (child
!= activeChild
)) {
665 activeChild
.active
= false;
666 assert (child
.enabled
);
673 * Switch the active widget with the next in the tab order.
675 * @param forward if true, then switch to the next enabled widget in the
676 * list, otherwise switch to the previous enabled widget in the list
678 public final void switchWidget(final boolean forward
) {
680 // Only switch if there are multiple enabled widgets
681 if ((children
.size() < 2) || (activeChild
== null)) {
685 int tabOrder
= activeChild
.tabOrder
;
694 // If at the end, pass the switch to my parent.
695 if ((!forward
) && (parent
!= this)) {
696 parent
.switchWidget(forward
);
700 tabOrder
= children
.size() - 1;
701 } else if (tabOrder
== children
.size()) {
702 // If at the end, pass the switch to my parent.
703 if ((forward
) && (parent
!= this)) {
704 parent
.switchWidget(forward
);
710 if (activeChild
.tabOrder
== tabOrder
) {
714 } while ((!children
.get(tabOrder
).enabled
)
715 && !(children
.get(tabOrder
) instanceof THScroller
)
716 && !(children
.get(tabOrder
) instanceof TVScroller
));
718 assert (children
.get(tabOrder
).enabled
);
720 activeChild
.active
= false;
721 children
.get(tabOrder
).active
= true;
722 activeChild
= children
.get(tabOrder
);
726 * Returns my active widget.
728 * @return widget that is active, or this if no children
730 public TWidget
getActiveChild() {
731 if ((this instanceof THScroller
)
732 || (this instanceof TVScroller
)
737 for (TWidget widget
: children
) {
739 return widget
.getActiveChild();
742 // No active children, return me
747 * Method that subclasses can override to handle keystrokes.
749 * @param keypress keystroke event
751 public void onKeypress(final TKeypressEvent keypress
) {
753 if ((children
.size() == 0)
755 // || (cast(TTreeView)this)
756 || (this instanceof TText
)
760 // tab / shift-tab - switch to next/previous widget
761 // right-arrow or down-arrow: same as tab
762 // left-arrow or up-arrow: same as shift-tab
763 if ((keypress
.equals(kbTab
))
764 || (keypress
.equals(kbRight
))
765 || (keypress
.equals(kbDown
))
767 parent
.switchWidget(true);
769 } else if ((keypress
.equals(kbShiftTab
))
770 || (keypress
.equals(kbBackTab
))
771 || (keypress
.equals(kbLeft
))
772 || (keypress
.equals(kbUp
))
774 parent
.switchWidget(false);
779 // If I have any buttons on me AND this is an Alt-key that matches
780 // its mnemonic, send it an Enter keystroke
781 for (TWidget widget
: children
) {
782 if (widget
instanceof TButton
) {
783 TButton button
= (TButton
) widget
;
784 if (button
.isEnabled()
785 && !keypress
.getKey().isFnKey()
786 && keypress
.getKey().isAlt()
787 && !keypress
.getKey().isCtrl()
788 && (Character
.toLowerCase(button
.getMnemonic().getShortcut())
789 == Character
.toLowerCase(keypress
.getKey().getChar()))
792 widget
.handleEvent(new TKeypressEvent(kbEnter
));
798 // Dispatch the keypress to an active widget
799 for (TWidget widget
: children
) {
801 widget
.handleEvent(keypress
);
808 * Method that subclasses can override to handle mouse button presses.
810 * @param mouse mouse button event
812 public void onMouseDown(final TMouseEvent mouse
) {
813 // Default: do nothing, pass to children instead
814 for (TWidget widget
: children
) {
815 if (widget
.mouseWouldHit(mouse
)) {
816 // Dispatch to this child, also activate it
819 // Set x and y relative to the child's coordinates
820 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
821 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
822 widget
.handleEvent(mouse
);
829 * Method that subclasses can override to handle mouse button releases.
831 * @param mouse mouse button event
833 public void onMouseUp(final TMouseEvent mouse
) {
834 // Default: do nothing, pass to children instead
835 for (TWidget widget
: children
) {
836 if (widget
.mouseWouldHit(mouse
)) {
837 // Dispatch to this child, also activate it
840 // Set x and y relative to the child's coordinates
841 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
842 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
843 widget
.handleEvent(mouse
);
850 * Method that subclasses can override to handle mouse movements.
852 * @param mouse mouse motion event
854 public void onMouseMotion(final TMouseEvent mouse
) {
855 // Default: do nothing, pass it on to ALL of my children. This way
856 // the children can see the mouse "leaving" their area.
857 for (TWidget widget
: children
) {
858 // Set x and y relative to the child's coordinates
859 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
860 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
861 widget
.handleEvent(mouse
);
866 * Method that subclasses can override to handle window/screen resize
869 * @param resize resize event
871 public void onResize(final TResizeEvent resize
) {
872 // Default: do nothing, pass to children instead
873 for (TWidget widget
: children
) {
874 widget
.onResize(resize
);
879 * Method that subclasses can override to handle posted command events.
881 * @param command command event
883 public void onCommand(final TCommandEvent command
) {
884 // Default: do nothing, pass to children instead
885 for (TWidget widget
: children
) {
886 widget
.onCommand(command
);
891 * Method that subclasses can override to handle menu or posted menu
894 * @param menu menu event
896 public void onMenu(final TMenuEvent menu
) {
897 // Default: do nothing, pass to children instead
898 for (TWidget widget
: children
) {
904 * Method that subclasses can override to do processing when the UI is
907 public void onIdle() {
908 // Default: do nothing, pass to children instead
909 for (TWidget widget
: children
) {
915 * Consume event. Subclasses that want to intercept all events in one go
916 * can override this method.
918 * @param event keyboard, mouse, resize, command, or menu event
920 public void handleEvent(final TInputEvent event
) {
921 // System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(),
926 // System.err.println(" -- discard --");
930 if (event
instanceof TKeypressEvent
) {
931 onKeypress((TKeypressEvent
) event
);
932 } else if (event
instanceof TMouseEvent
) {
934 TMouseEvent mouse
= (TMouseEvent
) event
;
936 switch (mouse
.getType()) {
947 onMouseMotion(mouse
);
951 throw new IllegalArgumentException("Invalid mouse event type: "
954 } else if (event
instanceof TResizeEvent
) {
955 onResize((TResizeEvent
) event
);
956 } else if (event
instanceof TCommandEvent
) {
957 onCommand((TCommandEvent
) event
);
958 } else if (event
instanceof TMenuEvent
) {
959 onMenu((TMenuEvent
) event
);
967 * Check if a mouse press/release event coordinate is contained in this
970 * @param mouse a mouse-based event
971 * @return whether or not a mouse click would be sent to this widget
973 public final boolean mouseWouldHit(final TMouseEvent mouse
) {
979 if ((mouse
.getAbsoluteX() >= getAbsoluteX())
980 && (mouse
.getAbsoluteX() < getAbsoluteX() + width
)
981 && (mouse
.getAbsoluteY() >= getAbsoluteY())
982 && (mouse
.getAbsoluteY() < getAbsoluteY() + height
)
990 * Convenience function to add a label to this container/window.
993 * @param x column relative to parent
994 * @param y row relative to parent
995 * @return the new label
997 public final TLabel
addLabel(final String text
, final int x
, final int y
) {
998 return addLabel(text
, x
, y
, "tlabel");
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 * @param colorKey ColorTheme key color to use for foreground text.
1008 * Default is "tlabel"
1009 * @return the new label
1011 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1012 final String colorKey
) {
1014 return new TLabel(this, text
, x
, y
, colorKey
);
1018 * Convenience function to add a button to this container/window.
1020 * @param text label on the button
1021 * @param x column relative to parent
1022 * @param y row relative to parent
1023 * @param action to call when button is pressed
1024 * @return the new button
1026 public final TButton
addButton(final String text
, final int x
, final int y
,
1027 final TAction action
) {
1029 return new TButton(this, text
, x
, y
, action
);
1033 * Convenience function to add a checkbox to this container/window.
1035 * @param x column relative to parent
1036 * @param y row relative to parent
1037 * @param label label to display next to (right of) the checkbox
1038 * @param checked initial check state
1039 * @return the new checkbox
1041 public final TCheckbox
addCheckbox(final int x
, final int y
,
1042 final String label
, final boolean checked
) {
1044 return new TCheckbox(this, x
, y
, label
, checked
);
1048 * Convenience function to add a progress bar to this container/window.
1050 * @param x column relative to parent
1051 * @param y row relative to parent
1052 * @param width width of progress bar
1053 * @param value initial value of percent complete
1054 * @return the new progress bar
1056 public final TProgressBar
addProgressBar(final int x
, final int y
,
1057 final int width
, final int value
) {
1059 return new TProgressBar(this, x
, y
, width
, value
);
1063 * Convenience function to add a radio button group to this
1066 * @param x column relative to parent
1067 * @param y row relative to parent
1068 * @param label label to display on the group box
1069 * @return the new radio button group
1071 public final TRadioGroup
addRadioGroup(final int x
, final int y
,
1072 final String label
) {
1074 return new TRadioGroup(this, x
, y
, label
);
1078 * Convenience function to add a text field to this container/window.
1080 * @param x column relative to parent
1081 * @param y row relative to parent
1082 * @param width visible text width
1083 * @param fixed if true, the text cannot exceed the display width
1084 * @return the new text field
1086 public final TField
addField(final int x
, final int y
,
1087 final int width
, final boolean fixed
) {
1089 return new TField(this, x
, y
, width
, fixed
);
1093 * Convenience function to add a text field to this container/window.
1095 * @param x column relative to parent
1096 * @param y row relative to parent
1097 * @param width visible text width
1098 * @param fixed if true, the text cannot exceed the display width
1099 * @param text initial text, default is empty string
1100 * @return the new text field
1102 public final TField
addField(final int x
, final int y
,
1103 final int width
, final boolean fixed
, final String text
) {
1105 return new TField(this, x
, y
, width
, fixed
, text
);
1109 * Convenience function to add a text field to this container/window.
1111 * @param x column relative to parent
1112 * @param y row relative to parent
1113 * @param width visible text width
1114 * @param fixed if true, the text cannot exceed the display width
1115 * @param text initial text, default is empty string
1116 * @param enterAction function to call when enter key is pressed
1117 * @param updateAction function to call when the text is updated
1118 * @return the new text field
1120 public final TField
addField(final int x
, final int y
,
1121 final int width
, final boolean fixed
, final String text
,
1122 final TAction enterAction
, final TAction updateAction
) {
1124 return new TField(this, x
, y
, width
, fixed
, text
, enterAction
,
1129 * Convenience function to add a scrollable text box to this
1132 * @param text text on the screen
1133 * @param x column relative to parent
1134 * @param y row relative to parent
1135 * @param width width of text area
1136 * @param height height of text area
1137 * @param colorKey ColorTheme key color to use for foreground text
1138 * @return the new text box
1140 public final TText
addText(final String text
, final int x
,
1141 final int y
, final int width
, final int height
, final String colorKey
) {
1143 return new TText(this, text
, x
, y
, width
, height
, colorKey
);
1147 * Convenience function to add a scrollable text box to this
1150 * @param text text on the screen
1151 * @param x column relative to parent
1152 * @param y row relative to parent
1153 * @param width width of text area
1154 * @param height height of text area
1155 * @return the new text box
1157 public final TText
addText(final String text
, final int x
, final int y
,
1158 final int width
, final int height
) {
1160 return new TText(this, text
, x
, y
, width
, height
, "ttext");
1164 * Convenience function to spawn a message box.
1166 * @param title window title, will be centered along the top border
1167 * @param caption message to display. Use embedded newlines to get a
1169 * @return the new message box
1171 public final TMessageBox
messageBox(final String title
,
1172 final String caption
) {
1174 return getApplication().messageBox(title
, caption
, TMessageBox
.Type
.OK
);
1178 * Convenience function to spawn a message box.
1180 * @param title window title, will be centered along the top border
1181 * @param caption message to display. Use embedded newlines to get a
1183 * @param type one of the TMessageBox.Type constants. Default is
1185 * @return the new message box
1187 public final TMessageBox
messageBox(final String title
,
1188 final String caption
, final TMessageBox
.Type type
) {
1190 return getApplication().messageBox(title
, caption
, type
);
1194 * Convenience function to spawn an input box.
1196 * @param title window title, will be centered along the top border
1197 * @param caption message to display. Use embedded newlines to get a
1199 * @return the new input box
1201 public final TInputBox
inputBox(final String title
, final String caption
) {
1203 return getApplication().inputBox(title
, caption
);
1207 * Convenience function to spawn an input box.
1209 * @param title window title, will be centered along the top border
1210 * @param caption message to display. Use embedded newlines to get a
1212 * @param text initial text to seed the field with
1213 * @return the new input box
1215 public final TInputBox
inputBox(final String title
, final String caption
,
1216 final String text
) {
1218 return getApplication().inputBox(title
, caption
, text
);
1222 * Convenience function to add a password text field to this
1225 * @param x column relative to parent
1226 * @param y row relative to parent
1227 * @param width visible text width
1228 * @param fixed if true, the text cannot exceed the display width
1229 * @return the new text field
1231 public final TPasswordField
addPasswordField(final int x
, final int y
,
1232 final int width
, final boolean fixed
) {
1234 return new TPasswordField(this, x
, y
, width
, fixed
);
1238 * Convenience function to add a password text field to this
1241 * @param x column relative to parent
1242 * @param y row relative to parent
1243 * @param width visible text width
1244 * @param fixed if true, the text cannot exceed the display width
1245 * @param text initial text, default is empty string
1246 * @return the new text field
1248 public final TPasswordField
addPasswordField(final int x
, final int y
,
1249 final int width
, final boolean fixed
, final String text
) {
1251 return new TPasswordField(this, x
, y
, width
, fixed
, text
);
1255 * Convenience function to add a password text field to this
1258 * @param x column relative to parent
1259 * @param y row relative to parent
1260 * @param width visible text width
1261 * @param fixed if true, the text cannot exceed the display width
1262 * @param text initial text, default is empty string
1263 * @param enterAction function to call when enter key is pressed
1264 * @param updateAction function to call when the text is updated
1265 * @return the new text field
1267 public final TPasswordField
addPasswordField(final int x
, final int y
,
1268 final int width
, final boolean fixed
, final String text
,
1269 final TAction enterAction
, final TAction updateAction
) {
1271 return new TPasswordField(this, x
, y
, width
, fixed
, text
, enterAction
,