d425c6683063005be6bc4caa6e672b9cbd18ed5d
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
69 * @param text the text string
71 public DemoTableWindow(final TApplication parent
, final String title
) {
73 super(parent
, title
, 0, 0, 44, 22, RESIZABLE
);
74 tableField
= new TTableWidget(this, 0, 0, 42, 20);
76 statusBar
= newStatusBar(i18n
.getString("statusBar"));
77 statusBar
.addShortcutKeypress(kbF1
, cmHelp
,
78 i18n
.getString("statusBarHelp"));
79 statusBar
.addShortcutKeypress(kbF2
, cmShell
,
80 i18n
.getString("statusBarShell"));
81 statusBar
.addShortcutKeypress(kbF10
, cmExit
,
82 i18n
.getString("statusBarExit"));
88 * @param parent the main application
90 public DemoTableWindow(final TApplication parent
) {
91 this(parent
, i18n
.getString("windowTitle"));
94 // ------------------------------------------------------------------------
95 // TWindow ----------------------------------------------------------------
96 // ------------------------------------------------------------------------
99 * Handle window/screen resize events.
101 * @param event resize event
104 public void onResize(final TResizeEvent event
) {
105 if (event
.getType() == TResizeEvent
.Type
.WIDGET
) {
106 // Resize the text field
107 TResizeEvent tableSize
= new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
108 event
.getWidth() - 2, event
.getHeight() - 2);
109 tableField
.onResize(tableSize
);
113 // Pass to children instead
114 for (TWidget widget
: getChildren()) {
115 widget
.onResize(event
);