1 package be
.nikiroo
.jvcard
.tui
.panes
;
3 import java
.io
.IOException
;
4 import java
.util
.ArrayList
;
5 import java
.util
.LinkedList
;
8 import be
.nikiroo
.jvcard
.Card
;
9 import be
.nikiroo
.jvcard
.launcher
.Main
;
10 import be
.nikiroo
.jvcard
.resources
.StringUtils
;
11 import be
.nikiroo
.jvcard
.resources
.Trans
;
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
.UiColors
.Element
;
17 import com
.googlecode
.lanterna
.input
.KeyType
;
19 public class FileList
extends MainContentList
{
20 private List
<String
> files
;
21 private List
<Card
> cards
;
23 public FileList(List
<String
> files
) {
28 * Change the list of currently selected files.
33 public void setFiles(List
<String
> files
) {
36 cards
= new ArrayList
<Card
>();
38 for (String file
: files
) {
39 addItem(file
); // TODO
47 public DataType
getDataType() {
48 return DataType
.CARD_FILES
;
52 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
54 // TODO: from ini file?
57 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
58 : Element
.CONTACT_LINE
;
59 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
60 : Element
.CONTACT_LINE_SEPARATOR
;
62 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
65 if (cards
.get(index
) != null)
66 count
+= cards
.get(index
).size();
68 String name
= files
.get(index
).replaceAll("\\\\", "/");
69 int indexSl
= name
.lastIndexOf('/');
71 name
= name
.substring(indexSl
+ 1);
74 name
= StringUtils
.sanitize(name
, Main
.isUnicode());
76 count
= " " + StringUtils
.padString(count
, SIZE_COL_1
) + " ";
78 + StringUtils
.padString(name
, width
- SIZE_COL_1
79 - getSeparator().length()) + " ";
81 parts
.add(new TextPart(count
, el
));
82 parts
.add(new TextPart(getSeparator(), elSep
));
83 parts
.add(new TextPart(name
, el
));
89 public List
<KeyAction
> getKeyBindings() {
90 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
93 actions
.add(new KeyAction(Mode
.CONTACT_LIST
, KeyType
.Enter
,
94 Trans
.StringId
.KEY_ACTION_VIEW_CARD
) {
96 public Object
getObject() {
97 int index
= getSelectedIndex();
99 if (index
< 0 || index
>= cards
.size())
102 if (cards
.get(index
) != null)
103 return cards
.get(index
);
105 String file
= files
.get(index
);
108 Card card
= Main
.getCard(file
);
109 cards
.set(index
, card
);
114 } catch (IOException ioe
) {
115 ioe
.printStackTrace();