9166e1c19bec44817a21297d87d949cb27b1a1f2
2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 package jexer
.backend
;
31 import java
.util
.LinkedList
;
32 import java
.util
.List
;
34 import jexer
.event
.TInputEvent
;
37 * MultiBackend mirrors its I/O to several backends.
39 public class MultiBackend
implements Backend
{
44 private MultiScreen multiScreen
;
47 * The list of backends to use.
49 private List
<Backend
> backends
= new LinkedList
<Backend
>();
52 * Public constructor requires one backend. Note that this backend's
53 * screen will be replaced with a MultiScreen.
55 * @param backend the backend to add
57 public MultiBackend(final Backend backend
) {
58 backends
.add(backend
);
59 if (backend
instanceof TWindowBackend
) {
60 multiScreen
= new MultiScreen(((TWindowBackend
) backend
).getOtherScreen());
62 multiScreen
= new MultiScreen(backend
.getScreen());
67 * Add a backend to the list.
69 * @param backend the backend to add
71 public void addBackend(final Backend backend
) {
72 backends
.add(backend
);
73 if (backend
instanceof TWindowBackend
) {
74 multiScreen
.addScreen(((TWindowBackend
) backend
).getOtherScreen());
76 multiScreen
.addScreen(backend
.getScreen());
81 * Remove a backend from the list.
83 * @param backend the backend to remove
85 public void removeBackend(final Backend backend
) {
86 if (backends
.size() > 1) {
87 if (backend
instanceof TWindowBackend
) {
88 multiScreen
.removeScreen(((TWindowBackend
) backend
).getOtherScreen());
90 multiScreen
.removeScreen(backend
.getScreen());
92 backends
.remove(backend
);
97 * Getter for sessionInfo.
99 * @return the SessionInfo
101 public SessionInfo
getSessionInfo() {
102 return backends
.get(0).getSessionInfo();
110 public Screen
getScreen() {
115 * Subclasses must provide an implementation that syncs the logical
116 * screen to the physical device.
118 public void flushScreen() {
119 for (Backend backend
: backends
) {
120 backend
.flushScreen();
125 * Subclasses must provide an implementation to get keyboard, mouse, and
126 * screen resize events.
128 * @param queue list to append new events to
130 public void getEvents(List
<TInputEvent
> queue
) {
131 for (Backend backend
: backends
) {
132 backend
.getEvents(queue
);
137 * Subclasses must provide an implementation that closes sockets,
138 * restores console, etc.
140 public void shutdown() {
141 for (Backend backend
: backends
) {
147 * Subclasses must provide an implementation that sets the window title.
149 * @param title the new title
151 public void setTitle(final String title
) {
152 for (Backend backend
: backends
) {
153 backend
.setTitle(title
);
158 * Set listener to a different Object.
160 * @param listener the new listening object that run() wakes up on new
163 public void setListener(final Object listener
) {
164 for (Backend backend
: backends
) {
165 backend
.setListener(listener
);