85910abea53e83d203bcda7b450ff1ea489dd2b1
2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import java
.io
.IOException
;
34 import java
.util
.List
;
35 import java
.util
.LinkedList
;
37 import jexer
.bits
.ColorTheme
;
38 import jexer
.event
.TCommandEvent
;
39 import jexer
.event
.TInputEvent
;
40 import jexer
.event
.TKeypressEvent
;
41 import jexer
.event
.TMenuEvent
;
42 import jexer
.event
.TMouseEvent
;
43 import jexer
.event
.TResizeEvent
;
44 import jexer
.io
.Screen
;
45 import jexer
.menu
.TMenu
;
46 import static jexer
.TKeypress
.*;
49 * TWidget is the base class of all objects that can be drawn on screen or
50 * handle user input events.
52 public abstract class TWidget
implements Comparable
<TWidget
> {
55 * Every widget has a parent widget that it may be "contained" in. For
56 * example, a TWindow might contain several TTextFields, or a TComboBox
57 * may contain a TScrollBar.
59 private TWidget parent
= null;
64 * @return parent widget
66 public final TWidget
getParent() {
71 * Backdoor access for TWindow's constructor. ONLY TWindow USES THIS.
73 * @param window the top-level window
74 * @param x column relative to parent
75 * @param y row relative to parent
76 * @param width width of window
77 * @param height height of window
79 protected final void setupForTWindow(final TWindow window
,
80 final int x
, final int y
, final int width
, final int height
) {
91 * Get this TWidget's parent TApplication.
93 * @return the parent TApplication
95 public TApplication
getApplication() {
96 return window
.getApplication();
104 public Screen
getScreen() {
105 return window
.getScreen();
109 * Child widgets that this widget contains.
111 private List
<TWidget
> children
;
114 * Get the list of child widgets that this widget contains.
116 * @return the list of child widgets
118 public List
<TWidget
> getChildren() {
123 * The currently active child widget that will receive keypress events.
125 private TWidget activeChild
= null;
128 * If true, this widget will receive events.
130 private boolean active
= false;
135 * @return if true, this widget will receive events
137 public final boolean isActive() {
144 * @param active if true, this widget will receive events
146 public final void setActive(final boolean active
) {
147 this.active
= active
;
151 * The window that this widget draws to.
153 private TWindow window
= null;
156 * Get the window this widget is on.
160 public final TWindow
getWindow() {
165 * Absolute X position of the top-left corner.
172 * @return absolute X position of the top-left corner
174 public final int getX() {
181 * @param x absolute X position of the top-left corner
183 public final void setX(final int x
) {
188 * Absolute Y position of the top-left corner.
195 * @return absolute Y position of the top-left corner
197 public final int getY() {
204 * @param y absolute Y position of the top-left corner
206 public final void setY(final int y
) {
213 private int width
= 0;
218 * @return widget width
220 public final int getWidth() {
227 * @param width new widget width
229 public final void setWidth(final int width
) {
236 private int height
= 0;
241 * @return widget height
243 public final int getHeight() {
250 * @param height new widget height
252 public final void setHeight(final int height
) {
253 this.height
= height
;
257 * My tab order inside a window or containing widget.
259 private int tabOrder
= 0;
262 * If true, this widget can be tabbed to or receive events.
264 private boolean enabled
= true;
269 * @return if true, this widget can be tabbed to or receive events
271 public final boolean isEnabled() {
278 * @param enabled if true, this widget can be tabbed to or receive events
280 public final void setEnabled(final boolean enabled
) {
281 this.enabled
= enabled
;
284 // See if there are any active siblings to switch to
285 boolean foundSibling
= false;
286 if (parent
!= null) {
287 for (TWidget w
: parent
.children
) {
289 && !(this instanceof THScroller
)
290 && !(this instanceof TVScroller
)
298 parent
.activeChild
= null;
305 * If true, this widget has a cursor.
307 private boolean cursorVisible
= false;
310 * Set visible cursor flag.
312 * @param cursorVisible if true, this widget has a cursor
314 public final void setCursorVisible(final boolean cursorVisible
) {
315 this.cursorVisible
= cursorVisible
;
319 * See if this widget has a visible cursor.
321 * @return if true, this widget has a visible cursor
323 public final boolean isCursorVisible() {
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
;
374 * Comparison operator sorts on:
376 * <li>tabOrder for TWidgets</li>
377 * <li>z for TWindows</li>
378 * <li>text for TTreeItems</li>
381 * @param that another TWidget, TWindow, or TTreeItem instance
382 * @return difference between this.tabOrder and that.tabOrder, or
383 * difference between this.z and that.z, or String.compareTo(text)
385 public final int compareTo(final TWidget that
) {
386 if ((this instanceof TWindow
)
387 && (that
instanceof TWindow
)
389 return (((TWindow
) this).getZ() - ((TWindow
) that
).getZ());
391 if ((this instanceof TTreeItem
)
392 && (that
instanceof TTreeItem
)
394 return (((TTreeItem
) this).getText().compareTo(
395 ((TTreeItem
) that
).getText()));
397 return (this.tabOrder
- that
.tabOrder
);
401 * See if this widget should render with the active color.
403 * @return true if this widget is active and all of its parents are
406 public final boolean isAbsoluteActive() {
407 if (parent
== this) {
410 return (active
&& parent
.isAbsoluteActive());
414 * Returns the cursor X position.
416 * @return absolute screen column number for the cursor's X position
418 public final int getCursorAbsoluteX() {
419 assert (cursorVisible
);
420 return getAbsoluteX() + cursorX
;
424 * Returns the cursor Y position.
426 * @return absolute screen row number for the cursor's Y position
428 public final int getCursorAbsoluteY() {
429 assert (cursorVisible
);
430 return getAbsoluteY() + cursorY
;
434 * Compute my absolute X position as the sum of my X plus all my parent's
437 * @return absolute screen column number for my X position
439 public final int getAbsoluteX() {
440 assert (parent
!= null);
441 if (parent
== this) {
444 if ((parent
instanceof TWindow
) && !(parent
instanceof TMenu
)) {
445 // Widgets on a TWindow have (0,0) as their top-left, but this is
446 // actually the TWindow's (1,1).
447 return parent
.getAbsoluteX() + x
+ 1;
449 return parent
.getAbsoluteX() + x
;
453 * Compute my absolute Y position as the sum of my Y plus all my parent's
456 * @return absolute screen row number for my Y position
458 public final int getAbsoluteY() {
459 assert (parent
!= null);
460 if (parent
== this) {
463 if ((parent
instanceof TWindow
) && !(parent
instanceof TMenu
)) {
464 // Widgets on a TWindow have (0,0) as their top-left, but this is
465 // actually the TWindow's (1,1).
466 return parent
.getAbsoluteY() + y
+ 1;
468 return parent
.getAbsoluteY() + y
;
472 * Get the global color theme.
474 * @return the ColorTheme
476 public final ColorTheme
getTheme() {
477 return window
.getApplication().getTheme();
481 * Draw my specific widget. When called, the screen rectangle I draw
482 * into is already setup (offset and clipping).
485 // Default widget draws nothing.
489 * Called by parent to render to TWindow.
491 public final void drawChildren() {
492 // Set my clipping rectangle
493 assert (window
!= null);
494 assert (getScreen() != null);
495 Screen screen
= getScreen();
497 screen
.setClipRight(width
);
498 screen
.setClipBottom(height
);
500 int absoluteRightEdge
= window
.getAbsoluteX() + window
.getWidth();
501 int absoluteBottomEdge
= window
.getAbsoluteY() + window
.getHeight();
502 if (!(this instanceof TWindow
) && !(this instanceof TVScroller
)) {
503 absoluteRightEdge
-= 1;
505 if (!(this instanceof TWindow
) && !(this instanceof THScroller
)) {
506 absoluteBottomEdge
-= 1;
508 int myRightEdge
= getAbsoluteX() + width
;
509 int myBottomEdge
= getAbsoluteY() + height
;
510 if (getAbsoluteX() > absoluteRightEdge
) {
512 screen
.setClipRight(0);
513 } else if (myRightEdge
> absoluteRightEdge
) {
514 screen
.setClipRight(screen
.getClipRight()
515 - (myRightEdge
- absoluteRightEdge
));
517 if (getAbsoluteY() > absoluteBottomEdge
) {
519 screen
.setClipBottom(0);
520 } else if (myBottomEdge
> absoluteBottomEdge
) {
521 screen
.setClipBottom(screen
.getClipBottom()
522 - (myBottomEdge
- absoluteBottomEdge
));
526 screen
.setOffsetX(getAbsoluteX());
527 screen
.setOffsetY(getAbsoluteY());
532 // Continue down the chain
533 for (TWidget widget
: children
) {
534 widget
.drawChildren();
539 * Default constructor for subclasses.
541 protected TWidget() {
542 children
= new LinkedList
<TWidget
>();
546 * Protected constructor.
548 * @param parent parent widget
550 protected TWidget(final TWidget parent
) {
555 * Protected constructor.
557 * @param parent parent widget
558 * @param x column relative to parent
559 * @param y row relative to parent
560 * @param width width of widget
561 * @param height height of widget
563 protected TWidget(final TWidget parent
, final int x
, final int y
,
564 final int width
, final int height
) {
566 this(parent
, true, x
, y
, width
, height
);
570 * Protected constructor used by subclasses that are disabled by default.
572 * @param parent parent widget
573 * @param enabled if true assume enabled
575 protected TWidget(final TWidget parent
, final boolean enabled
) {
576 this.enabled
= enabled
;
577 this.parent
= parent
;
578 this.window
= parent
.window
;
579 children
= new LinkedList
<TWidget
>();
580 parent
.addChild(this);
584 * Protected constructor used by subclasses that are disabled by default.
586 * @param parent parent widget
587 * @param enabled if true assume enabled
588 * @param x column relative to parent
589 * @param y row relative to parent
590 * @param width width of widget
591 * @param height height of widget
593 protected TWidget(final TWidget parent
, final boolean enabled
,
594 final int x
, final int y
, final int width
, final int height
) {
596 this.enabled
= enabled
;
597 this.parent
= parent
;
598 this.window
= parent
.window
;
599 children
= new LinkedList
<TWidget
>();
600 parent
.addChild(this);
605 this.height
= height
;
609 * Add a child widget to my list of children. We set its tabOrder to 0
610 * and increment the tabOrder of all other children.
612 * @param child TWidget to add
614 private void addChild(final TWidget child
) {
618 && !(child
instanceof THScroller
)
619 && !(child
instanceof TVScroller
)
621 for (TWidget widget
: children
) {
622 widget
.active
= false;
627 for (int i
= 0; i
< children
.size(); i
++) {
628 children
.get(i
).tabOrder
= i
;
633 * Switch the active child.
635 * @param child TWidget to activate
637 public final void activate(final TWidget child
) {
638 assert (child
.enabled
);
639 if ((child
instanceof THScroller
)
640 || (child
instanceof TVScroller
)
645 if (child
!= activeChild
) {
646 if (activeChild
!= null) {
647 activeChild
.active
= false;
655 * Switch the active child.
657 * @param tabOrder tabOrder of the child to activate. If that child
658 * isn't enabled, then the next enabled child will be activated.
660 public final void activate(final int tabOrder
) {
661 if (activeChild
== null) {
664 TWidget child
= null;
665 for (TWidget widget
: children
) {
667 && !(widget
instanceof THScroller
)
668 && !(widget
instanceof TVScroller
)
669 && (widget
.tabOrder
>= tabOrder
)
675 if ((child
!= null) && (child
!= activeChild
)) {
676 activeChild
.active
= false;
677 assert (child
.enabled
);
684 * Switch the active widget with the next in the tab order.
686 * @param forward if true, then switch to the next enabled widget in the
687 * list, otherwise switch to the previous enabled widget in the list
689 public final void switchWidget(final boolean forward
) {
691 // Only switch if there are multiple enabled widgets
692 if ((children
.size() < 2) || (activeChild
== null)) {
696 int tabOrder
= activeChild
.tabOrder
;
705 // If at the end, pass the switch to my parent.
706 if ((!forward
) && (parent
!= this)) {
707 parent
.switchWidget(forward
);
711 tabOrder
= children
.size() - 1;
712 } else if (tabOrder
== children
.size()) {
713 // If at the end, pass the switch to my parent.
714 if ((forward
) && (parent
!= this)) {
715 parent
.switchWidget(forward
);
721 if (activeChild
.tabOrder
== tabOrder
) {
725 } while ((!children
.get(tabOrder
).enabled
)
726 && !(children
.get(tabOrder
) instanceof THScroller
)
727 && !(children
.get(tabOrder
) instanceof TVScroller
));
729 assert (children
.get(tabOrder
).enabled
);
731 activeChild
.active
= false;
732 children
.get(tabOrder
).active
= true;
733 activeChild
= children
.get(tabOrder
);
737 * Returns my active widget.
739 * @return widget that is active, or this if no children
741 public TWidget
getActiveChild() {
742 if ((this instanceof THScroller
)
743 || (this instanceof TVScroller
)
748 for (TWidget widget
: children
) {
750 return widget
.getActiveChild();
753 // No active children, return me
758 * Method that subclasses can override to handle keystrokes.
760 * @param keypress keystroke event
762 public void onKeypress(final TKeypressEvent keypress
) {
764 if ((children
.size() == 0)
765 || (this instanceof TTreeView
)
766 || (this instanceof TText
)
770 // tab / shift-tab - switch to next/previous widget
771 // right-arrow or down-arrow: same as tab
772 // left-arrow or up-arrow: same as shift-tab
773 if ((keypress
.equals(kbTab
))
774 || (keypress
.equals(kbRight
))
775 || (keypress
.equals(kbDown
))
777 parent
.switchWidget(true);
779 } else if ((keypress
.equals(kbShiftTab
))
780 || (keypress
.equals(kbBackTab
))
781 || (keypress
.equals(kbLeft
))
782 || (keypress
.equals(kbUp
))
784 parent
.switchWidget(false);
789 // If I have any buttons on me AND this is an Alt-key that matches
790 // its mnemonic, send it an Enter keystroke
791 for (TWidget widget
: children
) {
792 if (widget
instanceof TButton
) {
793 TButton button
= (TButton
) widget
;
794 if (button
.isEnabled()
795 && !keypress
.getKey().isFnKey()
796 && keypress
.getKey().isAlt()
797 && !keypress
.getKey().isCtrl()
798 && (Character
.toLowerCase(button
.getMnemonic().getShortcut())
799 == Character
.toLowerCase(keypress
.getKey().getChar()))
802 widget
.handleEvent(new TKeypressEvent(kbEnter
));
808 // Dispatch the keypress to an active widget
809 for (TWidget widget
: children
) {
811 widget
.handleEvent(keypress
);
818 * Method that subclasses can override to handle mouse button presses.
820 * @param mouse mouse button event
822 public void onMouseDown(final TMouseEvent mouse
) {
823 // Default: do nothing, pass to children instead
824 for (TWidget widget
: children
) {
825 if (widget
.mouseWouldHit(mouse
)) {
826 // Dispatch to this child, also activate it
829 // Set x and y relative to the child's coordinates
830 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
831 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
832 widget
.handleEvent(mouse
);
839 * Method that subclasses can override to handle mouse button releases.
841 * @param mouse mouse button event
843 public void onMouseUp(final TMouseEvent mouse
) {
844 // Default: do nothing, pass to children instead
845 for (TWidget widget
: children
) {
846 if (widget
.mouseWouldHit(mouse
)) {
847 // Dispatch to this child, also activate it
850 // Set x and y relative to the child's coordinates
851 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
852 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
853 widget
.handleEvent(mouse
);
860 * Method that subclasses can override to handle mouse movements.
862 * @param mouse mouse motion event
864 public void onMouseMotion(final TMouseEvent mouse
) {
865 // Default: do nothing, pass it on to ALL of my children. This way
866 // the children can see the mouse "leaving" their area.
867 for (TWidget widget
: children
) {
868 // Set x and y relative to the child's coordinates
869 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
870 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
871 widget
.handleEvent(mouse
);
876 * Method that subclasses can override to handle window/screen resize
879 * @param resize resize event
881 public void onResize(final TResizeEvent resize
) {
882 // Default: do nothing, pass to children instead
883 for (TWidget widget
: children
) {
884 widget
.onResize(resize
);
889 * Method that subclasses can override to handle posted command events.
891 * @param command command event
893 public void onCommand(final TCommandEvent command
) {
894 // Default: do nothing, pass to children instead
895 for (TWidget widget
: children
) {
896 widget
.onCommand(command
);
901 * Method that subclasses can override to handle menu or posted menu
904 * @param menu menu event
906 public void onMenu(final TMenuEvent menu
) {
907 // Default: do nothing, pass to children instead
908 for (TWidget widget
: children
) {
914 * Method that subclasses can override to do processing when the UI is
917 public void onIdle() {
918 // Default: do nothing, pass to children instead
919 for (TWidget widget
: children
) {
925 * Consume event. Subclasses that want to intercept all events in one go
926 * can override this method.
928 * @param event keyboard, mouse, resize, command, or menu event
930 public void handleEvent(final TInputEvent event
) {
931 // System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(),
936 // System.err.println(" -- discard --");
940 if (event
instanceof TKeypressEvent
) {
941 onKeypress((TKeypressEvent
) event
);
942 } else if (event
instanceof TMouseEvent
) {
944 TMouseEvent mouse
= (TMouseEvent
) event
;
946 switch (mouse
.getType()) {
957 onMouseMotion(mouse
);
961 throw new IllegalArgumentException("Invalid mouse event type: "
964 } else if (event
instanceof TResizeEvent
) {
965 onResize((TResizeEvent
) event
);
966 } else if (event
instanceof TCommandEvent
) {
967 onCommand((TCommandEvent
) event
);
968 } else if (event
instanceof TMenuEvent
) {
969 onMenu((TMenuEvent
) event
);
977 * Check if a mouse press/release event coordinate is contained in this
980 * @param mouse a mouse-based event
981 * @return whether or not a mouse click would be sent to this widget
983 public final boolean mouseWouldHit(final TMouseEvent mouse
) {
989 if ((mouse
.getAbsoluteX() >= getAbsoluteX())
990 && (mouse
.getAbsoluteX() < getAbsoluteX() + width
)
991 && (mouse
.getAbsoluteY() >= getAbsoluteY())
992 && (mouse
.getAbsoluteY() < getAbsoluteY() + height
)
1000 * Convenience function to add a label to this container/window.
1003 * @param x column relative to parent
1004 * @param y row relative to parent
1005 * @return the new label
1007 public final TLabel
addLabel(final String text
, final int x
, final int y
) {
1008 return addLabel(text
, x
, y
, "tlabel");
1012 * Convenience function to add a label to this container/window.
1015 * @param x column relative to parent
1016 * @param y row relative to parent
1017 * @param colorKey ColorTheme key color to use for foreground text.
1018 * Default is "tlabel"
1019 * @return the new label
1021 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1022 final String colorKey
) {
1024 return new TLabel(this, text
, x
, y
, colorKey
);
1028 * Convenience function to add a button to this container/window.
1030 * @param text label on the button
1031 * @param x column relative to parent
1032 * @param y row relative to parent
1033 * @param action to call when button is pressed
1034 * @return the new button
1036 public final TButton
addButton(final String text
, final int x
, final int y
,
1037 final TAction action
) {
1039 return new TButton(this, text
, x
, y
, action
);
1043 * Convenience function to add a checkbox to this container/window.
1045 * @param x column relative to parent
1046 * @param y row relative to parent
1047 * @param label label to display next to (right of) the checkbox
1048 * @param checked initial check state
1049 * @return the new checkbox
1051 public final TCheckbox
addCheckbox(final int x
, final int y
,
1052 final String label
, final boolean checked
) {
1054 return new TCheckbox(this, x
, y
, label
, checked
);
1058 * Convenience function to add a progress bar to this container/window.
1060 * @param x column relative to parent
1061 * @param y row relative to parent
1062 * @param width width of progress bar
1063 * @param value initial value of percent complete
1064 * @return the new progress bar
1066 public final TProgressBar
addProgressBar(final int x
, final int y
,
1067 final int width
, final int value
) {
1069 return new TProgressBar(this, x
, y
, width
, value
);
1073 * Convenience function to add a radio button group to this
1076 * @param x column relative to parent
1077 * @param y row relative to parent
1078 * @param label label to display on the group box
1079 * @return the new radio button group
1081 public final TRadioGroup
addRadioGroup(final int x
, final int y
,
1082 final String label
) {
1084 return new TRadioGroup(this, x
, y
, label
);
1088 * Convenience function to add a text field to this container/window.
1090 * @param x column relative to parent
1091 * @param y row relative to parent
1092 * @param width visible text width
1093 * @param fixed if true, the text cannot exceed the display width
1094 * @return the new text field
1096 public final TField
addField(final int x
, final int y
,
1097 final int width
, final boolean fixed
) {
1099 return new TField(this, x
, y
, width
, fixed
);
1103 * Convenience function to add a text field to this container/window.
1105 * @param x column relative to parent
1106 * @param y row relative to parent
1107 * @param width visible text width
1108 * @param fixed if true, the text cannot exceed the display width
1109 * @param text initial text, default is empty string
1110 * @return the new text field
1112 public final TField
addField(final int x
, final int y
,
1113 final int width
, final boolean fixed
, final String text
) {
1115 return new TField(this, x
, y
, width
, fixed
, text
);
1119 * Convenience function to add a text field to this container/window.
1121 * @param x column relative to parent
1122 * @param y row relative to parent
1123 * @param width visible text width
1124 * @param fixed if true, the text cannot exceed the display width
1125 * @param text initial text, default is empty string
1126 * @param enterAction function to call when enter key is pressed
1127 * @param updateAction function to call when the text is updated
1128 * @return the new text field
1130 public final TField
addField(final int x
, final int y
,
1131 final int width
, final boolean fixed
, final String text
,
1132 final TAction enterAction
, final TAction updateAction
) {
1134 return new TField(this, x
, y
, width
, fixed
, text
, enterAction
,
1139 * Convenience function to add a scrollable text box to this
1142 * @param text text on the screen
1143 * @param x column relative to parent
1144 * @param y row relative to parent
1145 * @param width width of text area
1146 * @param height height of text area
1147 * @param colorKey ColorTheme key color to use for foreground text
1148 * @return the new text box
1150 public final TText
addText(final String text
, final int x
,
1151 final int y
, final int width
, final int height
, final String colorKey
) {
1153 return new TText(this, text
, x
, y
, width
, height
, colorKey
);
1157 * Convenience function to add a scrollable text box to this
1160 * @param text text on the screen
1161 * @param x column relative to parent
1162 * @param y row relative to parent
1163 * @param width width of text area
1164 * @param height height of text area
1165 * @return the new text box
1167 public final TText
addText(final String text
, final int x
, final int y
,
1168 final int width
, final int height
) {
1170 return new TText(this, text
, x
, y
, width
, height
, "ttext");
1174 * Convenience function to spawn a message box.
1176 * @param title window title, will be centered along the top border
1177 * @param caption message to display. Use embedded newlines to get a
1179 * @return the new message box
1181 public final TMessageBox
messageBox(final String title
,
1182 final String caption
) {
1184 return getApplication().messageBox(title
, caption
, TMessageBox
.Type
.OK
);
1188 * Convenience function to spawn a message box.
1190 * @param title window title, will be centered along the top border
1191 * @param caption message to display. Use embedded newlines to get a
1193 * @param type one of the TMessageBox.Type constants. Default is
1195 * @return the new message box
1197 public final TMessageBox
messageBox(final String title
,
1198 final String caption
, final TMessageBox
.Type type
) {
1200 return getApplication().messageBox(title
, caption
, type
);
1204 * Convenience function to spawn an input box.
1206 * @param title window title, will be centered along the top border
1207 * @param caption message to display. Use embedded newlines to get a
1209 * @return the new input box
1211 public final TInputBox
inputBox(final String title
, final String caption
) {
1213 return getApplication().inputBox(title
, caption
);
1217 * Convenience function to spawn an input box.
1219 * @param title window title, will be centered along the top border
1220 * @param caption message to display. Use embedded newlines to get a
1222 * @param text initial text to seed the field with
1223 * @return the new input box
1225 public final TInputBox
inputBox(final String title
, final String caption
,
1226 final String text
) {
1228 return getApplication().inputBox(title
, caption
, text
);
1232 * Convenience function to add a password text field to this
1235 * @param x column relative to parent
1236 * @param y row relative to parent
1237 * @param width visible text width
1238 * @param fixed if true, the text cannot exceed the display width
1239 * @return the new text field
1241 public final TPasswordField
addPasswordField(final int x
, final int y
,
1242 final int width
, final boolean fixed
) {
1244 return new TPasswordField(this, x
, y
, width
, fixed
);
1248 * Convenience function to add a password text field to this
1251 * @param x column relative to parent
1252 * @param y row relative to parent
1253 * @param width visible text width
1254 * @param fixed if true, the text cannot exceed the display width
1255 * @param text initial text, default is empty string
1256 * @return the new text field
1258 public final TPasswordField
addPasswordField(final int x
, final int y
,
1259 final int width
, final boolean fixed
, final String text
) {
1261 return new TPasswordField(this, x
, y
, width
, fixed
, text
);
1265 * Convenience function to add a password text field to this
1268 * @param x column relative to parent
1269 * @param y row relative to parent
1270 * @param width visible text width
1271 * @param fixed if true, the text cannot exceed the display width
1272 * @param text initial text, default is empty string
1273 * @param enterAction function to call when enter key is pressed
1274 * @param updateAction function to call when the text is updated
1275 * @return the new text field
1277 public final TPasswordField
addPasswordField(final int x
, final int y
,
1278 final int width
, final boolean fixed
, final String text
,
1279 final TAction enterAction
, final TAction updateAction
) {
1281 return new TPasswordField(this, x
, y
, width
, fixed
, text
, enterAction
,
1286 * Convenience function to add a tree view to this container/window.
1288 * @param x column relative to parent
1289 * @param y row relative to parent
1290 * @param width width of tree view
1291 * @param height height of tree view
1293 public final TTreeView
addTreeView(final int x
, final int y
,
1294 final int width
, final int height
) {
1296 return new TTreeView(this, x
, y
, width
, height
);
1300 * Convenience function to add a tree view to this container/window.
1302 * @param x column relative to parent
1303 * @param y row relative to parent
1304 * @param width width of tree view
1305 * @param height height of tree view
1306 * @param action action to perform when an item is selected
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
1320 public final String
fileOpenBox(final String path
) throws IOException
{
1321 return getApplication().fileOpenBox(path
);
1325 * Convenience function to spawn a file open box.
1327 * @param path path of selected file
1328 * @param type one of the Type constants
1329 * @return the result of the new file open box
1331 public final String
fileOpenBox(final String path
,
1332 final TFileOpenBox
.Type type
) throws IOException
{
1334 return getApplication().fileOpenBox(path
, type
);
1337 * Convenience function to add a directory list to this container/window.
1339 * @param path directory path, must be a directory
1340 * @param x column relative to parent
1341 * @param y row relative to parent
1342 * @param width width of text area
1343 * @param height height of text area
1345 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
1346 final int y
, final int width
, final int height
) {
1348 return new TDirectoryList(this, path
, x
, y
, width
, height
, null);
1352 * Convenience function to add a directory list to this container/window.
1354 * @param path directory path, must be a directory
1355 * @param x column relative to parent
1356 * @param y row relative to parent
1357 * @param width width of text area
1358 * @param height height of text area
1359 * @param action action to perform when an item is selected
1361 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
1362 final int y
, final int width
, final int height
, final TAction action
) {
1364 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
);