| 1 | /* |
| 2 | * Jexer - Java Text User Interface |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (C) 2017 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.util.ArrayList; |
| 32 | import java.util.List; |
| 33 | |
| 34 | import jexer.*; |
| 35 | import static jexer.TCommand.*; |
| 36 | import static jexer.TKeypress.*; |
| 37 | |
| 38 | /** |
| 39 | * This window demonstates the TRadioGroup, TRadioButton, and TCheckBox |
| 40 | * widgets. |
| 41 | */ |
| 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; |
| 53 | |
| 54 | // ------------------------------------------------------------------------ |
| 55 | // Constructors ----------------------------------------------------------- |
| 56 | // ------------------------------------------------------------------------ |
| 57 | |
| 58 | /** |
| 59 | * Constructor. |
| 60 | * |
| 61 | * @param parent the main application |
| 62 | */ |
| 63 | DemoCheckBoxWindow(final TApplication parent) { |
| 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 | */ |
| 73 | DemoCheckBoxWindow(final TApplication parent, final int flags) { |
| 74 | // Construct a demo window. X and Y don't matter because it will be |
| 75 | // centered on screen. |
| 76 | super(parent, "Radiobuttons, CheckBoxes, and ComboBox", |
| 77 | 0, 0, 60, 17, flags); |
| 78 | |
| 79 | int row = 1; |
| 80 | |
| 81 | // Add some widgets |
| 82 | addLabel("Check box example 1", 1, row); |
| 83 | addCheckBox(35, row++, "CheckBox 1", false); |
| 84 | addLabel("Check box example 2", 1, row); |
| 85 | addCheckBox(35, row++, "CheckBox 2", true); |
| 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 | |
| 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 | |
| 119 | addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4, |
| 120 | new TAction() { |
| 121 | public void DO() { |
| 122 | DemoCheckBoxWindow.this.getApplication() |
| 123 | .closeWindow(DemoCheckBoxWindow.this); |
| 124 | } |
| 125 | } |
| 126 | ); |
| 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"); |
| 133 | } |
| 134 | |
| 135 | } |