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
;
12 import jexer
.event
.TKeypressEvent
;
13 import be
.nikiroo
.jvcard
.tui
.TuiLauncherJexer
;
16 * A basic window for using with jVCard.
20 public abstract class TuiBasicWindow
extends TWindow
{
21 private TApplication app
;
22 private Map
<TKeypress
, TAction
> keyBindings
;
23 private List
<TAction
> closeListeners
;
26 * Create a new window with the given title.
29 * the application that will manage this window
33 public TuiBasicWindow(TApplication app
, String title
) {
34 // Note: will not support screen with less than 10x10
36 Math
.min(36, app
.getScreen().getWidth() - 9), //
37 Math
.min(16, app
.getScreen().getHeight() - 9) //
42 keyBindings
= new HashMap
<TKeypress
, TAction
>();
43 closeListeners
= new ArrayList
<TAction
>();
45 if (TuiLauncherJexer
.FULLSCREEN
) {
51 * Add a key binding, that is, describe a key to press and its action on he
59 public void addKeyBinding(TKeypress key
, TAction action
) {
60 keyBindings
.put(key
, action
);
64 * Add a close listener on this window that will be called when the window
70 public void addCloseListener(TAction listener
) {
71 closeListeners
.add(listener
);
78 app
.closeWindow(this);
82 public void onClose() {
84 for (TAction listener
: closeListeners
) {
90 public void onKeypress(TKeypressEvent keypress
) {
91 if (keyBindings
.containsKey(keypress
.getKey())) {
92 keyBindings
.get(keypress
.getKey()).DO();
94 super.onKeypress(keypress
);