2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 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
.awt
.image
.BufferedImage
;
32 import java
.io
.IOException
;
33 import java
.util
.List
;
34 import java
.util
.ArrayList
;
36 import jexer
.backend
.Screen
;
37 import jexer
.bits
.Cell
;
38 import jexer
.bits
.CellAttributes
;
39 import jexer
.bits
.ColorTheme
;
40 import jexer
.event
.TCommandEvent
;
41 import jexer
.event
.TInputEvent
;
42 import jexer
.event
.TKeypressEvent
;
43 import jexer
.event
.TMenuEvent
;
44 import jexer
.event
.TMouseEvent
;
45 import jexer
.event
.TResizeEvent
;
46 import jexer
.layout
.LayoutManager
;
47 import jexer
.menu
.TMenu
;
48 import jexer
.ttree
.TTreeItem
;
49 import jexer
.ttree
.TTreeView
;
50 import jexer
.ttree
.TTreeViewWidget
;
51 import static jexer
.TKeypress
.*;
54 * TWidget is the base class of all objects that can be drawn on screen or
55 * handle user input events.
57 public abstract class TWidget
implements Comparable
<TWidget
> {
59 // ------------------------------------------------------------------------
60 // Variables --------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Every widget has a parent widget that it may be "contained" in. For
65 * example, a TWindow might contain several TFields, or a TComboBox may
66 * contain a TList that itself contains a TVScroller.
68 private TWidget parent
= null;
71 * Child widgets that this widget contains.
73 private List
<TWidget
> children
;
76 * The currently active child widget that will receive keypress events.
78 private TWidget activeChild
= null;
81 * If true, this widget will receive events.
83 private boolean active
= false;
86 * The window that this widget draws to.
88 private TWindow window
= null;
91 * Absolute X position of the top-left corner.
96 * Absolute Y position of the top-left corner.
103 private int width
= 0;
108 private int height
= 0;
111 * My tab order inside a window or containing widget.
113 private int tabOrder
= 0;
116 * If true, this widget can be tabbed to or receive events.
118 private boolean enabled
= true;
121 * If true, this widget will be rendered.
123 private boolean visible
= true;
126 * If true, this widget has a cursor.
128 private boolean cursorVisible
= false;
131 * Cursor column position in relative coordinates.
133 private int cursorX
= 0;
136 * Cursor row position in relative coordinates.
138 private int cursorY
= 0;
143 private LayoutManager layout
= null;
145 // ------------------------------------------------------------------------
146 // Constructors -----------------------------------------------------------
147 // ------------------------------------------------------------------------
150 * Default constructor for subclasses.
152 protected TWidget() {
153 children
= new ArrayList
<TWidget
>();
157 * Protected constructor.
159 * @param parent parent widget
161 protected TWidget(final TWidget parent
) {
166 * Protected constructor.
168 * @param parent parent widget
169 * @param x column relative to parent
170 * @param y row relative to parent
171 * @param width width of widget
172 * @param height height of widget
174 protected TWidget(final TWidget parent
, final int x
, final int y
,
175 final int width
, final int height
) {
177 this(parent
, true, x
, y
, width
, height
);
181 * Protected constructor used by subclasses that are disabled by default.
183 * @param parent parent widget
184 * @param enabled if true assume enabled
186 protected TWidget(final TWidget parent
, final boolean enabled
) {
187 this.enabled
= enabled
;
188 this.parent
= parent
;
189 children
= new ArrayList
<TWidget
>();
191 if (parent
!= null) {
192 this.window
= parent
.window
;
193 parent
.addChild(this);
198 * Protected constructor used by subclasses that are disabled by default.
200 * @param parent parent widget
201 * @param enabled if true assume enabled
202 * @param x column relative to parent
203 * @param y row relative to parent
204 * @param width width of widget
205 * @param height height of widget
207 protected TWidget(final TWidget parent
, final boolean enabled
,
208 final int x
, final int y
, final int width
, final int height
) {
211 throw new IllegalArgumentException("width cannot be negative");
214 throw new IllegalArgumentException("height cannot be negative");
217 this.enabled
= enabled
;
218 this.parent
= parent
;
219 children
= new ArrayList
<TWidget
>();
224 this.height
= height
;
226 if (parent
!= null) {
227 this.window
= parent
.window
;
228 parent
.addChild(this);
233 * Backdoor access for TWindow's constructor. ONLY TWindow USES THIS.
235 * @param window the top-level window
236 * @param x column relative to parent
237 * @param y row relative to parent
238 * @param width width of window
239 * @param height height of window
241 protected final void setupForTWindow(final TWindow window
,
242 final int x
, final int y
, final int width
, final int height
) {
245 throw new IllegalArgumentException("width cannot be negative");
248 throw new IllegalArgumentException("height cannot be negative");
251 this.parent
= window
;
252 this.window
= window
;
256 this.height
= height
;
259 // ------------------------------------------------------------------------
260 // Event handlers ---------------------------------------------------------
261 // ------------------------------------------------------------------------
264 * Subclasses should override this method to cleanup resources. This is
265 * called by TWindow.onClose().
267 protected void close() {
268 // Default: call close() on children.
269 for (TWidget w
: getChildren()) {
275 * Check if a mouse press/release event coordinate is contained in this
278 * @param mouse a mouse-based event
279 * @return whether or not a mouse click would be sent to this widget
281 public final boolean mouseWouldHit(final TMouseEvent mouse
) {
287 if ((this instanceof TTreeItem
)
288 && ((y
< 0) || (y
> parent
.getHeight() - 1))
293 if ((mouse
.getAbsoluteX() >= getAbsoluteX())
294 && (mouse
.getAbsoluteX() < getAbsoluteX() + width
)
295 && (mouse
.getAbsoluteY() >= getAbsoluteY())
296 && (mouse
.getAbsoluteY() < getAbsoluteY() + height
)
304 * Method that subclasses can override to handle keystrokes.
306 * @param keypress keystroke event
308 public void onKeypress(final TKeypressEvent keypress
) {
309 assert (parent
!= null);
311 if ((children
.size() == 0)
312 || (this instanceof TTreeView
)
313 || (this instanceof TText
)
314 || (this instanceof TComboBox
)
318 // tab / shift-tab - switch to next/previous widget
319 // left-arrow or up-arrow: same as shift-tab
320 if ((keypress
.equals(kbTab
))
321 || (keypress
.equals(kbDown
) && !(this instanceof TComboBox
))
323 parent
.switchWidget(true);
325 } else if ((keypress
.equals(kbShiftTab
))
326 || (keypress
.equals(kbBackTab
))
327 || (keypress
.equals(kbUp
) && !(this instanceof TComboBox
))
329 parent
.switchWidget(false);
334 if ((children
.size() == 0)
335 && !(this instanceof TTreeView
)
339 // right-arrow or down-arrow: same as tab
340 if (keypress
.equals(kbRight
)) {
341 parent
.switchWidget(true);
343 } else if (keypress
.equals(kbLeft
)) {
344 parent
.switchWidget(false);
349 // If I have any buttons on me AND this is an Alt-key that matches
350 // its mnemonic, send it an Enter keystroke.
351 for (TWidget widget
: children
) {
352 if (widget
instanceof TButton
) {
353 TButton button
= (TButton
) widget
;
354 if (button
.isEnabled()
355 && !keypress
.getKey().isFnKey()
356 && keypress
.getKey().isAlt()
357 && !keypress
.getKey().isCtrl()
358 && (Character
.toLowerCase(button
.getMnemonic().getShortcut())
359 == Character
.toLowerCase(keypress
.getKey().getChar()))
362 widget
.onKeypress(new TKeypressEvent(kbEnter
));
368 // If I have any labels on me AND this is an Alt-key that matches
369 // its mnemonic, call its action.
370 for (TWidget widget
: children
) {
371 if (widget
instanceof TLabel
) {
372 TLabel label
= (TLabel
) widget
;
373 if (!keypress
.getKey().isFnKey()
374 && keypress
.getKey().isAlt()
375 && !keypress
.getKey().isCtrl()
376 && (Character
.toLowerCase(label
.getMnemonic().getShortcut())
377 == Character
.toLowerCase(keypress
.getKey().getChar()))
386 // If I have any radiobuttons on me AND this is an Alt-key that
387 // matches its mnemonic, select it and send a Space to it.
388 for (TWidget widget
: children
) {
389 if (widget
instanceof TRadioButton
) {
390 TRadioButton button
= (TRadioButton
) widget
;
391 if (button
.isEnabled()
392 && !keypress
.getKey().isFnKey()
393 && keypress
.getKey().isAlt()
394 && !keypress
.getKey().isCtrl()
395 && (Character
.toLowerCase(button
.getMnemonic().getShortcut())
396 == Character
.toLowerCase(keypress
.getKey().getChar()))
399 widget
.onKeypress(new TKeypressEvent(kbSpace
));
403 if (widget
instanceof TRadioGroup
) {
404 for (TWidget child
: widget
.getChildren()) {
405 if (child
instanceof TRadioButton
) {
406 TRadioButton button
= (TRadioButton
) child
;
407 if (button
.isEnabled()
408 && !keypress
.getKey().isFnKey()
409 && keypress
.getKey().isAlt()
410 && !keypress
.getKey().isCtrl()
411 && (Character
.toLowerCase(button
.getMnemonic().getShortcut())
412 == Character
.toLowerCase(keypress
.getKey().getChar()))
415 widget
.activate(child
);
416 child
.onKeypress(new TKeypressEvent(kbSpace
));
424 // If I have any checkboxes on me AND this is an Alt-key that matches
425 // its mnemonic, select it and set it to checked.
426 for (TWidget widget
: children
) {
427 if (widget
instanceof TCheckBox
) {
428 TCheckBox checkBox
= (TCheckBox
) widget
;
429 if (checkBox
.isEnabled()
430 && !keypress
.getKey().isFnKey()
431 && keypress
.getKey().isAlt()
432 && !keypress
.getKey().isCtrl()
433 && (Character
.toLowerCase(checkBox
.getMnemonic().getShortcut())
434 == Character
.toLowerCase(keypress
.getKey().getChar()))
437 checkBox
.setChecked(true);
443 // Dispatch the keypress to an active widget
444 for (TWidget widget
: children
) {
446 widget
.onKeypress(keypress
);
453 * Method that subclasses can override to handle mouse button presses.
455 * @param mouse mouse button event
457 public void onMouseDown(final TMouseEvent mouse
) {
458 // Default: do nothing, pass to children instead
459 if (activeChild
!= null) {
460 if (activeChild
.mouseWouldHit(mouse
)) {
461 // Dispatch to the active child
463 // Set x and y relative to the child's coordinates
464 mouse
.setX(mouse
.getAbsoluteX() - activeChild
.getAbsoluteX());
465 mouse
.setY(mouse
.getAbsoluteY() - activeChild
.getAbsoluteY());
466 activeChild
.onMouseDown(mouse
);
470 for (int i
= children
.size() - 1 ; i
>= 0 ; i
--) {
471 TWidget widget
= children
.get(i
);
472 if (widget
.mouseWouldHit(mouse
)) {
473 // Dispatch to this child, also activate it
476 // Set x and y relative to the child's coordinates
477 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
478 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
479 widget
.onMouseDown(mouse
);
486 * Method that subclasses can override to handle mouse button releases.
488 * @param mouse mouse button event
490 public void onMouseUp(final TMouseEvent mouse
) {
491 // Default: do nothing, pass to children instead
492 if (activeChild
!= null) {
493 if (activeChild
.mouseWouldHit(mouse
)) {
494 // Dispatch to the active child
496 // Set x and y relative to the child's coordinates
497 mouse
.setX(mouse
.getAbsoluteX() - activeChild
.getAbsoluteX());
498 mouse
.setY(mouse
.getAbsoluteY() - activeChild
.getAbsoluteY());
499 activeChild
.onMouseUp(mouse
);
503 for (int i
= children
.size() - 1 ; i
>= 0 ; i
--) {
504 TWidget widget
= children
.get(i
);
505 if (widget
.mouseWouldHit(mouse
)) {
506 // Dispatch to this child, also activate it
509 // Set x and y relative to the child's coordinates
510 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
511 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
512 widget
.onMouseUp(mouse
);
519 * Method that subclasses can override to handle mouse movements.
521 * @param mouse mouse motion event
523 public void onMouseMotion(final TMouseEvent mouse
) {
524 // Default: do nothing, pass it on to ALL of my children. This way
525 // the children can see the mouse "leaving" their area.
526 for (TWidget widget
: children
) {
527 // Set x and y relative to the child's coordinates
528 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
529 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
530 widget
.onMouseMotion(mouse
);
535 * Method that subclasses can override to handle mouse button
538 * @param mouse mouse button event
540 public void onMouseDoubleClick(final TMouseEvent mouse
) {
541 // Default: do nothing, pass to children instead
542 if (activeChild
!= null) {
543 if (activeChild
.mouseWouldHit(mouse
)) {
544 // Dispatch to the active child
546 // Set x and y relative to the child's coordinates
547 mouse
.setX(mouse
.getAbsoluteX() - activeChild
.getAbsoluteX());
548 mouse
.setY(mouse
.getAbsoluteY() - activeChild
.getAbsoluteY());
549 activeChild
.onMouseDoubleClick(mouse
);
553 for (int i
= children
.size() - 1 ; i
>= 0 ; i
--) {
554 TWidget widget
= children
.get(i
);
555 if (widget
.mouseWouldHit(mouse
)) {
556 // Dispatch to this child, also activate it
559 // Set x and y relative to the child's coordinates
560 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
561 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
562 widget
.onMouseDoubleClick(mouse
);
569 * Method that subclasses can override to handle window/screen resize
572 * @param resize resize event
574 public void onResize(final TResizeEvent resize
) {
575 // Default: change my width/height.
576 if (resize
.getType() == TResizeEvent
.Type
.WIDGET
) {
577 width
= resize
.getWidth();
578 height
= resize
.getHeight();
579 if (layout
!= null) {
580 if (this instanceof TWindow
) {
581 layout
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
582 width
- 2, height
- 2));
584 layout
.onResize(resize
);
588 // Let children see the screen resize
589 for (TWidget widget
: children
) {
590 widget
.onResize(resize
);
596 * Method that subclasses can override to handle posted command events.
598 * @param command command event
600 public void onCommand(final TCommandEvent command
) {
601 // Default: do nothing, pass to children instead
602 for (TWidget widget
: children
) {
603 widget
.onCommand(command
);
608 * Method that subclasses can override to handle menu or posted menu
611 * @param menu menu event
613 public void onMenu(final TMenuEvent menu
) {
615 // Special case: if a split command comes in, insert a TPanel and
616 // TSplitPane in the hierarchy here.
618 TSplitPane pane
= null;
619 List
<TWidget
> widgets
= null;
620 switch (menu
.getId()) {
621 case TMenu
.MID_SPLIT_VERTICAL
:
622 if (children
.size() == 0) {
625 panel
= new TPanel(null, x
, y
, width
, height
);
626 pane
= new TSplitPane(null, x
, y
, width
, height
, true);
627 widgets
= new ArrayList
<TWidget
>(children
);
628 for (TWidget w
: widgets
) {
629 w
.setParent(panel
, false);
632 pane
.setParent(this, false);
635 for (TWidget w
: widgets
) {
636 assert (w
.window
!= null);
637 assert (w
.parent
!= null);
639 assert (pane
.getWindow() != null);
640 assert (pane
.getParent() != null);
641 assert (panel
.getWindow() != null);
642 assert (panel
.getParent() != null);
643 assert (pane
.isActive() == true);
644 assert (panel
.isActive() == true);
646 case TMenu
.MID_SPLIT_HORIZONTAL
:
647 if (children
.size() == 0) {
650 panel
= new TPanel(null, x
, y
, width
, height
);
651 pane
= new TSplitPane(null, x
, y
, width
, height
, false);
652 widgets
= new ArrayList
<TWidget
>(children
);
653 for (TWidget w
: widgets
) {
654 w
.setParent(panel
, false);
657 pane
.setParent(this, false);
660 for (TWidget w
: widgets
) {
661 assert (w
.window
!= null);
662 assert (w
.parent
!= null);
664 assert (pane
.getWindow() != null);
665 assert (pane
.getParent() != null);
666 assert (panel
.getWindow() != null);
667 assert (panel
.getParent() != null);
668 assert (pane
.isActive() == true);
669 assert (panel
.isActive() == true);
675 // Default: do nothing, pass to children instead
676 for (TWidget widget
: children
) {
682 * Method that subclasses can override to do processing when the UI is
683 * idle. Note that repainting is NOT assumed. To get a refresh after
684 * onIdle, call doRepaint().
686 public void onIdle() {
687 // Default: do nothing, pass to children instead
688 for (TWidget widget
: children
) {
694 * Consume event. Subclasses that want to intercept all events in one go
695 * can override this method.
697 * @param event keyboard, mouse, resize, command, or menu event
699 public void handleEvent(final TInputEvent event
) {
701 System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(),
707 // System.err.println(" -- discard --");
711 if (event
instanceof TKeypressEvent
) {
712 onKeypress((TKeypressEvent
) event
);
713 } else if (event
instanceof TMouseEvent
) {
715 TMouseEvent mouse
= (TMouseEvent
) event
;
717 switch (mouse
.getType()) {
728 onMouseMotion(mouse
);
731 case MOUSE_DOUBLE_CLICK
:
732 onMouseDoubleClick(mouse
);
736 throw new IllegalArgumentException("Invalid mouse event type: "
739 } else if (event
instanceof TResizeEvent
) {
740 onResize((TResizeEvent
) event
);
741 } else if (event
instanceof TCommandEvent
) {
742 onCommand((TCommandEvent
) event
);
743 } else if (event
instanceof TMenuEvent
) {
744 onMenu((TMenuEvent
) event
);
751 // ------------------------------------------------------------------------
752 // TWidget ----------------------------------------------------------------
753 // ------------------------------------------------------------------------
758 * @return parent widget
760 public final TWidget
getParent() {
765 * Get the list of child widgets that this widget contains.
767 * @return the list of child widgets
769 public List
<TWidget
> getChildren() {
774 * Remove this widget from its parent container. close() will be called
775 * before it is removed.
777 public final void remove() {
782 * Remove this widget from its parent container.
784 * @param doClose if true, call the close() method before removing the
787 public final void remove(final boolean doClose
) {
788 if (parent
!= null) {
789 parent
.remove(this, doClose
);
794 * Remove a child widget from this container.
796 * @param child the child widget to remove
798 public final void remove(final TWidget child
) {
803 * Remove a child widget from this container.
805 * @param child the child widget to remove
806 * @param doClose if true, call the close() method before removing the
809 public final void remove(final TWidget child
, final boolean doClose
) {
810 if (!children
.contains(child
)) {
811 throw new IndexOutOfBoundsException("child widget is not in " +
812 "list of children of this parent");
817 children
.remove(child
);
820 if (layout
!= null) {
826 * Set this widget's parent to a different widget.
828 * @param newParent new parent widget
829 * @param doClose if true, call the close() method before removing the
830 * child from its existing parent widget
832 public final void setParent(final TWidget newParent
,
833 final boolean doClose
) {
835 if (parent
!= null) {
836 parent
.remove(this, doClose
);
839 assert (parent
== null);
840 assert (window
== null);
842 setWindow(parent
.window
);
843 parent
.addChild(this);
847 * Set this widget's window to a specific window.
849 * Having a null parent with a specified window is only used within Jexer
850 * by TStatusBar because TApplication routes events directly to it and
851 * calls its draw() method. Any other non-parented widgets will require
852 * similar special case functionality to receive events or be drawn to
855 * @param window the window to use
857 public final void setWindow(final TWindow window
) {
858 this.window
= window
;
859 for (TWidget child
: getChildren()) {
860 child
.setWindow(window
);
865 * Remove a child widget from this container, and all of its children
866 * recursively from their parent containers.
868 * @param child the child widget to remove
869 * @param doClose if true, call the close() method before removing each
872 public final void removeAll(final TWidget child
, final boolean doClose
) {
873 remove(child
, doClose
);
874 for (TWidget w
: child
.children
) {
875 child
.removeAll(w
, doClose
);
882 * @return if true, this widget will receive events
884 public final boolean isActive() {
891 * @param active if true, this widget will receive events
893 public final void setActive(final boolean active
) {
894 this.active
= active
;
898 * Get the window this widget is on.
902 public final TWindow
getWindow() {
909 * @return absolute X position of the top-left corner
911 public final int getX() {
918 * @param x absolute X position of the top-left corner
920 public final void setX(final int x
) {
927 * @return absolute Y position of the top-left corner
929 public final int getY() {
936 * @param y absolute Y position of the top-left corner
938 public final void setY(final int y
) {
945 * @return widget width
947 public int getWidth() {
954 * @param width new widget width
956 public void setWidth(final int width
) {
958 if (layout
!= null) {
959 layout
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
967 * @return widget height
969 public int getHeight() {
976 * @param height new widget height
978 public void setHeight(final int height
) {
979 this.height
= height
;
980 if (layout
!= null) {
981 layout
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
987 * Change the dimensions.
989 * @param x absolute X position of the top-left corner
990 * @param y absolute Y position of the top-left corner
991 * @param width new widget width
992 * @param height new widget height
994 public final void setDimensions(final int x
, final int y
, final int width
,
1001 if (layout
!= null) {
1002 layout
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1008 * Get the layout manager.
1010 * @return the layout manager, or null if not set
1012 public LayoutManager
getLayoutManager() {
1017 * Set the layout manager.
1019 * @param layout the new layout manager
1021 public void setLayoutManager(LayoutManager layout
) {
1022 if (this.layout
!= null) {
1023 for (TWidget w
: children
) {
1024 this.layout
.remove(w
);
1028 this.layout
= layout
;
1029 if (this.layout
!= null) {
1030 for (TWidget w
: children
) {
1039 * @return if true, this widget can be tabbed to or receive events
1041 public final boolean isEnabled() {
1048 * @param enabled if true, this widget can be tabbed to or receive events
1050 public final void setEnabled(final boolean enabled
) {
1051 this.enabled
= enabled
;
1054 // See if there are any active siblings to switch to
1055 boolean foundSibling
= false;
1056 if (parent
!= null) {
1057 for (TWidget w
: parent
.children
) {
1059 && !(this instanceof THScroller
)
1060 && !(this instanceof TVScroller
)
1063 foundSibling
= true;
1067 if (!foundSibling
) {
1068 parent
.activeChild
= null;
1077 * @param visible if true, this widget will be drawn
1079 public final void setVisible(final boolean visible
) {
1080 this.visible
= visible
;
1084 * See if this widget is visible.
1086 * @return if true, this widget will be drawn
1088 public final boolean isVisible() {
1093 * Set visible cursor flag.
1095 * @param cursorVisible if true, this widget has a cursor
1097 public final void setCursorVisible(final boolean cursorVisible
) {
1098 this.cursorVisible
= cursorVisible
;
1102 * See if this widget has a visible cursor.
1104 * @return if true, this widget has a visible cursor
1106 public final boolean isCursorVisible() {
1107 // If cursor is out of my bounds, it is not visible.
1108 if ((cursorX
>= width
)
1110 || (cursorY
>= height
)
1116 assert (window
!= null);
1118 if (window
instanceof TDesktop
) {
1119 // Desktop doesn't have a window border.
1120 return cursorVisible
;
1123 // If cursor is out of my window's bounds, it is not visible.
1124 if ((getCursorAbsoluteX() >= window
.getAbsoluteX()
1125 + window
.getWidth() - 1)
1126 || (getCursorAbsoluteX() < 0)
1127 || (getCursorAbsoluteY() >= window
.getAbsoluteY()
1128 + window
.getHeight() - 1)
1129 || (getCursorAbsoluteY() < 0)
1133 return cursorVisible
;
1137 * Get cursor X value.
1139 * @return cursor column position in relative coordinates
1141 public final int getCursorX() {
1146 * Set cursor X value.
1148 * @param cursorX column position in relative coordinates
1150 public final void setCursorX(final int cursorX
) {
1151 this.cursorX
= cursorX
;
1155 * Get cursor Y value.
1157 * @return cursor row position in relative coordinates
1159 public final int getCursorY() {
1164 * Set cursor Y value.
1166 * @param cursorY row position in relative coordinates
1168 public final void setCursorY(final int cursorY
) {
1169 this.cursorY
= cursorY
;
1173 * Get this TWidget's parent TApplication.
1175 * @return the parent TApplication, or null if not assigned
1177 public TApplication
getApplication() {
1178 if (window
!= null) {
1179 return window
.getApplication();
1187 * @return the Screen, or null if not assigned
1189 public Screen
getScreen() {
1190 if (window
!= null) {
1191 return window
.getScreen();
1197 * Comparison operator. For various subclasses it sorts on:
1199 * <li>tabOrder for TWidgets</li>
1200 * <li>z for TWindows</li>
1201 * <li>text for TTreeItems</li>
1204 * @param that another TWidget, TWindow, or TTreeItem instance
1205 * @return difference between this.tabOrder and that.tabOrder, or
1206 * difference between this.z and that.z, or String.compareTo(text)
1208 public final int compareTo(final TWidget that
) {
1209 if ((this instanceof TWindow
)
1210 && (that
instanceof TWindow
)
1212 return (((TWindow
) this).getZ() - ((TWindow
) that
).getZ());
1214 if ((this instanceof TTreeItem
)
1215 && (that
instanceof TTreeItem
)
1217 return (((TTreeItem
) this).getText().compareTo(
1218 ((TTreeItem
) that
).getText()));
1220 return (this.tabOrder
- that
.tabOrder
);
1224 * See if this widget should render with the active color.
1226 * @return true if this widget is active and all of its parents are
1229 public final boolean isAbsoluteActive() {
1230 if (parent
== this) {
1233 return (active
&& (parent
== null ?
true : parent
.isAbsoluteActive()));
1237 * Returns the cursor X position.
1239 * @return absolute screen column number for the cursor's X position
1241 public final int getCursorAbsoluteX() {
1242 return getAbsoluteX() + cursorX
;
1246 * Returns the cursor Y position.
1248 * @return absolute screen row number for the cursor's Y position
1250 public final int getCursorAbsoluteY() {
1251 return getAbsoluteY() + cursorY
;
1255 * Compute my absolute X position as the sum of my X plus all my parent's
1258 * @return absolute screen column number for my X position
1260 public final int getAbsoluteX() {
1261 assert (parent
!= null);
1262 if (parent
== this) {
1265 if ((parent
instanceof TWindow
)
1266 && !(parent
instanceof TMenu
)
1267 && !(parent
instanceof TDesktop
)
1269 // Widgets on a TWindow have (0,0) as their top-left, but this is
1270 // actually the TWindow's (1,1).
1271 return parent
.getAbsoluteX() + x
+ 1;
1273 return parent
.getAbsoluteX() + x
;
1277 * Compute my absolute Y position as the sum of my Y plus all my parent's
1280 * @return absolute screen row number for my Y position
1282 public final int getAbsoluteY() {
1283 assert (parent
!= null);
1284 if (parent
== this) {
1287 if ((parent
instanceof TWindow
)
1288 && !(parent
instanceof TMenu
)
1289 && !(parent
instanceof TDesktop
)
1291 // Widgets on a TWindow have (0,0) as their top-left, but this is
1292 // actually the TWindow's (1,1).
1293 return parent
.getAbsoluteY() + y
+ 1;
1295 return parent
.getAbsoluteY() + y
;
1299 * Get the global color theme.
1301 * @return the ColorTheme
1303 protected final ColorTheme
getTheme() {
1304 return window
.getApplication().getTheme();
1308 * Draw my specific widget. When called, the screen rectangle I draw
1309 * into is already setup (offset and clipping).
1311 public void draw() {
1312 // Default widget draws nothing.
1316 * Called by parent to render to TWindow. Note package private access.
1318 final void drawChildren() {
1319 if (window
== null) {
1323 // Set my clipping rectangle
1324 assert (window
!= null);
1325 assert (getScreen() != null);
1326 Screen screen
= getScreen();
1328 // Special case: TStatusBar is drawn by TApplication, not anything
1330 if (this instanceof TStatusBar
) {
1334 screen
.setClipRight(width
);
1335 screen
.setClipBottom(height
);
1337 int absoluteRightEdge
= window
.getAbsoluteX() + window
.getWidth();
1338 int absoluteBottomEdge
= window
.getAbsoluteY() + window
.getHeight();
1339 if (!(this instanceof TWindow
)
1340 && !(this instanceof TVScroller
)
1341 && !(parent
instanceof TDesktop
)
1343 absoluteRightEdge
-= 1;
1345 if (!(this instanceof TWindow
)
1346 && !(this instanceof THScroller
)
1347 && !(parent
instanceof TDesktop
)
1349 absoluteBottomEdge
-= 1;
1351 int myRightEdge
= getAbsoluteX() + width
;
1352 int myBottomEdge
= getAbsoluteY() + height
;
1353 if (getAbsoluteX() > absoluteRightEdge
) {
1355 screen
.setClipRight(0);
1356 } else if (myRightEdge
> absoluteRightEdge
) {
1357 screen
.setClipRight(screen
.getClipRight()
1358 - (myRightEdge
- absoluteRightEdge
));
1360 if (getAbsoluteY() > absoluteBottomEdge
) {
1362 screen
.setClipBottom(0);
1363 } else if (myBottomEdge
> absoluteBottomEdge
) {
1364 screen
.setClipBottom(screen
.getClipBottom()
1365 - (myBottomEdge
- absoluteBottomEdge
));
1369 screen
.setOffsetX(getAbsoluteX());
1370 screen
.setOffsetY(getAbsoluteY());
1374 assert (visible
== true);
1376 // Continue down the chain. Draw the active child last so that it
1378 for (TWidget widget
: children
) {
1379 if (widget
.isVisible() && (widget
!= activeChild
)) {
1380 widget
.drawChildren();
1383 if (activeChild
!= null) {
1384 activeChild
.drawChildren();
1389 * Repaint the screen on the next update.
1391 protected final void doRepaint() {
1392 window
.getApplication().doRepaint();
1396 * Add a child widget to my list of children. We set its tabOrder to 0
1397 * and increment the tabOrder of all other children.
1399 * @param child TWidget to add
1401 private void addChild(final TWidget child
) {
1402 children
.add(child
);
1405 && !(child
instanceof THScroller
)
1406 && !(child
instanceof TVScroller
)
1408 for (TWidget widget
: children
) {
1409 widget
.active
= false;
1411 child
.active
= true;
1412 activeChild
= child
;
1414 for (int i
= 0; i
< children
.size(); i
++) {
1415 children
.get(i
).tabOrder
= i
;
1417 if (layout
!= null) {
1423 * Reset the tab order of children to match their position in the list.
1424 * Available so that subclasses can re-order their widgets if needed.
1426 protected void resetTabOrder() {
1427 for (int i
= 0; i
< children
.size(); i
++) {
1428 children
.get(i
).tabOrder
= i
;
1433 * Switch the active child.
1435 * @param child TWidget to activate
1437 public final void activate(final TWidget child
) {
1438 assert (child
.enabled
);
1439 if ((child
instanceof THScroller
)
1440 || (child
instanceof TVScroller
)
1445 if (children
.size() == 1) {
1446 if (children
.get(0).enabled
== true) {
1447 child
.active
= true;
1448 activeChild
= child
;
1451 if (child
!= activeChild
) {
1452 if (activeChild
!= null) {
1453 activeChild
.active
= false;
1455 child
.active
= true;
1456 activeChild
= child
;
1462 * Switch the active child.
1464 * @param tabOrder tabOrder of the child to activate. If that child
1465 * isn't enabled, then the next enabled child will be activated.
1467 public final void activate(final int tabOrder
) {
1468 if (children
.size() == 1) {
1469 if (children
.get(0).enabled
== true) {
1470 children
.get(0).active
= true;
1471 activeChild
= children
.get(0);
1476 TWidget child
= null;
1477 for (TWidget widget
: children
) {
1478 if ((widget
.enabled
)
1479 && !(widget
instanceof THScroller
)
1480 && !(widget
instanceof TVScroller
)
1481 && (widget
.tabOrder
>= tabOrder
)
1487 if ((child
!= null) && (child
!= activeChild
)) {
1488 if (activeChild
!= null) {
1489 activeChild
.active
= false;
1491 assert (child
.enabled
);
1492 child
.active
= true;
1493 activeChild
= child
;
1498 * Make this widget the active child of its parent. Note that this is
1499 * not final since TWindow overrides activate().
1501 public void activate() {
1503 if (parent
!= null) {
1504 parent
.activate(this);
1510 * Switch the active widget with the next in the tab order.
1512 * @param forward if true, then switch to the next enabled widget in the
1513 * list, otherwise switch to the previous enabled widget in the list
1515 public final void switchWidget(final boolean forward
) {
1517 // No children: do nothing.
1518 if (children
.size() == 0) {
1522 assert (parent
!= null);
1524 // If there is only one child, make it active if it is enabled.
1525 if (children
.size() == 1) {
1526 if (children
.get(0).enabled
== true) {
1527 activeChild
= children
.get(0);
1528 activeChild
.active
= true;
1530 children
.get(0).active
= false;
1536 // Two or more children: go forward or backward to the next enabled
1539 if (activeChild
!= null) {
1540 tabOrder
= activeChild
.tabOrder
;
1550 // If at the end, pass the switch to my parent.
1551 if ((!forward
) && (parent
!= this)) {
1552 parent
.switchWidget(forward
);
1556 tabOrder
= children
.size() - 1;
1557 } else if (tabOrder
== children
.size()) {
1558 // If at the end, pass the switch to my parent.
1559 if ((forward
) && (parent
!= this)) {
1560 parent
.switchWidget(forward
);
1566 if (activeChild
== null) {
1567 if (tabOrder
== 0) {
1568 // We wrapped around
1571 } else if (activeChild
.tabOrder
== tabOrder
) {
1572 // We wrapped around
1575 } while ((!children
.get(tabOrder
).enabled
)
1576 && !(children
.get(tabOrder
) instanceof THScroller
)
1577 && !(children
.get(tabOrder
) instanceof TVScroller
));
1579 if (activeChild
!= null) {
1580 assert (children
.get(tabOrder
).enabled
);
1582 activeChild
.active
= false;
1584 if (children
.get(tabOrder
).enabled
== true) {
1585 children
.get(tabOrder
).active
= true;
1586 activeChild
= children
.get(tabOrder
);
1591 * Returns my active widget.
1593 * @return widget that is active, or this if no children
1595 public TWidget
getActiveChild() {
1596 if ((this instanceof THScroller
)
1597 || (this instanceof TVScroller
)
1602 for (TWidget widget
: children
) {
1603 if (widget
.active
) {
1604 return widget
.getActiveChild();
1607 // No active children, return me
1611 // ------------------------------------------------------------------------
1612 // Passthru for Screen functions ------------------------------------------
1613 // ------------------------------------------------------------------------
1616 * Get the attributes at one location.
1618 * @param x column coordinate. 0 is the left-most column.
1619 * @param y row coordinate. 0 is the top-most row.
1620 * @return attributes at (x, y)
1622 protected final CellAttributes
getAttrXY(final int x
, final int y
) {
1623 return getScreen().getAttrXY(x
, y
);
1627 * Set the attributes at one location.
1629 * @param x column coordinate. 0 is the left-most column.
1630 * @param y row coordinate. 0 is the top-most row.
1631 * @param attr attributes to use (bold, foreColor, backColor)
1633 protected final void putAttrXY(final int x
, final int y
,
1634 final CellAttributes attr
) {
1636 getScreen().putAttrXY(x
, y
, attr
);
1640 * Set the attributes at one location.
1642 * @param x column coordinate. 0 is the left-most column.
1643 * @param y row coordinate. 0 is the top-most row.
1644 * @param attr attributes to use (bold, foreColor, backColor)
1645 * @param clip if true, honor clipping/offset
1647 protected final void putAttrXY(final int x
, final int y
,
1648 final CellAttributes attr
, final boolean clip
) {
1650 getScreen().putAttrXY(x
, y
, attr
, clip
);
1654 * Fill the entire screen with one character with attributes.
1656 * @param ch character to draw
1657 * @param attr attributes to use (bold, foreColor, backColor)
1659 protected final void putAll(final int ch
, final CellAttributes attr
) {
1660 getScreen().putAll(ch
, attr
);
1664 * Render one character with attributes.
1666 * @param x column coordinate. 0 is the left-most column.
1667 * @param y row coordinate. 0 is the top-most row.
1668 * @param ch character + attributes to draw
1670 protected final void putCharXY(final int x
, final int y
, final Cell ch
) {
1671 getScreen().putCharXY(x
, y
, ch
);
1675 * Render one character with attributes.
1677 * @param x column coordinate. 0 is the left-most column.
1678 * @param y row coordinate. 0 is the top-most row.
1679 * @param ch character to draw
1680 * @param attr attributes to use (bold, foreColor, backColor)
1682 protected final void putCharXY(final int x
, final int y
, final int ch
,
1683 final CellAttributes attr
) {
1685 getScreen().putCharXY(x
, y
, ch
, attr
);
1689 * Render one character without changing the underlying attributes.
1691 * @param x column coordinate. 0 is the left-most column.
1692 * @param y row coordinate. 0 is the top-most row.
1693 * @param ch character to draw
1695 protected final void putCharXY(final int x
, final int y
, final int ch
) {
1696 getScreen().putCharXY(x
, y
, ch
);
1700 * Render a string. Does not wrap if the string exceeds the line.
1702 * @param x column coordinate. 0 is the left-most column.
1703 * @param y row coordinate. 0 is the top-most row.
1704 * @param str string to draw
1705 * @param attr attributes to use (bold, foreColor, backColor)
1707 protected final void putStringXY(final int x
, final int y
, final String str
,
1708 final CellAttributes attr
) {
1710 getScreen().putStringXY(x
, y
, str
, attr
);
1714 * Render a string without changing the underlying attribute. Does not
1715 * wrap if the string exceeds the line.
1717 * @param x column coordinate. 0 is the left-most column.
1718 * @param y row coordinate. 0 is the top-most row.
1719 * @param str string to draw
1721 protected final void putStringXY(final int x
, final int y
, final String str
) {
1722 getScreen().putStringXY(x
, y
, str
);
1726 * Draw a vertical line from (x, y) to (x, y + n).
1728 * @param x column coordinate. 0 is the left-most column.
1729 * @param y row coordinate. 0 is the top-most row.
1730 * @param n number of characters to draw
1731 * @param ch character to draw
1732 * @param attr attributes to use (bold, foreColor, backColor)
1734 protected final void vLineXY(final int x
, final int y
, final int n
,
1735 final int ch
, final CellAttributes attr
) {
1737 getScreen().vLineXY(x
, y
, n
, ch
, attr
);
1741 * Draw a horizontal line from (x, y) to (x + n, y).
1743 * @param x column coordinate. 0 is the left-most column.
1744 * @param y row coordinate. 0 is the top-most row.
1745 * @param n number of characters to draw
1746 * @param ch character to draw
1747 * @param attr attributes to use (bold, foreColor, backColor)
1749 protected final void hLineXY(final int x
, final int y
, final int n
,
1750 final int ch
, final CellAttributes attr
) {
1752 getScreen().hLineXY(x
, y
, n
, ch
, attr
);
1756 * Draw a box with a border and empty background.
1758 * @param left left column of box. 0 is the left-most row.
1759 * @param top top row of the box. 0 is the top-most row.
1760 * @param right right column of box
1761 * @param bottom bottom row of the box
1762 * @param border attributes to use for the border
1763 * @param background attributes to use for the background
1765 protected final void drawBox(final int left
, final int top
,
1766 final int right
, final int bottom
,
1767 final CellAttributes border
, final CellAttributes background
) {
1769 getScreen().drawBox(left
, top
, right
, bottom
, border
, background
);
1773 * Draw a box with a border and empty background.
1775 * @param left left column of box. 0 is the left-most row.
1776 * @param top top row of the box. 0 is the top-most row.
1777 * @param right right column of box
1778 * @param bottom bottom row of the box
1779 * @param border attributes to use for the border
1780 * @param background attributes to use for the background
1781 * @param borderType if 1, draw a single-line border; if 2, draw a
1782 * double-line border; if 3, draw double-line top/bottom edges and
1783 * single-line left/right edges (like Qmodem)
1784 * @param shadow if true, draw a "shadow" on the box
1786 protected final void drawBox(final int left
, final int top
,
1787 final int right
, final int bottom
,
1788 final CellAttributes border
, final CellAttributes background
,
1789 final int borderType
, final boolean shadow
) {
1791 getScreen().drawBox(left
, top
, right
, bottom
, border
, background
,
1792 borderType
, shadow
);
1796 * Draw a box shadow.
1798 * @param left left column of box. 0 is the left-most row.
1799 * @param top top row of the box. 0 is the top-most row.
1800 * @param right right column of box
1801 * @param bottom bottom row of the box
1803 protected final void drawBoxShadow(final int left
, final int top
,
1804 final int right
, final int bottom
) {
1806 getScreen().drawBoxShadow(left
, top
, right
, bottom
);
1809 // ------------------------------------------------------------------------
1810 // Other TWidget constructors ---------------------------------------------
1811 // ------------------------------------------------------------------------
1814 * Convenience function to add a label to this container/window.
1817 * @param x column relative to parent
1818 * @param y row relative to parent
1819 * @return the new label
1821 public final TLabel
addLabel(final String text
, final int x
, final int y
) {
1822 return addLabel(text
, x
, y
, "tlabel");
1826 * Convenience function to add a label to this container/window.
1829 * @param x column relative to parent
1830 * @param y row relative to parent
1831 * @param action to call when shortcut is pressed
1832 * @return the new label
1834 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1835 final TAction action
) {
1837 return addLabel(text
, x
, y
, "tlabel", action
);
1841 * Convenience function to add a label to this container/window.
1844 * @param x column relative to parent
1845 * @param y row relative to parent
1846 * @param colorKey ColorTheme key color to use for foreground text.
1847 * Default is "tlabel"
1848 * @return the new label
1850 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1851 final String colorKey
) {
1853 return new TLabel(this, text
, x
, y
, colorKey
);
1857 * Convenience function to add a label to this container/window.
1860 * @param x column relative to parent
1861 * @param y row relative to parent
1862 * @param colorKey ColorTheme key color to use for foreground text.
1863 * Default is "tlabel"
1864 * @param action to call when shortcut is pressed
1865 * @return the new label
1867 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1868 final String colorKey
, final TAction action
) {
1870 return new TLabel(this, text
, x
, y
, colorKey
, action
);
1874 * Convenience function to add a label to this container/window.
1877 * @param x column relative to parent
1878 * @param y row relative to parent
1879 * @param colorKey ColorTheme key color to use for foreground text.
1880 * Default is "tlabel"
1881 * @param useWindowBackground if true, use the window's background color
1882 * @return the new label
1884 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1885 final String colorKey
, final boolean useWindowBackground
) {
1887 return new TLabel(this, text
, x
, y
, colorKey
, useWindowBackground
);
1891 * Convenience function to add a label to this container/window.
1894 * @param x column relative to parent
1895 * @param y row relative to parent
1896 * @param colorKey ColorTheme key color to use for foreground text.
1897 * Default is "tlabel"
1898 * @param useWindowBackground if true, use the window's background color
1899 * @param action to call when shortcut is pressed
1900 * @return the new label
1902 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1903 final String colorKey
, final boolean useWindowBackground
,
1904 final TAction action
) {
1906 return new TLabel(this, text
, x
, y
, colorKey
, useWindowBackground
,
1911 * Convenience function to add a button to this container/window.
1913 * @param text label on the button
1914 * @param x column relative to parent
1915 * @param y row relative to parent
1916 * @param action action to call when button is pressed
1917 * @return the new button
1919 public final TButton
addButton(final String text
, final int x
, final int y
,
1920 final TAction action
) {
1922 return new TButton(this, text
, x
, y
, action
);
1926 * Convenience function to add a checkbox to this container/window.
1928 * @param x column relative to parent
1929 * @param y row relative to parent
1930 * @param label label to display next to (right of) the checkbox
1931 * @param checked initial check state
1932 * @return the new checkbox
1934 public final TCheckBox
addCheckBox(final int x
, final int y
,
1935 final String label
, final boolean checked
) {
1937 return new TCheckBox(this, x
, y
, label
, checked
);
1941 * Convenience function to add a combobox to this container/window.
1943 * @param x column relative to parent
1944 * @param y row relative to parent
1945 * @param width visible combobox width, including the down-arrow
1946 * @param values the possible values for the box, shown in the drop-down
1947 * @param valuesIndex the initial index in values, or -1 for no default
1949 * @param maxValuesHeight the maximum height of the values drop-down when
1951 * @param updateAction action to call when a new value is selected from
1952 * the list or enter is pressed in the edit field
1953 * @return the new combobox
1955 public final TComboBox
addComboBox(final int x
, final int y
,
1956 final int width
, final List
<String
> values
, final int valuesIndex
,
1957 final int maxValuesHeight
, final TAction updateAction
) {
1959 return new TComboBox(this, x
, y
, width
, values
, valuesIndex
,
1960 maxValuesHeight
, updateAction
);
1964 * Convenience function to add a spinner to this container/window.
1966 * @param x column relative to parent
1967 * @param y row relative to parent
1968 * @param upAction action to call when the up arrow is clicked or pressed
1969 * @param downAction action to call when the down arrow is clicked or
1971 * @return the new spinner
1973 public final TSpinner
addSpinner(final int x
, final int y
,
1974 final TAction upAction
, final TAction downAction
) {
1976 return new TSpinner(this, x
, y
, upAction
, downAction
);
1980 * Convenience function to add a calendar to this container/window.
1982 * @param x column relative to parent
1983 * @param y row relative to parent
1984 * @param updateAction action to call when the user changes the value of
1986 * @return the new calendar
1988 public final TCalendar
addCalendar(final int x
, final int y
,
1989 final TAction updateAction
) {
1991 return new TCalendar(this, x
, y
, updateAction
);
1995 * Convenience function to add a progress bar to this container/window.
1997 * @param x column relative to parent
1998 * @param y row relative to parent
1999 * @param width width of progress bar
2000 * @param value initial value of percent complete
2001 * @return the new progress bar
2003 public final TProgressBar
addProgressBar(final int x
, final int y
,
2004 final int width
, final int value
) {
2006 return new TProgressBar(this, x
, y
, width
, value
);
2010 * Convenience function to add a radio button group to this
2013 * @param x column relative to parent
2014 * @param y row relative to parent
2015 * @param label label to display on the group box
2016 * @return the new radio button group
2018 public final TRadioGroup
addRadioGroup(final int x
, final int y
,
2019 final String label
) {
2021 return new TRadioGroup(this, x
, y
, label
);
2025 * Convenience function to add a text field to this container/window.
2027 * @param x column relative to parent
2028 * @param y row relative to parent
2029 * @param width visible text width
2030 * @param fixed if true, the text cannot exceed the display width
2031 * @return the new text field
2033 public final TField
addField(final int x
, final int y
,
2034 final int width
, final boolean fixed
) {
2036 return new TField(this, x
, y
, width
, fixed
);
2040 * Convenience function to add a text field to this container/window.
2042 * @param x column relative to parent
2043 * @param y row relative to parent
2044 * @param width visible text width
2045 * @param fixed if true, the text cannot exceed the display width
2046 * @param text initial text, default is empty string
2047 * @return the new text field
2049 public final TField
addField(final int x
, final int y
,
2050 final int width
, final boolean fixed
, final String text
) {
2052 return new TField(this, x
, y
, width
, fixed
, text
);
2056 * Convenience function to add a text field to this container/window.
2058 * @param x column relative to parent
2059 * @param y row relative to parent
2060 * @param width visible text width
2061 * @param fixed if true, the text cannot exceed the display width
2062 * @param text initial text, default is empty string
2063 * @param enterAction function to call when enter key is pressed
2064 * @param updateAction function to call when the text is updated
2065 * @return the new text field
2067 public final TField
addField(final int x
, final int y
,
2068 final int width
, final boolean fixed
, final String text
,
2069 final TAction enterAction
, final TAction updateAction
) {
2071 return new TField(this, x
, y
, width
, fixed
, text
, enterAction
,
2076 * Convenience function to add a scrollable text box to this
2079 * @param text text on the screen
2080 * @param x column relative to parent
2081 * @param y row relative to parent
2082 * @param width width of text area
2083 * @param height height of text area
2084 * @param colorKey ColorTheme key color to use for foreground text
2085 * @return the new text box
2087 public final TText
addText(final String text
, final int x
,
2088 final int y
, final int width
, final int height
, final String colorKey
) {
2090 return new TText(this, text
, x
, y
, width
, height
, colorKey
);
2094 * Convenience function to add a scrollable text box to this
2097 * @param text text on the screen
2098 * @param x column relative to parent
2099 * @param y row relative to parent
2100 * @param width width of text area
2101 * @param height height of text area
2102 * @return the new text box
2104 public final TText
addText(final String text
, final int x
, final int y
,
2105 final int width
, final int height
) {
2107 return new TText(this, text
, x
, y
, width
, height
, "ttext");
2111 * Convenience function to add an editable text area box to this
2114 * @param text text on the screen
2115 * @param x column relative to parent
2116 * @param y row relative to parent
2117 * @param width width of text area
2118 * @param height height of text area
2119 * @return the new text box
2121 public final TEditorWidget
addEditor(final String text
, final int x
,
2122 final int y
, final int width
, final int height
) {
2124 return new TEditorWidget(this, text
, x
, y
, width
, height
);
2128 * Convenience function to spawn a message box.
2130 * @param title window title, will be centered along the top border
2131 * @param caption message to display. Use embedded newlines to get a
2133 * @return the new message box
2135 public final TMessageBox
messageBox(final String title
,
2136 final String caption
) {
2138 return getApplication().messageBox(title
, caption
, TMessageBox
.Type
.OK
);
2142 * Convenience function to spawn a message box.
2144 * @param title window title, will be centered along the top border
2145 * @param caption message to display. Use embedded newlines to get a
2147 * @param type one of the TMessageBox.Type constants. Default is
2149 * @return the new message box
2151 public final TMessageBox
messageBox(final String title
,
2152 final String caption
, final TMessageBox
.Type type
) {
2154 return getApplication().messageBox(title
, caption
, type
);
2158 * Convenience function to spawn an input box.
2160 * @param title window title, will be centered along the top border
2161 * @param caption message to display. Use embedded newlines to get a
2163 * @return the new input box
2165 public final TInputBox
inputBox(final String title
, final String caption
) {
2167 return getApplication().inputBox(title
, caption
);
2171 * Convenience function to spawn an input box.
2173 * @param title window title, will be centered along the top border
2174 * @param caption message to display. Use embedded newlines to get a
2176 * @param text initial text to seed the field with
2177 * @return the new input box
2179 public final TInputBox
inputBox(final String title
, final String caption
,
2180 final String text
) {
2182 return getApplication().inputBox(title
, caption
, text
);
2186 * Convenience function to spawn an input box.
2188 * @param title window title, will be centered along the top border
2189 * @param caption message to display. Use embedded newlines to get a
2191 * @param text initial text to seed the field with
2192 * @param type one of the Type constants. Default is Type.OK.
2193 * @return the new input box
2195 public final TInputBox
inputBox(final String title
, final String caption
,
2196 final String text
, final TInputBox
.Type type
) {
2198 return getApplication().inputBox(title
, caption
, text
, type
);
2202 * Convenience function to add a password text field to this
2205 * @param x column relative to parent
2206 * @param y row relative to parent
2207 * @param width visible text width
2208 * @param fixed if true, the text cannot exceed the display width
2209 * @return the new text field
2211 public final TPasswordField
addPasswordField(final int x
, final int y
,
2212 final int width
, final boolean fixed
) {
2214 return new TPasswordField(this, x
, y
, width
, fixed
);
2218 * Convenience function to add a password text field to this
2221 * @param x column relative to parent
2222 * @param y row relative to parent
2223 * @param width visible text width
2224 * @param fixed if true, the text cannot exceed the display width
2225 * @param text initial text, default is empty string
2226 * @return the new text field
2228 public final TPasswordField
addPasswordField(final int x
, final int y
,
2229 final int width
, final boolean fixed
, final String text
) {
2231 return new TPasswordField(this, x
, y
, width
, fixed
, text
);
2235 * Convenience function to add a password text field to this
2238 * @param x column relative to parent
2239 * @param y row relative to parent
2240 * @param width visible text width
2241 * @param fixed if true, the text cannot exceed the display width
2242 * @param text initial text, default is empty string
2243 * @param enterAction function to call when enter key is pressed
2244 * @param updateAction function to call when the text is updated
2245 * @return the new text field
2247 public final TPasswordField
addPasswordField(final int x
, final int y
,
2248 final int width
, final boolean fixed
, final String text
,
2249 final TAction enterAction
, final TAction updateAction
) {
2251 return new TPasswordField(this, x
, y
, width
, fixed
, text
, enterAction
,
2256 * Convenience function to add a scrollable tree view to this
2259 * @param x column relative to parent
2260 * @param y row relative to parent
2261 * @param width width of tree view
2262 * @param height height of tree view
2263 * @return the new tree view
2265 public final TTreeViewWidget
addTreeViewWidget(final int x
, final int y
,
2266 final int width
, final int height
) {
2268 return new TTreeViewWidget(this, x
, y
, width
, height
);
2272 * Convenience function to add a scrollable tree view to this
2275 * @param x column relative to parent
2276 * @param y row relative to parent
2277 * @param width width of tree view
2278 * @param height height of tree view
2279 * @param action action to perform when an item is selected
2280 * @return the new tree view
2282 public final TTreeViewWidget
addTreeViewWidget(final int x
, final int y
,
2283 final int width
, final int height
, final TAction action
) {
2285 return new TTreeViewWidget(this, x
, y
, width
, height
, action
);
2289 * Convenience function to spawn a file open box.
2291 * @param path path of selected file
2292 * @return the result of the new file open box
2293 * @throws IOException if a java.io operation throws
2295 public final String
fileOpenBox(final String path
) throws IOException
{
2296 return getApplication().fileOpenBox(path
);
2300 * Convenience function to spawn a file save box.
2302 * @param path path of selected file
2303 * @return the result of the new file open box
2304 * @throws IOException if a java.io operation throws
2306 public final String
fileSaveBox(final String path
) throws IOException
{
2307 return getApplication().fileOpenBox(path
, TFileOpenBox
.Type
.SAVE
);
2311 * Convenience function to spawn a file open box.
2313 * @param path path of selected file
2314 * @param type one of the Type constants
2315 * @return the result of the new file open box
2316 * @throws IOException if a java.io operation throws
2318 public final String
fileOpenBox(final String path
,
2319 final TFileOpenBox
.Type type
) throws IOException
{
2321 return getApplication().fileOpenBox(path
, type
);
2325 * Convenience function to spawn a file open box.
2327 * @param path path of selected file
2328 * @param type one of the Type constants
2329 * @param filter a string that files must match to be displayed
2330 * @return the result of the new file open box
2331 * @throws IOException of a java.io operation throws
2333 public final String
fileOpenBox(final String path
,
2334 final TFileOpenBox
.Type type
, final String filter
) throws IOException
{
2336 ArrayList
<String
> filters
= new ArrayList
<String
>();
2337 filters
.add(filter
);
2339 return getApplication().fileOpenBox(path
, type
, filters
);
2343 * Convenience function to spawn a file open box.
2345 * @param path path of selected file
2346 * @param type one of the Type constants
2347 * @param filters a list of strings that files must match to be displayed
2348 * @return the result of the new file open box
2349 * @throws IOException of a java.io operation throws
2351 public final String
fileOpenBox(final String path
,
2352 final TFileOpenBox
.Type type
,
2353 final List
<String
> filters
) throws IOException
{
2355 return getApplication().fileOpenBox(path
, type
, filters
);
2359 * Convenience function to add a directory list to this container/window.
2361 * @param path directory path, must be a directory
2362 * @param x column relative to parent
2363 * @param y row relative to parent
2364 * @param width width of text area
2365 * @param height height of text area
2366 * @return the new directory list
2368 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
2369 final int y
, final int width
, final int height
) {
2371 return new TDirectoryList(this, path
, x
, y
, width
, height
, null);
2375 * Convenience function to add a directory list to this container/window.
2377 * @param path directory path, must be a directory
2378 * @param x column relative to parent
2379 * @param y row relative to parent
2380 * @param width width of text area
2381 * @param height height of text area
2382 * @param action action to perform when an item is selected (enter or
2384 * @return the new directory list
2386 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
2387 final int y
, final int width
, final int height
, final TAction action
) {
2389 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
);
2393 * Convenience function to add a directory list to this container/window.
2395 * @param path directory path, must be a directory
2396 * @param x column relative to parent
2397 * @param y row relative to parent
2398 * @param width width of text area
2399 * @param height height of text area
2400 * @param action action to perform when an item is selected (enter or
2402 * @param singleClickAction action to perform when an item is selected
2404 * @return the new directory list
2406 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
2407 final int y
, final int width
, final int height
, final TAction action
,
2408 final TAction singleClickAction
) {
2410 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
,
2415 * Convenience function to add a directory list to this container/window.
2417 * @param path directory path, must be a directory
2418 * @param x column relative to parent
2419 * @param y row relative to parent
2420 * @param width width of text area
2421 * @param height height of text area
2422 * @param action action to perform when an item is selected (enter or
2424 * @param singleClickAction action to perform when an item is selected
2426 * @param filters a list of strings that files must match to be displayed
2427 * @return the new directory list
2429 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
2430 final int y
, final int width
, final int height
, final TAction action
,
2431 final TAction singleClickAction
, final List
<String
> filters
) {
2433 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
,
2434 singleClickAction
, filters
);
2438 * Convenience function to add a list to this container/window.
2440 * @param strings list of strings to show
2441 * @param x column relative to parent
2442 * @param y row relative to parent
2443 * @param width width of text area
2444 * @param height height of text area
2445 * @return the new directory list
2447 public final TList
addList(final List
<String
> strings
, final int x
,
2448 final int y
, final int width
, final int height
) {
2450 return new TList(this, strings
, x
, y
, width
, height
, null);
2454 * Convenience function to add a list to this container/window.
2456 * @param strings list of strings to show
2457 * @param x column relative to parent
2458 * @param y row relative to parent
2459 * @param width width of text area
2460 * @param height height of text area
2461 * @param enterAction action to perform when an item is selected
2462 * @return the new directory list
2464 public final TList
addList(final List
<String
> strings
, final int x
,
2465 final int y
, final int width
, final int height
,
2466 final TAction enterAction
) {
2468 return new TList(this, strings
, x
, y
, width
, height
, enterAction
);
2472 * Convenience function to add a list to this container/window.
2474 * @param strings list of strings to show
2475 * @param x column relative to parent
2476 * @param y row relative to parent
2477 * @param width width of text area
2478 * @param height height of text area
2479 * @param enterAction action to perform when an item is selected
2480 * @param moveAction action to perform when the user navigates to a new
2481 * item with arrow/page keys
2482 * @return the new directory list
2484 public final TList
addList(final List
<String
> strings
, final int x
,
2485 final int y
, final int width
, final int height
,
2486 final TAction enterAction
, final TAction moveAction
) {
2488 return new TList(this, strings
, x
, y
, width
, height
, enterAction
,
2493 * Convenience function to add a list to this container/window.
2495 * @param strings list of strings to show. This is allowed to be null
2496 * and set later with setList() or by subclasses.
2497 * @param x column relative to parent
2498 * @param y row relative to parent
2499 * @param width width of text area
2500 * @param height height of text area
2501 * @param enterAction action to perform when an item is selected
2502 * @param moveAction action to perform when the user navigates to a new
2503 * item with arrow/page keys
2504 * @param singleClickAction action to perform when the user clicks on an
2507 public TList
addList(final List
<String
> strings
, final int x
,
2508 final int y
, final int width
, final int height
,
2509 final TAction enterAction
, final TAction moveAction
,
2510 final TAction singleClickAction
) {
2512 return new TList(this, strings
, x
, y
, width
, height
, enterAction
,
2513 moveAction
, singleClickAction
);
2518 * Convenience function to add an image to this container/window.
2520 * @param x column relative to parent
2521 * @param y row relative to parent
2522 * @param width number of text cells for width of the image
2523 * @param height number of text cells for height of the image
2524 * @param image the image to display
2525 * @param left left column of the image. 0 is the left-most column.
2526 * @param top top row of the image. 0 is the top-most row.
2528 public final TImage
addImage(final int x
, final int y
,
2529 final int width
, final int height
,
2530 final BufferedImage image
, final int left
, final int top
) {
2532 return new TImage(this, x
, y
, width
, height
, image
, left
, top
);
2536 * Convenience function to add an image to this container/window.
2538 * @param x column relative to parent
2539 * @param y row relative to parent
2540 * @param width number of text cells for width of the image
2541 * @param height number of text cells for height of the image
2542 * @param image the image to display
2543 * @param left left column of the image. 0 is the left-most column.
2544 * @param top top row of the image. 0 is the top-most row.
2545 * @param clickAction function to call when mouse is pressed
2547 public final TImage
addImage(final int x
, final int y
,
2548 final int width
, final int height
,
2549 final BufferedImage image
, final int left
, final int top
,
2550 final TAction clickAction
) {
2552 return new TImage(this, x
, y
, width
, height
, image
, left
, top
,
2557 * Convenience function to add an editable 2D data table to this
2560 * @param x column relative to parent
2561 * @param y row relative to parent
2562 * @param width width of widget
2563 * @param height height of widget
2565 public TTableWidget
addTable(final int x
, final int y
, final int width
,
2568 return new TTableWidget(this, x
, y
, width
, height
);
2572 * Convenience function to add an editable 2D data table to this
2575 * @param x column relative to parent
2576 * @param y row relative to parent
2577 * @param width width of widget
2578 * @param height height of widget
2579 * @param gridColumns number of columns in grid
2580 * @param gridRows number of rows in grid
2582 public TTableWidget
addTable(final int x
, final int y
, final int width
,
2583 final int height
, final int gridColumns
, final int gridRows
) {
2585 return new TTableWidget(this, x
, y
, width
, height
, gridColumns
,
2590 * Convenience function to add a panel to this container/window.
2592 * @param x column relative to parent
2593 * @param y row relative to parent
2594 * @param width width of text area
2595 * @param height height of text area
2596 * @return the new panel
2598 public final TPanel
addPanel(final int x
, final int y
, final int width
,
2601 return new TPanel(this, x
, y
, width
, height
);
2605 * Convenience function to add a split pane to this container/window.
2607 * @param x column relative to parent
2608 * @param y row relative to parent
2609 * @param width width of text area
2610 * @param height height of text area
2611 * @param vertical if true, split vertically
2612 * @return the new split pane
2614 public final TSplitPane
addSplitPane(final int x
, final int y
,
2615 final int width
, final int height
, final boolean vertical
) {
2617 return new TSplitPane(this, x
, y
, width
, height
, vertical
);