1 package be
.nikiroo
.jvcard
.tui
.windows
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
9 import jexer
.TApplication
;
10 import jexer
.TKeypress
;
11 import jexer
.TStatusBar
;
13 import jexer
.event
.TKeypressEvent
;
14 import be
.nikiroo
.jvcard
.tui
.TuiLauncherJexer
;
17 * A basic window for using with jVCard.
21 public abstract class TuiBasicWindow
extends TWindow
{
22 private TApplication app
;
23 private Map
<TKeypress
, TAction
> keyBindings
;
24 private List
<TAction
> closeListeners
;
27 * Create a new window with the given title.
30 * the parent {@link TuiBasicWindow}
34 public TuiBasicWindow(TuiBasicWindow parent
, String title
) {
35 this(parent
.app
, title
, parent
.getWidth(), parent
.getHeight());
39 * Create a new window with the given title.
42 * the application that will manage this window
50 public TuiBasicWindow(TApplication app
, String title
, int width
, int height
) {
51 super(app
, title
, width
, height
);
55 keyBindings
= new HashMap
<TKeypress
, TAction
>();
56 closeListeners
= new ArrayList
<TAction
>();
58 if (TuiLauncherJexer
.FULLSCREEN
) {
64 * Add a key binding, that is, describe a key to press and its action on he
70 * the text to display for this command
74 public void addKeyBinding(TKeypress key
, String text
, TAction action
) {
75 keyBindings
.put(key
, action
);
77 TStatusBar statusbar
= getStatusBar();
78 if (statusbar
== null) {
79 statusbar
= newStatusBar("");
82 statusbar
.addShortcutKeypress(key
, null, text
);
86 * Add a close listener on this window that will be called when the window
92 public void addCloseListener(TAction listener
) {
93 closeListeners
.add(listener
);
97 public void onClose() {
99 for (TAction listener
: closeListeners
) {
105 public void onKeypress(TKeypressEvent keypress
) {
106 if (keyBindings
.containsKey(keypress
.getKey())) {
107 keyBindings
.get(keypress
.getKey()).DO();
109 super.onKeypress(keypress
);