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