d383261af91c6bac99d93c5f2990d317c303de8f
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]
32 import java
.awt
.event
.WindowEvent
;
33 import java
.awt
.event
.WindowListener
;
34 import javax
.swing
.JFrame
;
35 import javax
.swing
.JPanel
;
36 import javax
.swing
.JSplitPane
;
38 import jexer
.backend
.SwingBackend
;
41 * This class is the main driver for a simple demonstration of Jexer's
42 * capabilities. It shows two Swing demo applications running in the same
45 public class Demo5
implements WindowListener
{
47 // ------------------------------------------------------------------------
48 // Variables --------------------------------------------------------------
49 // ------------------------------------------------------------------------
52 * The first demo application instance.
54 DemoApplication app1
= null;
57 * The second demo application instance.
59 DemoApplication app2
= null;
61 // ------------------------------------------------------------------------
62 // WindowListener ---------------------------------------------------------
63 // ------------------------------------------------------------------------
66 * Pass window events into the event queue.
68 * @param event window event received
70 public void windowActivated(final WindowEvent event
) {
75 * Pass window events into the event queue.
77 * @param event window event received
79 public void windowClosed(final WindowEvent event
) {
84 * Pass window events into the event queue.
86 * @param event window event received
88 public void windowClosing(final WindowEvent event
) {
98 * Pass window events into the event queue.
100 * @param event window event received
102 public void windowDeactivated(final WindowEvent event
) {
107 * Pass window events into the event queue.
109 * @param event window event received
111 public void windowDeiconified(final WindowEvent event
) {
116 * Pass window events into the event queue.
118 * @param event window event received
120 public void windowIconified(final WindowEvent event
) {
125 * Pass window events into the event queue.
127 * @param event window event received
129 public void windowOpened(final WindowEvent event
) {
133 // ------------------------------------------------------------------------
134 // Demo5 ------------------------------------------------------------------
135 // ------------------------------------------------------------------------
138 * Run two demo applications in separate panes.
140 private void addApplications() {
143 * In this demo we will create two swing panels with two
144 * independently running applications, each with a different font
149 * First we create a panel to put it on. We need this to pass to
150 * SwingBackend's constructor, so that it knows not to create a new
153 JPanel app1Panel
= new JPanel();
156 * Next, we create the Swing backend. The "listener" (second
157 * argument, set to null) is what the backend wakes up on every event
158 * received. Typically this is the TApplication. TApplication sets
159 * it in its constructor, so we can pass null here and be fine.
161 SwingBackend app1Backend
= new SwingBackend(app1Panel
, null,
163 // Now that we have the backend, construct the TApplication.
164 app1
= new DemoApplication(app1Backend
);
167 * The second panel is the same sequence, except that we also change
168 * the font from the default Terminus to JVM monospaced.
170 JPanel app2Panel
= new JPanel();
171 SwingBackend app2Backend
= new SwingBackend(app2Panel
, null,
173 app2
= new DemoApplication(app2Backend
);
174 Font font
= new Font(Font
.MONOSPACED
, Font
.PLAIN
, 18);
175 app2Backend
.setFont(font
);
178 * Now that the applications are ready, spin them off on their
181 (new Thread(app1
)).start();
182 (new Thread(app2
)).start();
185 * The rest of this is standard Swing. Set up a frame, a split pane,
186 * put each of the panels on it, and make it visible.
188 JFrame frame
= new JFrame();
189 frame
.setDefaultCloseOperation(JFrame
.DISPOSE_ON_CLOSE
);
190 frame
.addWindowListener(this);
191 JSplitPane mainPane
= new JSplitPane(JSplitPane
.HORIZONTAL_SPLIT
,
192 app1Panel
, app2Panel
);
193 mainPane
.setOneTouchExpandable(true);
194 mainPane
.setDividerLocation(500);
195 mainPane
.setDividerSize(6);
196 mainPane
.setBorder(null);
197 frame
.setContentPane(mainPane
);
199 frame
.setTitle("Two Jexer Apps In One Swing UI");
200 frame
.setSize(1000, 640);
201 frame
.setVisible(true);
207 * @param args Command line arguments
209 public static void main(final String
[] args
) {
211 Demo5 demo
= new Demo5();
212 demo
.addApplications();
213 } catch (Exception e
) {