Commit | Line | Data |
---|---|---|
2ce6dab2 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
4 | * The MIT License (MIT) | |
5 | * | |
a69ed767 | 6 | * Copyright (C) 2019 Kevin Lamonte |
2ce6dab2 KL |
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 | ||
a69ed767 | 31 | import java.text.MessageFormat; |
3096642b | 32 | import java.util.Calendar; |
a69ed767 | 33 | import java.util.Date; |
3096642b KL |
34 | import java.util.GregorianCalendar; |
35 | import java.util.Locale; | |
a69ed767 | 36 | import java.util.ResourceBundle; |
051e2913 | 37 | |
a69ed767 KL |
38 | import jexer.TAction; |
39 | import jexer.TApplication; | |
40 | import jexer.TCalendar; | |
41 | import jexer.TField; | |
3096642b | 42 | import jexer.TLabel; |
a69ed767 KL |
43 | import jexer.TMessageBox; |
44 | import jexer.TWindow; | |
2ce6dab2 KL |
45 | import static jexer.TCommand.*; |
46 | import static jexer.TKeypress.*; | |
47 | ||
48 | /** | |
49 | * This window demonstates the TField and TPasswordField widgets. | |
50 | */ | |
51 | public class DemoTextFieldWindow extends TWindow { | |
52 | ||
a69ed767 KL |
53 | /** |
54 | * Translated strings. | |
55 | */ | |
56 | private static final ResourceBundle i18n = ResourceBundle.getBundle(DemoTextFieldWindow.class.getName()); | |
57 | ||
051e2913 KL |
58 | // ------------------------------------------------------------------------ |
59 | // Variables -------------------------------------------------------------- | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
62 | /** | |
63 | * Calendar. Has to be at class scope so that it can be accessed by the | |
64 | * anonymous TAction class. | |
65 | */ | |
66 | TCalendar calendar = null; | |
67 | ||
3096642b KL |
68 | /** |
69 | * Day of week label is updated with TSpinner clicks. | |
70 | */ | |
71 | TLabel dayOfWeekLabel; | |
72 | ||
73 | /** | |
74 | * Day of week to demonstrate TSpinner. Has to be at class scope so that | |
75 | * it can be accessed by the anonymous TAction class. | |
76 | */ | |
77 | GregorianCalendar dayOfWeekCalendar = new GregorianCalendar(); | |
78 | ||
43ad7b6c KL |
79 | // ------------------------------------------------------------------------ |
80 | // Constructors ----------------------------------------------------------- | |
81 | // ------------------------------------------------------------------------ | |
82 | ||
2ce6dab2 KL |
83 | /** |
84 | * Constructor. | |
85 | * | |
86 | * @param parent the main application | |
87 | */ | |
88 | DemoTextFieldWindow(final TApplication parent) { | |
89 | this(parent, TWindow.CENTERED | TWindow.RESIZABLE); | |
90 | } | |
91 | ||
92 | /** | |
93 | * Constructor. | |
94 | * | |
95 | * @param parent the main application | |
96 | * @param flags bitmask of MODAL, CENTERED, or RESIZABLE | |
97 | */ | |
98 | DemoTextFieldWindow(final TApplication parent, final int flags) { | |
99 | // Construct a demo window. X and Y don't matter because it | |
100 | // will be centered on screen. | |
a69ed767 | 101 | super(parent, i18n.getString("windowTitle"), 0, 0, 60, 20, flags); |
2ce6dab2 KL |
102 | |
103 | int row = 1; | |
104 | ||
a69ed767 | 105 | addLabel(i18n.getString("textField1"), 1, row); |
2ce6dab2 | 106 | addField(35, row++, 15, false, "Field text"); |
a69ed767 | 107 | addLabel(i18n.getString("textField2"), 1, row); |
2ce6dab2 | 108 | addField(35, row++, 15, true); |
a69ed767 | 109 | addLabel(i18n.getString("textField3"), 1, row); |
2ce6dab2 | 110 | addPasswordField(35, row++, 15, false); |
a69ed767 | 111 | addLabel(i18n.getString("textField4"), 1, row); |
2ce6dab2 | 112 | addPasswordField(35, row++, 15, true, "hunter2"); |
a69ed767 | 113 | addLabel(i18n.getString("textField5"), 1, row); |
24489803 | 114 | TField selected = addField(35, row++, 40, false, |
a69ed767 | 115 | i18n.getString("textField6")); |
2ce6dab2 KL |
116 | row += 1; |
117 | ||
051e2913 KL |
118 | calendar = addCalendar(1, row++, |
119 | new TAction() { | |
120 | public void DO() { | |
a69ed767 KL |
121 | getApplication().messageBox(i18n.getString("calendarTitle"), |
122 | MessageFormat.format(i18n.getString("calendarMessage"), | |
123 | new Date(calendar.getValue().getTimeInMillis())), | |
051e2913 KL |
124 | TMessageBox.Type.OK); |
125 | } | |
126 | } | |
127 | ); | |
128 | ||
3096642b KL |
129 | dayOfWeekLabel = addLabel("Wednesday-", 35, row - 1, "tmenu", false); |
130 | dayOfWeekLabel.setLabel(String.format("%-10s", | |
131 | dayOfWeekCalendar.getDisplayName(Calendar.DAY_OF_WEEK, | |
132 | Calendar.LONG, Locale.getDefault()))); | |
133 | ||
134 | addSpinner(35 + dayOfWeekLabel.getWidth(), row - 1, | |
135 | new TAction() { | |
136 | public void DO() { | |
137 | dayOfWeekCalendar.add(Calendar.DAY_OF_WEEK, 1); | |
138 | dayOfWeekLabel.setLabel(String.format("%-10s", | |
139 | dayOfWeekCalendar.getDisplayName( | |
140 | Calendar.DAY_OF_WEEK, Calendar.LONG, | |
141 | Locale.getDefault()))); | |
142 | } | |
143 | }, | |
144 | new TAction() { | |
145 | public void DO() { | |
146 | dayOfWeekCalendar.add(Calendar.DAY_OF_WEEK, -1); | |
147 | dayOfWeekLabel.setLabel(String.format("%-10s", | |
148 | dayOfWeekCalendar.getDisplayName( | |
149 | Calendar.DAY_OF_WEEK, Calendar.LONG, | |
150 | Locale.getDefault()))); | |
151 | } | |
152 | } | |
153 | ); | |
154 | ||
155 | ||
a69ed767 KL |
156 | addButton(i18n.getString("closeWindow"), |
157 | (getWidth() - 14) / 2, getHeight() - 4, | |
2ce6dab2 KL |
158 | new TAction() { |
159 | public void DO() { | |
160 | getApplication().closeWindow(DemoTextFieldWindow.this); | |
161 | } | |
162 | } | |
163 | ); | |
164 | ||
24489803 KL |
165 | activate(selected); |
166 | ||
a69ed767 KL |
167 | statusBar = newStatusBar(i18n.getString("statusBar")); |
168 | statusBar.addShortcutKeypress(kbF1, cmHelp, | |
169 | i18n.getString("statusBarHelp")); | |
170 | statusBar.addShortcutKeypress(kbF2, cmShell, | |
171 | i18n.getString("statusBarShell")); | |
172 | statusBar.addShortcutKeypress(kbF3, cmOpen, | |
173 | i18n.getString("statusBarOpen")); | |
174 | statusBar.addShortcutKeypress(kbF10, cmExit, | |
175 | i18n.getString("statusBarExit")); | |
2ce6dab2 | 176 | } |
43ad7b6c | 177 | |
2ce6dab2 | 178 | } |