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 + "everyhing else is either a file to open or a directory to open\n"
52 + "(we will only open 1st level files in given directories)");
54 } else if (!noMoreParams
&& arg
.equals("--tui")) {
56 } else if (!noMoreParams
&& arg
.equals("--gui")) {
60 files
.addAll(open(arg
));
64 if (files
.size() == 0) {
70 files
.addAll(open("."));
74 TuiLauncher
.start(textMode
, new MainWindow(new FileList(files
)));
75 } catch (IOException ioe
) {
76 ioe
.printStackTrace();
81 * String file = args.length > 0 ? args[0] : null; String file2 =
82 * args.length > 1 ? args[1] : null;
84 * if (file == null) file =
85 * "/home/niki/workspace/rcard/utils/CVcard/test.vcf"; if (file2 ==
86 * null) file2 = "/home/niki/workspace/rcard/utils/CVcard/test.abook";
88 * Card card = new Card(new File(file), Format.VCard21);
89 * System.out.println(card.toString());
91 * System.out.println("\n -- PINE -- \n");
93 * card = new Card(new File(file2), Format.Abook);
94 * System.out.println(card.toString(Format.Abook));
99 * Open the given path and add all its files if it is a directory or just
100 * this one if not to the returned list.
105 * @return the list of opened files
107 static private List
<File
> open(String path
) {
108 List
<File
> files
= new LinkedList
<File
>();
110 File file
= new File(path
);
112 if (file
.isDirectory()) {
113 for (File subfile
: file
.listFiles()) {
114 if (!subfile
.isDirectory())
121 System
.err
.println("File or directory not found: \"" + path
+ "\"");
127 static private void fullTestTable() throws IOException
{
128 final Table
<String
> table
= new Table
<String
>("Column 1", "Column 2",
130 table
.getTableModel().addRow("1", "2", "3");
131 table
.setSelectAction(new Runnable() {
134 List
<String
> data
= table
.getTableModel().getRow(
135 table
.getSelectedRow());
136 for (int i
= 0; i
< data
.size(); i
++) {
137 System
.out
.println(data
.get(i
));
142 Window win
= new BasicWindow();
143 win
.setComponent(table
);
145 DefaultTerminalFactory factory
= new DefaultTerminalFactory();
146 Terminal terminal
= factory
.createTerminal();
148 Screen screen
= new TerminalScreen(terminal
);
149 screen
.startScreen();
151 // Create gui and start gui
152 MultiWindowTextGUI gui
= new MultiWindowTextGUI(screen
,
153 new DefaultWindowManager(), new EmptySpace(TextColor
.ANSI
.BLUE
));
154 gui
.addWindowAndWait(win
);