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 KL |
31 | import java.text.MessageFormat; |
32 | import java.util.Date; | |
33 | import java.util.ResourceBundle; | |
051e2913 | 34 | |
a69ed767 KL |
35 | import jexer.TAction; |
36 | import jexer.TApplication; | |
37 | import jexer.TCalendar; | |
38 | import jexer.TField; | |
39 | import jexer.TMessageBox; | |
40 | import jexer.TWindow; | |
2ce6dab2 KL |
41 | import static jexer.TCommand.*; |
42 | import static jexer.TKeypress.*; | |
43 | ||
44 | /** | |
45 | * This window demonstates the TField and TPasswordField widgets. | |
46 | */ | |
47 | public class DemoTextFieldWindow extends TWindow { | |
48 | ||
a69ed767 KL |
49 | /** |
50 | * Translated strings. | |
51 | */ | |
52 | private static final ResourceBundle i18n = ResourceBundle.getBundle(DemoTextFieldWindow.class.getName()); | |
53 | ||
051e2913 KL |
54 | // ------------------------------------------------------------------------ |
55 | // Variables -------------------------------------------------------------- | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
58 | /** | |
59 | * Calendar. Has to be at class scope so that it can be accessed by the | |
60 | * anonymous TAction class. | |
61 | */ | |
62 | TCalendar calendar = null; | |
63 | ||
43ad7b6c KL |
64 | // ------------------------------------------------------------------------ |
65 | // Constructors ----------------------------------------------------------- | |
66 | // ------------------------------------------------------------------------ | |
67 | ||
2ce6dab2 KL |
68 | /** |
69 | * Constructor. | |
70 | * | |
71 | * @param parent the main application | |
72 | */ | |
73 | DemoTextFieldWindow(final TApplication parent) { | |
74 | this(parent, TWindow.CENTERED | TWindow.RESIZABLE); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Constructor. | |
79 | * | |
80 | * @param parent the main application | |
81 | * @param flags bitmask of MODAL, CENTERED, or RESIZABLE | |
82 | */ | |
83 | DemoTextFieldWindow(final TApplication parent, final int flags) { | |
84 | // Construct a demo window. X and Y don't matter because it | |
85 | // will be centered on screen. | |
a69ed767 | 86 | super(parent, i18n.getString("windowTitle"), 0, 0, 60, 20, flags); |
2ce6dab2 KL |
87 | |
88 | int row = 1; | |
89 | ||
a69ed767 | 90 | addLabel(i18n.getString("textField1"), 1, row); |
2ce6dab2 | 91 | addField(35, row++, 15, false, "Field text"); |
a69ed767 | 92 | addLabel(i18n.getString("textField2"), 1, row); |
2ce6dab2 | 93 | addField(35, row++, 15, true); |
a69ed767 | 94 | addLabel(i18n.getString("textField3"), 1, row); |
2ce6dab2 | 95 | addPasswordField(35, row++, 15, false); |
a69ed767 | 96 | addLabel(i18n.getString("textField4"), 1, row); |
2ce6dab2 | 97 | addPasswordField(35, row++, 15, true, "hunter2"); |
a69ed767 | 98 | addLabel(i18n.getString("textField5"), 1, row); |
24489803 | 99 | TField selected = addField(35, row++, 40, false, |
a69ed767 | 100 | i18n.getString("textField6")); |
2ce6dab2 KL |
101 | row += 1; |
102 | ||
051e2913 KL |
103 | calendar = addCalendar(1, row++, |
104 | new TAction() { | |
105 | public void DO() { | |
a69ed767 KL |
106 | getApplication().messageBox(i18n.getString("calendarTitle"), |
107 | MessageFormat.format(i18n.getString("calendarMessage"), | |
108 | new Date(calendar.getValue().getTimeInMillis())), | |
051e2913 KL |
109 | TMessageBox.Type.OK); |
110 | } | |
111 | } | |
112 | ); | |
113 | ||
a69ed767 KL |
114 | addButton(i18n.getString("closeWindow"), |
115 | (getWidth() - 14) / 2, getHeight() - 4, | |
2ce6dab2 KL |
116 | new TAction() { |
117 | public void DO() { | |
118 | getApplication().closeWindow(DemoTextFieldWindow.this); | |
119 | } | |
120 | } | |
121 | ); | |
122 | ||
24489803 KL |
123 | activate(selected); |
124 | ||
a69ed767 KL |
125 | statusBar = newStatusBar(i18n.getString("statusBar")); |
126 | statusBar.addShortcutKeypress(kbF1, cmHelp, | |
127 | i18n.getString("statusBarHelp")); | |
128 | statusBar.addShortcutKeypress(kbF2, cmShell, | |
129 | i18n.getString("statusBarShell")); | |
130 | statusBar.addShortcutKeypress(kbF3, cmOpen, | |
131 | i18n.getString("statusBarOpen")); | |
132 | statusBar.addShortcutKeypress(kbF10, cmExit, | |
133 | i18n.getString("statusBarExit")); | |
2ce6dab2 | 134 | } |
43ad7b6c | 135 | |
2ce6dab2 | 136 | } |