Not dead note
[fanfix.git] / src / jexer / demos / Demo6.java
CommitLineData
88a99379
KL
1/*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2017 Kevin Lamonte
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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.
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29package jexer.demos;
30
3e074355 31import jexer.TApplication;
88a99379
KL
32import jexer.backend.*;
33
34/**
35 * This class shows off the use of MultiBackend and MultiScreen.
36 */
37public class Demo6 {
38
39 /**
40 * Main entry point.
41 *
42 * @param args Command line arguments
43 */
44 public static void main(final String [] args) {
45 try {
3e074355
KL
46
47 /*
48 * In this demo we will create two applications spanning three
49 * screens. One of the applications will have both an ECMA48
50 * screen and a Swing screen, with all I/O mirrored between them.
51 * The second application will have a Swing screen containing a
52 * window showing the first application, also mirroring I/O
53 * between the window and the other two screens.
54 */
55
88a99379 56 /*
3e074355
KL
57 * We create the first screen and use it to establish a
58 * MultiBackend.
88a99379 59 */
3e074355 60 ECMA48Backend ecmaBackend = new ECMA48Backend();
88a99379 61 MultiBackend multiBackend = new MultiBackend(ecmaBackend);
3e074355
KL
62
63 /*
64 * Now we create the first application (a standard demo).
65 */
88a99379 66 DemoApplication demoApp = new DemoApplication(multiBackend);
3e074355
KL
67
68 /*
69 * We will need the width and height of the ECMA48 screen, so get
70 * the Screen reference now.
71 */
88a99379
KL
72 Screen multiScreen = multiBackend.getScreen();
73
3e074355
KL
74 /*
75 * Now we create the second screen (backend) for the first
76 * application. It will be the same size as the ECMA48 screen,
77 * with a font size of 16 points.
78 */
79 SwingBackend swingBackend = new SwingBackend(multiScreen.getWidth(),
80 multiScreen.getHeight(), 16);
81
82 /*
83 * Add this screen to the MultiBackend, and at this point we have
84 * one demo application spanning two physical screens.
85 */
88a99379 86 multiBackend.addBackend(swingBackend);
be72cb5c 87 multiBackend.setListener(demoApp);
88a99379 88
3e074355
KL
89 /*
90 * Time for the second application. This one will have a single
91 * window mirroring the contents of the first application. Let's
92 * make it a little larger than the first application's
93 * width/height.
94 */
95 int width = multiScreen.getWidth();
96 int height = multiScreen.getHeight();
97
98 /*
99 * Make a new Swing window for the second application.
100 */
101 SwingBackend monitorBackend = new SwingBackend(width + 5,
102 height + 5, 16);
103
104 /*
105 * Setup the second application, give it the basic file and
106 * window menus.
107 */
108 TApplication monitor = new TApplication(monitorBackend);
109 monitor.addFileMenu();
110 monitor.addWindowMenu();
111
112 /*
113 * Now add the third screen to the first application. We want to
114 * change the object it locks on in its draw() method to the
115 * MultiScreen, that will dramatically reduce (not totally
116 * eliminate) screen tearing/artifacts.
117 */
118 TWindowBackend windowBackend = new TWindowBackend(demoApp,
119 monitor, "Monitor Window", width + 2, height + 2);
120 windowBackend.setDrawLock(multiScreen);
121 multiBackend.addBackend(windowBackend);
122
123 /*
124 * Three screens, two applications: spin them up!
125 */
88a99379 126 (new Thread(demoApp)).start();
3e074355 127 (new Thread(monitor)).start();
88a99379
KL
128 } catch (Exception e) {
129 e.printStackTrace();
130 }
131 }
132
133}