Fix inclusion of lanterna's resources + fix warning
authorNiki Roo <niki@nikiroo.be>
Sat, 2 Apr 2016 11:44:03 +0000 (13:44 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 2 Apr 2016 11:44:03 +0000 (13:44 +0200)
Makefile
src/be/nikiroo/jvcard/resources/bundles/TransBundle.java
src/be/nikiroo/jvcard/tui/TuiLauncher.java
src/be/nikiroo/jvcard/tui/UiColors.java
src/be/nikiroo/jvcard/tui/panes/ContactDetailsRaw.java

index 83242cc2e6d4763f9db181b1a01d490cfb91c674..6348110a35c26c15eea49510e89e645d3d4fb2c2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -70,9 +70,10 @@ bin/files: src/be/nikiroo/jvcard/*/* src/be/nikiroo/jvcard/*
        @mkdir -p bin/
        @find src/be/ -name '*.java' > bin/files
 
-bin/lanterna: src/com/googlecode/lanterna/* src/com/googlecode/lanterna/*/* src/com/googlecode/lanterna/*/*/*
+bin/lanterna: src/resources/* src/com/googlecode/lanterna/* src/com/googlecode/lanterna/*/* src/com/googlecode/lanterna/*/*/*
        @mkdir -p bin/
        @find src/com/ -name '*.java' > bin/lanterna
+       cp -r src/resources/* bin/
        javac -encoding UTF-8 -source 5 @bin/lanterna -d bin/ || rm bin/lanterna
        @test -e bin/lanterna
 
index 6ff63bffeb9e3eebd17e6346d06a037d28258f98..7199158bba8d227322e4cc00e4d3bc52af0dbcf2 100644 (file)
@@ -76,7 +76,7 @@ public class TransBundle extends Bundle<StringId> {
                }
 
                if (values != null && values.length > 0)
-                       return String.format(locale, result, (Object[]) values);
+                       return String.format(locale, result, values);
                else
                        return result;
        }
index 066ba315c4be651db64e51a181850ec3d36d98b8..054fe4a88eb1436314e4f56d21bdb5a526ad09d3 100644 (file)
@@ -7,8 +7,6 @@ import be.nikiroo.jvcard.tui.panes.FileList;
 
 import com.googlecode.lanterna.TerminalSize;
 import com.googlecode.lanterna.TextColor;
-import com.googlecode.lanterna.gui2.DefaultWindowManager;
-import com.googlecode.lanterna.gui2.EmptySpace;
 import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
 import com.googlecode.lanterna.gui2.Window;
 import com.googlecode.lanterna.screen.Screen;
@@ -24,6 +22,8 @@ import com.googlecode.lanterna.terminal.Terminal;
  *
  */
 public class TuiLauncher {
+       static private Screen screen = null;
+
        /**
         * Start the TUI program.
         * 
@@ -42,6 +42,15 @@ public class TuiLauncher {
                TuiLauncher.start(textMode, win);
        }
 
+       /**
+        * Return the used {@link Screen}.
+        * 
+        * @return the {@link Screen}
+        */
+       static public Screen getScreen() {
+               return screen;
+       }
+
        /**
         * Start the TUI program.
         * 
@@ -78,14 +87,16 @@ public class TuiLauncher {
                        });
                }
 
-               Screen screen = new TerminalScreen(terminal);
+               screen = new TerminalScreen(terminal);
                screen.startScreen();
 
                // Create gui and start gui
                MultiWindowTextGUI gui = new MultiWindowTextGUI(screen,
-                               new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
-               gui.addWindowAndWait(win);
+                               TextColor.ANSI.BLUE);
 
+               gui.setTheme(UiColors.getCustomTheme());
+
+               gui.addWindowAndWait(win);
                screen.stopScreen();
        }
 }
index abac7d54b56146746a88b6ae83c2451ac9d11178..877c73964defee82004f1e4c76ffb1ad685fbc72 100644 (file)
@@ -1,13 +1,20 @@
 package be.nikiroo.jvcard.tui;
 
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.MissingResourceException;
+import java.util.Properties;
 
 import be.nikiroo.jvcard.resources.bundles.ColorBundle;
 import be.nikiroo.jvcard.resources.enums.ColorOption;
 
 import com.googlecode.lanterna.TextColor;
+import com.googlecode.lanterna.graphics.PropertiesTheme;
+import com.googlecode.lanterna.graphics.Theme;
+import com.googlecode.lanterna.gui2.AbstractTextGUI;
 import com.googlecode.lanterna.gui2.Label;
 
 /**
@@ -28,7 +35,8 @@ public class UiColors extends ColorBundle {
        }
 
        /**
-        * Create a new {@link Label} with the colours of the given {@link ColorOption}.
+        * Create a new {@link Label} with the colours of the given
+        * {@link ColorOption}.
         * 
         * @param el
         *            the {@link ColorOption}
@@ -105,6 +113,33 @@ public class UiColors extends ColorBundle {
                return getInstance().colorMap.get(el.name() + "_FG");
        }
 
+       /**
+        * Return a {@link Theme} following the colours defined in
+        * display.properties.
+        * 
+        * @return the {@link Theme}
+        */
+       static Theme getCustomTheme() {
+               // Create a properties-theme with our own custom values for some of it
+               Properties properties = new Properties();
+               try {
+                       ClassLoader classLoader = AbstractTextGUI.class.getClassLoader();
+                       InputStream resourceAsStream = classLoader
+                                       .getResourceAsStream("default-theme.properties");
+                       if (resourceAsStream == null) {
+                               resourceAsStream = new FileInputStream(
+                                               "src/main/resources/default-theme.properties");
+                       }
+                       properties.load(resourceAsStream);
+                       resourceAsStream.close();
+               } catch (IOException e) {
+               }
+               properties.put("com.googlecode.lanterna.background", "black");
+               PropertiesTheme theme = new PropertiesTheme(properties);
+
+               return theme;
+       }
+
        /**
         * Get the (unique) instance of this class.
         * 
index 2de99192050af84249affc547dbaa5a073e596d7..5a616b918fd7b3f5804185351dcca97f6cb2b5ae 100644 (file)
@@ -13,7 +13,10 @@ import be.nikiroo.jvcard.resources.enums.StringId;
 import be.nikiroo.jvcard.tui.KeyAction;
 import be.nikiroo.jvcard.tui.KeyAction.DataType;
 import be.nikiroo.jvcard.tui.KeyAction.Mode;
+import be.nikiroo.jvcard.tui.TuiLauncher;
 
+import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
+import com.googlecode.lanterna.gui2.dialogs.ActionListDialogBuilder;
 import com.googlecode.lanterna.input.KeyType;
 
 public class ContactDetailsRaw extends MainContentList {
@@ -114,6 +117,41 @@ public class ContactDetailsRaw extends MainContentList {
                });
                // TODO: ui
                actions.add(new KeyAction(Mode.ASK_USER, 'a', StringId.KEY_ACTION_ADD) {
+                       @Override
+                       public boolean onAction() {
+                               try{
+                               new ActionListDialogBuilder()
+                                               .setTitle("Action List Dialog")
+                                               .setDescription("Choose an item")
+                                               .addAction("First Item", new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               // Do 1st thing...
+                                                       }
+                                               })
+                                               .addAction("Second Item", new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               // Do 2nd thing...
+                                                       }
+                                               })
+                                               .addAction("Third Item", new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               // Do 3rd thing...
+                                                       }
+                                               })
+                                               .build()
+                                               .showDialog(
+                                                               new MultiWindowTextGUI(TuiLauncher.getScreen()));
+                               
+                               return true;
+                               }catch(Exception e){
+                                       e.printStackTrace();
+                                       throw e;
+                               }
+                       }
+
                        @Override
                        public Object getObject() {
                                return contact;