Commit | Line | Data |
---|---|---|
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 | */ | |
31 | package jexer.backend; | |
32 | ||
33 | import java.util.List; | |
34 | ||
35 | import jexer.event.TInputEvent; | |
36 | import jexer.io.AWTScreen; | |
37 | import jexer.io.AWTTerminal; | |
38 | ||
39 | /** | |
40 | * This class uses standard AWT calls to handle screen, keyboard, and mouse | |
41 | * I/O. | |
42 | */ | |
43 | public 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. | |
92554d64 KL |
52 | * |
53 | * @param listener the object this backend needs to wake up when new | |
54 | * input comes in | |
1ac2ccb1 | 55 | */ |
92554d64 | 56 | public AWTBackend(final Object listener) { |
1ac2ccb1 KL |
57 | // Create a screen |
58 | AWTScreen screen = new AWTScreen(); | |
59 | this.screen = screen; | |
92554d64 KL |
60 | |
61 | // Create the AWT event listeners | |
62 | terminal = new AWTTerminal(listener, screen); | |
63 | ||
30bd4abd KL |
64 | // Hang onto the session info |
65 | this.sessionInfo = terminal.getSessionInfo(); | |
1ac2ccb1 KL |
66 | } |
67 | ||
68 | /** | |
69 | * Sync the logical screen to the physical device. | |
70 | */ | |
71 | @Override | |
72 | public void flushScreen() { | |
73 | screen.flushPhysical(); | |
74 | } | |
75 | ||
76 | /** | |
77 | * Get keyboard, mouse, and screen resize events. | |
78 | * | |
79 | * @param queue list to append new events to | |
1ac2ccb1 KL |
80 | */ |
81 | @Override | |
92554d64 KL |
82 | public void getEvents(final List<TInputEvent> queue) { |
83 | if (terminal.hasEvents()) { | |
1ac2ccb1 KL |
84 | terminal.getEvents(queue); |
85 | } | |
86 | } | |
87 | ||
88 | /** | |
89 | * Close the I/O, restore the console, etc. | |
90 | */ | |
91 | @Override | |
92 | public void shutdown() { | |
93 | terminal.shutdown(); | |
94 | } | |
95 | ||
96 | } |