X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDemoApplication.java;h=5036dd017ff71ce0ae45a2590a1fcdb4d0890f02;hb=be72cb5ccbd42fe304c0acafc380c5636f0d03a2;hp=b07c783d1808b47f6088e00213f08c263978dc88;hpb=55d2b2c2b29ce51f4f910448a115073371deeae8;p=fanfix.git diff --git a/src/jexer/demos/DemoApplication.java b/src/jexer/demos/DemoApplication.java index b07c783..5036dd0 100644 --- a/src/jexer/demos/DemoApplication.java +++ b/src/jexer/demos/DemoApplication.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"), @@ -29,11 +29,12 @@ package jexer.demos; import java.io.*; -import java.util.*; import jexer.*; import jexer.event.*; import jexer.menu.*; +import jexer.backend.Backend; +import jexer.backend.SwingTerminal; /** * The demo application itself. @@ -73,6 +74,12 @@ public class DemoApplication extends TApplication { item.setEnabled(false); item = subMenu.addItem(2002, "&Normal (sub)"); + if (getScreen() instanceof SwingTerminal) { + TMenu swingMenu = addMenu("Swin&g"); + item = swingMenu.addItem(3000, "&Bigger +2"); + item = swingMenu.addItem(3001, "&Smaller -2"); + } + addWindowMenu(); addHelpMenu(); } @@ -133,6 +140,17 @@ public class DemoApplication extends TApplication { this(input, reader, writer, false); } + /** + * Public constructor. + * + * @param backend a Backend that is already ready to go. + */ + public DemoApplication(final Backend backend) { + super(backend); + + addAllWidgets(); + } + /** * Handle menu events. * @@ -143,6 +161,21 @@ public class DemoApplication extends TApplication { @Override public boolean onMenu(final TMenuEvent menu) { + if (menu.getId() == 3000) { + // Bigger +2 + assert (getScreen() instanceof SwingTerminal); + SwingTerminal terminal = (SwingTerminal) getScreen(); + terminal.setFontSize(terminal.getFontSize() + 2); + return true; + } + if (menu.getId() == 3001) { + // Smaller -2 + assert (getScreen() instanceof SwingTerminal); + SwingTerminal terminal = (SwingTerminal) getScreen(); + terminal.setFontSize(terminal.getFontSize() - 2); + return true; + } + if (menu.getId() == 2050) { new TEditColorThemeWindow(this); return true; @@ -153,20 +186,7 @@ public class DemoApplication extends TApplication { String filename = fileOpenBox("."); if (filename != null) { try { - File file = new File(filename); - StringBuilder fileContents = new StringBuilder(); - Scanner scanner = new Scanner(file); - String EOL = System.getProperty("line.separator"); - - try { - while (scanner.hasNextLine()) { - fileContents.append(scanner.nextLine() + EOL); - } - new DemoTextWindow(this, filename, - fileContents.toString()); - } finally { - scanner.close(); - } + new TEditorWindow(this, new File(filename)); } catch (IOException e) { e.printStackTrace(); }