71032ab1944b0915dc9fc3125539be4c265a3f4c
2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2016 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
.LinkedList
;
35 import jexer
.bits
.ColorTheme
;
36 import jexer
.event
.TCommandEvent
;
37 import jexer
.event
.TInputEvent
;
38 import jexer
.event
.TKeypressEvent
;
39 import jexer
.event
.TMenuEvent
;
40 import jexer
.event
.TMouseEvent
;
41 import jexer
.event
.TResizeEvent
;
42 import jexer
.io
.Screen
;
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
> {
53 * Every widget has a parent widget that it may be "contained" in. For
54 * example, a TWindow might contain several TTextFields, or a TComboBox
55 * may contain a TScrollBar.
57 private TWidget parent
= null;
62 * @return parent widget
64 public final TWidget
getParent() {
69 * Backdoor access for TWindow's constructor. ONLY TWindow USES THIS.
71 * @param window the top-level window
72 * @param x column relative to parent
73 * @param y row relative to parent
74 * @param width width of window
75 * @param height height of window
77 protected final void setupForTWindow(final TWindow window
,
78 final int x
, final int y
, final int width
, final int height
) {
89 * Get this TWidget's parent TApplication.
91 * @return the parent TApplication
93 public TApplication
getApplication() {
94 return window
.getApplication();
102 public Screen
getScreen() {
103 return window
.getScreen();
107 * Child widgets that this widget contains.
109 private List
<TWidget
> children
;
112 * Get the list of child widgets that this widget contains.
114 * @return the list of child widgets
116 public List
<TWidget
> getChildren() {
121 * The currently active child widget that will receive keypress events.
123 private TWidget activeChild
= null;
126 * If true, this widget will receive events.
128 private boolean active
= false;
133 * @return if true, this widget will receive events
135 public final boolean isActive() {
142 * @param active if true, this widget will receive events
144 public final void setActive(final boolean active
) {
145 this.active
= active
;
149 * The window that this widget draws to.
151 private TWindow window
= null;
154 * Get the window this widget is on.
158 public final TWindow
getWindow() {
163 * Absolute X position of the top-left corner.
170 * @return absolute X position of the top-left corner
172 public final int getX() {
179 * @param x absolute X position of the top-left corner
181 public final void setX(final int x
) {
186 * Absolute Y position of the top-left corner.
193 * @return absolute Y position of the top-left corner
195 public final int getY() {
202 * @param y absolute Y position of the top-left corner
204 public final void setY(final int y
) {
211 private int width
= 0;
216 * @return widget width
218 public final int getWidth() {
225 * @param width new widget width
227 public final void setWidth(final int width
) {
234 private int height
= 0;
239 * @return widget height
241 public final int getHeight() {
248 * @param height new widget height
250 public final void setHeight(final int height
) {
251 this.height
= height
;
255 * My tab order inside a window or containing widget.
257 private int tabOrder
= 0;
260 * If true, this widget can be tabbed to or receive events.
262 private boolean enabled
= true;
267 * @return if true, this widget can be tabbed to or receive events
269 public final boolean isEnabled() {
276 * @param enabled if true, this widget can be tabbed to or receive events
278 public final void setEnabled(final boolean enabled
) {
279 this.enabled
= enabled
;
282 // See if there are any active siblings to switch to
283 boolean foundSibling
= false;
284 if (parent
!= null) {
285 for (TWidget w
: parent
.children
) {
287 && !(this instanceof THScroller
)
288 && !(this instanceof TVScroller
)
296 parent
.activeChild
= null;
303 * If true, this widget has a cursor.
305 private boolean cursorVisible
= false;
308 * Set visible cursor flag.
310 * @param cursorVisible if true, this widget has a cursor
312 public final void setCursorVisible(final boolean cursorVisible
) {
313 this.cursorVisible
= cursorVisible
;
317 * See if this widget has a visible cursor.
319 * @return if true, this widget has a visible cursor
321 public final boolean isCursorVisible() {
322 return cursorVisible
;
326 * Cursor column position in relative coordinates.
328 private int cursorX
= 0;
331 * Get cursor X value.
333 * @return cursor column position in relative coordinates
335 public final int getCursorX() {
340 * Set cursor X value.
342 * @param cursorX column position in relative coordinates
344 public final void setCursorX(final int cursorX
) {
345 this.cursorX
= cursorX
;
349 * Cursor row position in relative coordinates.
351 private int cursorY
= 0;
354 * Get cursor Y value.
356 * @return cursor row position in relative coordinates
358 public final int getCursorY() {
363 * Set cursor Y value.
365 * @param cursorY row position in relative coordinates
367 public final void setCursorY(final int cursorY
) {
368 this.cursorY
= cursorY
;
372 * Comparison operator. For various subclasses it sorts on:
374 * <li>tabOrder for TWidgets</li>
375 * <li>z for TWindows</li>
376 * <li>text for TTreeItems</li>
379 * @param that another TWidget, TWindow, or TTreeItem instance
380 * @return difference between this.tabOrder and that.tabOrder, or
381 * difference between this.z and that.z, or String.compareTo(text)
383 public final int compareTo(final TWidget that
) {
384 if ((this instanceof TWindow
)
385 && (that
instanceof TWindow
)
387 return (((TWindow
) this).getZ() - ((TWindow
) that
).getZ());
389 if ((this instanceof TTreeItem
)
390 && (that
instanceof TTreeItem
)
392 return (((TTreeItem
) this).getText().compareTo(
393 ((TTreeItem
) that
).getText()));
395 return (this.tabOrder
- that
.tabOrder
);
399 * See if this widget should render with the active color.
401 * @return true if this widget is active and all of its parents are
404 public final boolean isAbsoluteActive() {
405 if (parent
== this) {
408 return (active
&& parent
.isAbsoluteActive());
412 * Returns the cursor X position.
414 * @return absolute screen column number for the cursor's X position
416 public final int getCursorAbsoluteX() {
417 assert (cursorVisible
);
418 return getAbsoluteX() + cursorX
;
422 * Returns the cursor Y position.
424 * @return absolute screen row number for the cursor's Y position
426 public final int getCursorAbsoluteY() {
427 assert (cursorVisible
);
428 return getAbsoluteY() + cursorY
;
432 * Compute my absolute X position as the sum of my X plus all my parent's
435 * @return absolute screen column number for my X position
437 public final int getAbsoluteX() {
438 assert (parent
!= null);
439 if (parent
== this) {
442 if ((parent
instanceof TWindow
) && !(parent
instanceof TMenu
)) {
443 // Widgets on a TWindow have (0,0) as their top-left, but this is
444 // actually the TWindow's (1,1).
445 return parent
.getAbsoluteX() + x
+ 1;
447 return parent
.getAbsoluteX() + x
;
451 * Compute my absolute Y position as the sum of my Y plus all my parent's
454 * @return absolute screen row number for my Y position
456 public final int getAbsoluteY() {
457 assert (parent
!= null);
458 if (parent
== this) {
461 if ((parent
instanceof TWindow
) && !(parent
instanceof TMenu
)) {
462 // Widgets on a TWindow have (0,0) as their top-left, but this is
463 // actually the TWindow's (1,1).
464 return parent
.getAbsoluteY() + y
+ 1;
466 return parent
.getAbsoluteY() + y
;
470 * Get the global color theme.
472 * @return the ColorTheme
474 public final ColorTheme
getTheme() {
475 return window
.getApplication().getTheme();
479 * Draw my specific widget. When called, the screen rectangle I draw
480 * into is already setup (offset and clipping).
483 // Default widget draws nothing.
487 * Called by parent to render to TWindow.
489 public final void drawChildren() {
490 // Set my clipping rectangle
491 assert (window
!= null);
492 assert (getScreen() != null);
493 Screen screen
= getScreen();
495 screen
.setClipRight(width
);
496 screen
.setClipBottom(height
);
498 int absoluteRightEdge
= window
.getAbsoluteX() + window
.getWidth();
499 int absoluteBottomEdge
= window
.getAbsoluteY() + window
.getHeight();
500 if (!(this instanceof TWindow
) && !(this instanceof TVScroller
)) {
501 absoluteRightEdge
-= 1;
503 if (!(this instanceof TWindow
) && !(this instanceof THScroller
)) {
504 absoluteBottomEdge
-= 1;
506 int myRightEdge
= getAbsoluteX() + width
;
507 int myBottomEdge
= getAbsoluteY() + height
;
508 if (getAbsoluteX() > absoluteRightEdge
) {
510 screen
.setClipRight(0);
511 } else if (myRightEdge
> absoluteRightEdge
) {
512 screen
.setClipRight(screen
.getClipRight()
513 - (myRightEdge
- absoluteRightEdge
));
515 if (getAbsoluteY() > absoluteBottomEdge
) {
517 screen
.setClipBottom(0);
518 } else if (myBottomEdge
> absoluteBottomEdge
) {
519 screen
.setClipBottom(screen
.getClipBottom()
520 - (myBottomEdge
- absoluteBottomEdge
));
524 screen
.setOffsetX(getAbsoluteX());
525 screen
.setOffsetY(getAbsoluteY());
530 // Continue down the chain
531 for (TWidget widget
: children
) {
532 widget
.drawChildren();
537 * Default constructor for subclasses.
539 protected TWidget() {
540 children
= new LinkedList
<TWidget
>();
544 * Protected constructor.
546 * @param parent parent widget
548 protected TWidget(final TWidget parent
) {
553 * Protected constructor.
555 * @param parent parent widget
556 * @param x column relative to parent
557 * @param y row relative to parent
558 * @param width width of widget
559 * @param height height of widget
561 protected TWidget(final TWidget parent
, final int x
, final int y
,
562 final int width
, final int height
) {
564 this(parent
, true, x
, y
, width
, height
);
568 * Protected constructor used by subclasses that are disabled by default.
570 * @param parent parent widget
571 * @param enabled if true assume enabled
573 protected TWidget(final TWidget parent
, final boolean enabled
) {
574 this.enabled
= enabled
;
575 this.parent
= parent
;
576 this.window
= parent
.window
;
577 children
= new LinkedList
<TWidget
>();
578 parent
.addChild(this);
582 * Protected constructor used by subclasses that are disabled by default.
584 * @param parent parent widget
585 * @param enabled if true assume enabled
586 * @param x column relative to parent
587 * @param y row relative to parent
588 * @param width width of widget
589 * @param height height of widget
591 protected TWidget(final TWidget parent
, final boolean enabled
,
592 final int x
, final int y
, final int width
, final int height
) {
594 this.enabled
= enabled
;
595 this.parent
= parent
;
596 this.window
= parent
.window
;
597 children
= new LinkedList
<TWidget
>();
598 parent
.addChild(this);
603 this.height
= height
;
607 * Add a child widget to my list of children. We set its tabOrder to 0
608 * and increment the tabOrder of all other children.
610 * @param child TWidget to add
612 private void addChild(final TWidget child
) {
616 && !(child
instanceof THScroller
)
617 && !(child
instanceof TVScroller
)
619 for (TWidget widget
: children
) {
620 widget
.active
= false;
625 for (int i
= 0; i
< children
.size(); i
++) {
626 children
.get(i
).tabOrder
= i
;
631 * Switch the active child.
633 * @param child TWidget to activate
635 public final void activate(final TWidget child
) {
636 assert (child
.enabled
);
637 if ((child
instanceof THScroller
)
638 || (child
instanceof TVScroller
)
643 if (child
!= activeChild
) {
644 if (activeChild
!= null) {
645 activeChild
.active
= false;
653 * Switch the active child.
655 * @param tabOrder tabOrder of the child to activate. If that child
656 * isn't enabled, then the next enabled child will be activated.
658 public final void activate(final int tabOrder
) {
659 if (activeChild
== null) {
662 TWidget child
= null;
663 for (TWidget widget
: children
) {
665 && !(widget
instanceof THScroller
)
666 && !(widget
instanceof TVScroller
)
667 && (widget
.tabOrder
>= tabOrder
)
673 if ((child
!= null) && (child
!= activeChild
)) {
674 activeChild
.active
= false;
675 assert (child
.enabled
);
682 * Switch the active widget with the next in the tab order.
684 * @param forward if true, then switch to the next enabled widget in the
685 * list, otherwise switch to the previous enabled widget in the list
687 public final void switchWidget(final boolean forward
) {
689 // Only switch if there are multiple enabled widgets
690 if ((children
.size() < 2) || (activeChild
== null)) {
694 int tabOrder
= activeChild
.tabOrder
;
703 // If at the end, pass the switch to my parent.
704 if ((!forward
) && (parent
!= this)) {
705 parent
.switchWidget(forward
);
709 tabOrder
= children
.size() - 1;
710 } else if (tabOrder
== children
.size()) {
711 // If at the end, pass the switch to my parent.
712 if ((forward
) && (parent
!= this)) {
713 parent
.switchWidget(forward
);
719 if (activeChild
.tabOrder
== tabOrder
) {
723 } while ((!children
.get(tabOrder
).enabled
)
724 && !(children
.get(tabOrder
) instanceof THScroller
)
725 && !(children
.get(tabOrder
) instanceof TVScroller
));
727 assert (children
.get(tabOrder
).enabled
);
729 activeChild
.active
= false;
730 children
.get(tabOrder
).active
= true;
731 activeChild
= children
.get(tabOrder
);
735 * Returns my active widget.
737 * @return widget that is active, or this if no children
739 public TWidget
getActiveChild() {
740 if ((this instanceof THScroller
)
741 || (this instanceof TVScroller
)
746 for (TWidget widget
: children
) {
748 return widget
.getActiveChild();
751 // No active children, return me
756 * Method that subclasses can override to handle keystrokes.
758 * @param keypress keystroke event
760 public void onKeypress(final TKeypressEvent keypress
) {
762 if ((children
.size() == 0)
763 || (this instanceof TTreeView
)
764 || (this instanceof TText
)
768 // tab / shift-tab - switch to next/previous widget
769 // right-arrow or down-arrow: same as tab
770 // left-arrow or up-arrow: same as shift-tab
771 if ((keypress
.equals(kbTab
))
772 || (keypress
.equals(kbRight
))
773 || (keypress
.equals(kbDown
))
775 parent
.switchWidget(true);
777 } else if ((keypress
.equals(kbShiftTab
))
778 || (keypress
.equals(kbBackTab
))
779 || (keypress
.equals(kbLeft
))
780 || (keypress
.equals(kbUp
))
782 parent
.switchWidget(false);
787 // If I have any buttons on me AND this is an Alt-key that matches
788 // its mnemonic, send it an Enter keystroke
789 for (TWidget widget
: children
) {
790 if (widget
instanceof TButton
) {
791 TButton button
= (TButton
) widget
;
792 if (button
.isEnabled()
793 && !keypress
.getKey().isFnKey()
794 && keypress
.getKey().isAlt()
795 && !keypress
.getKey().isCtrl()
796 && (Character
.toLowerCase(button
.getMnemonic().getShortcut())
797 == Character
.toLowerCase(keypress
.getKey().getChar()))
800 widget
.handleEvent(new TKeypressEvent(kbEnter
));
806 // Dispatch the keypress to an active widget
807 for (TWidget widget
: children
) {
809 widget
.handleEvent(keypress
);
816 * Method that subclasses can override to handle mouse button presses.
818 * @param mouse mouse button event
820 public void onMouseDown(final TMouseEvent mouse
) {
821 // Default: do nothing, pass to children instead
822 for (TWidget widget
: children
) {
823 if (widget
.mouseWouldHit(mouse
)) {
824 // Dispatch to this child, also activate it
827 // Set x and y relative to the child's coordinates
828 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
829 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
830 widget
.handleEvent(mouse
);
837 * Method that subclasses can override to handle mouse button releases.
839 * @param mouse mouse button event
841 public void onMouseUp(final TMouseEvent mouse
) {
842 // Default: do nothing, pass to children instead
843 for (TWidget widget
: children
) {
844 if (widget
.mouseWouldHit(mouse
)) {
845 // Dispatch to this child, also activate it
848 // Set x and y relative to the child's coordinates
849 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
850 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
851 widget
.handleEvent(mouse
);
858 * Method that subclasses can override to handle mouse movements.
860 * @param mouse mouse motion event
862 public void onMouseMotion(final TMouseEvent mouse
) {
863 // Default: do nothing, pass it on to ALL of my children. This way
864 // the children can see the mouse "leaving" their area.
865 for (TWidget widget
: children
) {
866 // Set x and y relative to the child's coordinates
867 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
868 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
869 widget
.handleEvent(mouse
);
874 * Method that subclasses can override to handle window/screen resize
877 * @param resize resize event
879 public void onResize(final TResizeEvent resize
) {
880 // Default: do nothing, pass to children instead
881 for (TWidget widget
: children
) {
882 widget
.onResize(resize
);
887 * Method that subclasses can override to handle posted command events.
889 * @param command command event
891 public void onCommand(final TCommandEvent command
) {
892 // Default: do nothing, pass to children instead
893 for (TWidget widget
: children
) {
894 widget
.onCommand(command
);
899 * Method that subclasses can override to handle menu or posted menu
902 * @param menu menu event
904 public void onMenu(final TMenuEvent menu
) {
905 // Default: do nothing, pass to children instead
906 for (TWidget widget
: children
) {
912 * Method that subclasses can override to do processing when the UI is
915 public void onIdle() {
916 // Default: do nothing, pass to children instead
917 for (TWidget widget
: children
) {
923 * Consume event. Subclasses that want to intercept all events in one go
924 * can override this method.
926 * @param event keyboard, mouse, resize, command, or menu event
928 public void handleEvent(final TInputEvent event
) {
929 // System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(),
934 // System.err.println(" -- discard --");
938 if (event
instanceof TKeypressEvent
) {
939 onKeypress((TKeypressEvent
) event
);
940 } else if (event
instanceof TMouseEvent
) {
942 TMouseEvent mouse
= (TMouseEvent
) event
;
944 switch (mouse
.getType()) {
955 onMouseMotion(mouse
);
959 throw new IllegalArgumentException("Invalid mouse event type: "
962 } else if (event
instanceof TResizeEvent
) {
963 onResize((TResizeEvent
) event
);
964 } else if (event
instanceof TCommandEvent
) {
965 onCommand((TCommandEvent
) event
);
966 } else if (event
instanceof TMenuEvent
) {
967 onMenu((TMenuEvent
) event
);
975 * Check if a mouse press/release event coordinate is contained in this
978 * @param mouse a mouse-based event
979 * @return whether or not a mouse click would be sent to this widget
981 public final boolean mouseWouldHit(final TMouseEvent mouse
) {
987 if ((mouse
.getAbsoluteX() >= getAbsoluteX())
988 && (mouse
.getAbsoluteX() < getAbsoluteX() + width
)
989 && (mouse
.getAbsoluteY() >= getAbsoluteY())
990 && (mouse
.getAbsoluteY() < getAbsoluteY() + height
)
998 * Convenience function to add a label to this container/window.
1001 * @param x column relative to parent
1002 * @param y row relative to parent
1003 * @return the new label
1005 public final TLabel
addLabel(final String text
, final int x
, final int y
) {
1006 return addLabel(text
, x
, y
, "tlabel");
1010 * Convenience function to add a label to this container/window.
1013 * @param x column relative to parent
1014 * @param y row relative to parent
1015 * @param colorKey ColorTheme key color to use for foreground text.
1016 * Default is "tlabel"
1017 * @return the new label
1019 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1020 final String colorKey
) {
1022 return new TLabel(this, text
, x
, y
, colorKey
);
1026 * Convenience function to add a button to this container/window.
1028 * @param text label on the button
1029 * @param x column relative to parent
1030 * @param y row relative to parent
1031 * @param action to call when button is pressed
1032 * @return the new button
1034 public final TButton
addButton(final String text
, final int x
, final int y
,
1035 final TAction action
) {
1037 return new TButton(this, text
, x
, y
, action
);
1041 * Convenience function to add a checkbox to this container/window.
1043 * @param x column relative to parent
1044 * @param y row relative to parent
1045 * @param label label to display next to (right of) the checkbox
1046 * @param checked initial check state
1047 * @return the new checkbox
1049 public final TCheckbox
addCheckbox(final int x
, final int y
,
1050 final String label
, final boolean checked
) {
1052 return new TCheckbox(this, x
, y
, label
, checked
);
1056 * Convenience function to add a progress bar to this container/window.
1058 * @param x column relative to parent
1059 * @param y row relative to parent
1060 * @param width width of progress bar
1061 * @param value initial value of percent complete
1062 * @return the new progress bar
1064 public final TProgressBar
addProgressBar(final int x
, final int y
,
1065 final int width
, final int value
) {
1067 return new TProgressBar(this, x
, y
, width
, value
);
1071 * Convenience function to add a radio button group to this
1074 * @param x column relative to parent
1075 * @param y row relative to parent
1076 * @param label label to display on the group box
1077 * @return the new radio button group
1079 public final TRadioGroup
addRadioGroup(final int x
, final int y
,
1080 final String label
) {
1082 return new TRadioGroup(this, x
, y
, label
);
1086 * Convenience function to add a text field to this container/window.
1088 * @param x column relative to parent
1089 * @param y row relative to parent
1090 * @param width visible text width
1091 * @param fixed if true, the text cannot exceed the display width
1092 * @return the new text field
1094 public final TField
addField(final int x
, final int y
,
1095 final int width
, final boolean fixed
) {
1097 return new TField(this, x
, y
, width
, fixed
);
1101 * Convenience function to add a text field to this container/window.
1103 * @param x column relative to parent
1104 * @param y row relative to parent
1105 * @param width visible text width
1106 * @param fixed if true, the text cannot exceed the display width
1107 * @param text initial text, default is empty string
1108 * @return the new text field
1110 public final TField
addField(final int x
, final int y
,
1111 final int width
, final boolean fixed
, final String text
) {
1113 return new TField(this, x
, y
, width
, fixed
, text
);
1117 * Convenience function to add a text field to this container/window.
1119 * @param x column relative to parent
1120 * @param y row relative to parent
1121 * @param width visible text width
1122 * @param fixed if true, the text cannot exceed the display width
1123 * @param text initial text, default is empty string
1124 * @param enterAction function to call when enter key is pressed
1125 * @param updateAction function to call when the text is updated
1126 * @return the new text field
1128 public final TField
addField(final int x
, final int y
,
1129 final int width
, final boolean fixed
, final String text
,
1130 final TAction enterAction
, final TAction updateAction
) {
1132 return new TField(this, x
, y
, width
, fixed
, text
, enterAction
,
1137 * Convenience function to add a scrollable text box to this
1140 * @param text text on the screen
1141 * @param x column relative to parent
1142 * @param y row relative to parent
1143 * @param width width of text area
1144 * @param height height of text area
1145 * @param colorKey ColorTheme key color to use for foreground text
1146 * @return the new text box
1148 public final TText
addText(final String text
, final int x
,
1149 final int y
, final int width
, final int height
, final String colorKey
) {
1151 return new TText(this, text
, x
, y
, width
, height
, colorKey
);
1155 * Convenience function to add a scrollable text box to this
1158 * @param text text on the screen
1159 * @param x column relative to parent
1160 * @param y row relative to parent
1161 * @param width width of text area
1162 * @param height height of text area
1163 * @return the new text box
1165 public final TText
addText(final String text
, final int x
, final int y
,
1166 final int width
, final int height
) {
1168 return new TText(this, text
, x
, y
, width
, height
, "ttext");
1172 * Convenience function to spawn a message box.
1174 * @param title window title, will be centered along the top border
1175 * @param caption message to display. Use embedded newlines to get a
1177 * @return the new message box
1179 public final TMessageBox
messageBox(final String title
,
1180 final String caption
) {
1182 return getApplication().messageBox(title
, caption
, TMessageBox
.Type
.OK
);
1186 * Convenience function to spawn a message box.
1188 * @param title window title, will be centered along the top border
1189 * @param caption message to display. Use embedded newlines to get a
1191 * @param type one of the TMessageBox.Type constants. Default is
1193 * @return the new message box
1195 public final TMessageBox
messageBox(final String title
,
1196 final String caption
, final TMessageBox
.Type type
) {
1198 return getApplication().messageBox(title
, caption
, type
);
1202 * Convenience function to spawn an input box.
1204 * @param title window title, will be centered along the top border
1205 * @param caption message to display. Use embedded newlines to get a
1207 * @return the new input box
1209 public final TInputBox
inputBox(final String title
, final String caption
) {
1211 return getApplication().inputBox(title
, caption
);
1215 * Convenience function to spawn an input box.
1217 * @param title window title, will be centered along the top border
1218 * @param caption message to display. Use embedded newlines to get a
1220 * @param text initial text to seed the field with
1221 * @return the new input box
1223 public final TInputBox
inputBox(final String title
, final String caption
,
1224 final String text
) {
1226 return getApplication().inputBox(title
, caption
, text
);
1230 * Convenience function to add a password text field to this
1233 * @param x column relative to parent
1234 * @param y row relative to parent
1235 * @param width visible text width
1236 * @param fixed if true, the text cannot exceed the display width
1237 * @return the new text field
1239 public final TPasswordField
addPasswordField(final int x
, final int y
,
1240 final int width
, final boolean fixed
) {
1242 return new TPasswordField(this, x
, y
, width
, fixed
);
1246 * Convenience function to add a password text field to this
1249 * @param x column relative to parent
1250 * @param y row relative to parent
1251 * @param width visible text width
1252 * @param fixed if true, the text cannot exceed the display width
1253 * @param text initial text, default is empty string
1254 * @return the new text field
1256 public final TPasswordField
addPasswordField(final int x
, final int y
,
1257 final int width
, final boolean fixed
, final String text
) {
1259 return new TPasswordField(this, x
, y
, width
, fixed
, text
);
1263 * Convenience function to add a password text field to this
1266 * @param x column relative to parent
1267 * @param y row relative to parent
1268 * @param width visible text width
1269 * @param fixed if true, the text cannot exceed the display width
1270 * @param text initial text, default is empty string
1271 * @param enterAction function to call when enter key is pressed
1272 * @param updateAction function to call when the text is updated
1273 * @return the new text field
1275 public final TPasswordField
addPasswordField(final int x
, final int y
,
1276 final int width
, final boolean fixed
, final String text
,
1277 final TAction enterAction
, final TAction updateAction
) {
1279 return new TPasswordField(this, x
, y
, width
, fixed
, text
, enterAction
,
1284 * Convenience function to add a tree view to this container/window.
1286 * @param x column relative to parent
1287 * @param y row relative to parent
1288 * @param width width of tree view
1289 * @param height height of tree view
1290 * @return the new tree view
1292 public final TTreeView
addTreeView(final int x
, final int y
,
1293 final int width
, final int height
) {
1295 return new TTreeView(this, x
, y
, width
, height
);
1299 * Convenience function to add a tree view to this container/window.
1301 * @param x column relative to parent
1302 * @param y row relative to parent
1303 * @param width width of tree view
1304 * @param height height of tree view
1305 * @param action action to perform when an item is selected
1306 * @return the new tree view
1308 public final TTreeView
addTreeView(final int x
, final int y
,
1309 final int width
, final int height
, final TAction action
) {
1311 return new TTreeView(this, x
, y
, width
, height
, action
);
1315 * Convenience function to spawn a file open box.
1317 * @param path path of selected file
1318 * @return the result of the new file open box
1319 * @throws IOException if a java.io operation throws
1321 public final String
fileOpenBox(final String path
) throws IOException
{
1322 return getApplication().fileOpenBox(path
);
1326 * Convenience function to spawn a file open box.
1328 * @param path path of selected file
1329 * @param type one of the Type constants
1330 * @return the result of the new file open box
1331 * @throws IOException if a java.io operation throws
1333 public final String
fileOpenBox(final String path
,
1334 final TFileOpenBox
.Type type
) throws IOException
{
1336 return getApplication().fileOpenBox(path
, type
);
1339 * Convenience function to add a directory list to this container/window.
1341 * @param path directory path, must be a directory
1342 * @param x column relative to parent
1343 * @param y row relative to parent
1344 * @param width width of text area
1345 * @param height height of text area
1346 * @return the new directory list
1348 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
1349 final int y
, final int width
, final int height
) {
1351 return new TDirectoryList(this, path
, x
, y
, width
, height
, null);
1355 * Convenience function to add a directory list to this container/window.
1357 * @param path directory path, must be a directory
1358 * @param x column relative to parent
1359 * @param y row relative to parent
1360 * @param width width of text area
1361 * @param height height of text area
1362 * @param action action to perform when an item is selected
1363 * @return the new directory list
1365 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
1366 final int y
, final int width
, final int height
, final TAction action
) {
1368 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
);
1372 * Convenience function to add a directory list to this container/window.
1374 * @param strings list of strings to show
1375 * @param x column relative to parent
1376 * @param y row relative to parent
1377 * @param width width of text area
1378 * @param height height of text area
1379 * @return the new directory list
1381 public final TList
addList(final List
<String
> strings
, final int x
,
1382 final int y
, final int width
, final int height
) {
1384 return new TList(this, strings
, x
, y
, width
, height
, null);
1388 * Convenience function to add a directory list to this container/window.
1390 * @param strings list of strings to show
1391 * @param x column relative to parent
1392 * @param y row relative to parent
1393 * @param width width of text area
1394 * @param height height of text area
1395 * @param enterAction action to perform when an item is selected
1396 * @return the new directory list
1398 public final TList
addList(final List
<String
> strings
, final int x
,
1399 final int y
, final int width
, final int height
,
1400 final TAction enterAction
) {
1402 return new TList(this, strings
, x
, y
, width
, height
, enterAction
);
1406 * Convenience function to add a directory list to this container/window.
1408 * @param strings list of strings to show
1409 * @param x column relative to parent
1410 * @param y row relative to parent
1411 * @param width width of text area
1412 * @param height height of text area
1413 * @param enterAction action to perform when an item is selected
1414 * @param moveAction action to perform when the user navigates to a new
1415 * item with arrow/page keys
1416 * @return the new directory list
1418 public final TList
addList(final List
<String
> strings
, final int x
,
1419 final int y
, final int width
, final int height
,
1420 final TAction enterAction
, final TAction moveAction
) {
1422 return new TList(this, strings
, x
, y
, width
, height
, enterAction
,