1 package be
.nikiroo
.jvcard
.tui
;
4 import java
.io
.IOException
;
5 import java
.util
.LinkedList
;
8 import be
.nikiroo
.jvcard
.tui
.panes
.FileList
;
10 import com
.googlecode
.lanterna
.TextColor
;
11 import com
.googlecode
.lanterna
.gui2
.BasicWindow
;
12 import com
.googlecode
.lanterna
.gui2
.DefaultWindowManager
;
13 import com
.googlecode
.lanterna
.gui2
.EmptySpace
;
14 import com
.googlecode
.lanterna
.gui2
.MultiWindowTextGUI
;
15 import com
.googlecode
.lanterna
.gui2
.Window
;
16 import com
.googlecode
.lanterna
.gui2
.table
.Table
;
17 import com
.googlecode
.lanterna
.screen
.Screen
;
18 import com
.googlecode
.lanterna
.screen
.TerminalScreen
;
19 import com
.googlecode
.lanterna
.terminal
.DefaultTerminalFactory
;
20 import com
.googlecode
.lanterna
.terminal
.Terminal
;
23 * This class contains the runnable Main method. It will parse the user supplied
24 * parameters and take action based upon those. Most of the time, it will start
31 public static final String APPLICATION_TITLE
= "jVcard";
32 public static final String APPLICATION_VERSION
= "1.0-beta1-dev";
34 public static void main(String
[] args
) {
35 Boolean textMode
= null;
36 boolean noMoreParams
= false;
37 boolean filesTried
= false;
39 List
<File
> files
= new LinkedList
<File
>();
40 for (String arg
: args
) {
41 if (!noMoreParams
&& arg
.equals("--")) {
43 } else if (!noMoreParams
&& arg
.equals("--help")) {
45 .println("TODO: implement some help text.\n"
46 + "Usable switches:\n"
47 + "\t--: stop looking for switches\n"
48 + "\t--help: this here thingy\n"
49 + "\t--tui: force pure text mode even if swing treminal is available\n"
50 + "\t--gui: force swing terminal mode\n"
51 + "\t--noutf: force non-utf8 mode if you need it\n"
52 + "\t--noutfa: force non-utf8 and no accents mode if you need it\n"
53 + "everyhing else is either a file to open or a directory to open\n"
54 + "(we will only open 1st level files in given directories)");
56 } else if (!noMoreParams
&& arg
.equals("--tui")) {
58 } else if (!noMoreParams
&& arg
.equals("--gui")) {
60 } else if (!noMoreParams
&& arg
.equals("--noutf")) {
61 UiColors
.getInstance().setUnicode(false);
64 files
.addAll(open(arg
));
68 if (files
.size() == 0) {
74 files
.addAll(open("."));
77 Window win
= new MainWindow(new FileList(files
));
80 TuiLauncher
.start(textMode
, win
);
81 } catch (IOException ioe
) {
82 ioe
.printStackTrace();
87 * String file = args.length > 0 ? args[0] : null; String file2 =
88 * args.length > 1 ? args[1] : null;
90 * if (file == null) file =
91 * "/home/niki/workspace/rcard/utils/CVcard/test.vcf"; if (file2 ==
92 * null) file2 = "/home/niki/workspace/rcard/utils/CVcard/test.abook";
94 * Card card = new Card(new File(file), Format.VCard21);
95 * System.out.println(card.toString());
97 * System.out.println("\n -- PINE -- \n");
99 * card = new Card(new File(file2), Format.Abook);
100 * System.out.println(card.toString(Format.Abook));
105 * Open the given path and add all its files if it is a directory or just
106 * this one if not to the returned list.
111 * @return the list of opened files
113 static private List
<File
> open(String path
) {
114 List
<File
> files
= new LinkedList
<File
>();
116 File file
= new File(path
);
118 if (file
.isDirectory()) {
119 for (File subfile
: file
.listFiles()) {
120 if (!subfile
.isDirectory())
127 System
.err
.println("File or directory not found: \"" + path
+ "\"");
133 static private void fullTestTable() throws IOException
{
134 final Table
<String
> table
= new Table
<String
>("Column 1", "Column 2",
136 table
.getTableModel().addRow("1", "2", "3");
137 table
.setSelectAction(new Runnable() {
140 List
<String
> data
= table
.getTableModel().getRow(
141 table
.getSelectedRow());
142 for (int i
= 0; i
< data
.size(); i
++) {
143 System
.out
.println(data
.get(i
));
148 Window win
= new BasicWindow();
149 win
.setComponent(table
);
151 DefaultTerminalFactory factory
= new DefaultTerminalFactory();
152 Terminal terminal
= factory
.createTerminal();
154 Screen screen
= new TerminalScreen(terminal
);
155 screen
.startScreen();
157 // Create gui and start gui
158 MultiWindowTextGUI gui
= new MultiWindowTextGUI(screen
,
159 new DefaultWindowManager(), new EmptySpace(TextColor
.ANSI
.BLUE
));
160 gui
.addWindowAndWait(win
);