Colours are now taken from a .properties file
[jvcard.git] / src / be / nikiroo / jvcard / tui / Main.java
index a0357bec89e4c0a59ee19899d0d8bbb32cd9723d..fd6d7de4e6e4e5583a36f742ff44fbb65ef277f2 100644 (file)
@@ -2,6 +2,8 @@ package be.nikiroo.jvcard.tui;
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.Field;
+import java.nio.charset.Charset;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -9,18 +11,8 @@ import be.nikiroo.jvcard.i18n.Trans;
 import be.nikiroo.jvcard.i18n.Trans.StringId;
 import be.nikiroo.jvcard.tui.panes.FileList;
 
-import com.googlecode.lanterna.TextColor;
-import com.googlecode.lanterna.gui2.BasicWindow;
-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.gui2.table.Table;
 import com.googlecode.lanterna.input.KeyStroke;
-import com.googlecode.lanterna.screen.Screen;
-import com.googlecode.lanterna.screen.TerminalScreen;
-import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
-import com.googlecode.lanterna.terminal.Terminal;
 
 /**
  * This class contains the runnable Main method. It will parse the user supplied
@@ -32,7 +24,7 @@ import com.googlecode.lanterna.terminal.Terminal;
  */
 public class Main {
        public static final String APPLICATION_TITLE = "jVcard";
-       public static final String APPLICATION_VERSION = "1.0-beta1-dev";
+       public static final String APPLICATION_VERSION = "1.0-beta2-dev";
 
        static private Trans transService;
 
@@ -45,7 +37,6 @@ public class Main {
         * @return the translation
         */
        static public String trans(StringId id) {
-
                if (transService == null)
                        return "";
 
@@ -119,6 +110,10 @@ public class Main {
                        }
                }
 
+               if (UiColors.getInstance().isUnicode()) {
+                       utf8();
+               }
+
                if (files.size() == 0) {
                        if (filesTried) {
                                System.exit(1);
@@ -167,35 +162,17 @@ public class Main {
                return files;
        }
 
-       static private void fullTestTable() throws IOException {
-               final Table<String> table = new Table<String>("Column 1", "Column 2",
-                               "Column 3");
-               table.getTableModel().addRow("1", "2", "3");
-               table.setSelectAction(new Runnable() {
-                       @Override
-                       public void run() {
-                               List<String> data = table.getTableModel().getRow(
-                                               table.getSelectedRow());
-                               for (int i = 0; i < data.size(); i++) {
-                                       System.out.println(data.get(i));
-                               }
-                       }
-               });
-
-               Window win = new BasicWindow();
-               win.setComponent(table);
-
-               DefaultTerminalFactory factory = new DefaultTerminalFactory();
-               Terminal terminal = factory.createTerminal();
-
-               Screen 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);
-
-               screen.stopScreen();
+       /**
+        * Really, really ask for UTF-8 encoding.
+        */
+       static private void utf8() {
+               try {
+                       System.setProperty("file.encoding", "UTF-8");
+                       Field charset = Charset.class.getDeclaredField("defaultCharset");
+                       charset.setAccessible(true);
+                       charset.set(null, null);
+               } catch (SecurityException | NoSuchFieldException
+                               | IllegalArgumentException | IllegalAccessException e) {
+               }
        }
 }