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