import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import jexer.bits.CellAttributes;
import jexer.bits.ColorTheme;
*/
private TMenu activeMenu = null;
+ /**
+ * Active keyboard accelerators.
+ */
+ private Map<TKeypress, TMenuItem> accelerators;
+
/**
* Windows and widgets pull colors from this ColorTheme.
*/
windows = new LinkedList<TWindow>();
menus = new LinkedList<TMenu>();
subMenus = new LinkedList<TMenu>();
+ accelerators = new HashMap<TKeypress, TMenuItem>();
}
/**
private void metaHandleEvent(final TInputEvent event) {
/*
- System.err.printf(String.format("metaHandleEvents event: %s\n",
- event)); System.err.flush();
+ System.err.printf(String.format("metaHandleEvents event: %s\n",
+ event)); System.err.flush();
*/
if (quit) {
return;
}
- // DEBUG
- if (event instanceof TKeypressEvent) {
- TKeypressEvent keypress = (TKeypressEvent) event;
- if (keypress.equals(kbAltX)) {
- quit = true;
- return;
- }
- }
- // DEBUG
-
// Special application-wide events -------------------------------
// Abort everything
return;
}
- /*
- TODO
-
if (event instanceof TKeypressEvent) {
TKeypressEvent keypress = (TKeypressEvent) event;
+
// See if this key matches an accelerator, and if so dispatch the
// menu event.
TKeypress keypressLowercase = keypress.getKey().toLowerCase();
- TMenuItem item = accelerators.get(keypressLowercase);
+ TMenuItem item = null;
+ synchronized (accelerators) {
+ item = accelerators.get(keypressLowercase);
+ }
if (item != null) {
// Let the menu item dispatch
item.dispatch();
}
}
}
- */
if (event instanceof TCommandEvent) {
if (onCommand((TCommandEvent) event)) {
*/
public final void addAccelerator(final TMenuItem item,
final TKeypress keypress) {
- /*
- TODO
- assert((keypress in accelerators) is null);
- accelerators[keypress] = item;
- */
+
+ // System.err.printf("addAccelerator: key %s item %s\n", keypress, item);
+
+ synchronized (accelerators) {
+ assert (accelerators.get(keypress) == null);
+ accelerators.put(keypress, item);
+ }
}
/**