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
.SwingScreen
;
37 import jexer
.io
.SwingTerminal
;
40 * This class uses standard Swing calls to handle screen, keyboard, and mouse
43 public final class SwingBackend
extends Backend
{
46 * Input events are processed by this Terminal.
48 private SwingTerminal terminal
;
53 * @param listener the object this backend needs to wake up when new
56 public SwingBackend(final Object listener
) {
58 SwingScreen screen
= new SwingScreen();
61 // Create the Swing event listeners
62 terminal
= new SwingTerminal(listener
, screen
);
64 // Hang onto the session info
65 this.sessionInfo
= terminal
.getSessionInfo();
69 * Sync the logical screen to the physical device.
72 public void flushScreen() {
73 screen
.flushPhysical();
77 * Get keyboard, mouse, and screen resize events.
79 * @param queue list to append new events to
82 public void getEvents(final List
<TInputEvent
> queue
) {
83 if (terminal
.hasEvents()) {
84 terminal
.getEvents(queue
);
89 * Close the I/O, restore the console, etc.
92 public void shutdown() {
93 ((SwingScreen
) screen
).shutdown();