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 panel
= new TPanel(null, x
, y
, width
, height
);
623 pane
= new TSplitPane(null, x
, y
, width
, height
, true);
624 widgets
= new ArrayList
<TWidget
>(children
);
625 for (TWidget w
: widgets
) {
626 w
.setParent(panel
, false);
629 pane
.setParent(this, false);
632 for (TWidget w
: widgets
) {
633 assert (w
.window
!= null);
634 assert (w
.parent
!= null);
636 assert (pane
.getWindow() != null);
637 assert (pane
.getParent() != null);
638 assert (panel
.getWindow() != null);
639 assert (panel
.getParent() != null);
640 assert (pane
.isActive() == true);
641 assert (panel
.isActive() == true);
643 case TMenu
.MID_SPLIT_HORIZONTAL
:
644 panel
= new TPanel(null, x
, y
, width
, height
);
645 pane
= new TSplitPane(null, x
, y
, width
, height
, false);
646 widgets
= new ArrayList
<TWidget
>(children
);
647 for (TWidget w
: widgets
) {
648 w
.setParent(panel
, false);
651 pane
.setParent(this, false);
654 for (TWidget w
: widgets
) {
655 assert (w
.window
!= null);
656 assert (w
.parent
!= null);
658 assert (pane
.getWindow() != null);
659 assert (pane
.getParent() != null);
660 assert (panel
.getWindow() != null);
661 assert (panel
.getParent() != null);
662 assert (pane
.isActive() == true);
663 assert (panel
.isActive() == true);
669 // Default: do nothing, pass to children instead
670 for (TWidget widget
: children
) {
676 * Method that subclasses can override to do processing when the UI is
677 * idle. Note that repainting is NOT assumed. To get a refresh after
678 * onIdle, call doRepaint().
680 public void onIdle() {
681 // Default: do nothing, pass to children instead
682 for (TWidget widget
: children
) {
688 * Consume event. Subclasses that want to intercept all events in one go
689 * can override this method.
691 * @param event keyboard, mouse, resize, command, or menu event
693 public void handleEvent(final TInputEvent event
) {
695 System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(),
701 // System.err.println(" -- discard --");
705 if (event
instanceof TKeypressEvent
) {
706 onKeypress((TKeypressEvent
) event
);
707 } else if (event
instanceof TMouseEvent
) {
709 TMouseEvent mouse
= (TMouseEvent
) event
;
711 switch (mouse
.getType()) {
722 onMouseMotion(mouse
);
725 case MOUSE_DOUBLE_CLICK
:
726 onMouseDoubleClick(mouse
);
730 throw new IllegalArgumentException("Invalid mouse event type: "
733 } else if (event
instanceof TResizeEvent
) {
734 onResize((TResizeEvent
) event
);
735 } else if (event
instanceof TCommandEvent
) {
736 onCommand((TCommandEvent
) event
);
737 } else if (event
instanceof TMenuEvent
) {
738 onMenu((TMenuEvent
) event
);
745 // ------------------------------------------------------------------------
746 // TWidget ----------------------------------------------------------------
747 // ------------------------------------------------------------------------
752 * @return parent widget
754 public final TWidget
getParent() {
759 * Get the list of child widgets that this widget contains.
761 * @return the list of child widgets
763 public List
<TWidget
> getChildren() {
768 * Remove this widget from its parent container. close() will be called
769 * before it is removed.
771 public final void remove() {
776 * Remove this widget from its parent container.
778 * @param doClose if true, call the close() method before removing the
781 public final void remove(final boolean doClose
) {
782 if (parent
!= null) {
783 parent
.remove(this, doClose
);
788 * Remove a child widget from this container.
790 * @param child the child widget to remove
792 public final void remove(final TWidget child
) {
797 * Remove a child widget from this container.
799 * @param child the child widget to remove
800 * @param doClose if true, call the close() method before removing the
803 public final void remove(final TWidget child
, final boolean doClose
) {
804 if (!children
.contains(child
)) {
805 throw new IndexOutOfBoundsException("child widget is not in " +
806 "list of children of this parent");
811 children
.remove(child
);
814 if (layout
!= null) {
820 * Set this widget's parent to a different widget.
822 * @param newParent new parent widget
823 * @param doClose if true, call the close() method before removing the
824 * child from its existing parent widget
826 public final void setParent(final TWidget newParent
,
827 final boolean doClose
) {
829 if (parent
!= null) {
830 parent
.remove(this, doClose
);
833 assert (parent
== null);
834 assert (window
== null);
836 setWindow(parent
.window
);
837 parent
.addChild(this);
841 * Set this widget's window to a specific window.
843 * Having a null parent with a specified window is only used within Jexer
844 * by TStatusBar because TApplication routes events directly to it and
845 * calls its draw() method. Any other non-parented widgets will require
846 * similar special case functionality to receive events or be drawn to
849 * @param window the window to use
851 public final void setWindow(final TWindow window
) {
852 this.window
= window
;
853 for (TWidget child
: getChildren()) {
854 child
.setWindow(window
);
859 * Remove a child widget from this container, and all of its children
860 * recursively from their parent containers.
862 * @param child the child widget to remove
863 * @param doClose if true, call the close() method before removing each
866 public final void removeAll(final TWidget child
, final boolean doClose
) {
867 remove(child
, doClose
);
868 for (TWidget w
: child
.children
) {
869 child
.removeAll(w
, doClose
);
876 * @return if true, this widget will receive events
878 public final boolean isActive() {
885 * @param active if true, this widget will receive events
887 public final void setActive(final boolean active
) {
888 this.active
= active
;
892 * Get the window this widget is on.
896 public final TWindow
getWindow() {
903 * @return absolute X position of the top-left corner
905 public final int getX() {
912 * @param x absolute X position of the top-left corner
914 public final void setX(final int x
) {
921 * @return absolute Y position of the top-left corner
923 public final int getY() {
930 * @param y absolute Y position of the top-left corner
932 public final void setY(final int y
) {
939 * @return widget width
941 public int getWidth() {
948 * @param width new widget width
950 public void setWidth(final int width
) {
952 if (layout
!= null) {
953 layout
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
961 * @return widget height
963 public int getHeight() {
970 * @param height new widget height
972 public void setHeight(final int height
) {
973 this.height
= height
;
974 if (layout
!= null) {
975 layout
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
981 * Change the dimensions.
983 * @param x absolute X position of the top-left corner
984 * @param y absolute Y position of the top-left corner
985 * @param width new widget width
986 * @param height new widget height
988 public final void setDimensions(final int x
, final int y
, final int width
,
995 if (layout
!= null) {
996 layout
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
1002 * Get the layout manager.
1004 * @return the layout manager, or null if not set
1006 public LayoutManager
getLayoutManager() {
1011 * Set the layout manager.
1013 * @param layout the new layout manager
1015 public void setLayoutManager(LayoutManager layout
) {
1016 if (this.layout
!= null) {
1017 for (TWidget w
: children
) {
1018 this.layout
.remove(w
);
1022 this.layout
= layout
;
1023 if (this.layout
!= null) {
1024 for (TWidget w
: children
) {
1033 * @return if true, this widget can be tabbed to or receive events
1035 public final boolean isEnabled() {
1042 * @param enabled if true, this widget can be tabbed to or receive events
1044 public final void setEnabled(final boolean enabled
) {
1045 this.enabled
= enabled
;
1048 // See if there are any active siblings to switch to
1049 boolean foundSibling
= false;
1050 if (parent
!= null) {
1051 for (TWidget w
: parent
.children
) {
1053 && !(this instanceof THScroller
)
1054 && !(this instanceof TVScroller
)
1057 foundSibling
= true;
1061 if (!foundSibling
) {
1062 parent
.activeChild
= null;
1071 * @param visible if true, this widget will be drawn
1073 public final void setVisible(final boolean visible
) {
1074 this.visible
= visible
;
1078 * See if this widget is visible.
1080 * @return if true, this widget will be drawn
1082 public final boolean isVisible() {
1087 * Set visible cursor flag.
1089 * @param cursorVisible if true, this widget has a cursor
1091 public final void setCursorVisible(final boolean cursorVisible
) {
1092 this.cursorVisible
= cursorVisible
;
1096 * See if this widget has a visible cursor.
1098 * @return if true, this widget has a visible cursor
1100 public final boolean isCursorVisible() {
1101 // If cursor is out of my bounds, it is not visible.
1102 if ((cursorX
>= width
)
1104 || (cursorY
>= height
)
1110 assert (window
!= null);
1112 // If cursor is out of my window's bounds, it is not visible.
1113 if ((getCursorAbsoluteX() >= window
.getAbsoluteX()
1114 + window
.getWidth() - 1)
1115 || (getCursorAbsoluteX() < 0)
1116 || (getCursorAbsoluteY() >= window
.getAbsoluteY()
1117 + window
.getHeight() - 1)
1118 || (getCursorAbsoluteY() < 0)
1122 return cursorVisible
;
1126 * Get cursor X value.
1128 * @return cursor column position in relative coordinates
1130 public final int getCursorX() {
1135 * Set cursor X value.
1137 * @param cursorX column position in relative coordinates
1139 public final void setCursorX(final int cursorX
) {
1140 this.cursorX
= cursorX
;
1144 * Get cursor Y value.
1146 * @return cursor row position in relative coordinates
1148 public final int getCursorY() {
1153 * Set cursor Y value.
1155 * @param cursorY row position in relative coordinates
1157 public final void setCursorY(final int cursorY
) {
1158 this.cursorY
= cursorY
;
1162 * Get this TWidget's parent TApplication.
1164 * @return the parent TApplication
1166 public TApplication
getApplication() {
1167 return window
.getApplication();
1173 * @return the Screen
1175 public Screen
getScreen() {
1176 return window
.getScreen();
1180 * Comparison operator. For various subclasses it sorts on:
1182 * <li>tabOrder for TWidgets</li>
1183 * <li>z for TWindows</li>
1184 * <li>text for TTreeItems</li>
1187 * @param that another TWidget, TWindow, or TTreeItem instance
1188 * @return difference between this.tabOrder and that.tabOrder, or
1189 * difference between this.z and that.z, or String.compareTo(text)
1191 public final int compareTo(final TWidget that
) {
1192 if ((this instanceof TWindow
)
1193 && (that
instanceof TWindow
)
1195 return (((TWindow
) this).getZ() - ((TWindow
) that
).getZ());
1197 if ((this instanceof TTreeItem
)
1198 && (that
instanceof TTreeItem
)
1200 return (((TTreeItem
) this).getText().compareTo(
1201 ((TTreeItem
) that
).getText()));
1203 return (this.tabOrder
- that
.tabOrder
);
1207 * See if this widget should render with the active color.
1209 * @return true if this widget is active and all of its parents are
1212 public final boolean isAbsoluteActive() {
1213 if (parent
== this) {
1216 return (active
&& (parent
== null ?
true : parent
.isAbsoluteActive()));
1220 * Returns the cursor X position.
1222 * @return absolute screen column number for the cursor's X position
1224 public final int getCursorAbsoluteX() {
1225 return getAbsoluteX() + cursorX
;
1229 * Returns the cursor Y position.
1231 * @return absolute screen row number for the cursor's Y position
1233 public final int getCursorAbsoluteY() {
1234 return getAbsoluteY() + cursorY
;
1238 * Compute my absolute X position as the sum of my X plus all my parent's
1241 * @return absolute screen column number for my X position
1243 public final int getAbsoluteX() {
1244 assert (parent
!= null);
1245 if (parent
== this) {
1248 if ((parent
instanceof TWindow
)
1249 && !(parent
instanceof TMenu
)
1250 && !(parent
instanceof TDesktop
)
1252 // Widgets on a TWindow have (0,0) as their top-left, but this is
1253 // actually the TWindow's (1,1).
1254 return parent
.getAbsoluteX() + x
+ 1;
1256 return parent
.getAbsoluteX() + x
;
1260 * Compute my absolute Y position as the sum of my Y plus all my parent's
1263 * @return absolute screen row number for my Y position
1265 public final int getAbsoluteY() {
1266 assert (parent
!= null);
1267 if (parent
== this) {
1270 if ((parent
instanceof TWindow
)
1271 && !(parent
instanceof TMenu
)
1272 && !(parent
instanceof TDesktop
)
1274 // Widgets on a TWindow have (0,0) as their top-left, but this is
1275 // actually the TWindow's (1,1).
1276 return parent
.getAbsoluteY() + y
+ 1;
1278 return parent
.getAbsoluteY() + y
;
1282 * Get the global color theme.
1284 * @return the ColorTheme
1286 protected final ColorTheme
getTheme() {
1287 return window
.getApplication().getTheme();
1291 * Draw my specific widget. When called, the screen rectangle I draw
1292 * into is already setup (offset and clipping).
1294 public void draw() {
1295 // Default widget draws nothing.
1299 * Called by parent to render to TWindow. Note package private access.
1301 final void drawChildren() {
1302 // Set my clipping rectangle
1303 assert (window
!= null);
1304 assert (getScreen() != null);
1305 Screen screen
= getScreen();
1307 // Special case: TStatusBar is drawn by TApplication, not anything
1309 if (this instanceof TStatusBar
) {
1313 screen
.setClipRight(width
);
1314 screen
.setClipBottom(height
);
1316 int absoluteRightEdge
= window
.getAbsoluteX() + window
.getWidth();
1317 int absoluteBottomEdge
= window
.getAbsoluteY() + window
.getHeight();
1318 if (!(this instanceof TWindow
) && !(this instanceof TVScroller
)) {
1319 absoluteRightEdge
-= 1;
1321 if (!(this instanceof TWindow
) && !(this instanceof THScroller
)) {
1322 absoluteBottomEdge
-= 1;
1324 int myRightEdge
= getAbsoluteX() + width
;
1325 int myBottomEdge
= getAbsoluteY() + height
;
1326 if (getAbsoluteX() > absoluteRightEdge
) {
1328 screen
.setClipRight(0);
1329 } else if (myRightEdge
> absoluteRightEdge
) {
1330 screen
.setClipRight(screen
.getClipRight()
1331 - (myRightEdge
- absoluteRightEdge
));
1333 if (getAbsoluteY() > absoluteBottomEdge
) {
1335 screen
.setClipBottom(0);
1336 } else if (myBottomEdge
> absoluteBottomEdge
) {
1337 screen
.setClipBottom(screen
.getClipBottom()
1338 - (myBottomEdge
- absoluteBottomEdge
));
1342 screen
.setOffsetX(getAbsoluteX());
1343 screen
.setOffsetY(getAbsoluteY());
1347 assert (visible
== true);
1349 // Continue down the chain. Draw the active child last so that it
1351 for (TWidget widget
: children
) {
1352 if (widget
.isVisible() && (widget
!= activeChild
)) {
1353 widget
.drawChildren();
1356 if (activeChild
!= null) {
1357 activeChild
.drawChildren();
1362 * Repaint the screen on the next update.
1364 protected final void doRepaint() {
1365 window
.getApplication().doRepaint();
1369 * Add a child widget to my list of children. We set its tabOrder to 0
1370 * and increment the tabOrder of all other children.
1372 * @param child TWidget to add
1374 private void addChild(final TWidget child
) {
1375 children
.add(child
);
1378 && !(child
instanceof THScroller
)
1379 && !(child
instanceof TVScroller
)
1381 for (TWidget widget
: children
) {
1382 widget
.active
= false;
1384 child
.active
= true;
1385 activeChild
= child
;
1387 for (int i
= 0; i
< children
.size(); i
++) {
1388 children
.get(i
).tabOrder
= i
;
1390 if (layout
!= null) {
1396 * Reset the tab order of children to match their position in the list.
1397 * Available so that subclasses can re-order their widgets if needed.
1399 protected void resetTabOrder() {
1400 for (int i
= 0; i
< children
.size(); i
++) {
1401 children
.get(i
).tabOrder
= i
;
1406 * Switch the active child.
1408 * @param child TWidget to activate
1410 public final void activate(final TWidget child
) {
1411 assert (child
.enabled
);
1412 if ((child
instanceof THScroller
)
1413 || (child
instanceof TVScroller
)
1418 if (children
.size() == 1) {
1419 if (children
.get(0).enabled
== true) {
1420 child
.active
= true;
1421 activeChild
= child
;
1424 if (child
!= activeChild
) {
1425 if (activeChild
!= null) {
1426 activeChild
.active
= false;
1428 child
.active
= true;
1429 activeChild
= child
;
1435 * Switch the active child.
1437 * @param tabOrder tabOrder of the child to activate. If that child
1438 * isn't enabled, then the next enabled child will be activated.
1440 public final void activate(final int tabOrder
) {
1441 if (children
.size() == 1) {
1442 if (children
.get(0).enabled
== true) {
1443 children
.get(0).active
= true;
1444 activeChild
= children
.get(0);
1449 TWidget child
= null;
1450 for (TWidget widget
: children
) {
1451 if ((widget
.enabled
)
1452 && !(widget
instanceof THScroller
)
1453 && !(widget
instanceof TVScroller
)
1454 && (widget
.tabOrder
>= tabOrder
)
1460 if ((child
!= null) && (child
!= activeChild
)) {
1461 if (activeChild
!= null) {
1462 activeChild
.active
= false;
1464 assert (child
.enabled
);
1465 child
.active
= true;
1466 activeChild
= child
;
1471 * Make this widget the active child of its parent. Note that this is
1472 * not final since TWindow overrides activate().
1474 public void activate() {
1476 if (parent
!= null) {
1477 parent
.activate(this);
1483 * Switch the active widget with the next in the tab order.
1485 * @param forward if true, then switch to the next enabled widget in the
1486 * list, otherwise switch to the previous enabled widget in the list
1488 public final void switchWidget(final boolean forward
) {
1490 // No children: do nothing.
1491 if (children
.size() == 0) {
1495 assert (parent
!= null);
1497 // If there is only one child, make it active if it is enabled.
1498 if (children
.size() == 1) {
1499 if (children
.get(0).enabled
== true) {
1500 activeChild
= children
.get(0);
1501 activeChild
.active
= true;
1503 children
.get(0).active
= false;
1509 // Two or more children: go forward or backward to the next enabled
1512 if (activeChild
!= null) {
1513 tabOrder
= activeChild
.tabOrder
;
1523 // If at the end, pass the switch to my parent.
1524 if ((!forward
) && (parent
!= this)) {
1525 parent
.switchWidget(forward
);
1529 tabOrder
= children
.size() - 1;
1530 } else if (tabOrder
== children
.size()) {
1531 // If at the end, pass the switch to my parent.
1532 if ((forward
) && (parent
!= this)) {
1533 parent
.switchWidget(forward
);
1539 if (activeChild
== null) {
1540 if (tabOrder
== 0) {
1541 // We wrapped around
1544 } else if (activeChild
.tabOrder
== tabOrder
) {
1545 // We wrapped around
1548 } while ((!children
.get(tabOrder
).enabled
)
1549 && !(children
.get(tabOrder
) instanceof THScroller
)
1550 && !(children
.get(tabOrder
) instanceof TVScroller
));
1552 if (activeChild
!= null) {
1553 assert (children
.get(tabOrder
).enabled
);
1555 activeChild
.active
= false;
1557 if (children
.get(tabOrder
).enabled
== true) {
1558 children
.get(tabOrder
).active
= true;
1559 activeChild
= children
.get(tabOrder
);
1564 * Returns my active widget.
1566 * @return widget that is active, or this if no children
1568 public TWidget
getActiveChild() {
1569 if ((this instanceof THScroller
)
1570 || (this instanceof TVScroller
)
1575 for (TWidget widget
: children
) {
1576 if (widget
.active
) {
1577 return widget
.getActiveChild();
1580 // No active children, return me
1584 // ------------------------------------------------------------------------
1585 // Passthru for Screen functions ------------------------------------------
1586 // ------------------------------------------------------------------------
1589 * Get the attributes at one location.
1591 * @param x column coordinate. 0 is the left-most column.
1592 * @param y row coordinate. 0 is the top-most row.
1593 * @return attributes at (x, y)
1595 protected final CellAttributes
getAttrXY(final int x
, final int y
) {
1596 return getScreen().getAttrXY(x
, y
);
1600 * Set the attributes at one location.
1602 * @param x column coordinate. 0 is the left-most column.
1603 * @param y row coordinate. 0 is the top-most row.
1604 * @param attr attributes to use (bold, foreColor, backColor)
1606 protected final void putAttrXY(final int x
, final int y
,
1607 final CellAttributes attr
) {
1609 getScreen().putAttrXY(x
, y
, attr
);
1613 * Set the attributes at one location.
1615 * @param x column coordinate. 0 is the left-most column.
1616 * @param y row coordinate. 0 is the top-most row.
1617 * @param attr attributes to use (bold, foreColor, backColor)
1618 * @param clip if true, honor clipping/offset
1620 protected final void putAttrXY(final int x
, final int y
,
1621 final CellAttributes attr
, final boolean clip
) {
1623 getScreen().putAttrXY(x
, y
, attr
, clip
);
1627 * Fill the entire screen with one character with attributes.
1629 * @param ch character to draw
1630 * @param attr attributes to use (bold, foreColor, backColor)
1632 protected final void putAll(final int ch
, final CellAttributes attr
) {
1633 getScreen().putAll(ch
, attr
);
1637 * Render one character with attributes.
1639 * @param x column coordinate. 0 is the left-most column.
1640 * @param y row coordinate. 0 is the top-most row.
1641 * @param ch character + attributes to draw
1643 protected final void putCharXY(final int x
, final int y
, final Cell ch
) {
1644 getScreen().putCharXY(x
, y
, ch
);
1648 * Render one character with attributes.
1650 * @param x column coordinate. 0 is the left-most column.
1651 * @param y row coordinate. 0 is the top-most row.
1652 * @param ch character to draw
1653 * @param attr attributes to use (bold, foreColor, backColor)
1655 protected final void putCharXY(final int x
, final int y
, final int ch
,
1656 final CellAttributes attr
) {
1658 getScreen().putCharXY(x
, y
, ch
, attr
);
1662 * Render one character without changing the underlying attributes.
1664 * @param x column coordinate. 0 is the left-most column.
1665 * @param y row coordinate. 0 is the top-most row.
1666 * @param ch character to draw
1668 protected final void putCharXY(final int x
, final int y
, final int ch
) {
1669 getScreen().putCharXY(x
, y
, ch
);
1673 * Render a string. Does not wrap if the string exceeds the line.
1675 * @param x column coordinate. 0 is the left-most column.
1676 * @param y row coordinate. 0 is the top-most row.
1677 * @param str string to draw
1678 * @param attr attributes to use (bold, foreColor, backColor)
1680 protected final void putStringXY(final int x
, final int y
, final String str
,
1681 final CellAttributes attr
) {
1683 getScreen().putStringXY(x
, y
, str
, attr
);
1687 * Render a string without changing the underlying attribute. Does not
1688 * wrap if the string exceeds the line.
1690 * @param x column coordinate. 0 is the left-most column.
1691 * @param y row coordinate. 0 is the top-most row.
1692 * @param str string to draw
1694 protected final void putStringXY(final int x
, final int y
, final String str
) {
1695 getScreen().putStringXY(x
, y
, str
);
1699 * Draw a vertical line from (x, y) to (x, y + n).
1701 * @param x column coordinate. 0 is the left-most column.
1702 * @param y row coordinate. 0 is the top-most row.
1703 * @param n number of characters to draw
1704 * @param ch character to draw
1705 * @param attr attributes to use (bold, foreColor, backColor)
1707 protected final void vLineXY(final int x
, final int y
, final int n
,
1708 final int ch
, final CellAttributes attr
) {
1710 getScreen().vLineXY(x
, y
, n
, ch
, attr
);
1714 * Draw a horizontal line from (x, y) to (x + n, y).
1716 * @param x column coordinate. 0 is the left-most column.
1717 * @param y row coordinate. 0 is the top-most row.
1718 * @param n number of characters to draw
1719 * @param ch character to draw
1720 * @param attr attributes to use (bold, foreColor, backColor)
1722 protected final void hLineXY(final int x
, final int y
, final int n
,
1723 final int ch
, final CellAttributes attr
) {
1725 getScreen().hLineXY(x
, y
, n
, ch
, attr
);
1729 * Draw a box with a border and empty background.
1731 * @param left left column of box. 0 is the left-most row.
1732 * @param top top row of the box. 0 is the top-most row.
1733 * @param right right column of box
1734 * @param bottom bottom row of the box
1735 * @param border attributes to use for the border
1736 * @param background attributes to use for the background
1738 protected final void drawBox(final int left
, final int top
,
1739 final int right
, final int bottom
,
1740 final CellAttributes border
, final CellAttributes background
) {
1742 getScreen().drawBox(left
, top
, right
, bottom
, border
, background
);
1746 * Draw a box with a border and empty background.
1748 * @param left left column of box. 0 is the left-most row.
1749 * @param top top row of the box. 0 is the top-most row.
1750 * @param right right column of box
1751 * @param bottom bottom row of the box
1752 * @param border attributes to use for the border
1753 * @param background attributes to use for the background
1754 * @param borderType if 1, draw a single-line border; if 2, draw a
1755 * double-line border; if 3, draw double-line top/bottom edges and
1756 * single-line left/right edges (like Qmodem)
1757 * @param shadow if true, draw a "shadow" on the box
1759 protected final void drawBox(final int left
, final int top
,
1760 final int right
, final int bottom
,
1761 final CellAttributes border
, final CellAttributes background
,
1762 final int borderType
, final boolean shadow
) {
1764 getScreen().drawBox(left
, top
, right
, bottom
, border
, background
,
1765 borderType
, shadow
);
1769 * Draw a box shadow.
1771 * @param left left column of box. 0 is the left-most row.
1772 * @param top top row of the box. 0 is the top-most row.
1773 * @param right right column of box
1774 * @param bottom bottom row of the box
1776 protected final void drawBoxShadow(final int left
, final int top
,
1777 final int right
, final int bottom
) {
1779 getScreen().drawBoxShadow(left
, top
, right
, bottom
);
1782 // ------------------------------------------------------------------------
1783 // Other TWidget constructors ---------------------------------------------
1784 // ------------------------------------------------------------------------
1787 * Convenience function to add a label to this container/window.
1790 * @param x column relative to parent
1791 * @param y row relative to parent
1792 * @return the new label
1794 public final TLabel
addLabel(final String text
, final int x
, final int y
) {
1795 return addLabel(text
, x
, y
, "tlabel");
1799 * Convenience function to add a label to this container/window.
1802 * @param x column relative to parent
1803 * @param y row relative to parent
1804 * @param action to call when shortcut is pressed
1805 * @return the new label
1807 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1808 final TAction action
) {
1810 return addLabel(text
, x
, y
, "tlabel", action
);
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 * @param colorKey ColorTheme key color to use for foreground text.
1820 * Default is "tlabel"
1821 * @return the new label
1823 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1824 final String colorKey
) {
1826 return new TLabel(this, text
, x
, y
, colorKey
);
1830 * Convenience function to add a label to this container/window.
1833 * @param x column relative to parent
1834 * @param y row relative to parent
1835 * @param colorKey ColorTheme key color to use for foreground text.
1836 * Default is "tlabel"
1837 * @param action to call when shortcut is pressed
1838 * @return the new label
1840 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1841 final String colorKey
, final TAction action
) {
1843 return new TLabel(this, text
, x
, y
, colorKey
, action
);
1847 * Convenience function to add a label to this container/window.
1850 * @param x column relative to parent
1851 * @param y row relative to parent
1852 * @param colorKey ColorTheme key color to use for foreground text.
1853 * Default is "tlabel"
1854 * @param useWindowBackground if true, use the window's background color
1855 * @return the new label
1857 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1858 final String colorKey
, final boolean useWindowBackground
) {
1860 return new TLabel(this, text
, x
, y
, colorKey
, useWindowBackground
);
1864 * Convenience function to add a label to this container/window.
1867 * @param x column relative to parent
1868 * @param y row relative to parent
1869 * @param colorKey ColorTheme key color to use for foreground text.
1870 * Default is "tlabel"
1871 * @param useWindowBackground if true, use the window's background color
1872 * @param action to call when shortcut is pressed
1873 * @return the new label
1875 public final TLabel
addLabel(final String text
, final int x
, final int y
,
1876 final String colorKey
, final boolean useWindowBackground
,
1877 final TAction action
) {
1879 return new TLabel(this, text
, x
, y
, colorKey
, useWindowBackground
,
1884 * Convenience function to add a button to this container/window.
1886 * @param text label on the button
1887 * @param x column relative to parent
1888 * @param y row relative to parent
1889 * @param action action to call when button is pressed
1890 * @return the new button
1892 public final TButton
addButton(final String text
, final int x
, final int y
,
1893 final TAction action
) {
1895 return new TButton(this, text
, x
, y
, action
);
1899 * Convenience function to add a checkbox to this container/window.
1901 * @param x column relative to parent
1902 * @param y row relative to parent
1903 * @param label label to display next to (right of) the checkbox
1904 * @param checked initial check state
1905 * @return the new checkbox
1907 public final TCheckBox
addCheckBox(final int x
, final int y
,
1908 final String label
, final boolean checked
) {
1910 return new TCheckBox(this, x
, y
, label
, checked
);
1914 * Convenience function to add a combobox to this container/window.
1916 * @param x column relative to parent
1917 * @param y row relative to parent
1918 * @param width visible combobox width, including the down-arrow
1919 * @param values the possible values for the box, shown in the drop-down
1920 * @param valuesIndex the initial index in values, or -1 for no default
1922 * @param maxValuesHeight the maximum height of the values drop-down when
1924 * @param updateAction action to call when a new value is selected from
1925 * the list or enter is pressed in the edit field
1926 * @return the new combobox
1928 public final TComboBox
addComboBox(final int x
, final int y
,
1929 final int width
, final List
<String
> values
, final int valuesIndex
,
1930 final int maxValuesHeight
, final TAction updateAction
) {
1932 return new TComboBox(this, x
, y
, width
, values
, valuesIndex
,
1933 maxValuesHeight
, updateAction
);
1937 * Convenience function to add a spinner to this container/window.
1939 * @param x column relative to parent
1940 * @param y row relative to parent
1941 * @param upAction action to call when the up arrow is clicked or pressed
1942 * @param downAction action to call when the down arrow is clicked or
1944 * @return the new spinner
1946 public final TSpinner
addSpinner(final int x
, final int y
,
1947 final TAction upAction
, final TAction downAction
) {
1949 return new TSpinner(this, x
, y
, upAction
, downAction
);
1953 * Convenience function to add a calendar to this container/window.
1955 * @param x column relative to parent
1956 * @param y row relative to parent
1957 * @param updateAction action to call when the user changes the value of
1959 * @return the new calendar
1961 public final TCalendar
addCalendar(final int x
, final int y
,
1962 final TAction updateAction
) {
1964 return new TCalendar(this, x
, y
, updateAction
);
1968 * Convenience function to add a progress bar to this container/window.
1970 * @param x column relative to parent
1971 * @param y row relative to parent
1972 * @param width width of progress bar
1973 * @param value initial value of percent complete
1974 * @return the new progress bar
1976 public final TProgressBar
addProgressBar(final int x
, final int y
,
1977 final int width
, final int value
) {
1979 return new TProgressBar(this, x
, y
, width
, value
);
1983 * Convenience function to add a radio button group to this
1986 * @param x column relative to parent
1987 * @param y row relative to parent
1988 * @param label label to display on the group box
1989 * @return the new radio button group
1991 public final TRadioGroup
addRadioGroup(final int x
, final int y
,
1992 final String label
) {
1994 return new TRadioGroup(this, x
, y
, label
);
1998 * Convenience function to add a text field to this container/window.
2000 * @param x column relative to parent
2001 * @param y row relative to parent
2002 * @param width visible text width
2003 * @param fixed if true, the text cannot exceed the display width
2004 * @return the new text field
2006 public final TField
addField(final int x
, final int y
,
2007 final int width
, final boolean fixed
) {
2009 return new TField(this, x
, y
, width
, fixed
);
2013 * Convenience function to add a text field to this container/window.
2015 * @param x column relative to parent
2016 * @param y row relative to parent
2017 * @param width visible text width
2018 * @param fixed if true, the text cannot exceed the display width
2019 * @param text initial text, default is empty string
2020 * @return the new text field
2022 public final TField
addField(final int x
, final int y
,
2023 final int width
, final boolean fixed
, final String text
) {
2025 return new TField(this, x
, y
, width
, fixed
, text
);
2029 * Convenience function to add a text field to this container/window.
2031 * @param x column relative to parent
2032 * @param y row relative to parent
2033 * @param width visible text width
2034 * @param fixed if true, the text cannot exceed the display width
2035 * @param text initial text, default is empty string
2036 * @param enterAction function to call when enter key is pressed
2037 * @param updateAction function to call when the text is updated
2038 * @return the new text field
2040 public final TField
addField(final int x
, final int y
,
2041 final int width
, final boolean fixed
, final String text
,
2042 final TAction enterAction
, final TAction updateAction
) {
2044 return new TField(this, x
, y
, width
, fixed
, text
, enterAction
,
2049 * Convenience function to add a scrollable text box to this
2052 * @param text text on the screen
2053 * @param x column relative to parent
2054 * @param y row relative to parent
2055 * @param width width of text area
2056 * @param height height of text area
2057 * @param colorKey ColorTheme key color to use for foreground text
2058 * @return the new text box
2060 public final TText
addText(final String text
, final int x
,
2061 final int y
, final int width
, final int height
, final String colorKey
) {
2063 return new TText(this, text
, x
, y
, width
, height
, colorKey
);
2067 * Convenience function to add a scrollable text box to this
2070 * @param text text on the screen
2071 * @param x column relative to parent
2072 * @param y row relative to parent
2073 * @param width width of text area
2074 * @param height height of text area
2075 * @return the new text box
2077 public final TText
addText(final String text
, final int x
, final int y
,
2078 final int width
, final int height
) {
2080 return new TText(this, text
, x
, y
, width
, height
, "ttext");
2084 * Convenience function to add an editable text area box to this
2087 * @param text text on the screen
2088 * @param x column relative to parent
2089 * @param y row relative to parent
2090 * @param width width of text area
2091 * @param height height of text area
2092 * @return the new text box
2094 public final TEditorWidget
addEditor(final String text
, final int x
,
2095 final int y
, final int width
, final int height
) {
2097 return new TEditorWidget(this, text
, x
, y
, width
, height
);
2101 * Convenience function to spawn a message box.
2103 * @param title window title, will be centered along the top border
2104 * @param caption message to display. Use embedded newlines to get a
2106 * @return the new message box
2108 public final TMessageBox
messageBox(final String title
,
2109 final String caption
) {
2111 return getApplication().messageBox(title
, caption
, TMessageBox
.Type
.OK
);
2115 * Convenience function to spawn a message box.
2117 * @param title window title, will be centered along the top border
2118 * @param caption message to display. Use embedded newlines to get a
2120 * @param type one of the TMessageBox.Type constants. Default is
2122 * @return the new message box
2124 public final TMessageBox
messageBox(final String title
,
2125 final String caption
, final TMessageBox
.Type type
) {
2127 return getApplication().messageBox(title
, caption
, type
);
2131 * Convenience function to spawn an input box.
2133 * @param title window title, will be centered along the top border
2134 * @param caption message to display. Use embedded newlines to get a
2136 * @return the new input box
2138 public final TInputBox
inputBox(final String title
, final String caption
) {
2140 return getApplication().inputBox(title
, caption
);
2144 * Convenience function to spawn an input box.
2146 * @param title window title, will be centered along the top border
2147 * @param caption message to display. Use embedded newlines to get a
2149 * @param text initial text to seed the field with
2150 * @return the new input box
2152 public final TInputBox
inputBox(final String title
, final String caption
,
2153 final String text
) {
2155 return getApplication().inputBox(title
, caption
, text
);
2159 * Convenience function to spawn an input box.
2161 * @param title window title, will be centered along the top border
2162 * @param caption message to display. Use embedded newlines to get a
2164 * @param text initial text to seed the field with
2165 * @param type one of the Type constants. Default is Type.OK.
2166 * @return the new input box
2168 public final TInputBox
inputBox(final String title
, final String caption
,
2169 final String text
, final TInputBox
.Type type
) {
2171 return getApplication().inputBox(title
, caption
, text
, type
);
2175 * Convenience function to add a password text field to this
2178 * @param x column relative to parent
2179 * @param y row relative to parent
2180 * @param width visible text width
2181 * @param fixed if true, the text cannot exceed the display width
2182 * @return the new text field
2184 public final TPasswordField
addPasswordField(final int x
, final int y
,
2185 final int width
, final boolean fixed
) {
2187 return new TPasswordField(this, x
, y
, width
, fixed
);
2191 * Convenience function to add a password text field to this
2194 * @param x column relative to parent
2195 * @param y row relative to parent
2196 * @param width visible text width
2197 * @param fixed if true, the text cannot exceed the display width
2198 * @param text initial text, default is empty string
2199 * @return the new text field
2201 public final TPasswordField
addPasswordField(final int x
, final int y
,
2202 final int width
, final boolean fixed
, final String text
) {
2204 return new TPasswordField(this, x
, y
, width
, fixed
, text
);
2208 * Convenience function to add a password text field to this
2211 * @param x column relative to parent
2212 * @param y row relative to parent
2213 * @param width visible text width
2214 * @param fixed if true, the text cannot exceed the display width
2215 * @param text initial text, default is empty string
2216 * @param enterAction function to call when enter key is pressed
2217 * @param updateAction function to call when the text is updated
2218 * @return the new text field
2220 public final TPasswordField
addPasswordField(final int x
, final int y
,
2221 final int width
, final boolean fixed
, final String text
,
2222 final TAction enterAction
, final TAction updateAction
) {
2224 return new TPasswordField(this, x
, y
, width
, fixed
, text
, enterAction
,
2229 * Convenience function to add a scrollable tree view to this
2232 * @param x column relative to parent
2233 * @param y row relative to parent
2234 * @param width width of tree view
2235 * @param height height of tree view
2236 * @return the new tree view
2238 public final TTreeViewWidget
addTreeViewWidget(final int x
, final int y
,
2239 final int width
, final int height
) {
2241 return new TTreeViewWidget(this, x
, y
, width
, height
);
2245 * Convenience function to add a scrollable tree view to this
2248 * @param x column relative to parent
2249 * @param y row relative to parent
2250 * @param width width of tree view
2251 * @param height height of tree view
2252 * @param action action to perform when an item is selected
2253 * @return the new tree view
2255 public final TTreeViewWidget
addTreeViewWidget(final int x
, final int y
,
2256 final int width
, final int height
, final TAction action
) {
2258 return new TTreeViewWidget(this, x
, y
, width
, height
, action
);
2262 * Convenience function to spawn a file open box.
2264 * @param path path of selected file
2265 * @return the result of the new file open box
2266 * @throws IOException if a java.io operation throws
2268 public final String
fileOpenBox(final String path
) throws IOException
{
2269 return getApplication().fileOpenBox(path
);
2273 * Convenience function to spawn a file save box.
2275 * @param path path of selected file
2276 * @return the result of the new file open box
2277 * @throws IOException if a java.io operation throws
2279 public final String
fileSaveBox(final String path
) throws IOException
{
2280 return getApplication().fileOpenBox(path
, TFileOpenBox
.Type
.SAVE
);
2284 * Convenience function to spawn a file open box.
2286 * @param path path of selected file
2287 * @param type one of the Type constants
2288 * @return the result of the new file open box
2289 * @throws IOException if a java.io operation throws
2291 public final String
fileOpenBox(final String path
,
2292 final TFileOpenBox
.Type type
) throws IOException
{
2294 return getApplication().fileOpenBox(path
, type
);
2298 * Convenience function to spawn a file open box.
2300 * @param path path of selected file
2301 * @param type one of the Type constants
2302 * @param filter a string that files must match to be displayed
2303 * @return the result of the new file open box
2304 * @throws IOException of a java.io operation throws
2306 public final String
fileOpenBox(final String path
,
2307 final TFileOpenBox
.Type type
, final String filter
) throws IOException
{
2309 ArrayList
<String
> filters
= new ArrayList
<String
>();
2310 filters
.add(filter
);
2312 return getApplication().fileOpenBox(path
, type
, filters
);
2316 * Convenience function to spawn a file open box.
2318 * @param path path of selected file
2319 * @param type one of the Type constants
2320 * @param filters a list of strings that files must match to be displayed
2321 * @return the result of the new file open box
2322 * @throws IOException of a java.io operation throws
2324 public final String
fileOpenBox(final String path
,
2325 final TFileOpenBox
.Type type
,
2326 final List
<String
> filters
) throws IOException
{
2328 return getApplication().fileOpenBox(path
, type
, filters
);
2332 * Convenience function to add a directory list to this container/window.
2334 * @param path directory path, must be a directory
2335 * @param x column relative to parent
2336 * @param y row relative to parent
2337 * @param width width of text area
2338 * @param height height of text area
2339 * @return the new directory list
2341 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
2342 final int y
, final int width
, final int height
) {
2344 return new TDirectoryList(this, path
, x
, y
, width
, height
, null);
2348 * Convenience function to add a directory list to this container/window.
2350 * @param path directory path, must be a directory
2351 * @param x column relative to parent
2352 * @param y row relative to parent
2353 * @param width width of text area
2354 * @param height height of text area
2355 * @param action action to perform when an item is selected (enter or
2357 * @return the new directory list
2359 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
2360 final int y
, final int width
, final int height
, final TAction action
) {
2362 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
);
2366 * Convenience function to add a directory list to this container/window.
2368 * @param path directory path, must be a directory
2369 * @param x column relative to parent
2370 * @param y row relative to parent
2371 * @param width width of text area
2372 * @param height height of text area
2373 * @param action action to perform when an item is selected (enter or
2375 * @param singleClickAction action to perform when an item is selected
2377 * @return the new directory list
2379 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
2380 final int y
, final int width
, final int height
, final TAction action
,
2381 final TAction singleClickAction
) {
2383 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
,
2388 * Convenience function to add a directory list to this container/window.
2390 * @param path directory path, must be a directory
2391 * @param x column relative to parent
2392 * @param y row relative to parent
2393 * @param width width of text area
2394 * @param height height of text area
2395 * @param action action to perform when an item is selected (enter or
2397 * @param singleClickAction action to perform when an item is selected
2399 * @param filters a list of strings that files must match to be displayed
2400 * @return the new directory list
2402 public final TDirectoryList
addDirectoryList(final String path
, final int x
,
2403 final int y
, final int width
, final int height
, final TAction action
,
2404 final TAction singleClickAction
, final List
<String
> filters
) {
2406 return new TDirectoryList(this, path
, x
, y
, width
, height
, action
,
2407 singleClickAction
, filters
);
2411 * Convenience function to add a list to this container/window.
2413 * @param strings list of strings to show
2414 * @param x column relative to parent
2415 * @param y row relative to parent
2416 * @param width width of text area
2417 * @param height height of text area
2418 * @return the new directory list
2420 public final TList
addList(final List
<String
> strings
, final int x
,
2421 final int y
, final int width
, final int height
) {
2423 return new TList(this, strings
, x
, y
, width
, height
, null);
2427 * Convenience function to add a list to this container/window.
2429 * @param strings list of strings to show
2430 * @param x column relative to parent
2431 * @param y row relative to parent
2432 * @param width width of text area
2433 * @param height height of text area
2434 * @param enterAction action to perform when an item is selected
2435 * @return the new directory list
2437 public final TList
addList(final List
<String
> strings
, final int x
,
2438 final int y
, final int width
, final int height
,
2439 final TAction enterAction
) {
2441 return new TList(this, strings
, x
, y
, width
, height
, enterAction
);
2445 * Convenience function to add a list to this container/window.
2447 * @param strings list of strings to show
2448 * @param x column relative to parent
2449 * @param y row relative to parent
2450 * @param width width of text area
2451 * @param height height of text area
2452 * @param enterAction action to perform when an item is selected
2453 * @param moveAction action to perform when the user navigates to a new
2454 * item with arrow/page keys
2455 * @return the new directory list
2457 public final TList
addList(final List
<String
> strings
, final int x
,
2458 final int y
, final int width
, final int height
,
2459 final TAction enterAction
, final TAction moveAction
) {
2461 return new TList(this, strings
, x
, y
, width
, height
, enterAction
,
2466 * Convenience function to add a list to this container/window.
2468 * @param strings list of strings to show. This is allowed to be null
2469 * and set later with setList() or by subclasses.
2470 * @param x column relative to parent
2471 * @param y row relative to parent
2472 * @param width width of text area
2473 * @param height height of text area
2474 * @param enterAction action to perform when an item is selected
2475 * @param moveAction action to perform when the user navigates to a new
2476 * item with arrow/page keys
2477 * @param singleClickAction action to perform when the user clicks on an
2480 public TList
addList(final List
<String
> strings
, final int x
,
2481 final int y
, final int width
, final int height
,
2482 final TAction enterAction
, final TAction moveAction
,
2483 final TAction singleClickAction
) {
2485 return new TList(this, strings
, x
, y
, width
, height
, enterAction
,
2486 moveAction
, singleClickAction
);
2491 * Convenience function to add an image to this container/window.
2493 * @param x column relative to parent
2494 * @param y row relative to parent
2495 * @param width number of text cells for width of the image
2496 * @param height number of text cells for height of the image
2497 * @param image the image to display
2498 * @param left left column of the image. 0 is the left-most column.
2499 * @param top top row of the image. 0 is the top-most row.
2501 public final TImage
addImage(final int x
, final int y
,
2502 final int width
, final int height
,
2503 final BufferedImage image
, final int left
, final int top
) {
2505 return new TImage(this, x
, y
, width
, height
, image
, left
, top
);
2509 * Convenience function to add an image to this container/window.
2511 * @param x column relative to parent
2512 * @param y row relative to parent
2513 * @param width number of text cells for width of the image
2514 * @param height number of text cells for height of the image
2515 * @param image the image to display
2516 * @param left left column of the image. 0 is the left-most column.
2517 * @param top top row of the image. 0 is the top-most row.
2518 * @param clickAction function to call when mouse is pressed
2520 public final TImage
addImage(final int x
, final int y
,
2521 final int width
, final int height
,
2522 final BufferedImage image
, final int left
, final int top
,
2523 final TAction clickAction
) {
2525 return new TImage(this, x
, y
, width
, height
, image
, left
, top
,
2530 * Convenience function to add an editable 2D data table to this
2533 * @param x column relative to parent
2534 * @param y row relative to parent
2535 * @param width width of widget
2536 * @param height height of widget
2538 public TTableWidget
addTable(final int x
, final int y
, final int width
,
2541 return new TTableWidget(this, x
, y
, width
, height
);
2545 * Convenience function to add an editable 2D data table to this
2548 * @param x column relative to parent
2549 * @param y row relative to parent
2550 * @param width width of widget
2551 * @param height height of widget
2552 * @param gridColumns number of columns in grid
2553 * @param gridRows number of rows in grid
2555 public TTableWidget
addTable(final int x
, final int y
, final int width
,
2556 final int height
, final int gridColumns
, final int gridRows
) {
2558 return new TTableWidget(this, x
, y
, width
, height
, gridColumns
,
2563 * Convenience function to add a panel to this container/window.
2565 * @param x column relative to parent
2566 * @param y row relative to parent
2567 * @param width width of text area
2568 * @param height height of text area
2569 * @return the new panel
2571 public final TPanel
addPanel(final int x
, final int y
, final int width
,
2574 return new TPanel(this, x
, y
, width
, height
);
2578 * Convenience function to add a split pane to this container/window.
2580 * @param x column relative to parent
2581 * @param y row relative to parent
2582 * @param width width of text area
2583 * @param height height of text area
2584 * @param vertical if true, split vertically
2585 * @return the new split pane
2587 public final TSplitPane
addSplitPane(final int x
, final int y
,
2588 final int width
, final int height
, final boolean vertical
) {
2590 return new TSplitPane(this, x
, y
, width
, height
, vertical
);