Commit | Line | Data |
---|---|---|
daa4106c | 1 | /* |
48e27807 KL |
2 | * Jexer - Java Text User Interface |
3 | * | |
e16dda65 | 4 | * The MIT License (MIT) |
48e27807 | 5 | * |
a69ed767 | 6 | * Copyright (C) 2019 Kevin Lamonte |
48e27807 | 7 | * |
e16dda65 KL |
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: | |
48e27807 | 14 | * |
e16dda65 KL |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
48e27807 | 17 | * |
e16dda65 KL |
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. | |
48e27807 KL |
25 | * |
26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
27 | * @version 1 | |
28 | */ | |
29 | package jexer; | |
30 | ||
382bc294 | 31 | import java.awt.image.BufferedImage; |
0d47c546 | 32 | import java.io.IOException; |
48e27807 | 33 | import java.util.List; |
2ce6dab2 | 34 | import java.util.ArrayList; |
48e27807 | 35 | |
42873e30 | 36 | import jexer.backend.Screen; |
a69ed767 KL |
37 | import jexer.bits.Cell; |
38 | import jexer.bits.CellAttributes; | |
928811d8 | 39 | import jexer.bits.ColorTheme; |
48e27807 KL |
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; | |
d8dc8aea | 46 | import jexer.layout.LayoutManager; |
928811d8 | 47 | import jexer.menu.TMenu; |
d36057df KL |
48 | import jexer.ttree.TTreeItem; |
49 | import jexer.ttree.TTreeView; | |
50 | import jexer.ttree.TTreeViewWidget; | |
48e27807 KL |
51 | import static jexer.TKeypress.*; |
52 | ||
53 | /** | |
54 | * TWidget is the base class of all objects that can be drawn on screen or | |
55 | * handle user input events. | |
56 | */ | |
2b9c27db | 57 | public abstract class TWidget implements Comparable<TWidget> { |
48e27807 | 58 | |
2ce6dab2 | 59 | // ------------------------------------------------------------------------ |
d36057df | 60 | // Variables -------------------------------------------------------------- |
2ce6dab2 KL |
61 | // ------------------------------------------------------------------------ |
62 | ||
48e27807 KL |
63 | /** |
64 | * Every widget has a parent widget that it may be "contained" in. For | |
051e2913 KL |
65 | * example, a TWindow might contain several TFields, or a TComboBox may |
66 | * contain a TList that itself contains a TVScroller. | |
48e27807 | 67 | */ |
fca67db0 KL |
68 | private TWidget parent = null; |
69 | ||
48e27807 KL |
70 | /** |
71 | * Child widgets that this widget contains. | |
72 | */ | |
73 | private List<TWidget> children; | |
74 | ||
75 | /** | |
76 | * The currently active child widget that will receive keypress events. | |
77 | */ | |
78 | private TWidget activeChild = null; | |
79 | ||
80 | /** | |
81 | * If true, this widget will receive events. | |
82 | */ | |
fca67db0 KL |
83 | private boolean active = false; |
84 | ||
48e27807 KL |
85 | /** |
86 | * The window that this widget draws to. | |
87 | */ | |
fca67db0 | 88 | private TWindow window = null; |
48e27807 KL |
89 | |
90 | /** | |
91 | * Absolute X position of the top-left corner. | |
92 | */ | |
fca67db0 KL |
93 | private int x = 0; |
94 | ||
95 | /** | |
d36057df | 96 | * Absolute Y position of the top-left corner. |
fca67db0 | 97 | */ |
d36057df | 98 | private int y = 0; |
fca67db0 KL |
99 | |
100 | /** | |
d36057df | 101 | * Width. |
fca67db0 | 102 | */ |
d36057df | 103 | private int width = 0; |
48e27807 KL |
104 | |
105 | /** | |
d36057df | 106 | * Height. |
48e27807 | 107 | */ |
d36057df | 108 | private int height = 0; |
fca67db0 KL |
109 | |
110 | /** | |
d36057df | 111 | * My tab order inside a window or containing widget. |
fca67db0 | 112 | */ |
d36057df | 113 | private int tabOrder = 0; |
fca67db0 KL |
114 | |
115 | /** | |
d36057df | 116 | * If true, this widget can be tabbed to or receive events. |
fca67db0 | 117 | */ |
d36057df | 118 | private boolean enabled = true; |
48e27807 | 119 | |
051e2913 KL |
120 | /** |
121 | * If true, this widget will be rendered. | |
122 | */ | |
123 | private boolean visible = true; | |
124 | ||
48e27807 | 125 | /** |
d36057df | 126 | * If true, this widget has a cursor. |
48e27807 | 127 | */ |
d36057df | 128 | private boolean cursorVisible = false; |
fca67db0 KL |
129 | |
130 | /** | |
d36057df | 131 | * Cursor column position in relative coordinates. |
fca67db0 | 132 | */ |
d36057df | 133 | private int cursorX = 0; |
fca67db0 KL |
134 | |
135 | /** | |
d36057df | 136 | * Cursor row position in relative coordinates. |
fca67db0 | 137 | */ |
d36057df | 138 | private int cursorY = 0; |
48e27807 | 139 | |
d8dc8aea KL |
140 | /** |
141 | * Layout manager. | |
142 | */ | |
143 | private LayoutManager layout = null; | |
144 | ||
d36057df KL |
145 | // ------------------------------------------------------------------------ |
146 | // Constructors ----------------------------------------------------------- | |
147 | // ------------------------------------------------------------------------ | |
fca67db0 KL |
148 | |
149 | /** | |
d36057df | 150 | * Default constructor for subclasses. |
fca67db0 | 151 | */ |
d36057df KL |
152 | protected TWidget() { |
153 | children = new ArrayList<TWidget>(); | |
fca67db0 KL |
154 | } |
155 | ||
156 | /** | |
d36057df | 157 | * Protected constructor. |
fca67db0 | 158 | * |
d36057df | 159 | * @param parent parent widget |
fca67db0 | 160 | */ |
d36057df KL |
161 | protected TWidget(final TWidget parent) { |
162 | this(parent, true); | |
fca67db0 | 163 | } |
48e27807 | 164 | |
0ee88b6d | 165 | /** |
d36057df | 166 | * Protected constructor. |
0ee88b6d | 167 | * |
d36057df KL |
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 | |
0ee88b6d | 173 | */ |
d36057df KL |
174 | protected TWidget(final TWidget parent, final int x, final int y, |
175 | final int width, final int height) { | |
0ee88b6d | 176 | |
d36057df | 177 | this(parent, true, x, y, width, height); |
0ee88b6d KL |
178 | } |
179 | ||
48e27807 | 180 | /** |
d36057df | 181 | * Protected constructor used by subclasses that are disabled by default. |
48e27807 | 182 | * |
d36057df KL |
183 | * @param parent parent widget |
184 | * @param enabled if true assume enabled | |
48e27807 | 185 | */ |
d36057df KL |
186 | protected TWidget(final TWidget parent, final boolean enabled) { |
187 | this.enabled = enabled; | |
188 | this.parent = parent; | |
d36057df KL |
189 | children = new ArrayList<TWidget>(); |
190 | ||
5218e73c KL |
191 | if (parent != null) { |
192 | this.window = parent.window; | |
d36057df KL |
193 | parent.addChild(this); |
194 | } | |
48e27807 KL |
195 | } |
196 | ||
197 | /** | |
d36057df | 198 | * Protected constructor used by subclasses that are disabled by default. |
48e27807 | 199 | * |
d36057df KL |
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 | |
48e27807 | 206 | */ |
d36057df KL |
207 | protected TWidget(final TWidget parent, final boolean enabled, |
208 | final int x, final int y, final int width, final int height) { | |
209 | ||
5d26b504 KL |
210 | if (width < 0) { |
211 | throw new IllegalArgumentException("width cannot be negative"); | |
212 | } | |
213 | if (height < 0) { | |
214 | throw new IllegalArgumentException("height cannot be negative"); | |
215 | } | |
216 | ||
48e27807 | 217 | this.enabled = enabled; |
d36057df | 218 | this.parent = parent; |
d36057df KL |
219 | children = new ArrayList<TWidget>(); |
220 | ||
d36057df KL |
221 | this.x = x; |
222 | this.y = y; | |
223 | this.width = width; | |
224 | this.height = height; | |
d8dc8aea KL |
225 | |
226 | if (parent != null) { | |
227 | this.window = parent.window; | |
228 | parent.addChild(this); | |
229 | } | |
d36057df | 230 | } |
48e27807 | 231 | |
7272e49f | 232 | /** |
d36057df | 233 | * Backdoor access for TWindow's constructor. ONLY TWindow USES THIS. |
7272e49f | 234 | * |
d36057df KL |
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 | |
7272e49f | 240 | */ |
d36057df KL |
241 | protected final void setupForTWindow(final TWindow window, |
242 | final int x, final int y, final int width, final int height) { | |
243 | ||
5d26b504 KL |
244 | if (width < 0) { |
245 | throw new IllegalArgumentException("width cannot be negative"); | |
246 | } | |
247 | if (height < 0) { | |
248 | throw new IllegalArgumentException("height cannot be negative"); | |
249 | } | |
250 | ||
d36057df KL |
251 | this.parent = window; |
252 | this.window = window; | |
253 | this.x = x; | |
254 | this.y = y; | |
255 | this.width = width; | |
256 | this.height = height; | |
7272e49f KL |
257 | } |
258 | ||
d36057df KL |
259 | // ------------------------------------------------------------------------ |
260 | // Event handlers --------------------------------------------------------- | |
261 | // ------------------------------------------------------------------------ | |
262 | ||
a69ed767 KL |
263 | /** |
264 | * Subclasses should override this method to cleanup resources. This is | |
265 | * called by TWindow.onClose(). | |
266 | */ | |
267 | protected void close() { | |
268 | // Default: call close() on children. | |
269 | for (TWidget w: getChildren()) { | |
270 | w.close(); | |
271 | } | |
272 | } | |
273 | ||
a06459bd | 274 | /** |
d36057df KL |
275 | * Check if a mouse press/release event coordinate is contained in this |
276 | * widget. | |
a06459bd | 277 | * |
d36057df KL |
278 | * @param mouse a mouse-based event |
279 | * @return whether or not a mouse click would be sent to this widget | |
a06459bd | 280 | */ |
d36057df KL |
281 | public final boolean mouseWouldHit(final TMouseEvent mouse) { |
282 | ||
283 | if (!enabled) { | |
24489803 KL |
284 | return false; |
285 | } | |
286 | ||
d36057df KL |
287 | if ((this instanceof TTreeItem) |
288 | && ((y < 0) || (y > parent.getHeight() - 1)) | |
24489803 KL |
289 | ) { |
290 | return false; | |
291 | } | |
a06459bd | 292 | |
d36057df KL |
293 | if ((mouse.getAbsoluteX() >= getAbsoluteX()) |
294 | && (mouse.getAbsoluteX() < getAbsoluteX() + width) | |
295 | && (mouse.getAbsoluteY() >= getAbsoluteY()) | |
296 | && (mouse.getAbsoluteY() < getAbsoluteY() + height) | |
297 | ) { | |
298 | return true; | |
299 | } | |
300 | return false; | |
301 | } | |
48e27807 | 302 | |
7272e49f | 303 | /** |
d36057df | 304 | * Method that subclasses can override to handle keystrokes. |
7272e49f | 305 | * |
d36057df | 306 | * @param keypress keystroke event |
7272e49f | 307 | */ |
d36057df | 308 | public void onKeypress(final TKeypressEvent keypress) { |
5218e73c | 309 | assert (parent != null); |
d36057df KL |
310 | |
311 | if ((children.size() == 0) | |
312 | || (this instanceof TTreeView) | |
313 | || (this instanceof TText) | |
a69ed767 | 314 | || (this instanceof TComboBox) |
d36057df KL |
315 | ) { |
316 | ||
317 | // Defaults: | |
318 | // tab / shift-tab - switch to next/previous widget | |
319 | // left-arrow or up-arrow: same as shift-tab | |
320 | if ((keypress.equals(kbTab)) | |
a69ed767 | 321 | || (keypress.equals(kbDown) && !(this instanceof TComboBox)) |
d36057df KL |
322 | ) { |
323 | parent.switchWidget(true); | |
324 | return; | |
325 | } else if ((keypress.equals(kbShiftTab)) | |
326 | || (keypress.equals(kbBackTab)) | |
a69ed767 | 327 | || (keypress.equals(kbUp) && !(this instanceof TComboBox)) |
d36057df KL |
328 | ) { |
329 | parent.switchWidget(false); | |
330 | return; | |
331 | } | |
332 | } | |
333 | ||
334 | if ((children.size() == 0) | |
335 | && !(this instanceof TTreeView) | |
336 | ) { | |
337 | ||
338 | // Defaults: | |
339 | // right-arrow or down-arrow: same as tab | |
340 | if (keypress.equals(kbRight)) { | |
341 | parent.switchWidget(true); | |
342 | return; | |
343 | } else if (keypress.equals(kbLeft)) { | |
344 | parent.switchWidget(false); | |
345 | return; | |
346 | } | |
347 | } | |
348 | ||
349 | // If I have any buttons on me AND this is an Alt-key that matches | |
00691e80 | 350 | // its mnemonic, send it an Enter keystroke. |
d36057df KL |
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())) | |
360 | ) { | |
361 | ||
362 | widget.onKeypress(new TKeypressEvent(kbEnter)); | |
363 | return; | |
364 | } | |
365 | } | |
366 | } | |
367 | ||
00691e80 KL |
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())) | |
378 | ) { | |
379 | ||
380 | label.dispatch(); | |
381 | return; | |
382 | } | |
383 | } | |
384 | } | |
385 | ||
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())) | |
397 | ) { | |
398 | activate(widget); | |
399 | widget.onKeypress(new TKeypressEvent(kbSpace)); | |
400 | return; | |
401 | } | |
402 | } | |
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())) | |
413 | ) { | |
414 | activate(widget); | |
415 | widget.activate(child); | |
416 | child.onKeypress(new TKeypressEvent(kbSpace)); | |
417 | return; | |
418 | } | |
419 | } | |
420 | } | |
421 | } | |
422 | } | |
423 | ||
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())) | |
435 | ) { | |
436 | activate(checkBox); | |
437 | checkBox.setChecked(true); | |
438 | return; | |
439 | } | |
440 | } | |
441 | } | |
442 | ||
d36057df KL |
443 | // Dispatch the keypress to an active widget |
444 | for (TWidget widget: children) { | |
445 | if (widget.active) { | |
446 | widget.onKeypress(keypress); | |
447 | return; | |
448 | } | |
449 | } | |
7272e49f KL |
450 | } |
451 | ||
452 | /** | |
d36057df | 453 | * Method that subclasses can override to handle mouse button presses. |
7272e49f | 454 | * |
d36057df | 455 | * @param mouse mouse button event |
7272e49f | 456 | */ |
d36057df KL |
457 | public void onMouseDown(final TMouseEvent mouse) { |
458 | // Default: do nothing, pass to children instead | |
a69ed767 KL |
459 | if (activeChild != null) { |
460 | if (activeChild.mouseWouldHit(mouse)) { | |
461 | // Dispatch to the active child | |
462 | ||
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); | |
467 | return; | |
468 | } | |
469 | } | |
d36057df KL |
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 | |
474 | activate(widget); | |
7272e49f | 475 | |
d36057df KL |
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); | |
480 | return; | |
481 | } | |
482 | } | |
483 | } | |
48e27807 | 484 | |
7272e49f | 485 | /** |
d36057df | 486 | * Method that subclasses can override to handle mouse button releases. |
7272e49f | 487 | * |
d36057df | 488 | * @param mouse mouse button event |
7272e49f | 489 | */ |
d36057df KL |
490 | public void onMouseUp(final TMouseEvent mouse) { |
491 | // Default: do nothing, pass to children instead | |
a69ed767 KL |
492 | if (activeChild != null) { |
493 | if (activeChild.mouseWouldHit(mouse)) { | |
494 | // Dispatch to the active child | |
495 | ||
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); | |
500 | return; | |
501 | } | |
502 | } | |
d36057df KL |
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 | |
507 | activate(widget); | |
508 | ||
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); | |
513 | return; | |
514 | } | |
515 | } | |
7272e49f KL |
516 | } |
517 | ||
518 | /** | |
d36057df | 519 | * Method that subclasses can override to handle mouse movements. |
7272e49f | 520 | * |
d36057df | 521 | * @param mouse mouse motion event |
7272e49f | 522 | */ |
d36057df KL |
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); | |
531 | } | |
7272e49f KL |
532 | } |
533 | ||
2ce6dab2 | 534 | /** |
d36057df KL |
535 | * Method that subclasses can override to handle mouse button |
536 | * double-clicks. | |
2ce6dab2 | 537 | * |
d36057df | 538 | * @param mouse mouse button event |
2ce6dab2 | 539 | */ |
d36057df KL |
540 | public void onMouseDoubleClick(final TMouseEvent mouse) { |
541 | // Default: do nothing, pass to children instead | |
a69ed767 KL |
542 | if (activeChild != null) { |
543 | if (activeChild.mouseWouldHit(mouse)) { | |
544 | // Dispatch to the active child | |
545 | ||
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); | |
550 | return; | |
551 | } | |
552 | } | |
d36057df KL |
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 | |
557 | activate(widget); | |
558 | ||
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); | |
563 | return; | |
564 | } | |
565 | } | |
2ce6dab2 KL |
566 | } |
567 | ||
568 | /** | |
d36057df KL |
569 | * Method that subclasses can override to handle window/screen resize |
570 | * events. | |
2ce6dab2 | 571 | * |
d36057df | 572 | * @param resize resize event |
2ce6dab2 | 573 | */ |
d36057df KL |
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(); | |
d8dc8aea | 579 | if (layout != null) { |
fc2af494 KL |
580 | if (this instanceof TWindow) { |
581 | layout.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, | |
582 | width - 2, height - 2)); | |
583 | } else { | |
584 | layout.onResize(resize); | |
585 | } | |
d8dc8aea | 586 | } |
d36057df KL |
587 | } else { |
588 | // Let children see the screen resize | |
589 | for (TWidget widget: children) { | |
590 | widget.onResize(resize); | |
591 | } | |
592 | } | |
2ce6dab2 KL |
593 | } |
594 | ||
48e27807 | 595 | /** |
d36057df | 596 | * Method that subclasses can override to handle posted command events. |
7668cb45 | 597 | * |
d36057df | 598 | * @param command command event |
2b9c27db | 599 | */ |
d36057df KL |
600 | public void onCommand(final TCommandEvent command) { |
601 | // Default: do nothing, pass to children instead | |
602 | for (TWidget widget: children) { | |
603 | widget.onCommand(command); | |
7668cb45 | 604 | } |
48e27807 KL |
605 | } |
606 | ||
607 | /** | |
d36057df KL |
608 | * Method that subclasses can override to handle menu or posted menu |
609 | * events. | |
48e27807 | 610 | * |
d36057df | 611 | * @param menu menu event |
48e27807 | 612 | */ |
d36057df KL |
613 | public void onMenu(final TMenuEvent menu) { |
614 | // Default: do nothing, pass to children instead | |
615 | for (TWidget widget: children) { | |
616 | widget.onMenu(menu); | |
48e27807 | 617 | } |
48e27807 KL |
618 | } |
619 | ||
620 | /** | |
d36057df KL |
621 | * Method that subclasses can override to do processing when the UI is |
622 | * idle. Note that repainting is NOT assumed. To get a refresh after | |
623 | * onIdle, call doRepaint(). | |
48e27807 | 624 | */ |
d36057df KL |
625 | public void onIdle() { |
626 | // Default: do nothing, pass to children instead | |
627 | for (TWidget widget: children) { | |
628 | widget.onIdle(); | |
629 | } | |
48e27807 KL |
630 | } |
631 | ||
632 | /** | |
d36057df KL |
633 | * Consume event. Subclasses that want to intercept all events in one go |
634 | * can override this method. | |
48e27807 | 635 | * |
d36057df | 636 | * @param event keyboard, mouse, resize, command, or menu event |
48e27807 | 637 | */ |
d36057df KL |
638 | public void handleEvent(final TInputEvent event) { |
639 | /* | |
640 | System.err.printf("TWidget (%s) event: %s\n", this.getClass().getName(), | |
641 | event); | |
642 | */ | |
643 | ||
644 | if (!enabled) { | |
645 | // Discard event | |
646 | // System.err.println(" -- discard --"); | |
647 | return; | |
648 | } | |
649 | ||
650 | if (event instanceof TKeypressEvent) { | |
651 | onKeypress((TKeypressEvent) event); | |
652 | } else if (event instanceof TMouseEvent) { | |
653 | ||
654 | TMouseEvent mouse = (TMouseEvent) event; | |
655 | ||
656 | switch (mouse.getType()) { | |
657 | ||
658 | case MOUSE_DOWN: | |
659 | onMouseDown(mouse); | |
660 | break; | |
661 | ||
662 | case MOUSE_UP: | |
663 | onMouseUp(mouse); | |
664 | break; | |
665 | ||
666 | case MOUSE_MOTION: | |
667 | onMouseMotion(mouse); | |
668 | break; | |
669 | ||
670 | case MOUSE_DOUBLE_CLICK: | |
671 | onMouseDoubleClick(mouse); | |
672 | break; | |
673 | ||
674 | default: | |
675 | throw new IllegalArgumentException("Invalid mouse event type: " | |
676 | + mouse.getType()); | |
677 | } | |
678 | } else if (event instanceof TResizeEvent) { | |
679 | onResize((TResizeEvent) event); | |
680 | } else if (event instanceof TCommandEvent) { | |
681 | onCommand((TCommandEvent) event); | |
682 | } else if (event instanceof TMenuEvent) { | |
683 | onMenu((TMenuEvent) event); | |
684 | } | |
685 | ||
686 | // Do nothing else | |
687 | return; | |
48e27807 KL |
688 | } |
689 | ||
d36057df KL |
690 | // ------------------------------------------------------------------------ |
691 | // TWidget ---------------------------------------------------------------- | |
692 | // ------------------------------------------------------------------------ | |
693 | ||
48e27807 | 694 | /** |
d36057df | 695 | * Get parent widget. |
48e27807 | 696 | * |
d36057df | 697 | * @return parent widget |
48e27807 | 698 | */ |
d36057df KL |
699 | public final TWidget getParent() { |
700 | return parent; | |
48e27807 KL |
701 | } |
702 | ||
703 | /** | |
d36057df | 704 | * Get the list of child widgets that this widget contains. |
48e27807 | 705 | * |
d36057df | 706 | * @return the list of child widgets |
48e27807 | 707 | */ |
d36057df KL |
708 | public List<TWidget> getChildren() { |
709 | return children; | |
48e27807 KL |
710 | } |
711 | ||
5218e73c KL |
712 | /** |
713 | * Remove this widget from its parent container. close() will be called | |
714 | * before it is removed. | |
715 | */ | |
716 | public final void remove() { | |
717 | remove(true); | |
718 | } | |
719 | ||
720 | /** | |
721 | * Remove this widget from its parent container. | |
722 | * | |
723 | * @param doClose if true, call the close() method before removing the | |
724 | * child | |
725 | */ | |
726 | public final void remove(final boolean doClose) { | |
727 | if (parent != null) { | |
728 | parent.remove(this, doClose); | |
729 | } | |
730 | } | |
731 | ||
5ffeabcc KL |
732 | /** |
733 | * Remove a child widget from this container. | |
734 | * | |
735 | * @param child the child widget to remove | |
736 | */ | |
737 | public final void remove(final TWidget child) { | |
738 | remove(child, true); | |
739 | } | |
740 | ||
5218e73c KL |
741 | /** |
742 | * Remove a child widget from this container. | |
743 | * | |
744 | * @param child the child widget to remove | |
745 | * @param doClose if true, call the close() method before removing the | |
746 | * child | |
747 | */ | |
748 | public final void remove(final TWidget child, final boolean doClose) { | |
749 | if (!children.contains(child)) { | |
750 | throw new IndexOutOfBoundsException("child widget is not in " + | |
751 | "list of children of this parent"); | |
752 | } | |
753 | if (doClose) { | |
754 | child.close(); | |
755 | } | |
756 | children.remove(child); | |
757 | child.parent = null; | |
5ffeabcc | 758 | child.window = null; |
d8dc8aea KL |
759 | if (layout != null) { |
760 | layout.remove(this); | |
761 | } | |
5218e73c KL |
762 | } |
763 | ||
764 | /** | |
765 | * Set this widget's parent to a different widget. | |
766 | * | |
767 | * @param newParent new parent widget | |
768 | * @param doClose if true, call the close() method before removing the | |
769 | * child from its existing parent widget | |
770 | */ | |
771 | public final void setParent(final TWidget newParent, | |
772 | final boolean doClose) { | |
773 | ||
774 | if (parent != null) { | |
775 | parent.remove(this, doClose); | |
5ffeabcc | 776 | window = null; |
5218e73c KL |
777 | } |
778 | assert (parent == null); | |
5ffeabcc KL |
779 | assert (window == null); |
780 | parent = newParent; | |
781 | setWindow(parent.window); | |
782 | parent.addChild(this); | |
5218e73c KL |
783 | } |
784 | ||
785 | /** | |
5ffeabcc KL |
786 | * Set this widget's window to a specific window. |
787 | * | |
788 | * Having a null parent with a specified window is only used within Jexer | |
789 | * by TStatusBar because TApplication routes events directly to it and | |
790 | * calls its draw() method. Any other non-parented widgets will require | |
791 | * similar special case functionality to receive events or be drawn to | |
792 | * screen. | |
5218e73c KL |
793 | * |
794 | * @param window the window to use | |
795 | */ | |
796 | public final void setWindow(final TWindow window) { | |
5218e73c | 797 | this.window = window; |
5ffeabcc KL |
798 | for (TWidget child: getChildren()) { |
799 | child.setWindow(window); | |
800 | } | |
5218e73c KL |
801 | } |
802 | ||
803 | /** | |
804 | * Remove a child widget from this container, and all of its children | |
805 | * recursively from their parent containers. | |
806 | * | |
807 | * @param child the child widget to remove | |
808 | * @param doClose if true, call the close() method before removing each | |
809 | * child | |
810 | */ | |
811 | public final void removeAll(final TWidget child, final boolean doClose) { | |
812 | remove(child, doClose); | |
813 | for (TWidget w: child.children) { | |
814 | child.removeAll(w, doClose); | |
815 | } | |
816 | } | |
817 | ||
928811d8 | 818 | /** |
d36057df | 819 | * Get active flag. |
928811d8 | 820 | * |
d36057df | 821 | * @return if true, this widget will receive events |
928811d8 | 822 | */ |
d36057df KL |
823 | public final boolean isActive() { |
824 | return active; | |
928811d8 KL |
825 | } |
826 | ||
48e27807 | 827 | /** |
d36057df KL |
828 | * Set active flag. |
829 | * | |
830 | * @param active if true, this widget will receive events | |
48e27807 | 831 | */ |
d36057df KL |
832 | public final void setActive(final boolean active) { |
833 | this.active = active; | |
48e27807 KL |
834 | } |
835 | ||
836 | /** | |
d36057df KL |
837 | * Get the window this widget is on. |
838 | * | |
839 | * @return the window | |
48e27807 | 840 | */ |
d36057df KL |
841 | public final TWindow getWindow() { |
842 | return window; | |
48e27807 KL |
843 | } |
844 | ||
be72cb5c | 845 | /** |
d36057df KL |
846 | * Get X position. |
847 | * | |
848 | * @return absolute X position of the top-left corner | |
be72cb5c | 849 | */ |
d36057df KL |
850 | public final int getX() { |
851 | return x; | |
be72cb5c KL |
852 | } |
853 | ||
48e27807 | 854 | /** |
d36057df KL |
855 | * Set X position. |
856 | * | |
857 | * @param x absolute X position of the top-left corner | |
48e27807 | 858 | */ |
d36057df KL |
859 | public final void setX(final int x) { |
860 | this.x = x; | |
48e27807 KL |
861 | } |
862 | ||
863 | /** | |
d36057df | 864 | * Get Y position. |
48e27807 | 865 | * |
d36057df | 866 | * @return absolute Y position of the top-left corner |
48e27807 | 867 | */ |
d36057df KL |
868 | public final int getY() { |
869 | return y; | |
30d336cc KL |
870 | } |
871 | ||
a83fea2b | 872 | /** |
d36057df | 873 | * Set Y position. |
a83fea2b | 874 | * |
d36057df | 875 | * @param y absolute Y position of the top-left corner |
a83fea2b | 876 | */ |
d36057df KL |
877 | public final void setY(final int y) { |
878 | this.y = y; | |
a83fea2b KL |
879 | } |
880 | ||
30d336cc | 881 | /** |
d36057df | 882 | * Get the width. |
30d336cc | 883 | * |
d36057df | 884 | * @return widget width |
30d336cc | 885 | */ |
d8dc8aea | 886 | public int getWidth() { |
d36057df | 887 | return this.width; |
48e27807 KL |
888 | } |
889 | ||
a83fea2b | 890 | /** |
d36057df | 891 | * Change the width. |
a83fea2b | 892 | * |
d36057df | 893 | * @param width new widget width |
a83fea2b | 894 | */ |
d8dc8aea | 895 | public void setWidth(final int width) { |
a83fea2b | 896 | this.width = width; |
d8dc8aea KL |
897 | if (layout != null) { |
898 | layout.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, | |
899 | width, height)); | |
900 | } | |
a83fea2b KL |
901 | } |
902 | ||
2ce6dab2 | 903 | /** |
d36057df | 904 | * Get the height. |
2ce6dab2 | 905 | * |
d36057df | 906 | * @return widget height |
2ce6dab2 | 907 | */ |
d8dc8aea | 908 | public int getHeight() { |
d36057df KL |
909 | return this.height; |
910 | } | |
2ce6dab2 | 911 | |
d36057df KL |
912 | /** |
913 | * Change the height. | |
914 | * | |
915 | * @param height new widget height | |
916 | */ | |
d8dc8aea | 917 | public void setHeight(final int height) { |
2ce6dab2 | 918 | this.height = height; |
d8dc8aea KL |
919 | if (layout != null) { |
920 | layout.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, | |
921 | width, height)); | |
922 | } | |
2ce6dab2 KL |
923 | } |
924 | ||
48e27807 | 925 | /** |
d36057df | 926 | * Change the dimensions. |
48e27807 | 927 | * |
d36057df KL |
928 | * @param x absolute X position of the top-left corner |
929 | * @param y absolute Y position of the top-left corner | |
930 | * @param width new widget width | |
931 | * @param height new widget height | |
48e27807 | 932 | */ |
d36057df KL |
933 | public final void setDimensions(final int x, final int y, final int width, |
934 | final int height) { | |
48e27807 | 935 | |
d36057df KL |
936 | setX(x); |
937 | setY(y); | |
938 | setWidth(width); | |
939 | setHeight(height); | |
d8dc8aea KL |
940 | if (layout != null) { |
941 | layout.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, | |
942 | width, height)); | |
943 | } | |
944 | } | |
945 | ||
946 | /** | |
947 | * Get the layout manager. | |
948 | * | |
949 | * @return the layout manager, or null if not set | |
950 | */ | |
951 | public LayoutManager getLayoutManager() { | |
952 | return layout; | |
953 | } | |
954 | ||
955 | /** | |
956 | * Set the layout manager. | |
957 | * | |
958 | * @param layout the new layout manager | |
959 | */ | |
960 | public void setLayoutManager(LayoutManager layout) { | |
961 | if (this.layout != null) { | |
962 | for (TWidget w: children) { | |
963 | this.layout.remove(w); | |
964 | } | |
965 | this.layout = null; | |
966 | } | |
967 | this.layout = layout; | |
968 | if (this.layout != null) { | |
969 | for (TWidget w: children) { | |
970 | this.layout.add(w); | |
971 | } | |
972 | } | |
48e27807 KL |
973 | } |
974 | ||
975 | /** | |
d36057df | 976 | * Get enabled flag. |
48e27807 | 977 | * |
d36057df | 978 | * @return if true, this widget can be tabbed to or receive events |
48e27807 | 979 | */ |
d36057df KL |
980 | public final boolean isEnabled() { |
981 | return enabled; | |
982 | } | |
48e27807 | 983 | |
d36057df KL |
984 | /** |
985 | * Set enabled flag. | |
986 | * | |
987 | * @param enabled if true, this widget can be tabbed to or receive events | |
988 | */ | |
989 | public final void setEnabled(final boolean enabled) { | |
990 | this.enabled = enabled; | |
991 | if (!enabled) { | |
992 | active = false; | |
993 | // See if there are any active siblings to switch to | |
994 | boolean foundSibling = false; | |
995 | if (parent != null) { | |
996 | for (TWidget w: parent.children) { | |
997 | if ((w.enabled) | |
998 | && !(this instanceof THScroller) | |
999 | && !(this instanceof TVScroller) | |
1000 | ) { | |
1001 | parent.activate(w); | |
1002 | foundSibling = true; | |
1003 | break; | |
1004 | } | |
1005 | } | |
1006 | if (!foundSibling) { | |
1007 | parent.activeChild = null; | |
1008 | } | |
48e27807 | 1009 | } |
48e27807 KL |
1010 | } |
1011 | } | |
1012 | ||
051e2913 KL |
1013 | /** |
1014 | * Set visible flag. | |
1015 | * | |
1016 | * @param visible if true, this widget will be drawn | |
1017 | */ | |
1018 | public final void setVisible(final boolean visible) { | |
1019 | this.visible = visible; | |
1020 | } | |
1021 | ||
1022 | /** | |
1023 | * See if this widget is visible. | |
1024 | * | |
1025 | * @return if true, this widget will be drawn | |
1026 | */ | |
1027 | public final boolean isVisible() { | |
1028 | return visible; | |
1029 | } | |
1030 | ||
48e27807 | 1031 | /** |
d36057df | 1032 | * Set visible cursor flag. |
48e27807 | 1033 | * |
d36057df | 1034 | * @param cursorVisible if true, this widget has a cursor |
48e27807 | 1035 | */ |
d36057df KL |
1036 | public final void setCursorVisible(final boolean cursorVisible) { |
1037 | this.cursorVisible = cursorVisible; | |
48e27807 KL |
1038 | } |
1039 | ||
1040 | /** | |
d36057df | 1041 | * See if this widget has a visible cursor. |
48e27807 | 1042 | * |
d36057df | 1043 | * @return if true, this widget has a visible cursor |
48e27807 | 1044 | */ |
d36057df KL |
1045 | public final boolean isCursorVisible() { |
1046 | // If cursor is out of my bounds, it is not visible. | |
1047 | if ((cursorX >= width) | |
1048 | || (cursorX < 0) | |
1049 | || (cursorY >= height) | |
1050 | || (cursorY < 0) | |
1051 | ) { | |
1052 | return false; | |
1053 | } | |
48e27807 | 1054 | |
5218e73c KL |
1055 | assert (window != null); |
1056 | ||
2bc32111 KL |
1057 | if (window instanceof TDesktop) { |
1058 | // Desktop doesn't have a window border. | |
1059 | return cursorVisible; | |
1060 | } | |
1061 | ||
d36057df KL |
1062 | // If cursor is out of my window's bounds, it is not visible. |
1063 | if ((getCursorAbsoluteX() >= window.getAbsoluteX() | |
1064 | + window.getWidth() - 1) | |
1065 | || (getCursorAbsoluteX() < 0) | |
1066 | || (getCursorAbsoluteY() >= window.getAbsoluteY() | |
1067 | + window.getHeight() - 1) | |
1068 | || (getCursorAbsoluteY() < 0) | |
1069 | ) { | |
1070 | return false; | |
48e27807 | 1071 | } |
d36057df KL |
1072 | return cursorVisible; |
1073 | } | |
48e27807 | 1074 | |
d36057df KL |
1075 | /** |
1076 | * Get cursor X value. | |
1077 | * | |
1078 | * @return cursor column position in relative coordinates | |
1079 | */ | |
1080 | public final int getCursorX() { | |
1081 | return cursorX; | |
1082 | } | |
48e27807 | 1083 | |
d36057df KL |
1084 | /** |
1085 | * Set cursor X value. | |
1086 | * | |
1087 | * @param cursorX column position in relative coordinates | |
1088 | */ | |
1089 | public final void setCursorX(final int cursorX) { | |
1090 | this.cursorX = cursorX; | |
1091 | } | |
48e27807 | 1092 | |
d36057df KL |
1093 | /** |
1094 | * Get cursor Y value. | |
1095 | * | |
1096 | * @return cursor row position in relative coordinates | |
1097 | */ | |
1098 | public final int getCursorY() { | |
1099 | return cursorY; | |
1100 | } | |
48e27807 | 1101 | |
d36057df KL |
1102 | /** |
1103 | * Set cursor Y value. | |
1104 | * | |
1105 | * @param cursorY row position in relative coordinates | |
1106 | */ | |
1107 | public final void setCursorY(final int cursorY) { | |
1108 | this.cursorY = cursorY; | |
1109 | } | |
48e27807 | 1110 | |
d36057df KL |
1111 | /** |
1112 | * Get this TWidget's parent TApplication. | |
1113 | * | |
c7a75ad3 | 1114 | * @return the parent TApplication, or null if not assigned |
d36057df KL |
1115 | */ |
1116 | public TApplication getApplication() { | |
c7a75ad3 KL |
1117 | if (window != null) { |
1118 | return window.getApplication(); | |
1119 | } | |
1120 | return null; | |
d36057df | 1121 | } |
48e27807 | 1122 | |
d36057df KL |
1123 | /** |
1124 | * Get the Screen. | |
1125 | * | |
c7a75ad3 | 1126 | * @return the Screen, or null if not assigned |
d36057df KL |
1127 | */ |
1128 | public Screen getScreen() { | |
c7a75ad3 KL |
1129 | if (window != null) { |
1130 | return window.getScreen(); | |
1131 | } | |
1132 | return null; | |
48e27807 KL |
1133 | } |
1134 | ||
1135 | /** | |
d36057df KL |
1136 | * Comparison operator. For various subclasses it sorts on: |
1137 | * <ul> | |
1138 | * <li>tabOrder for TWidgets</li> | |
1139 | * <li>z for TWindows</li> | |
1140 | * <li>text for TTreeItems</li> | |
1141 | * </ul> | |
48e27807 | 1142 | * |
d36057df KL |
1143 | * @param that another TWidget, TWindow, or TTreeItem instance |
1144 | * @return difference between this.tabOrder and that.tabOrder, or | |
1145 | * difference between this.z and that.z, or String.compareTo(text) | |
48e27807 | 1146 | */ |
d36057df KL |
1147 | public final int compareTo(final TWidget that) { |
1148 | if ((this instanceof TWindow) | |
1149 | && (that instanceof TWindow) | |
48e27807 | 1150 | ) { |
d36057df KL |
1151 | return (((TWindow) this).getZ() - ((TWindow) that).getZ()); |
1152 | } | |
1153 | if ((this instanceof TTreeItem) | |
1154 | && (that instanceof TTreeItem) | |
1155 | ) { | |
1156 | return (((TTreeItem) this).getText().compareTo( | |
1157 | ((TTreeItem) that).getText())); | |
48e27807 | 1158 | } |
d36057df KL |
1159 | return (this.tabOrder - that.tabOrder); |
1160 | } | |
48e27807 | 1161 | |
d36057df KL |
1162 | /** |
1163 | * See if this widget should render with the active color. | |
1164 | * | |
1165 | * @return true if this widget is active and all of its parents are | |
1166 | * active. | |
1167 | */ | |
1168 | public final boolean isAbsoluteActive() { | |
1169 | if (parent == this) { | |
1170 | return active; | |
48e27807 | 1171 | } |
5218e73c | 1172 | return (active && (parent == null ? true : parent.isAbsoluteActive())); |
48e27807 KL |
1173 | } |
1174 | ||
d36057df KL |
1175 | /** |
1176 | * Returns the cursor X position. | |
1177 | * | |
1178 | * @return absolute screen column number for the cursor's X position | |
1179 | */ | |
1180 | public final int getCursorAbsoluteX() { | |
1181 | return getAbsoluteX() + cursorX; | |
1182 | } | |
2ce6dab2 KL |
1183 | |
1184 | /** | |
d36057df | 1185 | * Returns the cursor Y position. |
2ce6dab2 | 1186 | * |
d36057df | 1187 | * @return absolute screen row number for the cursor's Y position |
2ce6dab2 | 1188 | */ |
d36057df KL |
1189 | public final int getCursorAbsoluteY() { |
1190 | return getAbsoluteY() + cursorY; | |
1191 | } | |
2ce6dab2 | 1192 | |
d36057df KL |
1193 | /** |
1194 | * Compute my absolute X position as the sum of my X plus all my parent's | |
1195 | * X's. | |
1196 | * | |
1197 | * @return absolute screen column number for my X position | |
1198 | */ | |
1199 | public final int getAbsoluteX() { | |
1200 | assert (parent != null); | |
1201 | if (parent == this) { | |
1202 | return x; | |
2ce6dab2 | 1203 | } |
d36057df KL |
1204 | if ((parent instanceof TWindow) |
1205 | && !(parent instanceof TMenu) | |
1206 | && !(parent instanceof TDesktop) | |
1207 | ) { | |
1208 | // Widgets on a TWindow have (0,0) as their top-left, but this is | |
1209 | // actually the TWindow's (1,1). | |
1210 | return parent.getAbsoluteX() + x + 1; | |
1211 | } | |
1212 | return parent.getAbsoluteX() + x; | |
1213 | } | |
2ce6dab2 | 1214 | |
d36057df KL |
1215 | /** |
1216 | * Compute my absolute Y position as the sum of my Y plus all my parent's | |
1217 | * Y's. | |
1218 | * | |
1219 | * @return absolute screen row number for my Y position | |
1220 | */ | |
1221 | public final int getAbsoluteY() { | |
1222 | assert (parent != null); | |
1223 | if (parent == this) { | |
1224 | return y; | |
1225 | } | |
1226 | if ((parent instanceof TWindow) | |
1227 | && !(parent instanceof TMenu) | |
1228 | && !(parent instanceof TDesktop) | |
2ce6dab2 | 1229 | ) { |
d36057df KL |
1230 | // Widgets on a TWindow have (0,0) as their top-left, but this is |
1231 | // actually the TWindow's (1,1). | |
1232 | return parent.getAbsoluteY() + y + 1; | |
2ce6dab2 | 1233 | } |
d36057df | 1234 | return parent.getAbsoluteY() + y; |
2ce6dab2 KL |
1235 | } |
1236 | ||
48e27807 | 1237 | /** |
d36057df | 1238 | * Get the global color theme. |
48e27807 | 1239 | * |
d36057df | 1240 | * @return the ColorTheme |
48e27807 | 1241 | */ |
a69ed767 | 1242 | protected final ColorTheme getTheme() { |
d36057df KL |
1243 | return window.getApplication().getTheme(); |
1244 | } | |
48e27807 | 1245 | |
d36057df KL |
1246 | /** |
1247 | * Draw my specific widget. When called, the screen rectangle I draw | |
1248 | * into is already setup (offset and clipping). | |
1249 | */ | |
1250 | public void draw() { | |
1251 | // Default widget draws nothing. | |
1252 | } | |
48e27807 | 1253 | |
d36057df | 1254 | /** |
a69ed767 | 1255 | * Called by parent to render to TWindow. Note package private access. |
d36057df | 1256 | */ |
a69ed767 | 1257 | final void drawChildren() { |
2bc32111 KL |
1258 | if (window == null) { |
1259 | return; | |
1260 | } | |
1261 | ||
d36057df KL |
1262 | // Set my clipping rectangle |
1263 | assert (window != null); | |
1264 | assert (getScreen() != null); | |
1265 | Screen screen = getScreen(); | |
1266 | ||
1267 | // Special case: TStatusBar is drawn by TApplication, not anything | |
1268 | // else. | |
1269 | if (this instanceof TStatusBar) { | |
1270 | return; | |
48e27807 KL |
1271 | } |
1272 | ||
d36057df KL |
1273 | screen.setClipRight(width); |
1274 | screen.setClipBottom(height); | |
92554d64 | 1275 | |
d36057df KL |
1276 | int absoluteRightEdge = window.getAbsoluteX() + window.getWidth(); |
1277 | int absoluteBottomEdge = window.getAbsoluteY() + window.getHeight(); | |
2bc32111 KL |
1278 | if (!(this instanceof TWindow) |
1279 | && !(this instanceof TVScroller) | |
a524aa2e | 1280 | && !(window instanceof TDesktop) |
2bc32111 | 1281 | ) { |
d36057df KL |
1282 | absoluteRightEdge -= 1; |
1283 | } | |
2bc32111 KL |
1284 | if (!(this instanceof TWindow) |
1285 | && !(this instanceof THScroller) | |
a524aa2e | 1286 | && !(window instanceof TDesktop) |
2bc32111 | 1287 | ) { |
d36057df | 1288 | absoluteBottomEdge -= 1; |
48e27807 | 1289 | } |
d36057df KL |
1290 | int myRightEdge = getAbsoluteX() + width; |
1291 | int myBottomEdge = getAbsoluteY() + height; | |
1292 | if (getAbsoluteX() > absoluteRightEdge) { | |
1293 | // I am offscreen | |
1294 | screen.setClipRight(0); | |
1295 | } else if (myRightEdge > absoluteRightEdge) { | |
1296 | screen.setClipRight(screen.getClipRight() | |
1297 | - (myRightEdge - absoluteRightEdge)); | |
1298 | } | |
1299 | if (getAbsoluteY() > absoluteBottomEdge) { | |
1300 | // I am offscreen | |
1301 | screen.setClipBottom(0); | |
1302 | } else if (myBottomEdge > absoluteBottomEdge) { | |
1303 | screen.setClipBottom(screen.getClipBottom() | |
1304 | - (myBottomEdge - absoluteBottomEdge)); | |
1305 | } | |
1306 | ||
1307 | // Set my offset | |
1308 | screen.setOffsetX(getAbsoluteX()); | |
1309 | screen.setOffsetY(getAbsoluteY()); | |
48e27807 | 1310 | |
d36057df KL |
1311 | // Draw me |
1312 | draw(); | |
11cedc9a | 1313 | assert (visible == true); |
d36057df | 1314 | |
a69ed767 KL |
1315 | // Continue down the chain. Draw the active child last so that it |
1316 | // is on top. | |
48e27807 | 1317 | for (TWidget widget: children) { |
a69ed767 | 1318 | if (widget.isVisible() && (widget != activeChild)) { |
051e2913 KL |
1319 | widget.drawChildren(); |
1320 | } | |
48e27807 | 1321 | } |
a69ed767 KL |
1322 | if (activeChild != null) { |
1323 | activeChild.drawChildren(); | |
1324 | } | |
48e27807 KL |
1325 | } |
1326 | ||
1327 | /** | |
d36057df | 1328 | * Repaint the screen on the next update. |
48e27807 | 1329 | */ |
a69ed767 | 1330 | protected final void doRepaint() { |
d36057df | 1331 | window.getApplication().doRepaint(); |
48e27807 KL |
1332 | } |
1333 | ||
1334 | /** | |
d36057df KL |
1335 | * Add a child widget to my list of children. We set its tabOrder to 0 |
1336 | * and increment the tabOrder of all other children. | |
48e27807 | 1337 | * |
d36057df | 1338 | * @param child TWidget to add |
48e27807 | 1339 | */ |
d36057df KL |
1340 | private void addChild(final TWidget child) { |
1341 | children.add(child); | |
48e27807 | 1342 | |
d36057df KL |
1343 | if ((child.enabled) |
1344 | && !(child instanceof THScroller) | |
1345 | && !(child instanceof TVScroller) | |
1346 | ) { | |
1347 | for (TWidget widget: children) { | |
1348 | widget.active = false; | |
48e27807 | 1349 | } |
d36057df KL |
1350 | child.active = true; |
1351 | activeChild = child; | |
48e27807 | 1352 | } |
d36057df KL |
1353 | for (int i = 0; i < children.size(); i++) { |
1354 | children.get(i).tabOrder = i; | |
48e27807 | 1355 | } |
d8dc8aea KL |
1356 | if (layout != null) { |
1357 | layout.add(child); | |
1358 | } | |
48e27807 KL |
1359 | } |
1360 | ||
00691e80 KL |
1361 | /** |
1362 | * Reset the tab order of children to match their position in the list. | |
1363 | * Available so that subclasses can re-order their widgets if needed. | |
1364 | */ | |
1365 | protected void resetTabOrder() { | |
1366 | for (int i = 0; i < children.size(); i++) { | |
1367 | children.get(i).tabOrder = i; | |
1368 | } | |
1369 | } | |
1370 | ||
b6faeac0 | 1371 | /** |
d36057df | 1372 | * Switch the active child. |
b6faeac0 | 1373 | * |
d36057df | 1374 | * @param child TWidget to activate |
b6faeac0 | 1375 | */ |
d36057df KL |
1376 | public final void activate(final TWidget child) { |
1377 | assert (child.enabled); | |
1378 | if ((child instanceof THScroller) | |
1379 | || (child instanceof TVScroller) | |
1380 | ) { | |
1381 | return; | |
b6faeac0 | 1382 | } |
b6faeac0 | 1383 | |
e23ea538 KL |
1384 | if (children.size() == 1) { |
1385 | if (children.get(0).enabled == true) { | |
1386 | child.active = true; | |
1387 | activeChild = child; | |
1388 | } | |
1389 | } else { | |
1390 | if (child != activeChild) { | |
1391 | if (activeChild != null) { | |
1392 | activeChild.active = false; | |
1393 | } | |
1394 | child.active = true; | |
1395 | activeChild = child; | |
12b55d76 | 1396 | } |
48e27807 KL |
1397 | } |
1398 | } | |
1399 | ||
1400 | /** | |
d36057df | 1401 | * Switch the active child. |
48e27807 | 1402 | * |
d36057df KL |
1403 | * @param tabOrder tabOrder of the child to activate. If that child |
1404 | * isn't enabled, then the next enabled child will be activated. | |
48e27807 | 1405 | */ |
d36057df | 1406 | public final void activate(final int tabOrder) { |
e23ea538 KL |
1407 | if (children.size() == 1) { |
1408 | if (children.get(0).enabled == true) { | |
1409 | children.get(0).active = true; | |
1410 | activeChild = children.get(0); | |
1411 | } | |
1412 | return; | |
1413 | } | |
1414 | ||
d36057df | 1415 | TWidget child = null; |
48e27807 | 1416 | for (TWidget widget: children) { |
d36057df KL |
1417 | if ((widget.enabled) |
1418 | && !(widget instanceof THScroller) | |
1419 | && !(widget instanceof TVScroller) | |
1420 | && (widget.tabOrder >= tabOrder) | |
1421 | ) { | |
1422 | child = widget; | |
1423 | break; | |
1424 | } | |
48e27807 | 1425 | } |
d36057df | 1426 | if ((child != null) && (child != activeChild)) { |
00691e80 KL |
1427 | if (activeChild != null) { |
1428 | activeChild.active = false; | |
1429 | } | |
d36057df KL |
1430 | assert (child.enabled); |
1431 | child.active = true; | |
1432 | activeChild = child; | |
48e27807 KL |
1433 | } |
1434 | } | |
1435 | ||
5218e73c KL |
1436 | /** |
1437 | * Make this widget the active child of its parent. Note that this is | |
1438 | * not final since TWindow overrides activate(). | |
1439 | */ | |
1440 | public void activate() { | |
1441 | if (enabled) { | |
1442 | if (parent != null) { | |
1443 | parent.activate(this); | |
1444 | } | |
1445 | } | |
1446 | } | |
1447 | ||
48e27807 | 1448 | /** |
d36057df | 1449 | * Switch the active widget with the next in the tab order. |
48e27807 | 1450 | * |
d36057df KL |
1451 | * @param forward if true, then switch to the next enabled widget in the |
1452 | * list, otherwise switch to the previous enabled widget in the list | |
48e27807 | 1453 | */ |
d36057df | 1454 | public final void switchWidget(final boolean forward) { |
48e27807 | 1455 | |
e23ea538 | 1456 | // No children: do nothing. |
00691e80 | 1457 | if (children.size() == 0) { |
e23ea538 KL |
1458 | return; |
1459 | } | |
1460 | ||
5218e73c KL |
1461 | assert (parent != null); |
1462 | ||
e23ea538 KL |
1463 | // If there is only one child, make it active if it is enabled. |
1464 | if (children.size() == 1) { | |
1465 | if (children.get(0).enabled == true) { | |
1466 | activeChild = children.get(0); | |
1467 | activeChild.active = true; | |
1468 | } else { | |
1469 | children.get(0).active = false; | |
1470 | activeChild = null; | |
1471 | } | |
48e27807 KL |
1472 | return; |
1473 | } | |
1474 | ||
e23ea538 KL |
1475 | // Two or more children: go forward or backward to the next enabled |
1476 | // child. | |
00691e80 KL |
1477 | int tabOrder = 0; |
1478 | if (activeChild != null) { | |
1479 | tabOrder = activeChild.tabOrder; | |
1480 | } | |
d36057df KL |
1481 | do { |
1482 | if (forward) { | |
1483 | tabOrder++; | |
1484 | } else { | |
1485 | tabOrder--; | |
1486 | } | |
1487 | if (tabOrder < 0) { | |
48e27807 | 1488 | |
d36057df KL |
1489 | // If at the end, pass the switch to my parent. |
1490 | if ((!forward) && (parent != this)) { | |
1491 | parent.switchWidget(forward); | |
1492 | return; | |
1493 | } | |
48e27807 | 1494 | |
d36057df KL |
1495 | tabOrder = children.size() - 1; |
1496 | } else if (tabOrder == children.size()) { | |
1497 | // If at the end, pass the switch to my parent. | |
1498 | if ((forward) && (parent != this)) { | |
1499 | parent.switchWidget(forward); | |
1500 | return; | |
1501 | } | |
48e27807 | 1502 | |
d36057df KL |
1503 | tabOrder = 0; |
1504 | } | |
00691e80 KL |
1505 | if (activeChild == null) { |
1506 | if (tabOrder == 0) { | |
1507 | // We wrapped around | |
1508 | break; | |
1509 | } | |
1510 | } else if (activeChild.tabOrder == tabOrder) { | |
d36057df | 1511 | // We wrapped around |
48e27807 | 1512 | break; |
d36057df KL |
1513 | } |
1514 | } while ((!children.get(tabOrder).enabled) | |
1515 | && !(children.get(tabOrder) instanceof THScroller) | |
1516 | && !(children.get(tabOrder) instanceof TVScroller)); | |
48e27807 | 1517 | |
00691e80 KL |
1518 | if (activeChild != null) { |
1519 | assert (children.get(tabOrder).enabled); | |
48e27807 | 1520 | |
00691e80 KL |
1521 | activeChild.active = false; |
1522 | } | |
1523 | if (children.get(tabOrder).enabled == true) { | |
1524 | children.get(tabOrder).active = true; | |
1525 | activeChild = children.get(tabOrder); | |
1526 | } | |
d36057df | 1527 | } |
48e27807 | 1528 | |
d36057df KL |
1529 | /** |
1530 | * Returns my active widget. | |
1531 | * | |
1532 | * @return widget that is active, or this if no children | |
1533 | */ | |
1534 | public TWidget getActiveChild() { | |
1535 | if ((this instanceof THScroller) | |
1536 | || (this instanceof TVScroller) | |
1537 | ) { | |
1538 | return parent; | |
1539 | } | |
b6faeac0 | 1540 | |
d36057df KL |
1541 | for (TWidget widget: children) { |
1542 | if (widget.active) { | |
1543 | return widget.getActiveChild(); | |
48e27807 | 1544 | } |
48e27807 | 1545 | } |
d36057df KL |
1546 | // No active children, return me |
1547 | return this; | |
48e27807 KL |
1548 | } |
1549 | ||
469c2b3c | 1550 | /** |
a524aa2e KL |
1551 | * Insert a vertical split between this widget and parent, and optionally |
1552 | * put another widget in the other side of the split. | |
469c2b3c KL |
1553 | * |
1554 | * @param newWidgetOnLeft if true, the new widget (if specified) will be | |
a524aa2e | 1555 | * on the left pane, and this widget will be placed on the right pane |
469c2b3c KL |
1556 | * @param newWidget the new widget to add to the other pane, or null |
1557 | * @return the new split pane widget | |
1558 | */ | |
1559 | public TSplitPane splitVertical(final boolean newWidgetOnLeft, | |
1560 | final TWidget newWidget) { | |
1561 | ||
469c2b3c KL |
1562 | TSplitPane splitPane = new TSplitPane(null, x, y, width, height, true); |
1563 | List<TWidget> widgets = new ArrayList<TWidget>(children); | |
a524aa2e KL |
1564 | TWidget myParent = parent; |
1565 | remove(false); | |
1566 | splitPane.setParent(myParent, false); | |
469c2b3c KL |
1567 | if (newWidgetOnLeft) { |
1568 | splitPane.setLeft(newWidget); | |
a524aa2e | 1569 | splitPane.setRight(this); |
469c2b3c KL |
1570 | } else { |
1571 | splitPane.setRight(newWidget); | |
a524aa2e | 1572 | splitPane.setLeft(this); |
469c2b3c | 1573 | } |
a524aa2e KL |
1574 | splitPane.activate(); |
1575 | if (newWidget != null) { | |
1576 | newWidget.activate(); | |
1577 | } else { | |
1578 | activate(); | |
1579 | } | |
1580 | assert (parent != null); | |
1581 | assert (window != null); | |
469c2b3c KL |
1582 | for (TWidget w: widgets) { |
1583 | assert (w.window != null); | |
1584 | assert (w.parent != null); | |
1585 | } | |
1586 | assert (splitPane.getWindow() != null); | |
1587 | assert (splitPane.getParent() != null); | |
469c2b3c | 1588 | assert (splitPane.isActive() == true); |
469c2b3c KL |
1589 | return splitPane; |
1590 | } | |
1591 | ||
1592 | /** | |
a524aa2e KL |
1593 | * Insert a horizontal split between this widget and parent, and |
1594 | * optionally put another widget in the other side of the split. | |
469c2b3c KL |
1595 | * |
1596 | * @param newWidgetOnTop if true, the new widget (if specified) will be | |
1597 | * on the top pane, and this widget's children will be placed on the | |
1598 | * bottom pane | |
1599 | * @param newWidget the new widget to add to the other pane, or null | |
1600 | * @return the new split pane widget | |
1601 | */ | |
1602 | public TSplitPane splitHorizontal(final boolean newWidgetOnTop, | |
1603 | final TWidget newWidget) { | |
1604 | ||
469c2b3c KL |
1605 | TSplitPane splitPane = new TSplitPane(null, x, y, width, height, false); |
1606 | List<TWidget> widgets = new ArrayList<TWidget>(children); | |
a524aa2e KL |
1607 | TWidget myParent = parent; |
1608 | remove(false); | |
1609 | splitPane.setParent(myParent, false); | |
469c2b3c KL |
1610 | if (newWidgetOnTop) { |
1611 | splitPane.setTop(newWidget); | |
a524aa2e | 1612 | splitPane.setBottom(this); |
469c2b3c KL |
1613 | } else { |
1614 | splitPane.setBottom(newWidget); | |
a524aa2e KL |
1615 | splitPane.setTop(this); |
1616 | } | |
1617 | splitPane.activate(); | |
1618 | if (newWidget != null) { | |
1619 | newWidget.activate(); | |
1620 | } else { | |
1621 | activate(); | |
469c2b3c | 1622 | } |
a524aa2e KL |
1623 | assert (parent != null); |
1624 | assert (window != null); | |
469c2b3c KL |
1625 | for (TWidget w: widgets) { |
1626 | assert (w.window != null); | |
1627 | assert (w.parent != null); | |
1628 | } | |
1629 | assert (splitPane.getWindow() != null); | |
1630 | assert (splitPane.getParent() != null); | |
469c2b3c | 1631 | assert (splitPane.isActive() == true); |
469c2b3c KL |
1632 | return splitPane; |
1633 | } | |
1634 | ||
a69ed767 KL |
1635 | // ------------------------------------------------------------------------ |
1636 | // Passthru for Screen functions ------------------------------------------ | |
1637 | // ------------------------------------------------------------------------ | |
1638 | ||
1639 | /** | |
1640 | * Get the attributes at one location. | |
1641 | * | |
1642 | * @param x column coordinate. 0 is the left-most column. | |
1643 | * @param y row coordinate. 0 is the top-most row. | |
1644 | * @return attributes at (x, y) | |
1645 | */ | |
1646 | protected final CellAttributes getAttrXY(final int x, final int y) { | |
1647 | return getScreen().getAttrXY(x, y); | |
1648 | } | |
1649 | ||
1650 | /** | |
1651 | * Set the attributes at one location. | |
1652 | * | |
1653 | * @param x column coordinate. 0 is the left-most column. | |
1654 | * @param y row coordinate. 0 is the top-most row. | |
1655 | * @param attr attributes to use (bold, foreColor, backColor) | |
1656 | */ | |
1657 | protected final void putAttrXY(final int x, final int y, | |
1658 | final CellAttributes attr) { | |
1659 | ||
1660 | getScreen().putAttrXY(x, y, attr); | |
1661 | } | |
1662 | ||
1663 | /** | |
1664 | * Set the attributes at one location. | |
1665 | * | |
1666 | * @param x column coordinate. 0 is the left-most column. | |
1667 | * @param y row coordinate. 0 is the top-most row. | |
1668 | * @param attr attributes to use (bold, foreColor, backColor) | |
1669 | * @param clip if true, honor clipping/offset | |
1670 | */ | |
1671 | protected final void putAttrXY(final int x, final int y, | |
1672 | final CellAttributes attr, final boolean clip) { | |
1673 | ||
1674 | getScreen().putAttrXY(x, y, attr, clip); | |
1675 | } | |
1676 | ||
1677 | /** | |
1678 | * Fill the entire screen with one character with attributes. | |
1679 | * | |
1680 | * @param ch character to draw | |
1681 | * @param attr attributes to use (bold, foreColor, backColor) | |
1682 | */ | |
218d18db | 1683 | protected final void putAll(final int ch, final CellAttributes attr) { |
a69ed767 KL |
1684 | getScreen().putAll(ch, attr); |
1685 | } | |
1686 | ||
1687 | /** | |
1688 | * Render one character with attributes. | |
1689 | * | |
1690 | * @param x column coordinate. 0 is the left-most column. | |
1691 | * @param y row coordinate. 0 is the top-most row. | |
1692 | * @param ch character + attributes to draw | |
1693 | */ | |
1694 | protected final void putCharXY(final int x, final int y, final Cell ch) { | |
1695 | getScreen().putCharXY(x, y, ch); | |
1696 | } | |
1697 | ||
1698 | /** | |
1699 | * Render one character with attributes. | |
1700 | * | |
1701 | * @param x column coordinate. 0 is the left-most column. | |
1702 | * @param y row coordinate. 0 is the top-most row. | |
1703 | * @param ch character to draw | |
1704 | * @param attr attributes to use (bold, foreColor, backColor) | |
1705 | */ | |
218d18db | 1706 | protected final void putCharXY(final int x, final int y, final int ch, |
a69ed767 KL |
1707 | final CellAttributes attr) { |
1708 | ||
1709 | getScreen().putCharXY(x, y, ch, attr); | |
1710 | } | |
1711 | ||
1712 | /** | |
1713 | * Render one character without changing the underlying attributes. | |
1714 | * | |
1715 | * @param x column coordinate. 0 is the left-most column. | |
1716 | * @param y row coordinate. 0 is the top-most row. | |
1717 | * @param ch character to draw | |
1718 | */ | |
218d18db | 1719 | protected final void putCharXY(final int x, final int y, final int ch) { |
a69ed767 KL |
1720 | getScreen().putCharXY(x, y, ch); |
1721 | } | |
1722 | ||
1723 | /** | |
1724 | * Render a string. Does not wrap if the string exceeds the line. | |
1725 | * | |
1726 | * @param x column coordinate. 0 is the left-most column. | |
1727 | * @param y row coordinate. 0 is the top-most row. | |
1728 | * @param str string to draw | |
1729 | * @param attr attributes to use (bold, foreColor, backColor) | |
1730 | */ | |
1731 | protected final void putStringXY(final int x, final int y, final String str, | |
1732 | final CellAttributes attr) { | |
1733 | ||
1734 | getScreen().putStringXY(x, y, str, attr); | |
1735 | } | |
1736 | ||
1737 | /** | |
1738 | * Render a string without changing the underlying attribute. Does not | |
1739 | * wrap if the string exceeds the line. | |
1740 | * | |
1741 | * @param x column coordinate. 0 is the left-most column. | |
1742 | * @param y row coordinate. 0 is the top-most row. | |
1743 | * @param str string to draw | |
1744 | */ | |
1745 | protected final void putStringXY(final int x, final int y, final String str) { | |
1746 | getScreen().putStringXY(x, y, str); | |
1747 | } | |
1748 | ||
1749 | /** | |
1750 | * Draw a vertical line from (x, y) to (x, y + n). | |
1751 | * | |
1752 | * @param x column coordinate. 0 is the left-most column. | |
1753 | * @param y row coordinate. 0 is the top-most row. | |
1754 | * @param n number of characters to draw | |
1755 | * @param ch character to draw | |
1756 | * @param attr attributes to use (bold, foreColor, backColor) | |
1757 | */ | |
1758 | protected final void vLineXY(final int x, final int y, final int n, | |
218d18db | 1759 | final int ch, final CellAttributes attr) { |
a69ed767 KL |
1760 | |
1761 | getScreen().vLineXY(x, y, n, ch, attr); | |
1762 | } | |
1763 | ||
1764 | /** | |
1765 | * Draw a horizontal line from (x, y) to (x + n, y). | |
1766 | * | |
1767 | * @param x column coordinate. 0 is the left-most column. | |
1768 | * @param y row coordinate. 0 is the top-most row. | |
1769 | * @param n number of characters to draw | |
1770 | * @param ch character to draw | |
1771 | * @param attr attributes to use (bold, foreColor, backColor) | |
1772 | */ | |
1773 | protected final void hLineXY(final int x, final int y, final int n, | |
218d18db | 1774 | final int ch, final CellAttributes attr) { |
a69ed767 KL |
1775 | |
1776 | getScreen().hLineXY(x, y, n, ch, attr); | |
1777 | } | |
1778 | ||
1779 | /** | |
1780 | * Draw a box with a border and empty background. | |
1781 | * | |
1782 | * @param left left column of box. 0 is the left-most row. | |
1783 | * @param top top row of the box. 0 is the top-most row. | |
1784 | * @param right right column of box | |
1785 | * @param bottom bottom row of the box | |
1786 | * @param border attributes to use for the border | |
1787 | * @param background attributes to use for the background | |
1788 | */ | |
1789 | protected final void drawBox(final int left, final int top, | |
1790 | final int right, final int bottom, | |
1791 | final CellAttributes border, final CellAttributes background) { | |
1792 | ||
1793 | getScreen().drawBox(left, top, right, bottom, border, background); | |
1794 | } | |
1795 | ||
1796 | /** | |
1797 | * Draw a box with a border and empty background. | |
1798 | * | |
1799 | * @param left left column of box. 0 is the left-most row. | |
1800 | * @param top top row of the box. 0 is the top-most row. | |
1801 | * @param right right column of box | |
1802 | * @param bottom bottom row of the box | |
1803 | * @param border attributes to use for the border | |
1804 | * @param background attributes to use for the background | |
1805 | * @param borderType if 1, draw a single-line border; if 2, draw a | |
1806 | * double-line border; if 3, draw double-line top/bottom edges and | |
1807 | * single-line left/right edges (like Qmodem) | |
1808 | * @param shadow if true, draw a "shadow" on the box | |
1809 | */ | |
1810 | protected final void drawBox(final int left, final int top, | |
1811 | final int right, final int bottom, | |
1812 | final CellAttributes border, final CellAttributes background, | |
1813 | final int borderType, final boolean shadow) { | |
1814 | ||
1815 | getScreen().drawBox(left, top, right, bottom, border, background, | |
1816 | borderType, shadow); | |
1817 | } | |
1818 | ||
1819 | /** | |
1820 | * Draw a box shadow. | |
1821 | * | |
1822 | * @param left left column of box. 0 is the left-most row. | |
1823 | * @param top top row of the box. 0 is the top-most row. | |
1824 | * @param right right column of box | |
1825 | * @param bottom bottom row of the box | |
1826 | */ | |
1827 | protected final void drawBoxShadow(final int left, final int top, | |
1828 | final int right, final int bottom) { | |
1829 | ||
1830 | getScreen().drawBoxShadow(left, top, right, bottom); | |
1831 | } | |
1832 | ||
2ce6dab2 KL |
1833 | // ------------------------------------------------------------------------ |
1834 | // Other TWidget constructors --------------------------------------------- | |
1835 | // ------------------------------------------------------------------------ | |
48e27807 | 1836 | |
30d336cc KL |
1837 | /** |
1838 | * Convenience function to add a label to this container/window. | |
1839 | * | |
1840 | * @param text label | |
1841 | * @param x column relative to parent | |
1842 | * @param y row relative to parent | |
1843 | * @return the new label | |
1844 | */ | |
1845 | public final TLabel addLabel(final String text, final int x, final int y) { | |
1846 | return addLabel(text, x, y, "tlabel"); | |
1847 | } | |
1848 | ||
00691e80 KL |
1849 | /** |
1850 | * Convenience function to add a label to this container/window. | |
1851 | * | |
1852 | * @param text label | |
1853 | * @param x column relative to parent | |
1854 | * @param y row relative to parent | |
1855 | * @param action to call when shortcut is pressed | |
1856 | * @return the new label | |
1857 | */ | |
1858 | public final TLabel addLabel(final String text, final int x, final int y, | |
1859 | final TAction action) { | |
1860 | ||
1861 | return addLabel(text, x, y, "tlabel", action); | |
1862 | } | |
1863 | ||
30d336cc KL |
1864 | /** |
1865 | * Convenience function to add a label to this container/window. | |
1866 | * | |
1867 | * @param text label | |
1868 | * @param x column relative to parent | |
1869 | * @param y row relative to parent | |
1870 | * @param colorKey ColorTheme key color to use for foreground text. | |
1871 | * Default is "tlabel" | |
1872 | * @return the new label | |
1873 | */ | |
1874 | public final TLabel addLabel(final String text, final int x, final int y, | |
1875 | final String colorKey) { | |
1876 | ||
1877 | return new TLabel(this, text, x, y, colorKey); | |
1878 | } | |
1879 | ||
00691e80 KL |
1880 | /** |
1881 | * Convenience function to add a label to this container/window. | |
1882 | * | |
1883 | * @param text label | |
1884 | * @param x column relative to parent | |
1885 | * @param y row relative to parent | |
1886 | * @param colorKey ColorTheme key color to use for foreground text. | |
1887 | * Default is "tlabel" | |
1888 | * @param action to call when shortcut is pressed | |
1889 | * @return the new label | |
1890 | */ | |
1891 | public final TLabel addLabel(final String text, final int x, final int y, | |
1892 | final String colorKey, final TAction action) { | |
1893 | ||
1894 | return new TLabel(this, text, x, y, colorKey, action); | |
1895 | } | |
1896 | ||
051e2913 KL |
1897 | /** |
1898 | * Convenience function to add a label to this container/window. | |
1899 | * | |
1900 | * @param text label | |
1901 | * @param x column relative to parent | |
1902 | * @param y row relative to parent | |
1903 | * @param colorKey ColorTheme key color to use for foreground text. | |
1904 | * Default is "tlabel" | |
1905 | * @param useWindowBackground if true, use the window's background color | |
1906 | * @return the new label | |
1907 | */ | |
1908 | public final TLabel addLabel(final String text, final int x, final int y, | |
1909 | final String colorKey, final boolean useWindowBackground) { | |
1910 | ||
1911 | return new TLabel(this, text, x, y, colorKey, useWindowBackground); | |
1912 | } | |
1913 | ||
00691e80 KL |
1914 | /** |
1915 | * Convenience function to add a label to this container/window. | |
1916 | * | |
1917 | * @param text label | |
1918 | * @param x column relative to parent | |
1919 | * @param y row relative to parent | |
1920 | * @param colorKey ColorTheme key color to use for foreground text. | |
1921 | * Default is "tlabel" | |
1922 | * @param useWindowBackground if true, use the window's background color | |
1923 | * @param action to call when shortcut is pressed | |
1924 | * @return the new label | |
1925 | */ | |
1926 | public final TLabel addLabel(final String text, final int x, final int y, | |
1927 | final String colorKey, final boolean useWindowBackground, | |
1928 | final TAction action) { | |
1929 | ||
1930 | return new TLabel(this, text, x, y, colorKey, useWindowBackground, | |
1931 | action); | |
1932 | } | |
1933 | ||
30d336cc KL |
1934 | /** |
1935 | * Convenience function to add a button to this container/window. | |
1936 | * | |
1937 | * @param text label on the button | |
1938 | * @param x column relative to parent | |
1939 | * @param y row relative to parent | |
051e2913 | 1940 | * @param action action to call when button is pressed |
30d336cc KL |
1941 | * @return the new button |
1942 | */ | |
1943 | public final TButton addButton(final String text, final int x, final int y, | |
1944 | final TAction action) { | |
1945 | ||
1946 | return new TButton(this, text, x, y, action); | |
1947 | } | |
1948 | ||
7272e49f KL |
1949 | /** |
1950 | * Convenience function to add a checkbox to this container/window. | |
1951 | * | |
1952 | * @param x column relative to parent | |
1953 | * @param y row relative to parent | |
1954 | * @param label label to display next to (right of) the checkbox | |
1955 | * @param checked initial check state | |
1956 | * @return the new checkbox | |
1957 | */ | |
051e2913 | 1958 | public final TCheckBox addCheckBox(final int x, final int y, |
7272e49f KL |
1959 | final String label, final boolean checked) { |
1960 | ||
051e2913 KL |
1961 | return new TCheckBox(this, x, y, label, checked); |
1962 | } | |
1963 | ||
1964 | /** | |
1965 | * Convenience function to add a combobox to this container/window. | |
1966 | * | |
1967 | * @param x column relative to parent | |
1968 | * @param y row relative to parent | |
1969 | * @param width visible combobox width, including the down-arrow | |
1970 | * @param values the possible values for the box, shown in the drop-down | |
1971 | * @param valuesIndex the initial index in values, or -1 for no default | |
1972 | * value | |
8ab60a33 KL |
1973 | * @param maxValuesHeight the maximum height of the values drop-down when |
1974 | * it is visible | |
051e2913 KL |
1975 | * @param updateAction action to call when a new value is selected from |
1976 | * the list or enter is pressed in the edit field | |
1977 | * @return the new combobox | |
1978 | */ | |
1979 | public final TComboBox addComboBox(final int x, final int y, | |
1980 | final int width, final List<String> values, final int valuesIndex, | |
8ab60a33 | 1981 | final int maxValuesHeight, final TAction updateAction) { |
051e2913 KL |
1982 | |
1983 | return new TComboBox(this, x, y, width, values, valuesIndex, | |
8ab60a33 | 1984 | maxValuesHeight, updateAction); |
051e2913 KL |
1985 | } |
1986 | ||
1987 | /** | |
1988 | * Convenience function to add a spinner to this container/window. | |
1989 | * | |
1990 | * @param x column relative to parent | |
1991 | * @param y row relative to parent | |
1992 | * @param upAction action to call when the up arrow is clicked or pressed | |
1993 | * @param downAction action to call when the down arrow is clicked or | |
1994 | * pressed | |
1995 | * @return the new spinner | |
1996 | */ | |
1997 | public final TSpinner addSpinner(final int x, final int y, | |
1998 | final TAction upAction, final TAction downAction) { | |
1999 | ||
2000 | return new TSpinner(this, x, y, upAction, downAction); | |
2001 | } | |
2002 | ||
2003 | /** | |
2004 | * Convenience function to add a calendar to this container/window. | |
2005 | * | |
2006 | * @param x column relative to parent | |
2007 | * @param y row relative to parent | |
2008 | * @param updateAction action to call when the user changes the value of | |
2009 | * the calendar | |
2010 | * @return the new calendar | |
2011 | */ | |
2012 | public final TCalendar addCalendar(final int x, final int y, | |
2013 | final TAction updateAction) { | |
2014 | ||
2015 | return new TCalendar(this, x, y, updateAction); | |
7272e49f | 2016 | } |
30d336cc | 2017 | |
d502a0e9 KL |
2018 | /** |
2019 | * Convenience function to add a progress bar to this container/window. | |
2020 | * | |
2021 | * @param x column relative to parent | |
2022 | * @param y row relative to parent | |
2023 | * @param width width of progress bar | |
2024 | * @param value initial value of percent complete | |
00d2622b | 2025 | * @return the new progress bar |
d502a0e9 KL |
2026 | */ |
2027 | public final TProgressBar addProgressBar(final int x, final int y, | |
2028 | final int width, final int value) { | |
2029 | ||
2030 | return new TProgressBar(this, x, y, width, value); | |
2031 | } | |
2032 | ||
00d2622b KL |
2033 | /** |
2034 | * Convenience function to add a radio button group to this | |
2035 | * container/window. | |
2036 | * | |
2037 | * @param x column relative to parent | |
2038 | * @param y row relative to parent | |
2039 | * @param label label to display on the group box | |
2040 | * @return the new radio button group | |
2041 | */ | |
2042 | public final TRadioGroup addRadioGroup(final int x, final int y, | |
2043 | final String label) { | |
2044 | ||
2045 | return new TRadioGroup(this, x, y, label); | |
2046 | } | |
2047 | ||
128e5be1 KL |
2048 | /** |
2049 | * Convenience function to add a text field to this container/window. | |
2050 | * | |
2051 | * @param x column relative to parent | |
2052 | * @param y row relative to parent | |
2053 | * @param width visible text width | |
2054 | * @param fixed if true, the text cannot exceed the display width | |
2055 | * @return the new text field | |
2056 | */ | |
2057 | public final TField addField(final int x, final int y, | |
2058 | final int width, final boolean fixed) { | |
2059 | ||
2060 | return new TField(this, x, y, width, fixed); | |
2061 | } | |
2062 | ||
2063 | /** | |
2064 | * Convenience function to add a text field to this container/window. | |
2065 | * | |
2066 | * @param x column relative to parent | |
2067 | * @param y row relative to parent | |
2068 | * @param width visible text width | |
2069 | * @param fixed if true, the text cannot exceed the display width | |
2070 | * @param text initial text, default is empty string | |
2071 | * @return the new text field | |
2072 | */ | |
2073 | public final TField addField(final int x, final int y, | |
2074 | final int width, final boolean fixed, final String text) { | |
2075 | ||
2076 | return new TField(this, x, y, width, fixed, text); | |
2077 | } | |
2078 | ||
2079 | /** | |
2080 | * Convenience function to add a text field to this container/window. | |
2081 | * | |
2082 | * @param x column relative to parent | |
2083 | * @param y row relative to parent | |
2084 | * @param width visible text width | |
2085 | * @param fixed if true, the text cannot exceed the display width | |
2086 | * @param text initial text, default is empty string | |
2087 | * @param enterAction function to call when enter key is pressed | |
2088 | * @param updateAction function to call when the text is updated | |
2089 | * @return the new text field | |
2090 | */ | |
2091 | public final TField addField(final int x, final int y, | |
2092 | final int width, final boolean fixed, final String text, | |
2093 | final TAction enterAction, final TAction updateAction) { | |
2094 | ||
2095 | return new TField(this, x, y, width, fixed, text, enterAction, | |
2096 | updateAction); | |
2097 | } | |
00d2622b | 2098 | |
cc99cba8 KL |
2099 | /** |
2100 | * Convenience function to add a scrollable text box to this | |
2101 | * container/window. | |
2102 | * | |
2103 | * @param text text on the screen | |
2104 | * @param x column relative to parent | |
2105 | * @param y row relative to parent | |
2106 | * @param width width of text area | |
2107 | * @param height height of text area | |
2108 | * @param colorKey ColorTheme key color to use for foreground text | |
2109 | * @return the new text box | |
2110 | */ | |
c6940ed9 | 2111 | public final TText addText(final String text, final int x, |
cc99cba8 KL |
2112 | final int y, final int width, final int height, final String colorKey) { |
2113 | ||
2114 | return new TText(this, text, x, y, width, height, colorKey); | |
2115 | } | |
2116 | ||
2117 | /** | |
2118 | * Convenience function to add a scrollable text box to this | |
2119 | * container/window. | |
2120 | * | |
2121 | * @param text text on the screen | |
2122 | * @param x column relative to parent | |
2123 | * @param y row relative to parent | |
2124 | * @param width width of text area | |
2125 | * @param height height of text area | |
2126 | * @return the new text box | |
2127 | */ | |
c6940ed9 | 2128 | public final TText addText(final String text, final int x, final int y, |
cc99cba8 KL |
2129 | final int width, final int height) { |
2130 | ||
2131 | return new TText(this, text, x, y, width, height, "ttext"); | |
2132 | } | |
2133 | ||
12b55d76 KL |
2134 | /** |
2135 | * Convenience function to add an editable text area box to this | |
2136 | * container/window. | |
2137 | * | |
2138 | * @param text text on the screen | |
2139 | * @param x column relative to parent | |
2140 | * @param y row relative to parent | |
2141 | * @param width width of text area | |
2142 | * @param height height of text area | |
2143 | * @return the new text box | |
2144 | */ | |
2145 | public final TEditorWidget addEditor(final String text, final int x, | |
2146 | final int y, final int width, final int height) { | |
2147 | ||
2148 | return new TEditorWidget(this, text, x, y, width, height); | |
2149 | } | |
2150 | ||
c6940ed9 KL |
2151 | /** |
2152 | * Convenience function to spawn a message box. | |
2153 | * | |
2154 | * @param title window title, will be centered along the top border | |
2155 | * @param caption message to display. Use embedded newlines to get a | |
2156 | * multi-line box. | |
2157 | * @return the new message box | |
2158 | */ | |
2159 | public final TMessageBox messageBox(final String title, | |
2160 | final String caption) { | |
2161 | ||
2162 | return getApplication().messageBox(title, caption, TMessageBox.Type.OK); | |
2163 | } | |
2164 | ||
2165 | /** | |
2166 | * Convenience function to spawn a message box. | |
2167 | * | |
2168 | * @param title window title, will be centered along the top border | |
2169 | * @param caption message to display. Use embedded newlines to get a | |
2170 | * multi-line box. | |
2171 | * @param type one of the TMessageBox.Type constants. Default is | |
2172 | * Type.OK. | |
2173 | * @return the new message box | |
2174 | */ | |
2175 | public final TMessageBox messageBox(final String title, | |
2176 | final String caption, final TMessageBox.Type type) { | |
2177 | ||
2178 | return getApplication().messageBox(title, caption, type); | |
2179 | } | |
2180 | ||
2181 | /** | |
2182 | * Convenience function to spawn an input box. | |
2183 | * | |
2184 | * @param title window title, will be centered along the top border | |
2185 | * @param caption message to display. Use embedded newlines to get a | |
2186 | * multi-line box. | |
2187 | * @return the new input box | |
2188 | */ | |
2189 | public final TInputBox inputBox(final String title, final String caption) { | |
2190 | ||
2191 | return getApplication().inputBox(title, caption); | |
2192 | } | |
2193 | ||
2194 | /** | |
2195 | * Convenience function to spawn an input box. | |
2196 | * | |
2197 | * @param title window title, will be centered along the top border | |
2198 | * @param caption message to display. Use embedded newlines to get a | |
2199 | * multi-line box. | |
2200 | * @param text initial text to seed the field with | |
2201 | * @return the new input box | |
2202 | */ | |
2203 | public final TInputBox inputBox(final String title, final String caption, | |
2204 | final String text) { | |
2205 | ||
2206 | return getApplication().inputBox(title, caption, text); | |
2207 | } | |
cc99cba8 | 2208 | |
2b427404 KL |
2209 | /** |
2210 | * Convenience function to spawn an input box. | |
2211 | * | |
2212 | * @param title window title, will be centered along the top border | |
2213 | * @param caption message to display. Use embedded newlines to get a | |
2214 | * multi-line box. | |
2215 | * @param text initial text to seed the field with | |
2216 | * @param type one of the Type constants. Default is Type.OK. | |
2217 | * @return the new input box | |
2218 | */ | |
2219 | public final TInputBox inputBox(final String title, final String caption, | |
2220 | final String text, final TInputBox.Type type) { | |
2221 | ||
2222 | return getApplication().inputBox(title, caption, text, type); | |
2223 | } | |
2224 | ||
87a17f3c KL |
2225 | /** |
2226 | * Convenience function to add a password text field to this | |
2227 | * container/window. | |
2228 | * | |
2229 | * @param x column relative to parent | |
2230 | * @param y row relative to parent | |
2231 | * @param width visible text width | |
2232 | * @param fixed if true, the text cannot exceed the display width | |
2233 | * @return the new text field | |
2234 | */ | |
2235 | public final TPasswordField addPasswordField(final int x, final int y, | |
2236 | final int width, final boolean fixed) { | |
2237 | ||
2238 | return new TPasswordField(this, x, y, width, fixed); | |
2239 | } | |
2240 | ||
2241 | /** | |
2242 | * Convenience function to add a password text field to this | |
2243 | * container/window. | |
2244 | * | |
2245 | * @param x column relative to parent | |
2246 | * @param y row relative to parent | |
2247 | * @param width visible text width | |
2248 | * @param fixed if true, the text cannot exceed the display width | |
2249 | * @param text initial text, default is empty string | |
2250 | * @return the new text field | |
2251 | */ | |
2252 | public final TPasswordField addPasswordField(final int x, final int y, | |
2253 | final int width, final boolean fixed, final String text) { | |
2254 | ||
2255 | return new TPasswordField(this, x, y, width, fixed, text); | |
2256 | } | |
2257 | ||
2258 | /** | |
2259 | * Convenience function to add a password text field to this | |
2260 | * container/window. | |
2261 | * | |
2262 | * @param x column relative to parent | |
2263 | * @param y row relative to parent | |
2264 | * @param width visible text width | |
2265 | * @param fixed if true, the text cannot exceed the display width | |
2266 | * @param text initial text, default is empty string | |
2267 | * @param enterAction function to call when enter key is pressed | |
2268 | * @param updateAction function to call when the text is updated | |
2269 | * @return the new text field | |
2270 | */ | |
2271 | public final TPasswordField addPasswordField(final int x, final int y, | |
2272 | final int width, final boolean fixed, final String text, | |
2273 | final TAction enterAction, final TAction updateAction) { | |
2274 | ||
2275 | return new TPasswordField(this, x, y, width, fixed, text, enterAction, | |
2276 | updateAction); | |
2277 | } | |
2278 | ||
7668cb45 | 2279 | /** |
d36057df KL |
2280 | * Convenience function to add a scrollable tree view to this |
2281 | * container/window. | |
7668cb45 KL |
2282 | * |
2283 | * @param x column relative to parent | |
2284 | * @param y row relative to parent | |
2285 | * @param width width of tree view | |
2286 | * @param height height of tree view | |
329fd62e | 2287 | * @return the new tree view |
7668cb45 | 2288 | */ |
d36057df | 2289 | public final TTreeViewWidget addTreeViewWidget(final int x, final int y, |
7668cb45 KL |
2290 | final int width, final int height) { |
2291 | ||
d36057df | 2292 | return new TTreeViewWidget(this, x, y, width, height); |
7668cb45 KL |
2293 | } |
2294 | ||
2295 | /** | |
d36057df KL |
2296 | * Convenience function to add a scrollable tree view to this |
2297 | * container/window. | |
7668cb45 KL |
2298 | * |
2299 | * @param x column relative to parent | |
2300 | * @param y row relative to parent | |
2301 | * @param width width of tree view | |
2302 | * @param height height of tree view | |
2303 | * @param action action to perform when an item is selected | |
329fd62e | 2304 | * @return the new tree view |
7668cb45 | 2305 | */ |
d36057df | 2306 | public final TTreeViewWidget addTreeViewWidget(final int x, final int y, |
7668cb45 KL |
2307 | final int width, final int height, final TAction action) { |
2308 | ||
d36057df | 2309 | return new TTreeViewWidget(this, x, y, width, height, action); |
7668cb45 KL |
2310 | } |
2311 | ||
0d47c546 KL |
2312 | /** |
2313 | * Convenience function to spawn a file open box. | |
2314 | * | |
2315 | * @param path path of selected file | |
2316 | * @return the result of the new file open box | |
329fd62e | 2317 | * @throws IOException if a java.io operation throws |
0d47c546 KL |
2318 | */ |
2319 | public final String fileOpenBox(final String path) throws IOException { | |
2320 | return getApplication().fileOpenBox(path); | |
2321 | } | |
2322 | ||
a69ed767 KL |
2323 | /** |
2324 | * Convenience function to spawn a file save box. | |
2325 | * | |
2326 | * @param path path of selected file | |
2327 | * @return the result of the new file open box | |
2328 | * @throws IOException if a java.io operation throws | |
2329 | */ | |
2330 | public final String fileSaveBox(final String path) throws IOException { | |
2331 | return getApplication().fileOpenBox(path, TFileOpenBox.Type.SAVE); | |
2332 | } | |
2333 | ||
0d47c546 KL |
2334 | /** |
2335 | * Convenience function to spawn a file open box. | |
2336 | * | |
2337 | * @param path path of selected file | |
2338 | * @param type one of the Type constants | |
2339 | * @return the result of the new file open box | |
329fd62e | 2340 | * @throws IOException if a java.io operation throws |
0d47c546 KL |
2341 | */ |
2342 | public final String fileOpenBox(final String path, | |
2343 | final TFileOpenBox.Type type) throws IOException { | |
2344 | ||
2345 | return getApplication().fileOpenBox(path, type); | |
2346 | } | |
a69ed767 KL |
2347 | |
2348 | /** | |
2349 | * Convenience function to spawn a file open box. | |
2350 | * | |
2351 | * @param path path of selected file | |
2352 | * @param type one of the Type constants | |
2353 | * @param filter a string that files must match to be displayed | |
2354 | * @return the result of the new file open box | |
2355 | * @throws IOException of a java.io operation throws | |
2356 | */ | |
2357 | public final String fileOpenBox(final String path, | |
2358 | final TFileOpenBox.Type type, final String filter) throws IOException { | |
2359 | ||
2360 | ArrayList<String> filters = new ArrayList<String>(); | |
2361 | filters.add(filter); | |
2362 | ||
2363 | return getApplication().fileOpenBox(path, type, filters); | |
2364 | } | |
2365 | ||
2366 | /** | |
2367 | * Convenience function to spawn a file open box. | |
2368 | * | |
2369 | * @param path path of selected file | |
2370 | * @param type one of the Type constants | |
2371 | * @param filters a list of strings that files must match to be displayed | |
2372 | * @return the result of the new file open box | |
2373 | * @throws IOException of a java.io operation throws | |
2374 | */ | |
2375 | public final String fileOpenBox(final String path, | |
2376 | final TFileOpenBox.Type type, | |
2377 | final List<String> filters) throws IOException { | |
2378 | ||
2379 | return getApplication().fileOpenBox(path, type, filters); | |
2380 | } | |
2381 | ||
0d47c546 KL |
2382 | /** |
2383 | * Convenience function to add a directory list to this container/window. | |
2384 | * | |
2385 | * @param path directory path, must be a directory | |
2386 | * @param x column relative to parent | |
2387 | * @param y row relative to parent | |
2388 | * @param width width of text area | |
2389 | * @param height height of text area | |
329fd62e | 2390 | * @return the new directory list |
0d47c546 KL |
2391 | */ |
2392 | public final TDirectoryList addDirectoryList(final String path, final int x, | |
2393 | final int y, final int width, final int height) { | |
2394 | ||
2395 | return new TDirectoryList(this, path, x, y, width, height, null); | |
2396 | } | |
2397 | ||
2398 | /** | |
2399 | * Convenience function to add a directory list to this container/window. | |
2400 | * | |
2401 | * @param path directory path, must be a directory | |
2402 | * @param x column relative to parent | |
2403 | * @param y row relative to parent | |
2404 | * @param width width of text area | |
2405 | * @param height height of text area | |
a69ed767 KL |
2406 | * @param action action to perform when an item is selected (enter or |
2407 | * double-click) | |
329fd62e | 2408 | * @return the new directory list |
0d47c546 KL |
2409 | */ |
2410 | public final TDirectoryList addDirectoryList(final String path, final int x, | |
2411 | final int y, final int width, final int height, final TAction action) { | |
2412 | ||
2413 | return new TDirectoryList(this, path, x, y, width, height, action); | |
2414 | } | |
7668cb45 | 2415 | |
3649b921 KL |
2416 | /** |
2417 | * Convenience function to add a directory list to this container/window. | |
2418 | * | |
a69ed767 KL |
2419 | * @param path directory path, must be a directory |
2420 | * @param x column relative to parent | |
2421 | * @param y row relative to parent | |
2422 | * @param width width of text area | |
2423 | * @param height height of text area | |
2424 | * @param action action to perform when an item is selected (enter or | |
2425 | * double-click) | |
2426 | * @param singleClickAction action to perform when an item is selected | |
2427 | * (single-click) | |
2428 | * @return the new directory list | |
2429 | */ | |
2430 | public final TDirectoryList addDirectoryList(final String path, final int x, | |
2431 | final int y, final int width, final int height, final TAction action, | |
2432 | final TAction singleClickAction) { | |
2433 | ||
2434 | return new TDirectoryList(this, path, x, y, width, height, action, | |
2435 | singleClickAction); | |
2436 | } | |
2437 | ||
2438 | /** | |
2439 | * Convenience function to add a directory list to this container/window. | |
2440 | * | |
2441 | * @param path directory path, must be a directory | |
2442 | * @param x column relative to parent | |
2443 | * @param y row relative to parent | |
2444 | * @param width width of text area | |
2445 | * @param height height of text area | |
2446 | * @param action action to perform when an item is selected (enter or | |
2447 | * double-click) | |
2448 | * @param singleClickAction action to perform when an item is selected | |
2449 | * (single-click) | |
2450 | * @param filters a list of strings that files must match to be displayed | |
2451 | * @return the new directory list | |
2452 | */ | |
2453 | public final TDirectoryList addDirectoryList(final String path, final int x, | |
2454 | final int y, final int width, final int height, final TAction action, | |
2455 | final TAction singleClickAction, final List<String> filters) { | |
2456 | ||
2457 | return new TDirectoryList(this, path, x, y, width, height, action, | |
2458 | singleClickAction, filters); | |
2459 | } | |
2460 | ||
2461 | /** | |
2462 | * Convenience function to add a list to this container/window. | |
2463 | * | |
3649b921 KL |
2464 | * @param strings list of strings to show |
2465 | * @param x column relative to parent | |
2466 | * @param y row relative to parent | |
2467 | * @param width width of text area | |
2468 | * @param height height of text area | |
2469 | * @return the new directory list | |
2470 | */ | |
2471 | public final TList addList(final List<String> strings, final int x, | |
2472 | final int y, final int width, final int height) { | |
2473 | ||
2474 | return new TList(this, strings, x, y, width, height, null); | |
2475 | } | |
2476 | ||
2477 | /** | |
a69ed767 | 2478 | * Convenience function to add a list to this container/window. |
3649b921 KL |
2479 | * |
2480 | * @param strings list of strings to show | |
2481 | * @param x column relative to parent | |
2482 | * @param y row relative to parent | |
2483 | * @param width width of text area | |
2484 | * @param height height of text area | |
2485 | * @param enterAction action to perform when an item is selected | |
2486 | * @return the new directory list | |
2487 | */ | |
2488 | public final TList addList(final List<String> strings, final int x, | |
2489 | final int y, final int width, final int height, | |
2490 | final TAction enterAction) { | |
2491 | ||
2492 | return new TList(this, strings, x, y, width, height, enterAction); | |
2493 | } | |
2494 | ||
2495 | /** | |
a69ed767 | 2496 | * Convenience function to add a list to this container/window. |
3649b921 KL |
2497 | * |
2498 | * @param strings list of strings to show | |
2499 | * @param x column relative to parent | |
2500 | * @param y row relative to parent | |
2501 | * @param width width of text area | |
2502 | * @param height height of text area | |
2503 | * @param enterAction action to perform when an item is selected | |
2504 | * @param moveAction action to perform when the user navigates to a new | |
2505 | * item with arrow/page keys | |
2506 | * @return the new directory list | |
2507 | */ | |
2508 | public final TList addList(final List<String> strings, final int x, | |
2509 | final int y, final int width, final int height, | |
2510 | final TAction enterAction, final TAction moveAction) { | |
2511 | ||
2512 | return new TList(this, strings, x, y, width, height, enterAction, | |
2513 | moveAction); | |
2514 | } | |
2515 | ||
9577a9d0 KL |
2516 | /** |
2517 | * Convenience function to add a list to this container/window. | |
2518 | * | |
2519 | * @param strings list of strings to show. This is allowed to be null | |
2520 | * and set later with setList() or by subclasses. | |
2521 | * @param x column relative to parent | |
2522 | * @param y row relative to parent | |
2523 | * @param width width of text area | |
2524 | * @param height height of text area | |
2525 | * @param enterAction action to perform when an item is selected | |
2526 | * @param moveAction action to perform when the user navigates to a new | |
2527 | * item with arrow/page keys | |
2528 | * @param singleClickAction action to perform when the user clicks on an | |
2529 | * item | |
2530 | */ | |
2531 | public TList addList(final List<String> strings, final int x, | |
2532 | final int y, final int width, final int height, | |
2533 | final TAction enterAction, final TAction moveAction, | |
2534 | final TAction singleClickAction) { | |
2535 | ||
2536 | return new TList(this, strings, x, y, width, height, enterAction, | |
2537 | moveAction, singleClickAction); | |
2538 | } | |
2539 | ||
2540 | ||
382bc294 KL |
2541 | /** |
2542 | * Convenience function to add an image to this container/window. | |
2543 | * | |
2544 | * @param x column relative to parent | |
2545 | * @param y row relative to parent | |
2546 | * @param width number of text cells for width of the image | |
2547 | * @param height number of text cells for height of the image | |
2548 | * @param image the image to display | |
2549 | * @param left left column of the image. 0 is the left-most column. | |
2550 | * @param top top row of the image. 0 is the top-most row. | |
2551 | */ | |
2552 | public final TImage addImage(final int x, final int y, | |
2553 | final int width, final int height, | |
2554 | final BufferedImage image, final int left, final int top) { | |
2555 | ||
2556 | return new TImage(this, x, y, width, height, image, left, top); | |
2557 | } | |
2558 | ||
2559 | /** | |
2560 | * Convenience function to add an image to this container/window. | |
2561 | * | |
2562 | * @param x column relative to parent | |
2563 | * @param y row relative to parent | |
2564 | * @param width number of text cells for width of the image | |
2565 | * @param height number of text cells for height of the image | |
2566 | * @param image the image to display | |
2567 | * @param left left column of the image. 0 is the left-most column. | |
2568 | * @param top top row of the image. 0 is the top-most row. | |
2569 | * @param clickAction function to call when mouse is pressed | |
2570 | */ | |
2571 | public final TImage addImage(final int x, final int y, | |
2572 | final int width, final int height, | |
2573 | final BufferedImage image, final int left, final int top, | |
2574 | final TAction clickAction) { | |
2575 | ||
2576 | return new TImage(this, x, y, width, height, image, left, top, | |
2577 | clickAction); | |
2578 | } | |
2579 | ||
2580 | /** | |
2581 | * Convenience function to add an editable 2D data table to this | |
2582 | * container/window. | |
2583 | * | |
2584 | * @param x column relative to parent | |
2585 | * @param y row relative to parent | |
2586 | * @param width width of widget | |
2587 | * @param height height of widget | |
2588 | */ | |
2589 | public TTableWidget addTable(final int x, final int y, final int width, | |
2590 | final int height) { | |
2591 | ||
2592 | return new TTableWidget(this, x, y, width, height); | |
2593 | } | |
2594 | ||
656c0ddd KL |
2595 | /** |
2596 | * Convenience function to add an editable 2D data table to this | |
2597 | * container/window. | |
2598 | * | |
2599 | * @param x column relative to parent | |
2600 | * @param y row relative to parent | |
2601 | * @param width width of widget | |
2602 | * @param height height of widget | |
2603 | * @param gridColumns number of columns in grid | |
2604 | * @param gridRows number of rows in grid | |
2605 | */ | |
2606 | public TTableWidget addTable(final int x, final int y, final int width, | |
2607 | final int height, final int gridColumns, final int gridRows) { | |
2608 | ||
2609 | return new TTableWidget(this, x, y, width, height, gridColumns, | |
2610 | gridRows); | |
2611 | } | |
2612 | ||
fc2af494 KL |
2613 | /** |
2614 | * Convenience function to add a panel to this container/window. | |
2615 | * | |
2616 | * @param x column relative to parent | |
2617 | * @param y row relative to parent | |
2618 | * @param width width of text area | |
2619 | * @param height height of text area | |
2620 | * @return the new panel | |
2621 | */ | |
2622 | public final TPanel addPanel(final int x, final int y, final int width, | |
2623 | final int height) { | |
2624 | ||
2625 | return new TPanel(this, x, y, width, height); | |
2626 | } | |
2627 | ||
5ffeabcc KL |
2628 | /** |
2629 | * Convenience function to add a split pane to this container/window. | |
2630 | * | |
2631 | * @param x column relative to parent | |
2632 | * @param y row relative to parent | |
2633 | * @param width width of text area | |
2634 | * @param height height of text area | |
2635 | * @param vertical if true, split vertically | |
2636 | * @return the new split pane | |
2637 | */ | |
2638 | public final TSplitPane addSplitPane(final int x, final int y, | |
2639 | final int width, final int height, final boolean vertical) { | |
2640 | ||
2641 | return new TSplitPane(this, x, y, width, height, vertical); | |
2642 | } | |
2643 | ||
48e27807 | 2644 | } |