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 | |
fc2af494 KL |
77 | setLayoutManager(new StretchLayoutManager(getWidth() - 2, |
78 | getHeight() - 2)); | |
d8dc8aea | 79 | |
e3dfbd23 KL |
80 | int row = 1; |
81 | ||
82 | // Add some widgets | |
a69ed767 KL |
83 | addLabel(i18n.getString("messageBoxLabel1"), 1, row); |
84 | addButton(i18n.getString("messageBoxButton1"), 35, row, | |
e3dfbd23 KL |
85 | new TAction() { |
86 | public void DO() { | |
a69ed767 KL |
87 | getApplication().messageBox(i18n. |
88 | getString("messageBoxTitle1"), | |
89 | i18n.getString("messageBoxPrompt1"), | |
e3dfbd23 KL |
90 | TMessageBox.Type.OK); |
91 | } | |
92 | } | |
93 | ); | |
94 | row += 2; | |
95 | ||
a69ed767 KL |
96 | addLabel(i18n.getString("messageBoxLabel2"), 1, row); |
97 | addButton(i18n.getString("messageBoxButton2"), 35, row, | |
e3dfbd23 KL |
98 | new TAction() { |
99 | public void DO() { | |
a69ed767 KL |
100 | getApplication().messageBox(i18n. |
101 | getString("messageBoxTitle2"), | |
102 | i18n.getString("messageBoxPrompt2"), | |
e3dfbd23 KL |
103 | TMessageBox.Type.OKCANCEL); |
104 | } | |
105 | } | |
106 | ); | |
107 | row += 2; | |
108 | ||
a69ed767 KL |
109 | addLabel(i18n.getString("messageBoxLabel3"), 1, row); |
110 | addButton(i18n.getString("messageBoxButton3"), 35, row, | |
e3dfbd23 KL |
111 | new TAction() { |
112 | public void DO() { | |
a69ed767 KL |
113 | getApplication().messageBox(i18n. |
114 | getString("messageBoxTitle3"), | |
115 | i18n.getString("messageBoxPrompt3"), | |
e3dfbd23 KL |
116 | TMessageBox.Type.YESNO); |
117 | } | |
118 | } | |
119 | ); | |
120 | row += 2; | |
121 | ||
a69ed767 KL |
122 | addLabel(i18n.getString("messageBoxLabel4"), 1, row); |
123 | addButton(i18n.getString("messageBoxButton4"), 35, row, | |
e3dfbd23 KL |
124 | new TAction() { |
125 | public void DO() { | |
a69ed767 KL |
126 | getApplication().messageBox(i18n. |
127 | getString("messageBoxTitle4"), | |
128 | i18n.getString("messageBoxPrompt4"), | |
e3dfbd23 KL |
129 | TMessageBox.Type.YESNOCANCEL); |
130 | } | |
131 | } | |
132 | ); | |
133 | row += 2; | |
134 | ||
a69ed767 KL |
135 | addLabel(i18n.getString("inputBoxLabel1"), 1, row); |
136 | addButton(i18n.getString("inputBoxButton1"), 35, row, | |
e3dfbd23 KL |
137 | new TAction() { |
138 | public void DO() { | |
a69ed767 KL |
139 | TInputBox in = getApplication().inputBox(i18n. |
140 | getString("inputBoxTitle1"), | |
141 | i18n.getString("inputBoxPrompt1"), | |
142 | i18n.getString("inputBoxInput1")); | |
143 | getApplication().messageBox(i18n. | |
144 | getString("inputBoxAnswerTitle1"), | |
145 | MessageFormat.format(i18n. | |
146 | getString("inputBoxAnswerPrompt1"), in.getText())); | |
e3dfbd23 KL |
147 | } |
148 | } | |
149 | ); | |
72b6bd90 KL |
150 | row += 2; |
151 | ||
a69ed767 KL |
152 | addLabel(i18n.getString("inputBoxLabel2"), 1, row); |
153 | addButton(i18n.getString("inputBoxButton2"), 35, row, | |
72b6bd90 KL |
154 | new TAction() { |
155 | public void DO() { | |
a69ed767 KL |
156 | TInputBox in = getApplication().inputBox(i18n. |
157 | getString("inputBoxTitle2"), | |
158 | i18n.getString("inputBoxPrompt2"), | |
159 | i18n.getString("inputBoxInput2"), | |
160 | TInputBox.Type.OKCANCEL); | |
161 | getApplication().messageBox(i18n. | |
162 | getString("inputBoxAnswerTitle2"), | |
163 | MessageFormat.format(i18n. | |
164 | getString("inputBoxAnswerPrompt2"), in.getText(), | |
165 | in.getResult())); | |
72b6bd90 KL |
166 | } |
167 | } | |
168 | ); | |
a69ed767 | 169 | row += 2; |
e3dfbd23 | 170 | |
a69ed767 KL |
171 | addButton(i18n.getString("closeWindow"), |
172 | (getWidth() - 14) / 2, getHeight() - 4, | |
e3dfbd23 KL |
173 | new TAction() { |
174 | public void DO() { | |
175 | getApplication().closeWindow(DemoMsgBoxWindow.this); | |
176 | } | |
177 | } | |
178 | ); | |
2ce6dab2 | 179 | |
a69ed767 KL |
180 | statusBar = newStatusBar(i18n.getString("statusBar")); |
181 | statusBar.addShortcutKeypress(kbF1, cmHelp, | |
182 | i18n.getString("statusBarHelp")); | |
183 | statusBar.addShortcutKeypress(kbF2, cmShell, | |
184 | i18n.getString("statusBarShell")); | |
185 | statusBar.addShortcutKeypress(kbF3, cmOpen, | |
186 | i18n.getString("statusBarOpen")); | |
187 | statusBar.addShortcutKeypress(kbF10, cmExit, | |
188 | i18n.getString("statusBarExit")); | |
e3dfbd23 KL |
189 | } |
190 | } |