2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 import java
.text
.MessageFormat
;
32 import java
.util
.Calendar
;
33 import java
.util
.Date
;
34 import java
.util
.GregorianCalendar
;
35 import java
.util
.Locale
;
36 import java
.util
.ResourceBundle
;
39 import jexer
.TApplication
;
40 import jexer
.TCalendar
;
43 import jexer
.TMessageBox
;
45 import jexer
.layout
.StretchLayoutManager
;
46 import static jexer
.TCommand
.*;
47 import static jexer
.TKeypress
.*;
50 * This window demonstates the TField and TPasswordField widgets.
52 public class DemoTextFieldWindow
extends TWindow
{
57 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(DemoTextFieldWindow
.class.getName());
59 // ------------------------------------------------------------------------
60 // Variables --------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Calendar. Has to be at class scope so that it can be accessed by the
65 * anonymous TAction class.
67 TCalendar calendar
= null;
70 * Day of week label is updated with TSpinner clicks.
72 TLabel dayOfWeekLabel
;
75 * Day of week to demonstrate TSpinner. Has to be at class scope so that
76 * it can be accessed by the anonymous TAction class.
78 GregorianCalendar dayOfWeekCalendar
= new GregorianCalendar();
80 // ------------------------------------------------------------------------
81 // Constructors -----------------------------------------------------------
82 // ------------------------------------------------------------------------
87 * @param parent the main application
89 DemoTextFieldWindow(final TApplication parent
) {
90 this(parent
, TWindow
.CENTERED
| TWindow
.RESIZABLE
);
96 * @param parent the main application
97 * @param flags bitmask of MODAL, CENTERED, or RESIZABLE
99 DemoTextFieldWindow(final TApplication parent
, final int flags
) {
100 // Construct a demo window. X and Y don't matter because it
101 // will be centered on screen.
102 super(parent
, i18n
.getString("windowTitle"), 0, 0, 60, 20, flags
);
104 setLayoutManager(new StretchLayoutManager(getWidth() - 2,
109 addLabel(i18n
.getString("textField1"), 1, row
);
110 addField(35, row
++, 15, false, "Field text");
111 addLabel(i18n
.getString("textField2"), 1, row
);
112 addField(35, row
++, 15, true);
113 addLabel(i18n
.getString("textField3"), 1, row
);
114 addPasswordField(35, row
++, 15, false);
115 addLabel(i18n
.getString("textField4"), 1, row
);
116 addPasswordField(35, row
++, 15, true, "hunter2");
117 addLabel(i18n
.getString("textField5"), 1, row
);
118 TField selected
= addField(35, row
++, 40, false,
119 i18n
.getString("textField6"));
122 calendar
= addCalendar(1, row
++,
125 getApplication().messageBox(i18n
.getString("calendarTitle"),
126 MessageFormat
.format(i18n
.getString("calendarMessage"),
127 new Date(calendar
.getValue().getTimeInMillis())),
128 TMessageBox
.Type
.OK
);
133 dayOfWeekLabel
= addLabel("Wednesday-", 35, row
- 1, "tmenu", false);
134 dayOfWeekLabel
.setLabel(String
.format("%-10s",
135 dayOfWeekCalendar
.getDisplayName(Calendar
.DAY_OF_WEEK
,
136 Calendar
.LONG
, Locale
.getDefault())));
138 addSpinner(35 + dayOfWeekLabel
.getWidth(), row
- 1,
141 dayOfWeekCalendar
.add(Calendar
.DAY_OF_WEEK
, 1);
142 dayOfWeekLabel
.setLabel(String
.format("%-10s",
143 dayOfWeekCalendar
.getDisplayName(
144 Calendar
.DAY_OF_WEEK
, Calendar
.LONG
,
145 Locale
.getDefault())));
150 dayOfWeekCalendar
.add(Calendar
.DAY_OF_WEEK
, -1);
151 dayOfWeekLabel
.setLabel(String
.format("%-10s",
152 dayOfWeekCalendar
.getDisplayName(
153 Calendar
.DAY_OF_WEEK
, Calendar
.LONG
,
154 Locale
.getDefault())));
160 addButton(i18n
.getString("closeWindow"),
161 (getWidth() - 14) / 2, getHeight() - 4,
164 getApplication().closeWindow(DemoTextFieldWindow
.this);
171 statusBar
= newStatusBar(i18n
.getString("statusBar"));
172 statusBar
.addShortcutKeypress(kbF1
, cmHelp
,
173 i18n
.getString("statusBarHelp"));
174 statusBar
.addShortcutKeypress(kbF2
, cmShell
,
175 i18n
.getString("statusBarShell"));
176 statusBar
.addShortcutKeypress(kbF3
, cmOpen
,
177 i18n
.getString("statusBarOpen"));
178 statusBar
.addShortcutKeypress(kbF10
, cmExit
,
179 i18n
.getString("statusBarExit"));