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 multiScreen
= new MultiScreen(backend
.getScreen());
63 * Add a backend to the list.
65 * @param backend the backend to add
67 public void addBackend(final Backend backend
) {
68 backends
.add(backend
);
69 multiScreen
.addScreen(backend
.getScreen());
73 * Remove a backend from the list.
75 * @param backend the backend to remove
77 public void removeBackend(final Backend backend
) {
78 if (backends
.size() > 1) {
79 multiScreen
.removeScreen(backend
.getScreen());
80 backends
.remove(backend
);
85 * Getter for sessionInfo.
87 * @return the SessionInfo
89 public final SessionInfo
getSessionInfo() {
90 return backends
.get(0).getSessionInfo();
98 public final Screen
getScreen() {
103 * Subclasses must provide an implementation that syncs the logical
104 * screen to the physical device.
106 public void flushScreen() {
107 for (Backend backend
: backends
) {
108 backend
.flushScreen();
113 * Subclasses must provide an implementation to get keyboard, mouse, and
114 * screen resize events.
116 * @param queue list to append new events to
118 public void getEvents(List
<TInputEvent
> queue
) {
119 for (Backend backend
: backends
) {
120 backend
.getEvents(queue
);
125 * Subclasses must provide an implementation that closes sockets,
126 * restores console, etc.
128 public void shutdown() {
129 for (Backend backend
: backends
) {
135 * Subclasses must provide an implementation that sets the window title.
137 * @param title the new title
139 public void setTitle(final String title
) {
140 for (Backend backend
: backends
) {
141 backend
.setTitle(title
);
146 * Set listener to a different Object.
148 * @param listener the new listening object that run() wakes up on new
151 public void setListener(final Object listener
) {
152 for (Backend backend
: backends
) {
153 backend
.setListener(listener
);