55cc4aa6b3dea79b74e1094ab50b5a52b58c0172
1 package be
.nikiroo
.jvcard
.tui
.windows
;
3 import java
.util
.HashMap
;
8 import jexer
.TApplication
;
9 import jexer
.TKeypress
;
12 import jexer
.event
.TKeypressEvent
;
13 import jexer
.event
.TResizeEvent
;
14 import be
.nikiroo
.jvcard
.tui
.panes
.MainContent
;
16 public abstract class TuiBrowserWindow
extends TWindow
{
17 private TApplication app
;
19 private boolean showHeader
;
20 private Map
<TKeypress
, TAction
> keyBindings
;
22 public TuiBrowserWindow(TApplication app
, String title
, boolean showHeaders
) {
23 super(app
, title
, 10, 10);
26 this.showHeader
= showHeaders
;
28 table
= new TTable(this, 0, 0, getWidth(), getHeight(), new TAction() {
31 onAction(table
.getSelectedLine(), table
.getSelectedColumn());
35 keyBindings
= new HashMap
<TKeypress
, TAction
>();
37 // TODO: fullscreen selection?
39 // TODO: auto-maximize on FS, auto-resize on maximize
40 // setFullscreen(true);
46 * Change the currently displayed data.
49 * the table headers (mandatory)
53 public void setData(List
<String
> headers
, List
<List
<String
>> lines
) {
54 int prevLine
= table
.getSelectedLine();
55 int prevColumn
= table
.getSelectedColumn();
58 table
.setHeaders(headers
, showHeader
);
59 for (List
<String
> line
: lines
) {
65 table
.setSelectedLine(Math
.min(prevLine
, table
.getNumberOfLines() - 1));
66 table
.setSelectedColumn(Math
.min(prevColumn
,
67 table
.getNumberOfColumns() - 1));
70 public void addKeyBinding(TKeypress key
, TAction action
) {
71 keyBindings
.put(key
, action
);
75 * Return the number of items in this {@link MainContent}, or -1 if this
76 * {@link MainContent} is not countable.
78 * @return -1 or the number of present items
81 return table
.getNumberOfLines();
88 app
.closeWindow(this);
92 * An item has been selected.
95 * the currently selected line
96 * @param selectedColumn
97 * the currently selected column
99 @SuppressWarnings("unused")
100 public void onAction(int selectedLine
, int selectedColumn
) {
104 public void onResize(TResizeEvent resize
) {
105 super.onResize(resize
);
106 table
.setWidth(getWidth());
107 table
.setHeight(getHeight());
112 public void onKeypress(TKeypressEvent keypress
) {
113 if (keyBindings
.containsKey(keypress
.getKey())) {
114 keyBindings
.get(keypress
.getKey()).DO();
116 super.onKeypress(keypress
);