resizing fixes
[fanfix.git] / src / jexer / demos / DemoCheckBoxWindow.java
CommitLineData
e3dfbd23
KL
1/*
2 * Jexer - Java Text User Interface
3 *
e16dda65 4 * The MIT License (MIT)
e3dfbd23 5 *
a69ed767 6 * Copyright (C) 2019 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 */
29package jexer.demos;
30
a69ed767 31import java.text.MessageFormat;
051e2913
KL
32import java.util.ArrayList;
33import java.util.List;
a69ed767
KL
34import java.util.ResourceBundle;
35
36import jexer.TAction;
37import jexer.TApplication;
38import jexer.TComboBox;
39import jexer.TMessageBox;
40import jexer.TRadioGroup;
41import jexer.TWindow;
d8dc8aea 42import jexer.layout.StretchLayoutManager;
2ce6dab2
KL
43import static jexer.TCommand.*;
44import static jexer.TKeypress.*;
e3dfbd23
KL
45
46/**
051e2913 47 * This window demonstates the TRadioGroup, TRadioButton, and TCheckBox
e3dfbd23
KL
48 * widgets.
49 */
051e2913
KL
50public class DemoCheckBoxWindow extends TWindow {
51
a69ed767
KL
52 /**
53 * Translated strings.
54 */
55 private static final ResourceBundle i18n = ResourceBundle.getBundle(DemoCheckBoxWindow.class.getName());
56
051e2913
KL
57 // ------------------------------------------------------------------------
58 // Variables --------------------------------------------------------------
59 // ------------------------------------------------------------------------
60
61 /**
62 * Combo box. Has to be at class scope so that it can be accessed by the
63 * anonymous TAction class.
64 */
65 TComboBox comboBox = null;
e3dfbd23 66
43ad7b6c
KL
67 // ------------------------------------------------------------------------
68 // Constructors -----------------------------------------------------------
69 // ------------------------------------------------------------------------
70
e3dfbd23
KL
71 /**
72 * Constructor.
73 *
74 * @param parent the main application
75 */
051e2913 76 DemoCheckBoxWindow(final TApplication parent) {
e3dfbd23
KL
77 this(parent, CENTERED | RESIZABLE);
78 }
79
80 /**
81 * Constructor.
82 *
83 * @param parent the main application
84 * @param flags bitmask of MODAL, CENTERED, or RESIZABLE
85 */
051e2913 86 DemoCheckBoxWindow(final TApplication parent, final int flags) {
e3dfbd23
KL
87 // Construct a demo window. X and Y don't matter because it will be
88 // centered on screen.
a69ed767 89 super(parent, i18n.getString("windowTitle"), 0, 0, 60, 17, flags);
e3dfbd23 90
d8dc8aea
KL
91 setLayoutManager(new StretchLayoutManager(getWidth(), getHeight()));
92
e3dfbd23
KL
93 int row = 1;
94
95 // Add some widgets
a69ed767
KL
96 addLabel(i18n.getString("checkBoxLabel1"), 1, row);
97 addCheckBox(35, row++, i18n.getString("checkBoxText1"), false);
98 addLabel(i18n.getString("checkBoxLabel2"), 1, row);
99 addCheckBox(35, row++, i18n.getString("checkBoxText2"), true);
e3dfbd23
KL
100 row += 2;
101
a69ed767
KL
102 TRadioGroup group = addRadioGroup(1, row,
103 i18n.getString("radioGroupTitle"));
104 group.addRadioButton(i18n.getString("radioOption1"));
105 group.addRadioButton(i18n.getString("radioOption2"));
106 group.addRadioButton(i18n.getString("radioOption3"));
e3dfbd23 107
051e2913 108 List<String> comboValues = new ArrayList<String>();
a69ed767
KL
109 comboValues.add(i18n.getString("comboBoxString0"));
110 comboValues.add(i18n.getString("comboBoxString1"));
111 comboValues.add(i18n.getString("comboBoxString2"));
112 comboValues.add(i18n.getString("comboBoxString3"));
113 comboValues.add(i18n.getString("comboBoxString4"));
114 comboValues.add(i18n.getString("comboBoxString5"));
115 comboValues.add(i18n.getString("comboBoxString6"));
116 comboValues.add(i18n.getString("comboBoxString7"));
117 comboValues.add(i18n.getString("comboBoxString8"));
118 comboValues.add(i18n.getString("comboBoxString9"));
119 comboValues.add(i18n.getString("comboBoxString10"));
051e2913
KL
120
121 comboBox = addComboBox(35, row, 12, comboValues, 2, 6,
122 new TAction() {
123 public void DO() {
a69ed767
KL
124 getApplication().messageBox(i18n.getString("messageBoxTitle"),
125 MessageFormat.format(i18n.getString("messageBoxPrompt"),
126 comboBox.getText()),
051e2913
KL
127 TMessageBox.Type.OK);
128 }
129 }
130 );
131
a69ed767
KL
132 addButton(i18n.getString("closeWindow"),
133 (getWidth() - 14) / 2, getHeight() - 4,
e3dfbd23
KL
134 new TAction() {
135 public void DO() {
051e2913
KL
136 DemoCheckBoxWindow.this.getApplication()
137 .closeWindow(DemoCheckBoxWindow.this);
e3dfbd23
KL
138 }
139 }
140 );
2ce6dab2 141
a69ed767
KL
142 statusBar = newStatusBar(i18n.getString("statusBar"));
143 statusBar.addShortcutKeypress(kbF1, cmHelp,
144 i18n.getString("statusBarHelp"));
145 statusBar.addShortcutKeypress(kbF2, cmShell,
146 i18n.getString("statusBarShell"));
147 statusBar.addShortcutKeypress(kbF3, cmOpen,
148 i18n.getString("statusBarOpen"));
149 statusBar.addShortcutKeypress(kbF10, cmExit,
150 i18n.getString("statusBarExit"));
e3dfbd23
KL
151 }
152
153}