X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDemoMainWindow.java;h=eef25e29aee47926195631f4ae7eea2bf517d22a;hb=43ad7b6c509c45c8f261e77ea059c10fed8c9f1c;hp=8840605e017ef90a00fcc210d86fafd42ae250df;hpb=71a389c9810382e014682dde52e94d3f34e385fa;p=fanfix.git diff --git a/src/jexer/demos/DemoMainWindow.java b/src/jexer/demos/DemoMainWindow.java index 8840605..eef25e2 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.*; @@ -38,21 +41,35 @@ import static jexer.TKeypress.*; */ public class DemoMainWindow extends TWindow { - // Timer that increments a number. + // ------------------------------------------------------------------------ + // Variables -------------------------------------------------------------- + // ------------------------------------------------------------------------ + + /** + * Timer that increments a number. + */ private TTimer timer; - // Timer label is updated with timer ticks. + /** + * Timer label is updated with timer ticks. + */ TLabel timerLabel; /** - * We need to override onClose so that the timer will no longer be called - * after we close the window. TTimers currently are completely unaware - * of the rest of the UI classes. + * Timer increment used by the timer loop. Has to be at class scope so + * that it can be accessed by the anonymous TAction class. */ - @Override - public void onClose() { - getApplication().removeTimer(timer); - } + int timerI = 0; + + /** + * Progress bar used by the timer loop. Has to be at class scope so that + * it can be accessed by the anonymous TAction class. + */ + TProgressBar progressBar; + + // ------------------------------------------------------------------------ + // Constructors ----------------------------------------------------------- + // ------------------------------------------------------------------------ /** * Construct demo window. It will be centered on screen. @@ -63,11 +80,6 @@ public class DemoMainWindow extends TWindow { this(parent, CENTERED | RESIZABLE); } - // These are used by the timer loop. They have to be at class scope so - // that they can be accessed by the anonymous TAction class. - int timerI = 0; - TProgressBar progressBar; - /** * Constructor. * @@ -194,6 +206,8 @@ public class DemoMainWindow extends TWindow { timerLabel.setWidth(timerLabel.getLabel().length()); if (timerI < 100) { timerI++; + } else { + timer.setRecurring(false); } progressBar.setValue(timerI); } @@ -206,4 +220,48 @@ public class DemoMainWindow extends TWindow { statusBar.addShortcutKeypress(kbF3, cmOpen, "Open"); statusBar.addShortcutKeypress(kbF10, cmExit, "Exit"); } + + // ------------------------------------------------------------------------ + // TWindow ---------------------------------------------------------------- + // ------------------------------------------------------------------------ + + /** + * We need to override onClose so that the timer will no longer be called + * after we close the window. TTimers currently are completely unaware + * of the rest of the UI classes. + */ + @Override + public void onClose() { + getApplication().removeTimer(timer); + } + + /** + * 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); + } + }