1 package be
.nikiroo
.jvcard
.tui
.panes
;
4 import java
.io
.IOException
;
5 import java
.util
.ArrayList
;
6 import java
.util
.LinkedList
;
9 import be
.nikiroo
.jvcard
.Card
;
10 import be
.nikiroo
.jvcard
.i18n
.Trans
;
11 import be
.nikiroo
.jvcard
.parsers
.Format
;
12 import be
.nikiroo
.jvcard
.tui
.KeyAction
;
13 import be
.nikiroo
.jvcard
.tui
.KeyAction
.DataType
;
14 import be
.nikiroo
.jvcard
.tui
.KeyAction
.Mode
;
15 import be
.nikiroo
.jvcard
.tui
.StringUtils
;
16 import be
.nikiroo
.jvcard
.tui
.UiColors
;
17 import be
.nikiroo
.jvcard
.tui
.UiColors
.Element
;
19 import com
.googlecode
.lanterna
.input
.KeyType
;
21 public class FileList
extends MainContentList
{
22 private List
<String
> files
;
23 private List
<Card
> cards
;
25 public FileList(List
<String
> files
) {
30 * Change the list of currently selected files.
35 public void setFiles(List
<String
> files
) {
38 cards
= new ArrayList
<Card
>();
40 for (String file
: files
) {
41 addItem(file
); // TODO
49 public DataType
getDataType() {
50 return DataType
.CARD_FILES
;
54 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
56 // TODO: from ini file?
59 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
60 : Element
.CONTACT_LINE
;
61 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
62 : Element
.CONTACT_LINE_SEPARATOR
;
64 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
67 if (cards
.get(index
) != null)
68 count
+= cards
.get(index
).size();
70 String name
= files
.get(index
).replaceAll("\\\\", "/");
71 int indexSl
= name
.lastIndexOf('/');
73 name
= name
.substring(indexSl
+ 1);
76 name
= StringUtils
.sanitize(name
, UiColors
.getInstance().isUnicode());
78 count
= " " + StringUtils
.padString(count
, SIZE_COL_1
) + " ";
80 + StringUtils
.padString(name
, width
- SIZE_COL_1
81 - getSeparator().length()) + " ";
83 parts
.add(new TextPart(count
, el
));
84 parts
.add(new TextPart(getSeparator(), elSep
));
85 parts
.add(new TextPart(name
, el
));
91 public List
<KeyAction
> getKeyBindings() {
92 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
95 actions
.add(new KeyAction(Mode
.CONTACT_LIST
, KeyType
.Enter
,
96 Trans
.StringId
.KEY_ACTION_VIEW_CARD
) {
98 public Object
getObject() {
99 int index
= getSelectedIndex();
101 if (index
< 0 || index
>= cards
.size())
104 if (cards
.get(index
) != null)
105 return cards
.get(index
);
107 String file
= files
.get(index
);
110 Card card
= FileList
.getCard(file
);
111 cards
.set(index
, card
);
116 } catch (IOException ioe
) {
117 ioe
.printStackTrace();
126 static private Card
getCard(String input
) throws IOException
{
127 Format format
= Format
.Abook
;
129 if (ext
.contains(".")) {
130 String tab
[] = ext
.split("\\.");
131 if (tab
.length
> 1 && tab
[tab
.length
- 1].equalsIgnoreCase("vcf")) {
132 format
= Format
.VCard21
;
138 card
= new Card(new File(input
), format
);
139 } catch (IOException ioe
) {
140 ioe
.printStackTrace();