X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDemoMainWindow.java;h=209bd1350ccef2f4a2d7464dcd0d7b2c126d86f2;hb=be72cb5ccbd42fe304c0acafc380c5636f0d03a2;hp=febdb4096b7e27064d9a67a9c710dfa94ea9c2cf;hpb=2ce6dab2bbd951e6d0f09f94759efda5ee4b65ac;p=fanfix.git diff --git a/src/jexer/demos/DemoMainWindow.java b/src/jexer/demos/DemoMainWindow.java index febdb40..209bd13 100644 --- a/src/jexer/demos/DemoMainWindow.java +++ b/src/jexer/demos/DemoMainWindow.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2016 Kevin Lamonte + * Copyright (C) 2017 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -28,7 +28,10 @@ */ package jexer.demos; +import java.io.*; + import jexer.*; +import jexer.event.*; import static jexer.TCommand.*; import static jexer.TKeypress.*; @@ -77,7 +80,7 @@ public class DemoMainWindow extends TWindow { private DemoMainWindow(final TApplication parent, final int flags) { // Construct a demo window. X and Y don't matter because it will be // centered on screen. - super(parent, "Demo Window", 0, 0, 60, 22, flags); + super(parent, "Demo Window", 0, 0, 64, 23, flags); int row = 1; @@ -122,17 +125,22 @@ public class DemoMainWindow extends TWindow { ); row += 2; - /* - if (!isModal()) { - addLabel("Editor window", 1, row); - addButton("Edito&r", 35, row, - { - new TEditor(application, 0, 0, 60, 15); + addLabel("Editor window", 1, row); + addButton("&1 Widget", 35, row, + new TAction() { + public void DO() { + new DemoEditorWindow(getApplication()); } - ); - } + } + ); + addButton("&2 Window", 48, row, + new TAction() { + public void DO() { + new TEditorWindow(getApplication()); + } + } + ); row += 2; - */ addLabel("Text areas", 1, row); addButton("&Text", 35, row, @@ -189,6 +197,8 @@ public class DemoMainWindow extends TWindow { timerLabel.setWidth(timerLabel.getLabel().length()); if (timerI < 100) { timerI++; + } else { + timer.setRecurring(false); } progressBar.setValue(timerI); } @@ -201,4 +211,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); + } + }