6101d27dc637bd1d6a0137781d64df470b10d479
[nikiroo-utils.git] / src / jexer / demos / DemoTreeViewWindow.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * License: LGPLv3 or later
5 *
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
9 *
10 * Copyright (C) 2015 Kevin Lamonte
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * 02110-1301 USA
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
30 */
31 package jexer.demos;
32
33 import java.io.IOException;
34
35 import jexer.*;
36 import jexer.event.*;
37
38 /**
39 * This window demonstates the TTreeView widget.
40 */
41 public class DemoTreeViewWindow extends TWindow {
42
43 /**
44 * Hang onto my TTreeView so I can resize it with the window.
45 */
46 private TTreeView treeView;
47
48 /**
49 * Public constructor.
50 *
51 * @param parent the main application
52 * @throws IOException if a java.io operation throws
53 */
54 public DemoTreeViewWindow(final TApplication parent) throws IOException {
55 super(parent, "Tree View", 0, 0, 44, 16, TWindow.RESIZABLE);
56
57 // Load the treeview with "stuff"
58 treeView = addTreeView(1, 1, 40, 12);
59 new TDirectoryTreeItem(treeView, ".", true);
60 }
61
62 /**
63 * Handle window/screen resize events.
64 *
65 * @param resize resize event
66 */
67 @Override
68 public void onResize(final TResizeEvent resize) {
69 if (resize.getType() == TResizeEvent.Type.WIDGET) {
70 // Resize the text field
71 treeView.setWidth(resize.getWidth() - 4);
72 treeView.setHeight(resize.getHeight() - 4);
73 treeView.reflow();
74 return;
75 }
76
77 // Pass to children instead
78 for (TWidget widget: getChildren()) {
79 widget.onResize(resize);
80 }
81 }
82
83 }