2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 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
.io
.IOException
;
32 import java
.util
.List
;
33 import java
.util
.ArrayList
;
35 import jexer
.backend
.Screen
;
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
.menu
.TMenu
;
44 import static jexer
.TKeypress
.*;
47 * TWidget is the base class of all objects that can be drawn on screen or
48 * handle user input events.
50 public abstract class TWidget
implements Comparable
<TWidget
> {
52 // ------------------------------------------------------------------------
53 // Common widget attributes -----------------------------------------------
54 // ------------------------------------------------------------------------
57 * Every widget has a parent widget that it may be "contained" in. For
58 * example, a TWindow might contain several TTextFields, or a TComboBox
59 * may contain a TScrollBar.
61 private TWidget parent
= null;
66 * @return parent widget
68 public final TWidget
getParent() {
73 * Child widgets that this widget contains.
75 private List
<TWidget
> children
;
78 * Get the list of child widgets that this widget contains.
80 * @return the list of child widgets
82 public List
<TWidget
> getChildren() {
87 * The currently active child widget that will receive keypress events.
89 private TWidget activeChild
= null;
92 * If true, this widget will receive events.
94 private boolean active
= false;
99 * @return if true, this widget will receive events
101 public final boolean isActive() {
108 * @param active if true, this widget will receive events
110 public final void setActive(final boolean active
) {
111 this.active
= active
;
115 * The window that this widget draws to.
117 private TWindow window
= null;
120 * Get the window this widget is on.
124 public final TWindow
getWindow() {
129 * Absolute X position of the top-left corner.
136 * @return absolute X position of the top-left corner
138 public final int getX() {
145 * @param x absolute X position of the top-left corner
147 public final void setX(final int x
) {
152 * Absolute Y position of the top-left corner.
159 * @return absolute Y position of the top-left corner
161 public final int getY() {
168 * @param y absolute Y position of the top-left corner
170 public final void setY(final int y
) {
177 private int width
= 0;
182 * @return widget width
184 public final int getWidth() {
191 * @param width new widget width
193 public final void setWidth(final int width
) {
200 private int height
= 0;
205 * @return widget height
207 public final int getHeight() {
214 * @param height new widget height
216 public final void setHeight(final int height
) {
217 this.height
= height
;
221 * Change the dimensions.
223 * @param x absolute X position of the top-left corner
224 * @param y absolute Y position of the top-left corner
225 * @param width new widget width
226 * @param height new widget height
228 public final void setDimensions(final int x
, final int y
, final int width
,
238 * My tab order inside a window or containing widget.
240 private int tabOrder
= 0;
243 * If true, this widget can be tabbed to or receive events.
245 private boolean enabled
= true;
250 * @return if true, this widget can be tabbed to or receive events
252 public final boolean isEnabled() {
259 * @param enabled if true, this widget can be tabbed to or receive events
261 public final void setEnabled(final boolean enabled
) {
262 this.enabled
= enabled
;
265 // See if there are any active siblings to switch to
266 boolean foundSibling
= false;
267 if (parent
!= null) {
268 for (TWidget w
: parent
.children
) {
270 && !(this instanceof THScroller
)
271 && !(this instanceof TVScroller
)
279 parent
.activeChild
= null;
286 * If true, this widget has a cursor.
288 private boolean cursorVisible
= false;
291 * Set visible cursor flag.
293 * @param cursorVisible if true, this widget has a cursor
295 public final void setCursorVisible(final boolean cursorVisible
) {
296 this.cursorVisible
= cursorVisible
;
300 * See if this widget has a visible cursor.
302 * @return if true, this widget has a visible cursor
304 public final boolean isCursorVisible() {
305 // If cursor is out of my bounds, it is not visible.
306 if ((cursorX
>= width
)
308 || (cursorY
>= height
)
314 // If cursor is out of my window's bounds, it is not visible.
315 if ((getCursorAbsoluteX() >= window
.getAbsoluteX()
316 + window
.getWidth() - 1)
317 || (getCursorAbsoluteX() < 0)
318 || (getCursorAbsoluteY() >= window
.getAbsoluteY()
319 + window
.getHeight() - 1)
320 || (getCursorAbsoluteY() < 0)
324 return cursorVisible
;
328 * Cursor column position in relative coordinates.
330 private int cursorX
= 0;
333 * Get cursor X value.
335 * @return cursor column position in relative coordinates
337 public final int getCursorX() {
342 * Set cursor X value.
344 * @param cursorX column position in relative coordinates
346 public final void setCursorX(final int cursorX
) {
347 this.cursorX
= cursorX
;
351 * Cursor row position in relative coordinates.
353 private int cursorY
= 0;
356 * Get cursor Y value.
358 * @return cursor row position in relative coordinates
360 public final int getCursorY() {
365 * Set cursor Y value.
367 * @param cursorY row position in relative coordinates
369 public final void setCursorY(final int cursorY
) {
370 this.cursorY
= cursorY
;
373 // ------------------------------------------------------------------------
374 // TApplication integration -----------------------------------------------
375 // ------------------------------------------------------------------------
378 * Get this TWidget's parent TApplication.
380 * @return the parent TApplication
382 public TApplication
getApplication() {
383 return window
.getApplication();
391 public Screen
getScreen() {
392 return window
.getScreen();
396 * Comparison operator. For various subclasses it sorts on:
398 * <li>tabOrder for TWidgets</li>
399 * <li>z for TWindows</li>
400 * <li>text for TTreeItems</li>
403 * @param that another TWidget, TWindow, or TTreeItem instance
404 * @return difference between this.tabOrder and that.tabOrder, or
405 * difference between this.z and that.z, or String.compareTo(text)
407 public final int compareTo(final TWidget that
) {
408 if ((this instanceof TWindow
)
409 && (that
instanceof TWindow
)
411 return (((TWindow
) this).getZ() - ((TWindow
) that
).getZ());
413 if ((this instanceof TTreeItem
)
414 && (that
instanceof TTreeItem
)
416 return (((TTreeItem
) this).getText().compareTo(
417 ((TTreeItem
) that
).getText()));
419 return (this.tabOrder
- that
.tabOrder
);
423 * See if this widget should render with the active color.
425 * @return true if this widget is active and all of its parents are
428 public final boolean isAbsoluteActive() {
429 if (parent
== this) {
432 return (active
&& parent
.isAbsoluteActive());
436 * Returns the cursor X position.
438 * @return absolute screen column number for the cursor's X position
440 public final int getCursorAbsoluteX() {
441 return getAbsoluteX() + cursorX
;
445 * Returns the cursor Y position.
447 * @return absolute screen row number for the cursor's Y position
449 public final int getCursorAbsoluteY() {
450 return getAbsoluteY() + cursorY
;
454 * Compute my absolute X position as the sum of my X plus all my parent's
457 * @return absolute screen column number for my X position
459 public final int getAbsoluteX() {
460 assert (parent
!= null);
461 if (parent
== this) {
464 if ((parent
instanceof TWindow
)
465 && !(parent
instanceof TMenu
)
466 && !(parent
instanceof TDesktop
)
468 // Widgets on a TWindow have (0,0) as their top-left, but this is
469 // actually the TWindow's (1,1).
470 return parent
.getAbsoluteX() + x
+ 1;
472 return parent
.getAbsoluteX() + x
;
476 * Compute my absolute Y position as the sum of my Y plus all my parent's
479 * @return absolute screen row number for my Y position
481 public final int getAbsoluteY() {
482 assert (parent
!= null);
483 if (parent
== this) {
486 if ((parent
instanceof TWindow
)
487 && !(parent
instanceof TMenu
)
488 && !(parent
instanceof TDesktop
)
490 // Widgets on a TWindow have (0,0) as their top-left, but this is
491 // actually the TWindow's (1,1).
492 return parent
.getAbsoluteY() + y
+ 1;
494 return parent
.getAbsoluteY() + y
;
498 * Get the global color theme.
500 * @return the ColorTheme
502 public final ColorTheme
getTheme() {
503 return window
.getApplication().getTheme();
507 * Draw my specific widget. When called, the screen rectangle I draw
508 * into is already setup (offset and clipping).
511 // Default widget draws nothing.
515 * Called by parent to render to TWindow.
517 public final void drawChildren() {
518 // Set my clipping rectangle
519 assert (window
!= null);
520 assert (getScreen() != null);
521 Screen screen
= getScreen();
523 // Special case: TStatusBar is drawn by TApplication, not anything
525 if (this instanceof TStatusBar
) {
529 screen
.setClipRight(width
);
530 screen
.setClipBottom(height
);
532 int absoluteRightEdge
= window
.getAbsoluteX() + window
.getWidth();
533 int absoluteBottomEdge
= window
.getAbsoluteY() + window
.getHeight();
534 if (!(this instanceof TWindow
) && !(this instanceof TVScroller
)) {
535 absoluteRightEdge
-= 1;
537 if (!(this instanceof TWindow
) && !(this instanceof THScroller
)) {
538 absoluteBottomEdge
-= 1;
540 int myRightEdge
= getAbsoluteX() + width
;
541 int myBottomEdge
= getAbsoluteY() + height
;
542 if (getAbsoluteX() > absoluteRightEdge
) {
544 screen
.setClipRight(0);
545 } else if (myRightEdge
> absoluteRightEdge
) {
546 screen
.setClipRight(screen
.getClipRight()
547 - (myRightEdge
- absoluteRightEdge
));
549 if (getAbsoluteY() > absoluteBottomEdge
) {
551 screen
.setClipBottom(0);
552 } else if (myBottomEdge
> absoluteBottomEdge
) {
553 screen
.setClipBottom(screen
.getClipBottom()
554 - (myBottomEdge
- absoluteBottomEdge
));
558 screen
.setOffsetX(getAbsoluteX());
559 screen
.setOffsetY(getAbsoluteY());
564 // Continue down the chain
565 for (TWidget widget
: children
) {
566 widget
.drawChildren();
571 * Repaint the screen on the next update.
573 public void doRepaint() {
574 window
.getApplication().doRepaint();
577 // ------------------------------------------------------------------------
578 // Constructors -----------------------------------------------------------
579 // ------------------------------------------------------------------------
582 * Default constructor for subclasses.
584 protected TWidget() {
585 children
= new ArrayList
<TWidget
>();
589 * Protected constructor.
591 * @param parent parent widget
593 protected TWidget(final TWidget parent
) {
598 * Protected constructor.
600 * @param parent parent widget
601 * @param x column relative to parent
602 * @param y row relative to parent
603 * @param width width of widget
604 * @param height height of widget
606 protected TWidget(final TWidget parent
, final int x
, final int y
,
607 final int width
, final int height
) {
609 this(parent
, true, x
, y
, width
, height
);
613 * Protected constructor used by subclasses that are disabled by default.
615 * @param parent parent widget
616 * @param enabled if true assume enabled
618 protected TWidget(final TWidget parent
, final boolean enabled
) {
619 this.enabled
= enabled
;
620 this.parent
= parent
;
621 this.window
= parent
.window
;
622 children
= new ArrayList
<TWidget
>();
624 // Do not add TStatusBars, they are drawn by TApplication
625 if (this instanceof TStatusBar
) {
627 parent
.addChild(this);
632 * Protected constructor used by subclasses that are disabled by default.
634 * @param parent parent widget
635 * @param enabled if true assume enabled
636 * @param x column relative to parent
637 * @param y row relative to parent
638 * @param width width of widget
639 * @param height height of widget
641 protected TWidget(final TWidget parent
, final boolean enabled
,
642 final int x
, final int y
, final int width
, final int height
) {
644 this.enabled
= enabled
;
645 this.parent
= parent
;
646 this.window
= parent
.window
;
647 children
= new ArrayList
<TWidget
>();
649 // Do not add TStatusBars, they are drawn by TApplication
650 if (this instanceof TStatusBar
) {
652 parent
.addChild(this);
658 this.height
= height
;
662 * Backdoor access for TWindow's constructor. ONLY TWindow USES THIS.
664 * @param window the top-level window
665 * @param x column relative to parent
666 * @param y row relative to parent
667 * @param width width of window
668 * @param height height of window
670 protected final void setupForTWindow(final TWindow window
,
671 final int x
, final int y
, final int width
, final int height
) {
673 this.parent
= window
;
674 this.window
= window
;
678 this.height
= height
;
681 // ------------------------------------------------------------------------
682 // General behavior -------------------------------------------------------
683 // ------------------------------------------------------------------------
686 * Add a child widget to my list of children. We set its tabOrder to 0
687 * and increment the tabOrder of all other children.
689 * @param child TWidget to add
691 private void addChild(final TWidget child
) {
695 && !(child
instanceof THScroller
)
696 && !(child
instanceof TVScroller
)
698 for (TWidget widget
: children
) {
699 widget
.active
= false;
704 for (int i
= 0; i
< children
.size(); i
++) {
705 children
.get(i
).tabOrder
= i
;
710 * Switch the active child.
712 * @param child TWidget to activate
714 public final void activate(final TWidget child
) {
715 assert (child
.enabled
);
716 if ((child
instanceof THScroller
)
717 || (child
instanceof TVScroller
)
722 if (child
!= activeChild
) {
723 if (activeChild
!= null) {
724 activeChild
.active
= false;
732 * Switch the active child.
734 * @param tabOrder tabOrder of the child to activate. If that child
735 * isn't enabled, then the next enabled child will be activated.
737 public final void activate(final int tabOrder
) {
738 if (activeChild
== null) {
741 TWidget child
= null;
742 for (TWidget widget
: children
) {
744 && !(widget
instanceof THScroller
)
745 && !(widget
instanceof TVScroller
)
746 && (widget
.tabOrder
>= tabOrder
)
752 if ((child
!= null) && (child
!= activeChild
)) {
753 activeChild
.active
= false;
754 assert (child
.enabled
);
761 * Switch the active widget with the next in the tab order.
763 * @param forward if true, then switch to the next enabled widget in the
764 * list, otherwise switch to the previous enabled widget in the list
766 public final void switchWidget(final boolean forward
) {
768 // Only switch if there are multiple enabled widgets
769 if ((children
.size() < 2) || (activeChild
== null)) {
773 int tabOrder
= activeChild
.tabOrder
;
782 // If at the end, pass the switch to my parent.
783 if ((!forward
) && (parent
!= this)) {
784 parent
.switchWidget(forward
);
788 tabOrder
= children
.size() - 1;
789 } else if (tabOrder
== children
.size()) {
790 // If at the end, pass the switch to my parent.
791 if ((forward
) && (parent
!= this)) {
792 parent
.switchWidget(forward
);
798 if (activeChild
.tabOrder
== tabOrder
) {
802 } while ((!children
.get(tabOrder
).enabled
)
803 && !(children
.get(tabOrder
) instanceof THScroller
)
804 && !(children
.get(tabOrder
) instanceof TVScroller
));
806 assert (children
.get(tabOrder
).enabled
);
808 activeChild
.active
= false;
809 children
.get(tabOrder
).active
= true;
810 activeChild
= children
.get(tabOrder
);
814 * Returns my active widget.
816 * @return widget that is active, or this if no children
818 public TWidget
getActiveChild() {
819 if ((this instanceof THScroller
)
820 || (this instanceof TVScroller
)
825 for (TWidget widget
: children
) {
827 return widget
.getActiveChild();
830 // No active children, return me
834 // ------------------------------------------------------------------------
835 // Event handlers ---------------------------------------------------------
836 // ------------------------------------------------------------------------
839 * Check if a mouse press/release event coordinate is contained in this
842 * @param mouse a mouse-based event
843 * @return whether or not a mouse click would be sent to this widget
845 public final boolean mouseWouldHit(final TMouseEvent mouse
) {
851 if ((mouse
.getAbsoluteX() >= getAbsoluteX())
852 && (mouse
.getAbsoluteX() < getAbsoluteX() + width
)
853 && (mouse
.getAbsoluteY() >= getAbsoluteY())
854 && (mouse
.getAbsoluteY() < getAbsoluteY() + height
)
862 * Method that subclasses can override to handle keystrokes.
864 * @param keypress keystroke event
866 public void onKeypress(final TKeypressEvent keypress
) {
868 if ((children
.size() == 0)
869 || (this instanceof TTreeView
)
870 || (this instanceof TText
)
874 // tab / shift-tab - switch to next/previous widget
875 // right-arrow or down-arrow: same as tab
876 // left-arrow or up-arrow: same as shift-tab
877 if ((keypress
.equals(kbTab
))
878 || (keypress
.equals(kbRight
))
879 || (keypress
.equals(kbDown
))
881 parent
.switchWidget(true);
883 } else if ((keypress
.equals(kbShiftTab
))
884 || (keypress
.equals(kbBackTab
))
885 || (keypress
.equals(kbLeft
))
886 || (keypress
.equals(kbUp
))
888 parent
.switchWidget(false);
893 // If I have any buttons on me AND this is an Alt-key that matches
894 // its mnemonic, send it an Enter keystroke
895 for (TWidget widget
: children
) {
896 if (widget
instanceof TButton
) {
897 TButton button
= (TButton
) widget
;
898 if (button
.isEnabled()
899 && !keypress
.getKey().isFnKey()
900 && keypress
.getKey().isAlt()
901 && !keypress
.getKey().isCtrl()
902 && (Character
.toLowerCase(button
.getMnemonic().getShortcut())
903 == Character
.toLowerCase(keypress
.getKey().getChar()))
906 widget
.handleEvent(new TKeypressEvent(kbEnter
));
912 // Dispatch the keypress to an active widget
913 for (TWidget widget
: children
) {
915 widget
.handleEvent(keypress
);
922 * Method that subclasses can override to handle mouse button presses.
924 * @param mouse mouse button event
926 public void onMouseDown(final TMouseEvent mouse
) {
927 // Default: do nothing, pass to children instead
928 for (int i
= children
.size() - 1 ; i
>= 0 ; i
--) {
929 TWidget widget
= children
.get(i
);
930 if (widget
.mouseWouldHit(mouse
)) {
931 // Dispatch to this child, also activate it
934 // Set x and y relative to the child's coordinates
935 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
936 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
937 widget
.handleEvent(mouse
);
944 * Method that subclasses can override to handle mouse button releases.
946 * @param mouse mouse button event
948 public void onMouseUp(final TMouseEvent mouse
) {
949 // Default: do nothing, pass to children instead
950 for (int i
= children
.size() - 1 ; i
>= 0 ; i
--) {
951 TWidget widget
= children
.get(i
);
952 if (widget
.mouseWouldHit(mouse
)) {
953 // Dispatch to this child, also activate it
956 // Set x and y relative to the child's coordinates
957 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
958 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
959 widget
.handleEvent(mouse
);
966 * Method that subclasses can override to handle mouse movements.
968 * @param mouse mouse motion event
970 public void onMouseMotion(final TMouseEvent mouse
) {
971 // Default: do nothing, pass it on to ALL of my children. This way
972 // the children can see the mouse "leaving" their area.
973 for (TWidget widget
: children
) {
974 // Set x and y relative to the child's coordinates
975 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
976 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
977 widget
.handleEvent(mouse
);
982 * Method that subclasses can override to handle mouse button
985 * @param mouse mouse button event
987 public void onMouseDoubleClick(final TMouseEvent mouse
) {
988 // Default: do nothing, pass to children instead
989 for (int i
= children
.size() - 1 ; i
>= 0 ; i
--) {
990 TWidget widget
= children
.get(i
);
991 if (widget
.mouseWouldHit(mouse
)) {
992 // Dispatch to this child, also activate it
995 // Set x and y relative to the child's coordinates
996 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
997 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
998 widget
.handleEvent(mouse
);
1005 * Method that subclasses can override to handle window/screen resize
1008 * @param resize resize event
1010 public void onResize(final TResizeEvent resize
) {
1011 // Default: change my width/height.
1012 if (resize
.getType() == TResizeEvent
.Type
.WIDGET
) {
1013 width
= resize
.getWidth();
1014 height
= resize
.getHeight();
1016 // Let children see the screen resize
1017 for (TWidget widget
: children
) {
1018 widget
.onResize(resize
);
1024 * Method that subclasses can override to handle posted command events.
1026 * @param command command event
1028 public void onCommand(final TCommandEvent command
) {
1029 // Default: do nothing, pass to children instead
1030 for (TWidget widget
: children
) {
1031 widget
.onCommand(command
);
1036 * Method that subclasses can override to handle menu or posted menu
1039 * @param menu menu event
1041 public void onMenu(final TMenuEvent menu
) {
1042 // Default: do nothing, pass to children instead
1043 for (TWidget widget
: children
) {
1044 widget
.onMenu(menu
);
1049 * Method that subclasses can override to do processing when the UI is
1050 * idle. Note that repainting is NOT assumed. To get a refresh after
1051 * onIdle, call doRepaint().
1053 public void onIdle() {
1054 // Default: do nothing, pass to children instead
1055 for (TWidget widget
: children
) {
1061 * Consume event. Subclasses that want to intercept all events in one go
1062 * can override this method.
1064 * @param event keyboard, mouse, resize, command, or menu event
1066 public void handleEvent(final TInputEvent event
) {
1067 // System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(),
1072 // System.err.println(" -- discard --");
1076 if (event
instanceof TKeypressEvent
) {
1077 onKeypress((TKeypressEvent
) event
);
1078 } else if (event
instanceof TMouseEvent
) {
1080 TMouseEvent mouse
= (TMouseEvent
) event
;
1082 switch (mouse
.getType()) {
1093 onMouseMotion(mouse
);
1096 case MOUSE_DOUBLE_CLICK
:
1097 onMouseDoubleClick(mouse
);
1101 throw new IllegalArgumentException("Invalid mouse event type: "
1104 } else if (event
instanceof TResizeEvent
) {
1105 onResize((TResizeEvent
) event
);
1106 } else if (event
instanceof TCommandEvent
) {
1107 onCommand((TCommandEvent
) event
);
1108 } else if (event
instanceof TMenuEvent
) {
1109 onMenu((TMenuEvent
) event
);
1116 // ------------------------------------------------------------------------
1117 // Other TWidget constructors ---------------------------------------------
1118 // ------------------------------------------------------------------------
1121 * Convenience function to add a label to this container/window.
1124 * @param x column relative to parent
1125 * @param y row relative to parent
1126 * @return the new label
1128 public final TLabel
addLabel(final String text
, final int x
, final int y
) {
1129 return addLabel(text
, x
, y
, "tlabel");
1133 * Convenience function to add a label to this container/window.
1136 * @param x column relative to parent
1137 * @param y row relative to parent
1138 * @param colorKey ColorTheme key color to use for foreground text.
1139 * Default is "tlabel"
1140 * @return the new label
1142 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1143 final String colorKey
) {
1145 return new TLabel(this, text
, x
, y
, colorKey
);
1149 * Convenience function to add a button to this container/window.
1151 * @param text label on the button
1152 * @param x column relative to parent
1153 * @param y row relative to parent
1154 * @param action to call when button is pressed
1155 * @return the new button
1157 public final TButton
addButton(final String text
, final int x
, final int y
,
1158 final TAction action
) {
1160 return new TButton(this, text
, x
, y
, action
);
1164 * Convenience function to add a checkbox to this container/window.
1166 * @param x column relative to parent
1167 * @param y row relative to parent
1168 * @param label label to display next to (right of) the checkbox
1169 * @param checked initial check state
1170 * @return the new checkbox
1172 public final TCheckbox
addCheckbox(final int x
, final int y
,
1173 final String label
, final boolean checked
) {
1175 return new TCheckbox(this, x
, y
, label
, checked
);
1179 * Convenience function to add a progress bar to this container/window.
1181 * @param x column relative to parent
1182 * @param y row relative to parent
1183 * @param width width of progress bar
1184 * @param value initial value of percent complete
1185 * @return the new progress bar
1187 public final TProgressBar
addProgressBar(final int x
, final int y
,
1188 final int width
, final int value
) {
1190 return new TProgressBar(this, x
, y
, width
, value
);
1194 * Convenience function to add a radio button group to this
1197 * @param x column relative to parent
1198 * @param y row relative to parent
1199 * @param label label to display on the group box
1200 * @return the new radio button group
1202 public final TRadioGroup
addRadioGroup(final int x
, final int y
,
1203 final String label
) {
1205 return new TRadioGroup(this, x
, y
, label
);
1209 * Convenience function to add a text field to this container/window.
1211 * @param x column relative to parent
1212 * @param y row relative to parent
1213 * @param width visible text width
1214 * @param fixed if true, the text cannot exceed the display width
1215 * @return the new text field
1217 public final TField
addField(final int x
, final int y
,
1218 final int width
, final boolean fixed
) {
1220 return new TField(this, x
, y
, width
, fixed
);
1224 * Convenience function to add a text field to this container/window.
1226 * @param x column relative to parent
1227 * @param y row relative to parent
1228 * @param width visible text width
1229 * @param fixed if true, the text cannot exceed the display width
1230 * @param text initial text, default is empty string
1231 * @return the new text field
1233 public final TField
addField(final int x
, final int y
,
1234 final int width
, final boolean fixed
, final String text
) {
1236 return new TField(this, x
, y
, width
, fixed
, text
);
1240 * Convenience function to add a text field to this container/window.
1242 * @param x column relative to parent
1243 * @param y row relative to parent
1244 * @param width visible text width
1245 * @param fixed if true, the text cannot exceed the display width
1246 * @param text initial text, default is empty string
1247 * @param enterAction function to call when enter key is pressed
1248 * @param updateAction function to call when the text is updated
1249 * @return the new text field
1251 public final TField
addField(final int x
, final int y
,
1252 final int width
, final boolean fixed
, final String text
,
1253 final TAction enterAction
, final TAction updateAction
) {
1255 return new TField(this, x
, y
, width
, fixed
, text
, enterAction
,
1260 * Convenience function to add a scrollable text box to this
1263 * @param text text on the screen
1264 * @param x column relative to parent
1265 * @param y row relative to parent
1266 * @param width width of text area
1267 * @param height height of text area
1268 * @param colorKey ColorTheme key color to use for foreground text
1269 * @return the new text box
1271 public final TText
addText(final String text
, final int x
,
1272 final int y
, final int width
, final int height
, final String colorKey
) {
1274 return new TText(this, text
, x
, y
, width
, height
, colorKey
);
1278 * Convenience function to add a scrollable text box to this
1281 * @param text text on the screen
1282 * @param x column relative to parent
1283 * @param y row relative to parent
1284 * @param width width of text area
1285 * @param height height of text area
1286 * @return the new text box
1288 public final TText
addText(final String text
, final int x
, final int y
,
1289 final int width
, final int height
) {
1291 return new TText(this, text
, x
, y
, width
, height
, "ttext");
1295 * Convenience function to add an editable text area box to this
1298 * @param text text on the screen
1299 * @param x column relative to parent
1300 * @param y row relative to parent
1301 * @param width width of text area
1302 * @param height height of text area
1303 * @return the new text box
1305 public final TEditorWidget
addEditor(final String text
, final int x
,
1306 final int y
, final int width
, final int height
) {
1308 return new TEditorWidget(this, text
, x
, y
, width
, height
);
1312 * Convenience function to spawn a message box.
1314 * @param title window title, will be centered along the top border
1315 * @param caption message to display. Use embedded newlines to get a
1317 * @return the new message box
1319 public final TMessageBox
messageBox(final String title
,
1320 final String caption
) {
1322 return getApplication().messageBox(title
, caption
, TMessageBox
.Type
.OK
);
1326 * Convenience function to spawn a message box.
1328 * @param title window title, will be centered along the top border
1329 * @param caption message to display. Use embedded newlines to get a
1331 * @param type one of the TMessageBox.Type constants. Default is
1333 * @return the new message box
1335 public final TMessageBox
messageBox(final String title
,
1336 final String caption
, final TMessageBox
.Type type
) {
1338 return getApplication().messageBox(title
, caption
, type
);
1342 * Convenience function to spawn an input box.
1344 * @param title window title, will be centered along the top border
1345 * @param caption message to display. Use embedded newlines to get a
1347 * @return the new input box
1349 public final TInputBox
inputBox(final String title
, final String caption
) {
1351 return getApplication().inputBox(title
, caption
);
1355 * Convenience function to spawn an input box.
1357 * @param title window title, will be centered along the top border
1358 * @param caption message to display. Use embedded newlines to get a
1360 * @param text initial text to seed the field with
1361 * @return the new input box
1363 public final TInputBox
inputBox(final String title
, final String caption
,
1364 final String text
) {
1366 return getApplication().inputBox(title
, caption
, text
);
1370 * Convenience function to add a password text field to this
1373 * @param x column relative to parent
1374 * @param y row relative to parent
1375 * @param width visible text width
1376 * @param fixed if true, the text cannot exceed the display width
1377 * @return the new text field
1379 public final TPasswordField
addPasswordField(final int x
, final int y
,
1380 final int width
, final boolean fixed
) {
1382 return new TPasswordField(this, x
, y
, width
, fixed
);
1386 * Convenience function to add a password text field to this
1389 * @param x column relative to parent
1390 * @param y row relative to parent
1391 * @param width visible text width
1392 * @param fixed if true, the text cannot exceed the display width
1393 * @param text initial text, default is empty string
1394 * @return the new text field
1396 public final TPasswordField
addPasswordField(final int x
, final int y
,
1397 final int width
, final boolean fixed
, final String text
) {
1399 return new TPasswordField(this, x
, y
, width
, fixed
, text
);
1403 * Convenience function to add a password text field to this
1406 * @param x column relative to parent
1407 * @param y row relative to parent
1408 * @param width visible text width
1409 * @param fixed if true, the text cannot exceed the display width
1410 * @param text initial text, default is empty string
1411 * @param enterAction function to call when enter key is pressed
1412 * @param updateAction function to call when the text is updated
1413 * @return the new text field
1415 public final TPasswordField
addPasswordField(final int x
, final int y
,
1416 final int width
, final boolean fixed
, final String text
,
1417 final TAction enterAction
, final TAction updateAction
) {
1419 return new TPasswordField(this, x
, y
, width
, fixed
, text
, enterAction
,
1424 * Convenience function to add a tree view to this container/window.
1426 * @param x column relative to parent
1427 * @param y row relative to parent
1428 * @param width width of tree view
1429 * @param height height of tree view
1430 * @return the new tree view
1432 public final TTreeView
addTreeView(final int x
, final int y
,
1433 final int width
, final int height
) {
1435 return new TTreeView(this, x
, y
, width
, height
);
1439 * Convenience function to add a tree view to this container/window.
1441 * @param x column relative to parent
1442 * @param y row relative to parent
1443 * @param width width of tree view
1444 * @param height height of tree view
1445 * @param action action to perform when an item is selected
1446 * @return the new tree view
1448 public final TTreeView
addTreeView(final int x
, final int y
,
1449 final int width
, final int height
, final TAction action
) {
1451 return new TTreeView(this, x
, y
, width
, height
, action
);
1455 * Convenience function to spawn a file open box.
1457 * @param path path of selected file
1458 * @return the result of the new file open box
1459 * @throws IOException if a java.io operation throws
1461 public final String
fileOpenBox(final String path
) throws IOException
{
1462 return getApplication().fileOpenBox(path
);
1466 * Convenience function to spawn a file open box.
1468 * @param path path of selected file
1469 * @param type one of the Type constants
1470 * @return the result of the new file open box
1471 * @throws IOException if a java.io operation throws
1473 public final String
fileOpenBox(final String path
,
1474 final TFileOpenBox
.Type type
) throws IOException
{
1476 return getApplication().fileOpenBox(path
, type
);
1479 * Convenience function to add a directory list to this container/window.
1481 * @param path directory path, must be a directory
1482 * @param x column relative to parent
1483 * @param y row relative to parent
1484 * @param width width of text area
1485 * @param height height of text area
1486 * @return the new directory list
1488 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
1489 final int y
, final int width
, final int height
) {
1491 return new TDirectoryList(this, path
, x
, y
, width
, height
, null);
1495 * Convenience function to add a directory list to this container/window.
1497 * @param path directory path, must be a directory
1498 * @param x column relative to parent
1499 * @param y row relative to parent
1500 * @param width width of text area
1501 * @param height height of text area
1502 * @param action action to perform when an item is selected
1503 * @return the new directory list
1505 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
1506 final int y
, final int width
, final int height
, final TAction action
) {
1508 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
);
1512 * Convenience function to add a directory list to this container/window.
1514 * @param strings list of strings to show
1515 * @param x column relative to parent
1516 * @param y row relative to parent
1517 * @param width width of text area
1518 * @param height height of text area
1519 * @return the new directory list
1521 public final TList
addList(final List
<String
> strings
, final int x
,
1522 final int y
, final int width
, final int height
) {
1524 return new TList(this, strings
, x
, y
, width
, height
, null);
1528 * Convenience function to add a directory list to this container/window.
1530 * @param strings list of strings to show
1531 * @param x column relative to parent
1532 * @param y row relative to parent
1533 * @param width width of text area
1534 * @param height height of text area
1535 * @param enterAction action to perform when an item is selected
1536 * @return the new directory list
1538 public final TList
addList(final List
<String
> strings
, final int x
,
1539 final int y
, final int width
, final int height
,
1540 final TAction enterAction
) {
1542 return new TList(this, strings
, x
, y
, width
, height
, enterAction
);
1546 * Convenience function to add a directory list to this container/window.
1548 * @param strings list of strings to show
1549 * @param x column relative to parent
1550 * @param y row relative to parent
1551 * @param width width of text area
1552 * @param height height of text area
1553 * @param enterAction action to perform when an item is selected
1554 * @param moveAction action to perform when the user navigates to a new
1555 * item with arrow/page keys
1556 * @return the new directory list
1558 public final TList
addList(final List
<String
> strings
, final int x
,
1559 final int y
, final int width
, final int height
,
1560 final TAction enterAction
, final TAction moveAction
) {
1562 return new TList(this, strings
, x
, y
, width
, height
, enterAction
,