| 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.util.ResourceBundle; |
| 32 | |
| 33 | import jexer.TApplication; |
| 34 | import jexer.TTableWidget; |
| 35 | import jexer.TWidget; |
| 36 | import jexer.TWindow; |
| 37 | import jexer.event.TResizeEvent; |
| 38 | import static jexer.TCommand.*; |
| 39 | import static jexer.TKeypress.*; |
| 40 | |
| 41 | /** |
| 42 | * This window demonstates the TTable widget. |
| 43 | */ |
| 44 | public class DemoTableWindow extends TWindow { |
| 45 | |
| 46 | /** |
| 47 | * Translated strings. |
| 48 | */ |
| 49 | private static final ResourceBundle i18n = ResourceBundle.getBundle(DemoTableWindow.class.getName()); |
| 50 | |
| 51 | // ------------------------------------------------------------------------ |
| 52 | // Variables -------------------------------------------------------------- |
| 53 | // ------------------------------------------------------------------------ |
| 54 | |
| 55 | /** |
| 56 | * Hang onto my TTable so I can resize it with the window. |
| 57 | */ |
| 58 | private TTableWidget tableField; |
| 59 | |
| 60 | // ------------------------------------------------------------------------ |
| 61 | // Constructors ----------------------------------------------------------- |
| 62 | // ------------------------------------------------------------------------ |
| 63 | |
| 64 | /** |
| 65 | * Public constructor makes a text window out of any string. |
| 66 | * |
| 67 | * @param parent the main application |
| 68 | * @param title the text string |
| 69 | */ |
| 70 | public DemoTableWindow(final TApplication parent, final String title) { |
| 71 | |
| 72 | super(parent, title, 0, 0, 44, 22, RESIZABLE); |
| 73 | tableField = new TTableWidget(this, 0, 0, 42, 20); |
| 74 | |
| 75 | statusBar = newStatusBar(i18n.getString("statusBar")); |
| 76 | statusBar.addShortcutKeypress(kbF1, cmHelp, |
| 77 | i18n.getString("statusBarHelp")); |
| 78 | statusBar.addShortcutKeypress(kbF2, cmShell, |
| 79 | i18n.getString("statusBarShell")); |
| 80 | statusBar.addShortcutKeypress(kbF10, cmExit, |
| 81 | i18n.getString("statusBarExit")); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Public constructor. |
| 86 | * |
| 87 | * @param parent the main application |
| 88 | */ |
| 89 | public DemoTableWindow(final TApplication parent) { |
| 90 | this(parent, i18n.getString("windowTitle")); |
| 91 | } |
| 92 | |
| 93 | // ------------------------------------------------------------------------ |
| 94 | // TWindow ---------------------------------------------------------------- |
| 95 | // ------------------------------------------------------------------------ |
| 96 | |
| 97 | /** |
| 98 | * Handle window/screen resize events. |
| 99 | * |
| 100 | * @param event resize event |
| 101 | */ |
| 102 | @Override |
| 103 | public void onResize(final TResizeEvent event) { |
| 104 | if (event.getType() == TResizeEvent.Type.WIDGET) { |
| 105 | // Resize the text field |
| 106 | TResizeEvent tableSize = new TResizeEvent(TResizeEvent.Type.WIDGET, |
| 107 | event.getWidth() - 2, event.getHeight() - 2); |
| 108 | tableField.onResize(tableSize); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | // Pass to children instead |
| 113 | for (TWidget widget: getChildren()) { |
| 114 | widget.onResize(event); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | } |