stubs for AWTBackend
[fanfix.git] / src / jexer / backend / AWTBackend.java
CommitLineData
1ac2ccb1
KL
1/**
2 * Jexer - Java Text User Interface
3 *
4 * License: LGPLv3 or later
5 *
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.
9 *
10 * Copyright (C) 2015 Kevin Lamonte
11 *
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.
16 *
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.
21 *
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
26 * 02110-1301 USA
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
30 */
31package jexer.backend;
32
33import java.util.List;
34
35import jexer.event.TInputEvent;
36import jexer.io.AWTScreen;
37import jexer.io.AWTTerminal;
38
39/**
40 * This class uses standard AWT calls to handle screen, keyboard, and mouse
41 * I/O.
42 */
43public final class AWTBackend extends Backend {
44
45 /**
46 * Input events are processed by this Terminal.
47 */
48 private AWTTerminal terminal;
49
50 /**
51 * Public constructor.
52 */
53 public AWTBackend() {
54 // Create a screen
55 AWTScreen screen = new AWTScreen();
56 this.screen = screen;
57 // Create the listeners
58 terminal = new AWTTerminal(screen);
59 }
60
61 /**
62 * Sync the logical screen to the physical device.
63 */
64 @Override
65 public void flushScreen() {
66 screen.flushPhysical();
67 }
68
69 /**
70 * Get keyboard, mouse, and screen resize events.
71 *
72 * @param queue list to append new events to
73 * @param timeout maximum amount of time (in millis) to wait for an
74 * event. 0 means to return immediately, i.e. perform a poll.
75 */
76 @Override
77 public void getEvents(final List<TInputEvent> queue, final int timeout) {
78 if (timeout > 0) {
79 // Try to sleep, let the terminal's input thread wake me up if
80 // something came in.
81 synchronized (terminal) {
82 try {
83 terminal.wait(timeout);
84 if (terminal.hasEvents()) {
85 // System.err.println("getEvents()");
86 terminal.getEvents(queue);
87 } else {
88 // If I got here, then I timed out. Call
89 // terminal.getIdleEvents() to pick up stragglers
90 // like bare resize.
91 // System.err.println("getIdleEvents()");
92 terminal.getIdleEvents(queue);
93 }
94 } catch (InterruptedException e) {
95 // Spurious interrupt, pretend it was like a timeout.
96 // System.err.println("[interrupt] getEvents()");
97 terminal.getIdleEvents(queue);
98 }
99 }
100 } else {
101 // Asking for a poll, go get it.
102 // System.err.println("[polled] getEvents()");
103 terminal.getEvents(queue);
104 }
105 }
106
107 /**
108 * Close the I/O, restore the console, etc.
109 */
110 @Override
111 public void shutdown() {
112 terminal.shutdown();
113 }
114
115}