Merge commit '77d3a60869e7a780c6ae069e51530e1eacece5e2'
[fanfix.git] / src / jexer / demos / DesktopDemoApplication.java
index c546aacaadaa63e6b6447be3b0d0563305afadd0..73d0c5f88ae028e8c83fe9b4355ed5c506d4ca50 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  */
 package jexer.demos;
 
-import java.io.*;
-import java.util.*;
+import java.io.File;
+import java.io.IOException;
+import java.util.ResourceBundle;
+import java.util.Scanner;
 
-import jexer.*;
-import jexer.event.*;
-import jexer.menu.*;
+import jexer.TAction;
+import jexer.TApplication;
+import jexer.TWindow;
+import jexer.event.TMenuEvent;
+import jexer.menu.TMenu;
 
 /**
  * The demo application itself.
  */
 public class DesktopDemoApplication extends TApplication {
 
+    /**
+     * Translated strings.
+     */
+    private static final ResourceBundle i18n = ResourceBundle.getBundle(DesktopDemoApplication.class.getName());
+
+    // ------------------------------------------------------------------------
+    // Constructors -----------------------------------------------------------
+    // ------------------------------------------------------------------------
+
+    /**
+     * Public constructor.
+     *
+     * @param backendType one of the TApplication.BackendType values
+     * @throws Exception if TApplication can't instantiate the Backend.
+     */
+    public DesktopDemoApplication(final BackendType backendType) throws Exception {
+        super(backendType);
+        addAllWidgets();
+        getBackend().setTitle(i18n.getString("applicationTitle"));
+    }
+
+    // ------------------------------------------------------------------------
+    // TApplication -----------------------------------------------------------
+    // ------------------------------------------------------------------------
+
+    /**
+     * Handle menu events.
+     *
+     * @param menu menu event
+     * @return if true, the event was processed and should not be passed onto
+     * a window
+     */
+    @Override
+    public boolean onMenu(final TMenuEvent menu) {
+
+        if (menu.getId() == TMenu.MID_OPEN_FILE) {
+            try {
+                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();
+                         }
+                     } catch (IOException e) {
+                         e.printStackTrace();
+                     }
+                 }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            return true;
+        }
+        return super.onMenu(menu);
+    }
+
+    // ------------------------------------------------------------------------
+    // DesktopDemoApplication -------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * Add all the widgets of the demo.
      */
@@ -54,14 +128,14 @@ public class DesktopDemoApplication extends TApplication {
         final DesktopDemo desktop = new DesktopDemo(this);
         setDesktop(desktop);
 
-        desktop.addButton("&Remove HATCH", 2, 5,
+        desktop.addButton(i18n.getString("removeHatch"), 2, 5,
             new TAction() {
                 public void DO() {
                     desktop.drawHatch = false;
                 }
             }
         );
-        desktop.addButton("&Show HATCH", 2, 8,
+        desktop.addButton(i18n.getString("showHatch"), 2, 8,
             new TAction() {
                 public void DO() {
                     desktop.drawHatch = true;
@@ -69,58 +143,60 @@ public class DesktopDemoApplication extends TApplication {
             }
         );
 
-        final TWindow windowA = addWindow("Window A", 25, 14);
-        final TWindow windowB = addWindow("Window B", 25, 14);
-        windowA.addButton("&Show Window B", 2, 2,
+        final TWindow windowA = addWindow(i18n.getString("windowATitle"),
+            25, 14);
+        final TWindow windowB = addWindow(i18n.getString("windowBTitle"),
+            25, 14);
+        windowA.addButton(i18n.getString("showWindowB"), 2, 2,
             new TAction() {
                 public void DO() {
                     windowB.show();
                 }
             }
         );
-        windowA.addButton("H&ide Window B", 2, 4,
+        windowA.addButton(i18n.getString("hideWindowB"), 2, 4,
             new TAction() {
                 public void DO() {
                     windowB.hide();
                 }
             }
         );
-        windowA.addButton("&Maximize Window B", 2, 6,
+        windowA.addButton(i18n.getString("maximizeWindowB"), 2, 6,
             new TAction() {
                 public void DO() {
                     windowB.maximize();
                 }
             }
         );
-        windowA.addButton("&Restore Window B", 2, 8,
+        windowA.addButton(i18n.getString("restoreWindowB"), 2, 8,
             new TAction() {
                 public void DO() {
                     windowB.restore();
                 }
             }
         );
-        windowB.addButton("&Show Window A", 2, 2,
+        windowB.addButton(i18n.getString("showWindowA"), 2, 2,
             new TAction() {
                 public void DO() {
                     windowA.show();
                 }
             }
         );
-        windowB.addButton("H&ide Window A", 2, 4,
+        windowB.addButton(i18n.getString("hideWindowA"), 2, 4,
             new TAction() {
                 public void DO() {
                     windowA.hide();
                 }
             }
         );
-        windowB.addButton("&Maximize Window A", 2, 6,
+        windowB.addButton(i18n.getString("maximizeWindowA"), 2, 6,
             new TAction() {
                 public void DO() {
                     windowA.maximize();
                 }
             }
         );
-        windowB.addButton("&Restore Window A", 2, 8,
+        windowB.addButton(i18n.getString("restoreWindowA"), 2, 8,
             new TAction() {
                 public void DO() {
                     windowA.restore();
@@ -128,40 +204,41 @@ public class DesktopDemoApplication extends TApplication {
             }
         );
 
-        desktop.addButton("S&how Window B", 25, 2,
+        desktop.addButton(i18n.getString("showWindowB"), 25, 2,
             new TAction() {
                 public void DO() {
                     windowB.show();
                 }
             }
         );
-        desktop.addButton("H&ide Window B", 25, 5,
+        desktop.addButton(i18n.getString("hideWindowB"), 25, 5,
             new TAction() {
                 public void DO() {
                     windowB.hide();
                 }
             }
         );
-        desktop.addButton("Sh&ow Window A", 25, 8,
+        desktop.addButton(i18n.getString("showWindowA"), 25, 8,
             new TAction() {
                 public void DO() {
                     windowA.show();
                 }
             }
         );
-        desktop.addButton("Hid&e Window A", 25, 11,
+        desktop.addButton(i18n.getString("hideWindowA"), 25, 11,
             new TAction() {
                 public void DO() {
                     windowA.hide();
                 }
             }
         );
-        desktop.addButton("&Create Window C", 25, 15,
+        desktop.addButton(i18n.getString("createWindowC"), 25, 15,
             new TAction() {
                 public void DO() {
                     final TWindow windowC = desktop.getApplication().addWindow(
-                        "Window C", 30, 20, TWindow.NOCLOSEBOX);
-                    windowC.addButton("&Close Me", 5, 5,
+                        i18n.getString("windowCTitle"), 30, 20,
+                        TWindow.NOCLOSEBOX);
+                    windowC.addButton(i18n.getString("closeMe"), 5, 5,
                         new TAction() {
                             public void DO() {
                                 windowC.close();
@@ -172,73 +249,20 @@ public class DesktopDemoApplication extends TApplication {
             }
         );
 
-        desktop.addButton("Enable focusFollowsMouse", 25, 18,
+        desktop.addButton(i18n.getString("enableFFM"), 25, 18,
             new TAction() {
                 public void DO() {
                     DesktopDemoApplication.this.setFocusFollowsMouse(true);
                 }
             }
         );
-        desktop.addButton("Disable focusFollowsMouse", 25, 21,
+        desktop.addButton(i18n.getString("disableFFM"), 25, 21,
             new TAction() {
                 public void DO() {
                     DesktopDemoApplication.this.setFocusFollowsMouse(false);
                 }
             }
         );
-
     }
 
-    /**
-     * Handle menu events.
-     *
-     * @param menu menu event
-     * @return if true, the event was processed and should not be passed onto
-     * a window
-     */
-    @Override
-    public boolean onMenu(final TMenuEvent menu) {
-
-        if (menu.getId() == TMenu.MID_OPEN_FILE) {
-            try {
-                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();
-                         }
-                     } catch (IOException e) {
-                         e.printStackTrace();
-                     }
-                 }
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-            return true;
-        }
-        return super.onMenu(menu);
-    }
-
-    /**
-     * Public constructor.
-     *
-     * @param backendType one of the TApplication.BackendType values
-     * @throws Exception if TApplication can't instantiate the Backend.
-     */
-    public DesktopDemoApplication(final BackendType backendType) throws Exception {
-        super(backendType);
-        addAllWidgets();
-        getBackend().setTitle("Jexer Demo Application");
-    }
 }