X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDemoMainWindow.java;h=eef25e29aee47926195631f4ae7eea2bf517d22a;hb=43ad7b6c509c45c8f261e77ea059c10fed8c9f1c;hp=9a834645c5aa6c6176453fc6838dc452ec2b7d6f;hpb=0d47c5460c8e9d1198928308767a63ad35f46eb8;p=fanfix.git diff --git a/src/jexer/demos/DemoMainWindow.java b/src/jexer/demos/DemoMainWindow.java index 9a83464..eef25e2 100644 --- a/src/jexer/demos/DemoMainWindow.java +++ b/src/jexer/demos/DemoMainWindow.java @@ -1,36 +1,39 @@ /* * Jexer - Java Text User Interface * - * License: LGPLv3 or later + * The MIT License (MIT) * - * This module is licensed under the GNU Lesser General Public License - * Version 3. Please see the file "COPYING" in this directory for more - * information about the GNU Lesser General Public License Version 3. + * Copyright (C) 2017 Kevin Lamonte * - * Copyright (C) 2015 Kevin Lamonte + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 3 of - * the License, or (at your option) any later version. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, see - * http://www.gnu.org/licenses/, or write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * @author Kevin Lamonte [kevin.lamonte@gmail.com] * @version 1 */ package jexer.demos; +import java.io.*; + import jexer.*; +import jexer.event.*; +import static jexer.TCommand.*; +import static jexer.TKeypress.*; /** * This is the main "demo" application window. It makes use of the TTimer, @@ -38,21 +41,35 @@ import jexer.*; */ 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. * @@ -77,21 +89,19 @@ 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, 23, flags); + super(parent, "Demo Window", 0, 0, 64, 23, flags); int row = 1; // Add some widgets - if (!isModal()) { - addLabel("Message Boxes", 1, row); - addButton("&MessageBoxes", 35, row, - new TAction() { - public void DO() { - new DemoMsgBoxWindow(getApplication()); - } + addLabel("Message Boxes", 1, row); + addButton("&MessageBoxes", 35, row, + new TAction() { + public void DO() { + new DemoMsgBoxWindow(getApplication()); } - ); - } + } + ); row += 2; addLabel("Open me as modal", 1, row); @@ -102,81 +112,87 @@ public class DemoMainWindow extends TWindow { } } ); + row += 2; + addLabel("Text fields", 1, row); + addButton("Field&s", 35, row, + new TAction() { + public void DO() { + new DemoTextFieldWindow(getApplication()); + } + } + ); row += 2; - addLabel("Variable-width text field:", 1, row); - addField(35, row++, 15, false, "Field text"); - addLabel("Fixed-width text field:", 1, row); - addField(35, row++, 15, true); - addLabel("Variable-width password:", 1, row); - addPasswordField(35, row++, 15, false); - addLabel("Fixed-width password:", 1, row); - addPasswordField(35, row++, 15, true, "hunter2"); + addLabel("Radio buttons and checkboxes", 1, row); + addButton("&Checkboxes", 35, row, + new TAction() { + public void DO() { + new DemoCheckboxWindow(getApplication()); + } + } + ); row += 2; - if (!isModal()) { - addLabel("Radio buttons and checkboxes", 1, row); - addButton("&Checkboxes", 35, row, - new TAction() { - public void DO() { - new DemoCheckboxWindow(getApplication()); - } + 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; - /* - if (!isModal()) { - addLabel("Editor window", 1, row); - addButton("Edito&r", 35, row, - { - new TEditor(application, 0, 0, 60, 15); + addLabel("Text areas", 1, row); + addButton("&Text", 35, row, + new TAction() { + public void DO() { + new DemoTextWindow(getApplication()); } - ); - } + } + ); row += 2; - */ - - if (!isModal()) { - addLabel("Text areas", 1, row); - addButton("&Text", 35, row, - new TAction() { - public void DO() { - new DemoTextWindow(getApplication()); + + addLabel("Tree views", 1, row); + addButton("Tree&View", 35, row, + new TAction() { + public void DO() { + try { + new DemoTreeViewWindow(getApplication()); + } catch (Exception e) { + e.printStackTrace(); } } - ); - } + } + ); row += 2; - if (!isModal()) { - addLabel("Tree views", 1, row); - addButton("Tree&View", 35, row, - new TAction() { - public void DO() { - try { - new DemoTreeViewWindow(getApplication()); - } catch (Exception e) { - e.printStackTrace(); - } - } + addLabel("Terminal", 1, row); + addButton("Termi&nal", 35, row, + new TAction() { + public void DO() { + getApplication().openTerminal(0, 0); } - ); - } + } + ); row += 2; - if (!isModal()) { - addLabel("Terminal", 1, row); - addButton("Termi&nal", 35, row, - new TAction() { - public void DO() { - getApplication().openTerminal(0, 0); - } + addLabel("Color editor", 1, row); + addButton("Co&lors", 35, row, + new TAction() { + public void DO() { + new TEditColorThemeWindow(getApplication()); } - ); - } + } + ); row += 2; progressBar = addProgressBar(1, row, 22, 0); @@ -190,10 +206,62 @@ public class DemoMainWindow extends TWindow { timerLabel.setWidth(timerLabel.getLabel().length()); if (timerI < 100) { timerI++; + } else { + timer.setRecurring(false); } progressBar.setValue(timerI); } } ); + + statusBar = newStatusBar("Demo Main Window"); + statusBar.addShortcutKeypress(kbF1, cmHelp, "Help"); + statusBar.addShortcutKeypress(kbF2, cmShell, "Shell"); + 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); + } + }