a56da43760e3b38176f90e4dc33d034530b70d4a
[fanfix.git] / DemoMsgBoxWindow.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2016 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 */
29 package jexer.demos;
30
31 import jexer.*;
32
33 /**
34 * This window demonstates the TMessageBox and TInputBox widgets.
35 */
36 public class DemoMsgBoxWindow extends TWindow {
37
38 /**
39 * Constructor.
40 *
41 * @param parent the main application
42 */
43 DemoMsgBoxWindow(final TApplication parent) {
44 this(parent, TWindow.CENTERED | TWindow.RESIZABLE);
45 }
46
47 /**
48 * Constructor.
49 *
50 * @param parent the main application
51 * @param flags bitmask of MODAL, CENTERED, or RESIZABLE
52 */
53 DemoMsgBoxWindow(final TApplication parent, final int flags) {
54 // Construct a demo window. X and Y don't matter because it
55 // will be centered on screen.
56 super(parent, "Message Boxes", 0, 0, 60, 15, flags);
57
58 int row = 1;
59
60 // Add some widgets
61 addLabel("Default OK message box", 1, row);
62 addButton("Open O&K MB", 35, row,
63 new TAction() {
64 public void DO() {
65 getApplication().messageBox("OK MessageBox",
66 "This is an example of a OK MessageBox. This is the\n" +
67 "default MessageBox.\n" +
68 "\n" +
69 "Note that the MessageBox text can span multiple\n" +
70 "lines.\n" +
71 "\n" +
72 "The default result (if someone hits the top-left\n" +
73 "close button) is OK.\n",
74 TMessageBox.Type.OK);
75 }
76 }
77 );
78 row += 2;
79
80 addLabel("OK/Cancel message box", 1, row);
81 addButton("O&pen OKC MB", 35, row,
82 new TAction() {
83 public void DO() {
84 getApplication().messageBox("OK/Cancel MessageBox",
85 "This is an example of a OK/Cancel MessageBox.\n" +
86 "\n" +
87 "Note that the MessageBox text can span multiple\n" +
88 "lines.\n" +
89 "\n" +
90 "The default result (if someone hits the top-left\n" +
91 "close button) is CANCEL.\n",
92 TMessageBox.Type.OKCANCEL);
93 }
94 }
95 );
96 row += 2;
97
98 addLabel("Yes/No message box", 1, row);
99 addButton("Open &YN MB", 35, row,
100 new TAction() {
101 public void DO() {
102 getApplication().messageBox("Yes/No MessageBox",
103 "This is an example of a Yes/No MessageBox.\n" +
104 "\n" +
105 "Note that the MessageBox text can span multiple\n" +
106 "lines.\n" +
107 "\n" +
108 "The default result (if someone hits the top-left\n" +
109 "close button) is NO.\n",
110 TMessageBox.Type.YESNO);
111 }
112 }
113 );
114 row += 2;
115
116 addLabel("Yes/No/Cancel message box", 1, row);
117 addButton("Ope&n YNC MB", 35, row,
118 new TAction() {
119 public void DO() {
120 getApplication().messageBox("Yes/No/Cancel MessageBox",
121 "This is an example of a Yes/No/Cancel MessageBox.\n" +
122 "\n" +
123 "Note that the MessageBox text can span multiple\n" +
124 "lines.\n" +
125 "\n" +
126 "The default result (if someone hits the top-left\n" +
127 "close button) is CANCEL.\n",
128 TMessageBox.Type.YESNOCANCEL);
129 }
130 }
131 );
132 row += 2;
133
134 addLabel("Input box", 1, row);
135 addButton("Open &input box", 35, row,
136 new TAction() {
137 public void DO() {
138 TInputBox in = getApplication().inputBox("Input Box",
139 "This is an example of an InputBox.\n" +
140 "\n" +
141 "Note that the InputBox text can span multiple\n" +
142 "lines.\n",
143 "some input text");
144 getApplication().messageBox("Your InputBox Answer",
145 "You entered: " + in.getText());
146 }
147 }
148 );
149
150 addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4,
151 new TAction() {
152 public void DO() {
153 getApplication().closeWindow(DemoMsgBoxWindow.this);
154 }
155 }
156 );
157 }
158 }
159