demo ttablewidget window
[fanfix.git] / src / jexer / demos / DemoTableWindow.java
CommitLineData
766e7308
KL
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 */
29package jexer.demos;
30
31import java.util.ResourceBundle;
32
33import jexer.TApplication;
34import jexer.TTableWidget;
35import jexer.TWidget;
36import jexer.TWindow;
37import jexer.event.TResizeEvent;
38import static jexer.TCommand.*;
39import static jexer.TKeypress.*;
40
41/**
42 * This window demonstates the TTable widget.
43 */
44public 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 * @param text the text string
70 */
71 public DemoTableWindow(final TApplication parent, final String title) {
72
73 super(parent, title, 0, 0, 44, 22, RESIZABLE);
74 tableField = new TTableWidget(this, 0, 0, 42, 20);
75
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"));
83 }
84
85 /**
86 * Public constructor.
87 *
88 * @param parent the main application
89 */
90 public DemoTableWindow(final TApplication parent) {
91 this(parent, i18n.getString("windowTitle"));
92 }
93
94 // ------------------------------------------------------------------------
95 // TWindow ----------------------------------------------------------------
96 // ------------------------------------------------------------------------
97
98 /**
99 * Handle window/screen resize events.
100 *
101 * @param event resize event
102 */
103 @Override
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);
110 return;
111 }
112
113 // Pass to children instead
114 for (TWidget widget: getChildren()) {
115 widget.onResize(event);
116 }
117 }
118
119}