c9ddc13f0772eb116dc50327356a424460d84e0b
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]
33 import java
.util
.List
;
34 import java
.util
.LinkedList
;
36 import jexer
.TKeypress
;
37 import jexer
.bits
.Color
;
38 import jexer
.event
.TInputEvent
;
39 import jexer
.event
.TKeypressEvent
;
40 import jexer
.event
.TMouseEvent
;
41 import jexer
.event
.TResizeEvent
;
42 import jexer
.session
.SessionInfo
;
43 import jexer
.session
.TSessionInfo
;
44 import static jexer
.TKeypress
.*;
47 * This class reads keystrokes and mouse events from an AWT Frame.
49 public final class AWTTerminal
{
52 * The session information.
54 private SessionInfo sessionInfo
;
57 * Getter for sessionInfo.
59 * @return the SessionInfo
61 public SessionInfo
getSessionInfo() {
66 * The event queue, filled up by a thread reading on input.
68 private List
<TInputEvent
> eventQueue
;
71 * If true, we want the reader thread to exit gracefully.
73 private boolean stopReaderThread
;
78 private Thread readerThread
;
81 * true if mouse1 was down. Used to report mouse1 on the release event.
83 private boolean mouse1
;
86 * true if mouse2 was down. Used to report mouse2 on the release event.
88 private boolean mouse2
;
91 * true if mouse3 was down. Used to report mouse3 on the release event.
93 private boolean mouse3
;
96 * Check if there are events in the queue.
98 * @return if true, getEvents() has something to return to the backend
100 public boolean hasEvents() {
101 synchronized (eventQueue
) {
102 return (eventQueue
.size() > 0);
107 * Constructor sets up state for getEvent().
109 * @param screen the top-level AWT frame
111 public AWTTerminal(final AWTScreen screen
) {
115 stopReaderThread
= false;
116 sessionInfo
= new TSessionInfo();
117 eventQueue
= new LinkedList
<TInputEvent
>();
121 * Restore terminal to normal state.
123 public void shutdown() {
124 // System.err.println("=== shutdown() ==="); System.err.flush();
128 * Return any events in the IO queue.
130 * @param queue list to append new events to
132 public void getEvents(final List
<TInputEvent
> queue
) {
133 synchronized (eventQueue
) {
134 if (eventQueue
.size() > 0) {
135 synchronized (queue
) {
136 queue
.addAll(eventQueue
);
144 * Return any events in the IO queue due to timeout.
146 * @param queue list to append new events to
148 public void getIdleEvents(final List
<TInputEvent
> queue
) {
150 // Insert any polling action here...
152 // Return any events that showed up
153 synchronized (eventQueue
) {
154 if (eventQueue
.size() > 0) {
155 synchronized (queue
) {
156 queue
.addAll(eventQueue
);