Commit | Line | Data |
---|---|---|
e3dfbd23 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
e16dda65 | 4 | * The MIT License (MIT) |
e3dfbd23 | 5 | * |
a2018e99 | 6 | * Copyright (C) 2017 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 | ||
051e2913 KL |
31 | import java.util.ArrayList; |
32 | import java.util.List; | |
33 | ||
e3dfbd23 | 34 | import jexer.*; |
2ce6dab2 KL |
35 | import static jexer.TCommand.*; |
36 | import static jexer.TKeypress.*; | |
e3dfbd23 KL |
37 | |
38 | /** | |
051e2913 | 39 | * This window demonstates the TRadioGroup, TRadioButton, and TCheckBox |
e3dfbd23 KL |
40 | * widgets. |
41 | */ | |
051e2913 KL |
42 | public class DemoCheckBoxWindow extends TWindow { |
43 | ||
44 | // ------------------------------------------------------------------------ | |
45 | // Variables -------------------------------------------------------------- | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
48 | /** | |
49 | * Combo box. Has to be at class scope so that it can be accessed by the | |
50 | * anonymous TAction class. | |
51 | */ | |
52 | TComboBox comboBox = null; | |
e3dfbd23 | 53 | |
43ad7b6c KL |
54 | // ------------------------------------------------------------------------ |
55 | // Constructors ----------------------------------------------------------- | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
e3dfbd23 KL |
58 | /** |
59 | * Constructor. | |
60 | * | |
61 | * @param parent the main application | |
62 | */ | |
051e2913 | 63 | DemoCheckBoxWindow(final TApplication parent) { |
e3dfbd23 KL |
64 | this(parent, CENTERED | RESIZABLE); |
65 | } | |
66 | ||
67 | /** | |
68 | * Constructor. | |
69 | * | |
70 | * @param parent the main application | |
71 | * @param flags bitmask of MODAL, CENTERED, or RESIZABLE | |
72 | */ | |
051e2913 | 73 | DemoCheckBoxWindow(final TApplication parent, final int flags) { |
e3dfbd23 KL |
74 | // Construct a demo window. X and Y don't matter because it will be |
75 | // centered on screen. | |
051e2913 KL |
76 | super(parent, "Radiobuttons, CheckBoxes, and ComboBox", |
77 | 0, 0, 60, 17, flags); | |
e3dfbd23 KL |
78 | |
79 | int row = 1; | |
80 | ||
81 | // Add some widgets | |
82 | addLabel("Check box example 1", 1, row); | |
051e2913 | 83 | addCheckBox(35, row++, "CheckBox 1", false); |
e3dfbd23 | 84 | addLabel("Check box example 2", 1, row); |
051e2913 | 85 | addCheckBox(35, row++, "CheckBox 2", true); |
e3dfbd23 KL |
86 | row += 2; |
87 | ||
88 | TRadioGroup group = addRadioGroup(1, row, "Group 1"); | |
89 | group.addRadioButton("Radio option 1"); | |
90 | group.addRadioButton("Radio option 2"); | |
91 | group.addRadioButton("Radio option 3"); | |
92 | ||
051e2913 KL |
93 | List<String> comboValues = new ArrayList<String>(); |
94 | comboValues.add("String 0"); | |
95 | comboValues.add("String 1"); | |
96 | comboValues.add("String 2"); | |
97 | comboValues.add("String 3"); | |
98 | comboValues.add("String 4"); | |
99 | comboValues.add("String 5"); | |
100 | comboValues.add("String 6"); | |
101 | comboValues.add("String 7"); | |
102 | comboValues.add("String 8"); | |
103 | comboValues.add("String 9"); | |
104 | comboValues.add("String 10"); | |
105 | ||
106 | comboBox = addComboBox(35, row, 12, comboValues, 2, 6, | |
107 | new TAction() { | |
108 | public void DO() { | |
109 | getApplication().messageBox("ComboBox", | |
110 | "You selected the following value:\n" + | |
111 | "\n" + | |
112 | comboBox.getText() + | |
113 | "\n", | |
114 | TMessageBox.Type.OK); | |
115 | } | |
116 | } | |
117 | ); | |
118 | ||
e3dfbd23 KL |
119 | addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4, |
120 | new TAction() { | |
121 | public void DO() { | |
051e2913 KL |
122 | DemoCheckBoxWindow.this.getApplication() |
123 | .closeWindow(DemoCheckBoxWindow.this); | |
e3dfbd23 KL |
124 | } |
125 | } | |
126 | ); | |
2ce6dab2 KL |
127 | |
128 | statusBar = newStatusBar("Radiobuttons and checkboxes"); | |
129 | statusBar.addShortcutKeypress(kbF1, cmHelp, "Help"); | |
130 | statusBar.addShortcutKeypress(kbF2, cmShell, "Shell"); | |
131 | statusBar.addShortcutKeypress(kbF3, cmOpen, "Open"); | |
132 | statusBar.addShortcutKeypress(kbF10, cmExit, "Exit"); | |
e3dfbd23 KL |
133 | } |
134 | ||
135 | } |