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
<File
> files
;
23 private List
<Card
> cards
;
25 public FileList(List
<File
> files
) {
26 super(UiColors
.Element
.CONTACT_LINE
,
27 UiColors
.Element
.CONTACT_LINE_SELECTED
);
33 * Change the list of currently selected files.
38 public void setFiles(List
<File
> files
) {
41 cards
= new ArrayList
<Card
>();
43 for (File file
: files
) {
44 addItem(file
.getName());
52 public DataType
getDataType() {
53 return DataType
.CARD_FILES
;
57 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
59 // TODO: from ini file?
62 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
63 : Element
.CONTACT_LINE
;
64 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
65 : Element
.CONTACT_LINE_SEPARATOR
;
67 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
70 if (cards
.get(index
) != null)
71 count
+= cards
.get(index
).size();
73 String name
= files
.get(index
).getName();
75 count
= " " + StringUtils
.padString(count
, SIZE_COL_1
) + " ";
77 + StringUtils
.padString(name
, width
- SIZE_COL_1
78 - getSeparator().length()) + " ";
80 parts
.add(new TextPart(count
, el
));
81 parts
.add(new TextPart(getSeparator(), elSep
));
82 parts
.add(new TextPart(name
, el
));
88 public List
<KeyAction
> getKeyBindings() {
89 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
92 actions
.add(new KeyAction(Mode
.CONTACT_LIST
, KeyType
.Enter
,
93 Trans
.StringId
.KEY_ACTION_VIEW_CARD
) {
95 public Object
getObject() {
96 int index
= getSelectedIndex();
98 if (index
< 0 || index
>= cards
.size())
101 if (cards
.get(index
) != null)
102 return cards
.get(index
);
104 File file
= files
.get(index
);
105 Format format
= Format
.Abook
;
106 String ext
= file
.getName();
107 if (ext
.contains(".")) {
108 String tab
[] = ext
.split("\\.");
110 && tab
[tab
.length
- 1].equalsIgnoreCase("vcf")) {
111 format
= Format
.VCard21
;
115 Card card
= new Card(file
, format
);
116 cards
.set(index
, card
);
121 } catch (IOException ioe
) {
122 ioe
.printStackTrace();
132 public Mode
getMode() {
133 return Mode
.FILE_LIST
;