2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 import java
.util
.ResourceBundle
;
33 import jexer
.TApplication
;
34 import jexer
.TTableWidget
;
37 import jexer
.event
.TResizeEvent
;
38 import static jexer
.TCommand
.*;
39 import static jexer
.TKeypress
.*;
42 * This window demonstates the TTable widget.
44 public class DemoTableWindow
extends TWindow
{
49 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(DemoTableWindow
.class.getName());
51 // ------------------------------------------------------------------------
52 // Variables --------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * Hang onto my TTable so I can resize it with the window.
58 private TTableWidget tableField
;
60 // ------------------------------------------------------------------------
61 // Constructors -----------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * Public constructor makes a text window out of any string.
67 * @param parent the main application
68 * @param title the text string
70 public DemoTableWindow(final TApplication parent
, final String title
) {
72 super(parent
, title
, 0, 0, 44, 22, RESIZABLE
);
73 tableField
= new TTableWidget(this, 0, 0, 42, 20);
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"));
87 * @param parent the main application
89 public DemoTableWindow(final TApplication parent
) {
90 this(parent
, i18n
.getString("windowTitle"));
93 // ------------------------------------------------------------------------
94 // TWindow ----------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * Handle window/screen resize events.
100 * @param event resize event
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
);
112 // Pass to children instead
113 for (TWidget widget
: getChildren()) {
114 widget
.onResize(event
);