Improve UI, take "dirty" check into account, move launcher to Main.java
[jvcard.git] / src / be / nikiroo / jvcard / test / TestCli.java
1 package be.nikiroo.jvcard.test;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.LinkedList;
6 import java.util.List;
7
8 import be.nikiroo.jvcard.Card;
9 import be.nikiroo.jvcard.parsers.Format;
10 import be.nikiroo.jvcard.tui.MainWindow;
11 import be.nikiroo.jvcard.tui.TuiLauncher;
12 import be.nikiroo.jvcard.tui.panes.ContactList;
13 import be.nikiroo.jvcard.tui.panes.FileList;
14
15 import com.googlecode.lanterna.TerminalSize;
16 import com.googlecode.lanterna.TextColor;
17 import com.googlecode.lanterna.gui2.BasicWindow;
18 import com.googlecode.lanterna.gui2.Button;
19 import com.googlecode.lanterna.gui2.DefaultWindowManager;
20 import com.googlecode.lanterna.gui2.EmptySpace;
21 import com.googlecode.lanterna.gui2.GridLayout;
22 import com.googlecode.lanterna.gui2.Label;
23 import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
24 import com.googlecode.lanterna.gui2.Panel;
25 import com.googlecode.lanterna.gui2.TextBox;
26 import com.googlecode.lanterna.gui2.Window;
27 import com.googlecode.lanterna.gui2.table.Table;
28 import com.googlecode.lanterna.screen.Screen;
29 import com.googlecode.lanterna.screen.TerminalScreen;
30 import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
31 import com.googlecode.lanterna.terminal.Terminal;
32
33 public class TestCli {
34 public static void main(String[] args) throws IOException {
35 Boolean textMode = null;
36 if (args.length > 0 && args[0].equals("--tui"))
37 textMode = true;
38 if (args.length > 0 && args[0].equals("--gui"))
39 textMode = false;
40
41 Window win = null;
42
43 // TODO: do not hardcode that:
44 Card card = new Card(new File("/home/niki/.addressbook"), Format.Abook);
45 win = new MainWindow(new ContactList(card));
46 //
47 List<File> files = new LinkedList<File>();
48 files.add(new File("/home/niki/vcf/coworkers.vcf"));
49 files.add(new File("/home/niki/vcf/oce.vcf"));
50 win = new MainWindow(new FileList(files));
51 //
52
53 TuiLauncher.start(textMode, win);
54
55 /*
56 * String file = args.length > 0 ? args[0] : null; String file2 =
57 * args.length > 1 ? args[1] : null;
58 *
59 * if (file == null) file =
60 * "/home/niki/workspace/rcard/utils/CVcard/test.vcf"; if (file2 ==
61 * null) file2 = "/home/niki/workspace/rcard/utils/CVcard/test.abook";
62 *
63 * Card card = new Card(new File(file), Format.VCard21);
64 * System.out.println(card.toString());
65 *
66 * System.out.println("\n -- PINE -- \n");
67 *
68 * card = new Card(new File(file2), Format.Abook);
69 * System.out.println(card.toString(Format.Abook));
70 */
71 }
72
73 static private Table test2() throws IOException {
74 final Table<String> table = new Table<String>("Column 1", "Column 2",
75 "Column 3");
76 table.getTableModel().addRow("1", "2", "3");
77 table.setSelectAction(new Runnable() {
78 @Override
79 public void run() {
80 List<String> data = table.getTableModel().getRow(
81 table.getSelectedRow());
82 for (int i = 0; i < data.size(); i++) {
83 System.out.println(data.get(i));
84 }
85 }
86 });
87
88 return table;
89 }
90
91 static private void test() throws IOException {
92 // Setup terminal and screen layers
93 Terminal terminal = new DefaultTerminalFactory().createTerminal();
94 Screen screen = new TerminalScreen(terminal);
95 screen.startScreen();
96
97 // Create panel to hold components
98 Panel panel = new Panel();
99 panel.setLayoutManager(new GridLayout(2));
100
101 panel.addComponent(new Label("Forename"));
102 panel.addComponent(new TextBox());
103
104 panel.addComponent(new Label("Surname"));
105 panel.addComponent(new TextBox());
106
107 panel.addComponent(new EmptySpace(new TerminalSize(0, 0))); // Empty
108 // space
109 // underneath
110 // labels
111 panel.addComponent(new Button("Submit"));
112
113 // Create window to hold the panel
114 BasicWindow window = new BasicWindow();
115 window.setComponent(panel);
116
117 // Create gui and start gui
118 MultiWindowTextGUI gui = new MultiWindowTextGUI(screen,
119 new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
120 gui.addWindowAndWait(window);
121 }
122 }