Commit | Line | Data |
---|---|---|
2ce6dab2 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
4 | * The MIT License (MIT) | |
5 | * | |
a2018e99 | 6 | * Copyright (C) 2017 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 | ||
051e2913 KL |
31 | import java.util.*; |
32 | ||
2ce6dab2 KL |
33 | import jexer.*; |
34 | import static jexer.TCommand.*; | |
35 | import static jexer.TKeypress.*; | |
36 | ||
37 | /** | |
38 | * This window demonstates the TField and TPasswordField widgets. | |
39 | */ | |
40 | public class DemoTextFieldWindow extends TWindow { | |
41 | ||
051e2913 KL |
42 | // ------------------------------------------------------------------------ |
43 | // Variables -------------------------------------------------------------- | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
46 | /** | |
47 | * Calendar. Has to be at class scope so that it can be accessed by the | |
48 | * anonymous TAction class. | |
49 | */ | |
50 | TCalendar calendar = null; | |
51 | ||
43ad7b6c KL |
52 | // ------------------------------------------------------------------------ |
53 | // Constructors ----------------------------------------------------------- | |
54 | // ------------------------------------------------------------------------ | |
55 | ||
2ce6dab2 KL |
56 | /** |
57 | * Constructor. | |
58 | * | |
59 | * @param parent the main application | |
60 | */ | |
61 | DemoTextFieldWindow(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 | DemoTextFieldWindow(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. | |
051e2913 | 74 | super(parent, "Text Fields", 0, 0, 60, 20, flags); |
2ce6dab2 KL |
75 | |
76 | int row = 1; | |
77 | ||
78 | addLabel("Variable-width text field:", 1, row); | |
79 | addField(35, row++, 15, false, "Field text"); | |
80 | addLabel("Fixed-width text field:", 1, row); | |
81 | addField(35, row++, 15, true); | |
82 | addLabel("Variable-width password:", 1, row); | |
83 | addPasswordField(35, row++, 15, false); | |
84 | addLabel("Fixed-width password:", 1, row); | |
85 | addPasswordField(35, row++, 15, true, "hunter2"); | |
24489803 KL |
86 | addLabel("Very long text field:", 1, row); |
87 | TField selected = addField(35, row++, 40, false, | |
88 | "Very very long field text that should be outside the window"); | |
2ce6dab2 KL |
89 | row += 1; |
90 | ||
051e2913 KL |
91 | calendar = addCalendar(1, row++, |
92 | new TAction() { | |
93 | public void DO() { | |
94 | getApplication().messageBox("Calendar", | |
95 | "You selected the following date:\n" + | |
96 | "\n" + | |
97 | new Date(calendar.getValue().getTimeInMillis()) + | |
98 | "\n", | |
99 | TMessageBox.Type.OK); | |
100 | } | |
101 | } | |
102 | ); | |
103 | ||
2ce6dab2 KL |
104 | addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4, |
105 | new TAction() { | |
106 | public void DO() { | |
107 | getApplication().closeWindow(DemoTextFieldWindow.this); | |
108 | } | |
109 | } | |
110 | ); | |
111 | ||
24489803 KL |
112 | activate(selected); |
113 | ||
2ce6dab2 KL |
114 | statusBar = newStatusBar("Text fields"); |
115 | statusBar.addShortcutKeypress(kbF1, cmHelp, "Help"); | |
116 | statusBar.addShortcutKeypress(kbF2, cmShell, "Shell"); | |
117 | statusBar.addShortcutKeypress(kbF3, cmOpen, "Open"); | |
118 | statusBar.addShortcutKeypress(kbF10, cmExit, "Exit"); | |
119 | } | |
43ad7b6c | 120 | |
2ce6dab2 | 121 | } |