Commit | Line | Data |
---|---|---|
e3dfbd23 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
e16dda65 | 4 | * The MIT License (MIT) |
e3dfbd23 | 5 | * |
a69ed767 | 6 | * Copyright (C) 2019 Kevin Lamonte |
e3dfbd23 | 7 | * |
e16dda65 KL |
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: | |
e3dfbd23 | 14 | * |
e16dda65 KL |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
e3dfbd23 | 17 | * |
e16dda65 KL |
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. | |
e3dfbd23 KL |
25 | * |
26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
27 | * @version 1 | |
28 | */ | |
29 | package jexer.demos; | |
30 | ||
a69ed767 KL |
31 | import java.text.MessageFormat; |
32 | import java.util.ResourceBundle; | |
33 | ||
34 | import jexer.TAction; | |
35 | import jexer.TApplication; | |
36 | import jexer.TInputBox; | |
37 | import jexer.TMessageBox; | |
38 | import jexer.TWindow; | |
d8dc8aea | 39 | import jexer.layout.StretchLayoutManager; |
2ce6dab2 KL |
40 | import static jexer.TCommand.*; |
41 | import static jexer.TKeypress.*; | |
e3dfbd23 KL |
42 | |
43 | /** | |
44 | * This window demonstates the TMessageBox and TInputBox widgets. | |
45 | */ | |
7668cb45 | 46 | public class DemoMsgBoxWindow extends TWindow { |
e3dfbd23 | 47 | |
a69ed767 KL |
48 | /** |
49 | * Translated strings. | |
50 | */ | |
51 | private static final ResourceBundle i18n = ResourceBundle.getBundle(DemoMsgBoxWindow.class.getName()); | |
52 | ||
43ad7b6c KL |
53 | // ------------------------------------------------------------------------ |
54 | // Constructors ----------------------------------------------------------- | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
e3dfbd23 KL |
57 | /** |
58 | * Constructor. | |
59 | * | |
60 | * @param parent the main application | |
61 | */ | |
62 | DemoMsgBoxWindow(final TApplication parent) { | |
63 | this(parent, TWindow.CENTERED | TWindow.RESIZABLE); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Constructor. | |
68 | * | |
69 | * @param parent the main application | |
70 | * @param flags bitmask of MODAL, CENTERED, or RESIZABLE | |
71 | */ | |
72 | DemoMsgBoxWindow(final TApplication parent, final int flags) { | |
73 | // Construct a demo window. X and Y don't matter because it | |
74 | // will be centered on screen. | |
a69ed767 | 75 | super(parent, i18n.getString("windowTitle"), 0, 0, 64, 18, flags); |
e3dfbd23 | 76 | |
d8dc8aea KL |
77 | setLayoutManager(new StretchLayoutManager(getWidth(), getHeight())); |
78 | ||
e3dfbd23 KL |
79 | int row = 1; |
80 | ||
81 | // Add some widgets | |
a69ed767 KL |
82 | addLabel(i18n.getString("messageBoxLabel1"), 1, row); |
83 | addButton(i18n.getString("messageBoxButton1"), 35, row, | |
e3dfbd23 KL |
84 | new TAction() { |
85 | public void DO() { | |
a69ed767 KL |
86 | getApplication().messageBox(i18n. |
87 | getString("messageBoxTitle1"), | |
88 | i18n.getString("messageBoxPrompt1"), | |
e3dfbd23 KL |
89 | TMessageBox.Type.OK); |
90 | } | |
91 | } | |
92 | ); | |
93 | row += 2; | |
94 | ||
a69ed767 KL |
95 | addLabel(i18n.getString("messageBoxLabel2"), 1, row); |
96 | addButton(i18n.getString("messageBoxButton2"), 35, row, | |
e3dfbd23 KL |
97 | new TAction() { |
98 | public void DO() { | |
a69ed767 KL |
99 | getApplication().messageBox(i18n. |
100 | getString("messageBoxTitle2"), | |
101 | i18n.getString("messageBoxPrompt2"), | |
e3dfbd23 KL |
102 | TMessageBox.Type.OKCANCEL); |
103 | } | |
104 | } | |
105 | ); | |
106 | row += 2; | |
107 | ||
a69ed767 KL |
108 | addLabel(i18n.getString("messageBoxLabel3"), 1, row); |
109 | addButton(i18n.getString("messageBoxButton3"), 35, row, | |
e3dfbd23 KL |
110 | new TAction() { |
111 | public void DO() { | |
a69ed767 KL |
112 | getApplication().messageBox(i18n. |
113 | getString("messageBoxTitle3"), | |
114 | i18n.getString("messageBoxPrompt3"), | |
e3dfbd23 KL |
115 | TMessageBox.Type.YESNO); |
116 | } | |
117 | } | |
118 | ); | |
119 | row += 2; | |
120 | ||
a69ed767 KL |
121 | addLabel(i18n.getString("messageBoxLabel4"), 1, row); |
122 | addButton(i18n.getString("messageBoxButton4"), 35, row, | |
e3dfbd23 KL |
123 | new TAction() { |
124 | public void DO() { | |
a69ed767 KL |
125 | getApplication().messageBox(i18n. |
126 | getString("messageBoxTitle4"), | |
127 | i18n.getString("messageBoxPrompt4"), | |
e3dfbd23 KL |
128 | TMessageBox.Type.YESNOCANCEL); |
129 | } | |
130 | } | |
131 | ); | |
132 | row += 2; | |
133 | ||
a69ed767 KL |
134 | addLabel(i18n.getString("inputBoxLabel1"), 1, row); |
135 | addButton(i18n.getString("inputBoxButton1"), 35, row, | |
e3dfbd23 KL |
136 | new TAction() { |
137 | public void DO() { | |
a69ed767 KL |
138 | TInputBox in = getApplication().inputBox(i18n. |
139 | getString("inputBoxTitle1"), | |
140 | i18n.getString("inputBoxPrompt1"), | |
141 | i18n.getString("inputBoxInput1")); | |
142 | getApplication().messageBox(i18n. | |
143 | getString("inputBoxAnswerTitle1"), | |
144 | MessageFormat.format(i18n. | |
145 | getString("inputBoxAnswerPrompt1"), in.getText())); | |
e3dfbd23 KL |
146 | } |
147 | } | |
148 | ); | |
72b6bd90 KL |
149 | row += 2; |
150 | ||
a69ed767 KL |
151 | addLabel(i18n.getString("inputBoxLabel2"), 1, row); |
152 | addButton(i18n.getString("inputBoxButton2"), 35, row, | |
72b6bd90 KL |
153 | new TAction() { |
154 | public void DO() { | |
a69ed767 KL |
155 | TInputBox in = getApplication().inputBox(i18n. |
156 | getString("inputBoxTitle2"), | |
157 | i18n.getString("inputBoxPrompt2"), | |
158 | i18n.getString("inputBoxInput2"), | |
159 | TInputBox.Type.OKCANCEL); | |
160 | getApplication().messageBox(i18n. | |
161 | getString("inputBoxAnswerTitle2"), | |
162 | MessageFormat.format(i18n. | |
163 | getString("inputBoxAnswerPrompt2"), in.getText(), | |
164 | in.getResult())); | |
72b6bd90 KL |
165 | } |
166 | } | |
167 | ); | |
a69ed767 | 168 | row += 2; |
e3dfbd23 | 169 | |
a69ed767 KL |
170 | addButton(i18n.getString("closeWindow"), |
171 | (getWidth() - 14) / 2, getHeight() - 4, | |
e3dfbd23 KL |
172 | new TAction() { |
173 | public void DO() { | |
174 | getApplication().closeWindow(DemoMsgBoxWindow.this); | |
175 | } | |
176 | } | |
177 | ); | |
2ce6dab2 | 178 | |
a69ed767 KL |
179 | statusBar = newStatusBar(i18n.getString("statusBar")); |
180 | statusBar.addShortcutKeypress(kbF1, cmHelp, | |
181 | i18n.getString("statusBarHelp")); | |
182 | statusBar.addShortcutKeypress(kbF2, cmShell, | |
183 | i18n.getString("statusBarShell")); | |
184 | statusBar.addShortcutKeypress(kbF3, cmOpen, | |
185 | i18n.getString("statusBarOpen")); | |
186 | statusBar.addShortcutKeypress(kbF10, cmExit, | |
187 | i18n.getString("statusBarExit")); | |
e3dfbd23 KL |
188 | } |
189 | } |