1 package be
.nikiroo
.jvcard
.tui
;
4 import java
.io
.IOException
;
5 import java
.util
.LinkedList
;
8 import be
.nikiroo
.jvcard
.i18n
.Trans
;
9 import be
.nikiroo
.jvcard
.i18n
.Trans
.StringId
;
10 import be
.nikiroo
.jvcard
.tui
.panes
.FileList
;
12 import com
.googlecode
.lanterna
.TextColor
;
13 import com
.googlecode
.lanterna
.gui2
.BasicWindow
;
14 import com
.googlecode
.lanterna
.gui2
.DefaultWindowManager
;
15 import com
.googlecode
.lanterna
.gui2
.EmptySpace
;
16 import com
.googlecode
.lanterna
.gui2
.MultiWindowTextGUI
;
17 import com
.googlecode
.lanterna
.gui2
.Window
;
18 import com
.googlecode
.lanterna
.gui2
.table
.Table
;
19 import com
.googlecode
.lanterna
.input
.KeyStroke
;
20 import com
.googlecode
.lanterna
.screen
.Screen
;
21 import com
.googlecode
.lanterna
.screen
.TerminalScreen
;
22 import com
.googlecode
.lanterna
.terminal
.DefaultTerminalFactory
;
23 import com
.googlecode
.lanterna
.terminal
.Terminal
;
26 * This class contains the runnable Main method. It will parse the user supplied
27 * parameters and take action based upon those. Most of the time, it will start
34 public static final String APPLICATION_TITLE
= "jVcard";
35 public static final String APPLICATION_VERSION
= "1.0-beta1-dev";
37 static private Trans transService
;
40 * Translate the given {@link StringId}.
45 * @return the translation
47 static public String
trans(StringId id
) {
49 if (transService
== null)
52 return transService
.trans(id
);
56 * Translate the given {@link KeyStroke}.
59 * the key to translate
61 * @return the translation
63 static public String
trans(KeyStroke key
) {
64 if (transService
== null)
67 return transService
.trans(key
);
71 * Start the application.
74 * the parameters (see --help to know hich are supported)
76 public static void main(String
[] args
) {
77 Boolean textMode
= null;
78 boolean noMoreParams
= false;
79 boolean filesTried
= false;
81 // get the "system default" language to help translate the --help
83 String language
= null;
84 transService
= new Trans(null);
86 List
<File
> files
= new LinkedList
<File
>();
87 for (int index
= 0; index
< args
.length
; index
++) {
88 String arg
= args
[index
];
89 if (!noMoreParams
&& arg
.equals("--")) {
91 } else if (!noMoreParams
&& arg
.equals("--help")) {
93 .println("TODO: implement some help text.\n"
94 + "Usable switches:\n"
95 + "\t--: stop looking for switches\n"
96 + "\t--help: this here thingy\n"
97 + "\t--lang LANGUAGE: choose the language, for instance en_GB\n"
98 + "\t--tui: force pure text mode even if swing treminal is available\n"
99 + "\t--gui: force swing terminal mode\n"
100 + "\t--noutf: force non-utf8 mode if you need it\n"
101 + "\t--noutfa: force non-utf8 and no accents mode if you need it\n"
102 + "everyhing else is either a file to open or a directory to open\n"
103 + "(we will only open 1st level files in given directories)");
105 } else if (!noMoreParams
&& arg
.equals("--tui")) {
107 } else if (!noMoreParams
&& arg
.equals("--gui")) {
109 } else if (!noMoreParams
&& arg
.equals("--noutf")) {
110 UiColors
.getInstance().setUnicode(false);
111 } else if (!noMoreParams
&& arg
.equals("--lang")) {
113 if (index
< args
.length
)
114 language
= args
[index
];
115 transService
= new Trans(language
);
118 files
.addAll(open(arg
));
122 if (files
.size() == 0) {
128 files
.addAll(open("."));
131 Window win
= new MainWindow(new FileList(files
));
134 TuiLauncher
.start(textMode
, win
);
135 } catch (IOException ioe
) {
136 ioe
.printStackTrace();
142 * Open the given path and add all its files if it is a directory or just
143 * this one if not to the returned list.
148 * @return the list of opened files
150 static private List
<File
> open(String path
) {
151 List
<File
> files
= new LinkedList
<File
>();
153 File file
= new File(path
);
155 if (file
.isDirectory()) {
156 for (File subfile
: file
.listFiles()) {
157 if (!subfile
.isDirectory())
164 System
.err
.println("File or directory not found: \"" + path
+ "\"");
170 static private void fullTestTable() throws IOException
{
171 final Table
<String
> table
= new Table
<String
>("Column 1", "Column 2",
173 table
.getTableModel().addRow("1", "2", "3");
174 table
.setSelectAction(new Runnable() {
177 List
<String
> data
= table
.getTableModel().getRow(
178 table
.getSelectedRow());
179 for (int i
= 0; i
< data
.size(); i
++) {
180 System
.out
.println(data
.get(i
));
185 Window win
= new BasicWindow();
186 win
.setComponent(table
);
188 DefaultTerminalFactory factory
= new DefaultTerminalFactory();
189 Terminal terminal
= factory
.createTerminal();
191 Screen screen
= new TerminalScreen(terminal
);
192 screen
.startScreen();
194 // Create gui and start gui
195 MultiWindowTextGUI gui
= new MultiWindowTextGUI(screen
,
196 new DefaultWindowManager(), new EmptySpace(TextColor
.ANSI
.BLUE
));
197 gui
.addWindowAndWait(win
);