2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 package jexer
.backend
;
33 import java
.util
.List
;
35 import jexer
.event
.TInputEvent
;
36 import jexer
.io
.AWTScreen
;
37 import jexer
.io
.AWTTerminal
;
40 * This class uses standard AWT calls to handle screen, keyboard, and mouse
43 public final class AWTBackend
extends Backend
{
46 * Input events are processed by this Terminal.
48 private AWTTerminal terminal
;
55 AWTScreen screen
= new AWTScreen();
57 // Create the listeners
58 terminal
= new AWTTerminal(screen
);
59 // Hang onto the session info
60 this.sessionInfo
= terminal
.getSessionInfo();
64 * Sync the logical screen to the physical device.
67 public void flushScreen() {
68 screen
.flushPhysical();
72 * Get keyboard, mouse, and screen resize events.
74 * @param queue list to append new events to
75 * @param timeout maximum amount of time (in millis) to wait for an
76 * event. 0 means to return immediately, i.e. perform a poll.
79 public void getEvents(final List
<TInputEvent
> queue
, final int timeout
) {
81 // Try to sleep, let the terminal's input thread wake me up if
83 synchronized (terminal
) {
85 terminal
.wait(timeout
);
86 if (terminal
.hasEvents()) {
87 // System.err.println("getEvents()");
88 terminal
.getEvents(queue
);
90 // If I got here, then I timed out. Call
91 // terminal.getIdleEvents() to pick up stragglers
93 // System.err.println("getIdleEvents()");
94 terminal
.getIdleEvents(queue
);
96 } catch (InterruptedException e
) {
97 // Spurious interrupt, pretend it was like a timeout.
98 // System.err.println("[interrupt] getEvents()");
99 terminal
.getIdleEvents(queue
);
103 // Asking for a poll, go get it.
104 // System.err.println("[polled] getEvents()");
105 terminal
.getEvents(queue
);
110 * Close the I/O, restore the console, etc.
113 public void shutdown() {