X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDemoMainWindow.java;h=85d03414307465fe3930f881d979c2e4fc7b81f3;hb=df602ccf5e32585c26dc618dd3b4a759b6820943;hp=8840605e017ef90a00fcc210d86fafd42ae250df;hpb=71a389c9810382e014682dde52e94d3f34e385fa;p=nikiroo-utils.git diff --git a/src/jexer/demos/DemoMainWindow.java b/src/jexer/demos/DemoMainWindow.java index 8840605..85d0341 100644 --- a/src/jexer/demos/DemoMainWindow.java +++ b/src/jexer/demos/DemoMainWindow.java @@ -28,7 +28,10 @@ */ package jexer.demos; +import java.io.*; + import jexer.*; +import jexer.event.*; import static jexer.TCommand.*; import static jexer.TKeypress.*; @@ -206,4 +209,34 @@ public class DemoMainWindow extends TWindow { statusBar.addShortcutKeypress(kbF3, cmOpen, "Open"); statusBar.addShortcutKeypress(kbF10, cmExit, "Exit"); } + + /** + * Method that subclasses can override to handle posted command events. + * + * @param command command event + */ + @Override + public void onCommand(final TCommandEvent command) { + if (command.equals(cmOpen)) { + try { + String filename = fileOpenBox("."); + if (filename != null) { + try { + new TEditorWindow(getApplication(), new File(filename)); + } catch (IOException e) { + messageBox("Error", "Error reading file: " + + e.getMessage()); + } + } + } catch (IOException e) { + messageBox("Error", "Error opening file dialog: " + + e.getMessage()); + } + return; + } + + // Didn't handle it, let children get it instead + super.onCommand(command); + } + }