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 return cursorVisible
;
309 * Cursor column position in relative coordinates.
311 private int cursorX
= 0;
314 * Get cursor X value.
316 * @return cursor column position in relative coordinates
318 public final int getCursorX() {
323 * Set cursor X value.
325 * @param cursorX column position in relative coordinates
327 public final void setCursorX(final int cursorX
) {
328 this.cursorX
= cursorX
;
332 * Cursor row position in relative coordinates.
334 private int cursorY
= 0;
337 * Get cursor Y value.
339 * @return cursor row position in relative coordinates
341 public final int getCursorY() {
346 * Set cursor Y value.
348 * @param cursorY row position in relative coordinates
350 public final void setCursorY(final int cursorY
) {
351 this.cursorY
= cursorY
;
354 // ------------------------------------------------------------------------
355 // TApplication integration -----------------------------------------------
356 // ------------------------------------------------------------------------
359 * Get this TWidget's parent TApplication.
361 * @return the parent TApplication
363 public TApplication
getApplication() {
364 return window
.getApplication();
372 public Screen
getScreen() {
373 return window
.getScreen();
377 * Comparison operator. For various subclasses it sorts on:
379 * <li>tabOrder for TWidgets</li>
380 * <li>z for TWindows</li>
381 * <li>text for TTreeItems</li>
384 * @param that another TWidget, TWindow, or TTreeItem instance
385 * @return difference between this.tabOrder and that.tabOrder, or
386 * difference between this.z and that.z, or String.compareTo(text)
388 public final int compareTo(final TWidget that
) {
389 if ((this instanceof TWindow
)
390 && (that
instanceof TWindow
)
392 return (((TWindow
) this).getZ() - ((TWindow
) that
).getZ());
394 if ((this instanceof TTreeItem
)
395 && (that
instanceof TTreeItem
)
397 return (((TTreeItem
) this).getText().compareTo(
398 ((TTreeItem
) that
).getText()));
400 return (this.tabOrder
- that
.tabOrder
);
404 * See if this widget should render with the active color.
406 * @return true if this widget is active and all of its parents are
409 public final boolean isAbsoluteActive() {
410 if (parent
== this) {
413 return (active
&& parent
.isAbsoluteActive());
417 * Returns the cursor X position.
419 * @return absolute screen column number for the cursor's X position
421 public final int getCursorAbsoluteX() {
422 assert (cursorVisible
);
423 return getAbsoluteX() + cursorX
;
427 * Returns the cursor Y position.
429 * @return absolute screen row number for the cursor's Y position
431 public final int getCursorAbsoluteY() {
432 assert (cursorVisible
);
433 return getAbsoluteY() + cursorY
;
437 * Compute my absolute X position as the sum of my X plus all my parent's
440 * @return absolute screen column number for my X position
442 public final int getAbsoluteX() {
443 assert (parent
!= null);
444 if (parent
== this) {
447 if ((parent
instanceof TWindow
)
448 && !(parent
instanceof TMenu
)
449 && !(parent
instanceof TDesktop
)
451 // Widgets on a TWindow have (0,0) as their top-left, but this is
452 // actually the TWindow's (1,1).
453 return parent
.getAbsoluteX() + x
+ 1;
455 return parent
.getAbsoluteX() + x
;
459 * Compute my absolute Y position as the sum of my Y plus all my parent's
462 * @return absolute screen row number for my Y position
464 public final int getAbsoluteY() {
465 assert (parent
!= null);
466 if (parent
== this) {
469 if ((parent
instanceof TWindow
)
470 && !(parent
instanceof TMenu
)
471 && !(parent
instanceof TDesktop
)
473 // Widgets on a TWindow have (0,0) as their top-left, but this is
474 // actually the TWindow's (1,1).
475 return parent
.getAbsoluteY() + y
+ 1;
477 return parent
.getAbsoluteY() + y
;
481 * Get the global color theme.
483 * @return the ColorTheme
485 public final ColorTheme
getTheme() {
486 return window
.getApplication().getTheme();
490 * Draw my specific widget. When called, the screen rectangle I draw
491 * into is already setup (offset and clipping).
494 // Default widget draws nothing.
498 * Called by parent to render to TWindow.
500 public final void drawChildren() {
501 // Set my clipping rectangle
502 assert (window
!= null);
503 assert (getScreen() != null);
504 Screen screen
= getScreen();
506 // Special case: TStatusBar is drawn by TApplication, not anything
508 if (this instanceof TStatusBar
) {
512 screen
.setClipRight(width
);
513 screen
.setClipBottom(height
);
515 int absoluteRightEdge
= window
.getAbsoluteX() + window
.getWidth();
516 int absoluteBottomEdge
= window
.getAbsoluteY() + window
.getHeight();
517 if (!(this instanceof TWindow
) && !(this instanceof TVScroller
)) {
518 absoluteRightEdge
-= 1;
520 if (!(this instanceof TWindow
) && !(this instanceof THScroller
)) {
521 absoluteBottomEdge
-= 1;
523 int myRightEdge
= getAbsoluteX() + width
;
524 int myBottomEdge
= getAbsoluteY() + height
;
525 if (getAbsoluteX() > absoluteRightEdge
) {
527 screen
.setClipRight(0);
528 } else if (myRightEdge
> absoluteRightEdge
) {
529 screen
.setClipRight(screen
.getClipRight()
530 - (myRightEdge
- absoluteRightEdge
));
532 if (getAbsoluteY() > absoluteBottomEdge
) {
534 screen
.setClipBottom(0);
535 } else if (myBottomEdge
> absoluteBottomEdge
) {
536 screen
.setClipBottom(screen
.getClipBottom()
537 - (myBottomEdge
- absoluteBottomEdge
));
541 screen
.setOffsetX(getAbsoluteX());
542 screen
.setOffsetY(getAbsoluteY());
547 // Continue down the chain
548 for (TWidget widget
: children
) {
549 widget
.drawChildren();
554 * Repaint the screen on the next update.
556 public void doRepaint() {
557 window
.getApplication().doRepaint();
560 // ------------------------------------------------------------------------
561 // Constructors -----------------------------------------------------------
562 // ------------------------------------------------------------------------
565 * Default constructor for subclasses.
567 protected TWidget() {
568 children
= new ArrayList
<TWidget
>();
572 * Protected constructor.
574 * @param parent parent widget
576 protected TWidget(final TWidget parent
) {
581 * Protected constructor.
583 * @param parent parent widget
584 * @param x column relative to parent
585 * @param y row relative to parent
586 * @param width width of widget
587 * @param height height of widget
589 protected TWidget(final TWidget parent
, final int x
, final int y
,
590 final int width
, final int height
) {
592 this(parent
, true, x
, y
, width
, height
);
596 * Protected constructor used by subclasses that are disabled by default.
598 * @param parent parent widget
599 * @param enabled if true assume enabled
601 protected TWidget(final TWidget parent
, final boolean enabled
) {
602 this.enabled
= enabled
;
603 this.parent
= parent
;
604 this.window
= parent
.window
;
605 children
= new ArrayList
<TWidget
>();
606 parent
.addChild(this);
610 * Protected constructor used by subclasses that are disabled by default.
612 * @param parent parent widget
613 * @param enabled if true assume enabled
614 * @param x column relative to parent
615 * @param y row relative to parent
616 * @param width width of widget
617 * @param height height of widget
619 protected TWidget(final TWidget parent
, final boolean enabled
,
620 final int x
, final int y
, final int width
, final int height
) {
622 this.enabled
= enabled
;
623 this.parent
= parent
;
624 this.window
= parent
.window
;
625 children
= new ArrayList
<TWidget
>();
626 parent
.addChild(this);
631 this.height
= height
;
635 * Backdoor access for TWindow's constructor. ONLY TWindow USES THIS.
637 * @param window the top-level window
638 * @param x column relative to parent
639 * @param y row relative to parent
640 * @param width width of window
641 * @param height height of window
643 protected final void setupForTWindow(final TWindow window
,
644 final int x
, final int y
, final int width
, final int height
) {
646 this.parent
= window
;
647 this.window
= window
;
651 this.height
= height
;
654 // ------------------------------------------------------------------------
655 // General behavior -------------------------------------------------------
656 // ------------------------------------------------------------------------
659 * Add a child widget to my list of children. We set its tabOrder to 0
660 * and increment the tabOrder of all other children.
662 * @param child TWidget to add
664 private void addChild(final TWidget child
) {
668 && !(child
instanceof THScroller
)
669 && !(child
instanceof TVScroller
)
671 for (TWidget widget
: children
) {
672 widget
.active
= false;
677 for (int i
= 0; i
< children
.size(); i
++) {
678 children
.get(i
).tabOrder
= i
;
683 * Switch the active child.
685 * @param child TWidget to activate
687 public final void activate(final TWidget child
) {
688 assert (child
.enabled
);
689 if ((child
instanceof THScroller
)
690 || (child
instanceof TVScroller
)
695 if (child
!= activeChild
) {
696 if (activeChild
!= null) {
697 activeChild
.active
= false;
705 * Switch the active child.
707 * @param tabOrder tabOrder of the child to activate. If that child
708 * isn't enabled, then the next enabled child will be activated.
710 public final void activate(final int tabOrder
) {
711 if (activeChild
== null) {
714 TWidget child
= null;
715 for (TWidget widget
: children
) {
717 && !(widget
instanceof THScroller
)
718 && !(widget
instanceof TVScroller
)
719 && (widget
.tabOrder
>= tabOrder
)
725 if ((child
!= null) && (child
!= activeChild
)) {
726 activeChild
.active
= false;
727 assert (child
.enabled
);
734 * Switch the active widget with the next in the tab order.
736 * @param forward if true, then switch to the next enabled widget in the
737 * list, otherwise switch to the previous enabled widget in the list
739 public final void switchWidget(final boolean forward
) {
741 // Only switch if there are multiple enabled widgets
742 if ((children
.size() < 2) || (activeChild
== null)) {
746 int tabOrder
= activeChild
.tabOrder
;
755 // If at the end, pass the switch to my parent.
756 if ((!forward
) && (parent
!= this)) {
757 parent
.switchWidget(forward
);
761 tabOrder
= children
.size() - 1;
762 } else if (tabOrder
== children
.size()) {
763 // If at the end, pass the switch to my parent.
764 if ((forward
) && (parent
!= this)) {
765 parent
.switchWidget(forward
);
771 if (activeChild
.tabOrder
== tabOrder
) {
775 } while ((!children
.get(tabOrder
).enabled
)
776 && !(children
.get(tabOrder
) instanceof THScroller
)
777 && !(children
.get(tabOrder
) instanceof TVScroller
));
779 assert (children
.get(tabOrder
).enabled
);
781 activeChild
.active
= false;
782 children
.get(tabOrder
).active
= true;
783 activeChild
= children
.get(tabOrder
);
787 * Returns my active widget.
789 * @return widget that is active, or this if no children
791 public TWidget
getActiveChild() {
792 if ((this instanceof THScroller
)
793 || (this instanceof TVScroller
)
798 for (TWidget widget
: children
) {
800 return widget
.getActiveChild();
803 // No active children, return me
807 // ------------------------------------------------------------------------
808 // Event handlers ---------------------------------------------------------
809 // ------------------------------------------------------------------------
812 * Check if a mouse press/release event coordinate is contained in this
815 * @param mouse a mouse-based event
816 * @return whether or not a mouse click would be sent to this widget
818 public final boolean mouseWouldHit(final TMouseEvent mouse
) {
824 if ((mouse
.getAbsoluteX() >= getAbsoluteX())
825 && (mouse
.getAbsoluteX() < getAbsoluteX() + width
)
826 && (mouse
.getAbsoluteY() >= getAbsoluteY())
827 && (mouse
.getAbsoluteY() < getAbsoluteY() + height
)
835 * Method that subclasses can override to handle keystrokes.
837 * @param keypress keystroke event
839 public void onKeypress(final TKeypressEvent keypress
) {
841 if ((children
.size() == 0)
842 || (this instanceof TTreeView
)
843 || (this instanceof TText
)
847 // tab / shift-tab - switch to next/previous widget
848 // right-arrow or down-arrow: same as tab
849 // left-arrow or up-arrow: same as shift-tab
850 if ((keypress
.equals(kbTab
))
851 || (keypress
.equals(kbRight
))
852 || (keypress
.equals(kbDown
))
854 parent
.switchWidget(true);
856 } else if ((keypress
.equals(kbShiftTab
))
857 || (keypress
.equals(kbBackTab
))
858 || (keypress
.equals(kbLeft
))
859 || (keypress
.equals(kbUp
))
861 parent
.switchWidget(false);
866 // If I have any buttons on me AND this is an Alt-key that matches
867 // its mnemonic, send it an Enter keystroke
868 for (TWidget widget
: children
) {
869 if (widget
instanceof TButton
) {
870 TButton button
= (TButton
) widget
;
871 if (button
.isEnabled()
872 && !keypress
.getKey().isFnKey()
873 && keypress
.getKey().isAlt()
874 && !keypress
.getKey().isCtrl()
875 && (Character
.toLowerCase(button
.getMnemonic().getShortcut())
876 == Character
.toLowerCase(keypress
.getKey().getChar()))
879 widget
.handleEvent(new TKeypressEvent(kbEnter
));
885 // Dispatch the keypress to an active widget
886 for (TWidget widget
: children
) {
888 widget
.handleEvent(keypress
);
895 * Method that subclasses can override to handle mouse button presses.
897 * @param mouse mouse button event
899 public void onMouseDown(final TMouseEvent mouse
) {
900 // Default: do nothing, pass to children instead
901 for (int i
= children
.size() - 1 ; i
>= 0 ; i
--) {
902 TWidget widget
= children
.get(i
);
903 if (widget
.mouseWouldHit(mouse
)) {
904 // Dispatch to this child, also activate it
907 // Set x and y relative to the child's coordinates
908 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
909 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
910 widget
.handleEvent(mouse
);
917 * Method that subclasses can override to handle mouse button releases.
919 * @param mouse mouse button event
921 public void onMouseUp(final TMouseEvent mouse
) {
922 // Default: do nothing, pass to children instead
923 for (int i
= children
.size() - 1 ; i
>= 0 ; i
--) {
924 TWidget widget
= children
.get(i
);
925 if (widget
.mouseWouldHit(mouse
)) {
926 // Dispatch to this child, also activate it
929 // Set x and y relative to the child's coordinates
930 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
931 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
932 widget
.handleEvent(mouse
);
939 * Method that subclasses can override to handle mouse movements.
941 * @param mouse mouse motion event
943 public void onMouseMotion(final TMouseEvent mouse
) {
944 // Default: do nothing, pass it on to ALL of my children. This way
945 // the children can see the mouse "leaving" their area.
946 for (TWidget widget
: children
) {
947 // Set x and y relative to the child's coordinates
948 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
949 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
950 widget
.handleEvent(mouse
);
955 * Method that subclasses can override to handle window/screen resize
958 * @param resize resize event
960 public void onResize(final TResizeEvent resize
) {
961 // Default: change my width/height.
962 if (resize
.getType() == TResizeEvent
.Type
.WIDGET
) {
963 width
= resize
.getWidth();
964 height
= resize
.getHeight();
966 // Let children see the screen resize
967 for (TWidget widget
: children
) {
968 widget
.onResize(resize
);
974 * Method that subclasses can override to handle posted command events.
976 * @param command command event
978 public void onCommand(final TCommandEvent command
) {
979 // Default: do nothing, pass to children instead
980 for (TWidget widget
: children
) {
981 widget
.onCommand(command
);
986 * Method that subclasses can override to handle menu or posted menu
989 * @param menu menu event
991 public void onMenu(final TMenuEvent menu
) {
992 // Default: do nothing, pass to children instead
993 for (TWidget widget
: children
) {
999 * Method that subclasses can override to do processing when the UI is
1000 * idle. Note that repainting is NOT assumed. To get a refresh after
1001 * onIdle, call doRepaint().
1003 public void onIdle() {
1004 // Default: do nothing, pass to children instead
1005 for (TWidget widget
: children
) {
1011 * Consume event. Subclasses that want to intercept all events in one go
1012 * can override this method.
1014 * @param event keyboard, mouse, resize, command, or menu event
1016 public void handleEvent(final TInputEvent event
) {
1017 // System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(),
1022 // System.err.println(" -- discard --");
1026 if (event
instanceof TKeypressEvent
) {
1027 onKeypress((TKeypressEvent
) event
);
1028 } else if (event
instanceof TMouseEvent
) {
1030 TMouseEvent mouse
= (TMouseEvent
) event
;
1032 switch (mouse
.getType()) {
1043 onMouseMotion(mouse
);
1047 throw new IllegalArgumentException("Invalid mouse event type: "
1050 } else if (event
instanceof TResizeEvent
) {
1051 onResize((TResizeEvent
) event
);
1052 } else if (event
instanceof TCommandEvent
) {
1053 onCommand((TCommandEvent
) event
);
1054 } else if (event
instanceof TMenuEvent
) {
1055 onMenu((TMenuEvent
) event
);
1062 // ------------------------------------------------------------------------
1063 // Other TWidget constructors ---------------------------------------------
1064 // ------------------------------------------------------------------------
1067 * Convenience function to add a label to this container/window.
1070 * @param x column relative to parent
1071 * @param y row relative to parent
1072 * @return the new label
1074 public final TLabel
addLabel(final String text
, final int x
, final int y
) {
1075 return addLabel(text
, x
, y
, "tlabel");
1079 * Convenience function to add a label to this container/window.
1082 * @param x column relative to parent
1083 * @param y row relative to parent
1084 * @param colorKey ColorTheme key color to use for foreground text.
1085 * Default is "tlabel"
1086 * @return the new label
1088 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1089 final String colorKey
) {
1091 return new TLabel(this, text
, x
, y
, colorKey
);
1095 * Convenience function to add a button to this container/window.
1097 * @param text label on the button
1098 * @param x column relative to parent
1099 * @param y row relative to parent
1100 * @param action to call when button is pressed
1101 * @return the new button
1103 public final TButton
addButton(final String text
, final int x
, final int y
,
1104 final TAction action
) {
1106 return new TButton(this, text
, x
, y
, action
);
1110 * Convenience function to add a checkbox to this container/window.
1112 * @param x column relative to parent
1113 * @param y row relative to parent
1114 * @param label label to display next to (right of) the checkbox
1115 * @param checked initial check state
1116 * @return the new checkbox
1118 public final TCheckbox
addCheckbox(final int x
, final int y
,
1119 final String label
, final boolean checked
) {
1121 return new TCheckbox(this, x
, y
, label
, checked
);
1125 * Convenience function to add a progress bar to this container/window.
1127 * @param x column relative to parent
1128 * @param y row relative to parent
1129 * @param width width of progress bar
1130 * @param value initial value of percent complete
1131 * @return the new progress bar
1133 public final TProgressBar
addProgressBar(final int x
, final int y
,
1134 final int width
, final int value
) {
1136 return new TProgressBar(this, x
, y
, width
, value
);
1140 * Convenience function to add a radio button group to this
1143 * @param x column relative to parent
1144 * @param y row relative to parent
1145 * @param label label to display on the group box
1146 * @return the new radio button group
1148 public final TRadioGroup
addRadioGroup(final int x
, final int y
,
1149 final String label
) {
1151 return new TRadioGroup(this, x
, y
, label
);
1155 * Convenience function to add a text field to this container/window.
1157 * @param x column relative to parent
1158 * @param y row relative to parent
1159 * @param width visible text width
1160 * @param fixed if true, the text cannot exceed the display width
1161 * @return the new text field
1163 public final TField
addField(final int x
, final int y
,
1164 final int width
, final boolean fixed
) {
1166 return new TField(this, x
, y
, width
, fixed
);
1170 * Convenience function to add a text field to this container/window.
1172 * @param x column relative to parent
1173 * @param y row relative to parent
1174 * @param width visible text width
1175 * @param fixed if true, the text cannot exceed the display width
1176 * @param text initial text, default is empty string
1177 * @return the new text field
1179 public final TField
addField(final int x
, final int y
,
1180 final int width
, final boolean fixed
, final String text
) {
1182 return new TField(this, x
, y
, width
, fixed
, text
);
1186 * Convenience function to add a text field to this container/window.
1188 * @param x column relative to parent
1189 * @param y row relative to parent
1190 * @param width visible text width
1191 * @param fixed if true, the text cannot exceed the display width
1192 * @param text initial text, default is empty string
1193 * @param enterAction function to call when enter key is pressed
1194 * @param updateAction function to call when the text is updated
1195 * @return the new text field
1197 public final TField
addField(final int x
, final int y
,
1198 final int width
, final boolean fixed
, final String text
,
1199 final TAction enterAction
, final TAction updateAction
) {
1201 return new TField(this, x
, y
, width
, fixed
, text
, enterAction
,
1206 * Convenience function to add a scrollable text box to this
1209 * @param text text on the screen
1210 * @param x column relative to parent
1211 * @param y row relative to parent
1212 * @param width width of text area
1213 * @param height height of text area
1214 * @param colorKey ColorTheme key color to use for foreground text
1215 * @return the new text box
1217 public final TText
addText(final String text
, final int x
,
1218 final int y
, final int width
, final int height
, final String colorKey
) {
1220 return new TText(this, text
, x
, y
, width
, height
, colorKey
);
1224 * Convenience function to add a scrollable text box to this
1227 * @param text text on the screen
1228 * @param x column relative to parent
1229 * @param y row relative to parent
1230 * @param width width of text area
1231 * @param height height of text area
1232 * @return the new text box
1234 public final TText
addText(final String text
, final int x
, final int y
,
1235 final int width
, final int height
) {
1237 return new TText(this, text
, x
, y
, width
, height
, "ttext");
1241 * Convenience function to add an editable text area box to this
1244 * @param text text on the screen
1245 * @param x column relative to parent
1246 * @param y row relative to parent
1247 * @param width width of text area
1248 * @param height height of text area
1249 * @return the new text box
1251 public final TEditorWidget
addEditor(final String text
, final int x
,
1252 final int y
, final int width
, final int height
) {
1254 return new TEditorWidget(this, text
, x
, y
, width
, height
);
1258 * Convenience function to spawn a message box.
1260 * @param title window title, will be centered along the top border
1261 * @param caption message to display. Use embedded newlines to get a
1263 * @return the new message box
1265 public final TMessageBox
messageBox(final String title
,
1266 final String caption
) {
1268 return getApplication().messageBox(title
, caption
, TMessageBox
.Type
.OK
);
1272 * Convenience function to spawn a message box.
1274 * @param title window title, will be centered along the top border
1275 * @param caption message to display. Use embedded newlines to get a
1277 * @param type one of the TMessageBox.Type constants. Default is
1279 * @return the new message box
1281 public final TMessageBox
messageBox(final String title
,
1282 final String caption
, final TMessageBox
.Type type
) {
1284 return getApplication().messageBox(title
, caption
, type
);
1288 * Convenience function to spawn an input box.
1290 * @param title window title, will be centered along the top border
1291 * @param caption message to display. Use embedded newlines to get a
1293 * @return the new input box
1295 public final TInputBox
inputBox(final String title
, final String caption
) {
1297 return getApplication().inputBox(title
, caption
);
1301 * Convenience function to spawn an input box.
1303 * @param title window title, will be centered along the top border
1304 * @param caption message to display. Use embedded newlines to get a
1306 * @param text initial text to seed the field with
1307 * @return the new input box
1309 public final TInputBox
inputBox(final String title
, final String caption
,
1310 final String text
) {
1312 return getApplication().inputBox(title
, caption
, text
);
1316 * Convenience function to add a password text field to this
1319 * @param x column relative to parent
1320 * @param y row relative to parent
1321 * @param width visible text width
1322 * @param fixed if true, the text cannot exceed the display width
1323 * @return the new text field
1325 public final TPasswordField
addPasswordField(final int x
, final int y
,
1326 final int width
, final boolean fixed
) {
1328 return new TPasswordField(this, x
, y
, width
, fixed
);
1332 * Convenience function to add a password text field to this
1335 * @param x column relative to parent
1336 * @param y row relative to parent
1337 * @param width visible text width
1338 * @param fixed if true, the text cannot exceed the display width
1339 * @param text initial text, default is empty string
1340 * @return the new text field
1342 public final TPasswordField
addPasswordField(final int x
, final int y
,
1343 final int width
, final boolean fixed
, final String text
) {
1345 return new TPasswordField(this, x
, y
, width
, fixed
, text
);
1349 * Convenience function to add a password text field to this
1352 * @param x column relative to parent
1353 * @param y row relative to parent
1354 * @param width visible text width
1355 * @param fixed if true, the text cannot exceed the display width
1356 * @param text initial text, default is empty string
1357 * @param enterAction function to call when enter key is pressed
1358 * @param updateAction function to call when the text is updated
1359 * @return the new text field
1361 public final TPasswordField
addPasswordField(final int x
, final int y
,
1362 final int width
, final boolean fixed
, final String text
,
1363 final TAction enterAction
, final TAction updateAction
) {
1365 return new TPasswordField(this, x
, y
, width
, fixed
, text
, enterAction
,
1370 * Convenience function to add a tree view to this container/window.
1372 * @param x column relative to parent
1373 * @param y row relative to parent
1374 * @param width width of tree view
1375 * @param height height of tree view
1376 * @return the new tree view
1378 public final TTreeView
addTreeView(final int x
, final int y
,
1379 final int width
, final int height
) {
1381 return new TTreeView(this, x
, y
, width
, height
);
1385 * Convenience function to add a tree view to this container/window.
1387 * @param x column relative to parent
1388 * @param y row relative to parent
1389 * @param width width of tree view
1390 * @param height height of tree view
1391 * @param action action to perform when an item is selected
1392 * @return the new tree view
1394 public final TTreeView
addTreeView(final int x
, final int y
,
1395 final int width
, final int height
, final TAction action
) {
1397 return new TTreeView(this, x
, y
, width
, height
, action
);
1401 * Convenience function to spawn a file open box.
1403 * @param path path of selected file
1404 * @return the result of the new file open box
1405 * @throws IOException if a java.io operation throws
1407 public final String
fileOpenBox(final String path
) throws IOException
{
1408 return getApplication().fileOpenBox(path
);
1412 * Convenience function to spawn a file open box.
1414 * @param path path of selected file
1415 * @param type one of the Type constants
1416 * @return the result of the new file open box
1417 * @throws IOException if a java.io operation throws
1419 public final String
fileOpenBox(final String path
,
1420 final TFileOpenBox
.Type type
) throws IOException
{
1422 return getApplication().fileOpenBox(path
, type
);
1425 * Convenience function to add a directory list to this container/window.
1427 * @param path directory path, must be a directory
1428 * @param x column relative to parent
1429 * @param y row relative to parent
1430 * @param width width of text area
1431 * @param height height of text area
1432 * @return the new directory list
1434 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
1435 final int y
, final int width
, final int height
) {
1437 return new TDirectoryList(this, path
, x
, y
, width
, height
, null);
1441 * Convenience function to add a directory list to this container/window.
1443 * @param path directory path, must be a directory
1444 * @param x column relative to parent
1445 * @param y row relative to parent
1446 * @param width width of text area
1447 * @param height height of text area
1448 * @param action action to perform when an item is selected
1449 * @return the new directory list
1451 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
1452 final int y
, final int width
, final int height
, final TAction action
) {
1454 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
);
1458 * Convenience function to add a directory list to this container/window.
1460 * @param strings list of strings to show
1461 * @param x column relative to parent
1462 * @param y row relative to parent
1463 * @param width width of text area
1464 * @param height height of text area
1465 * @return the new directory list
1467 public final TList
addList(final List
<String
> strings
, final int x
,
1468 final int y
, final int width
, final int height
) {
1470 return new TList(this, strings
, x
, y
, width
, height
, null);
1474 * Convenience function to add a directory list to this container/window.
1476 * @param strings list of strings to show
1477 * @param x column relative to parent
1478 * @param y row relative to parent
1479 * @param width width of text area
1480 * @param height height of text area
1481 * @param enterAction action to perform when an item is selected
1482 * @return the new directory list
1484 public final TList
addList(final List
<String
> strings
, final int x
,
1485 final int y
, final int width
, final int height
,
1486 final TAction enterAction
) {
1488 return new TList(this, strings
, x
, y
, width
, height
, enterAction
);
1492 * Convenience function to add a directory list to this container/window.
1494 * @param strings list of strings to show
1495 * @param x column relative to parent
1496 * @param y row relative to parent
1497 * @param width width of text area
1498 * @param height height of text area
1499 * @param enterAction action to perform when an item is selected
1500 * @param moveAction action to perform when the user navigates to a new
1501 * item with arrow/page keys
1502 * @return the new directory list
1504 public final TList
addList(final List
<String
> strings
, final int x
,
1505 final int y
, final int width
, final int height
,
1506 final TAction enterAction
, final TAction moveAction
) {
1508 return new TList(this, strings
, x
, y
, width
, height
, enterAction
,