2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 import jexer
.bits
.CellAttributes
;
32 import jexer
.bits
.GraphicsChars
;
33 import jexer
.event
.TKeypressEvent
;
34 import jexer
.event
.TMenuEvent
;
35 import jexer
.event
.TMouseEvent
;
36 import jexer
.event
.TResizeEvent
;
39 * TDesktop is a special-class window that is drawn underneath everything
42 public class TDesktop
extends TWindow
{
47 * @param parent parent application
49 public TDesktop(final TApplication parent
) {
51 super(parent
, "", 0, 0, parent
.getScreen().getWidth(),
52 parent
.getScreen().getHeight() - 1);
58 * The default TDesktop draws a hatch character across everything.
62 CellAttributes background
= getTheme().getColor("tdesktop.background");
63 putAll(GraphicsChars
.HATCH
, background
);
67 * Handle mouse button presses.
69 * @param mouse mouse button event
72 public void onMouseDown(final TMouseEvent mouse
) {
76 for (TWidget widget
: getChildren()) {
77 if (widget
.mouseWouldHit(mouse
)) {
78 // Dispatch to this child, also activate it
81 // Set x and y relative to the child's coordinates
82 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
83 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
84 widget
.handleEvent(mouse
);
91 * Handle mouse button releases.
93 * @param mouse mouse button release event
96 public void onMouseUp(final TMouseEvent mouse
) {
100 for (TWidget widget
: getChildren()) {
101 if (widget
.mouseWouldHit(mouse
)) {
102 // Dispatch to this child, also activate it
105 // Set x and y relative to the child's coordinates
106 mouse
.setX(mouse
.getAbsoluteX() - widget
.getAbsoluteX());
107 mouse
.setY(mouse
.getAbsoluteY() - widget
.getAbsoluteY());
108 widget
.handleEvent(mouse
);
115 * Handle mouse movements.
117 * @param mouse mouse motion event
120 public void onMouseMotion(final TMouseEvent mouse
) {
123 // Default: do nothing, pass to children instead
124 super.onMouseMotion(mouse
);
130 * @param keypress keystroke event
133 public void onKeypress(final TKeypressEvent keypress
) {
134 // Default: do nothing, pass to children instead
135 super.onKeypress(keypress
);
139 * Handle posted menu events.
141 * @param menu menu event
144 public void onMenu(final TMenuEvent menu
) {
145 // Default: do nothing, pass to children instead