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