1 package be
.nikiroo
.jvcard
.tui
.panes
;
3 import java
.util
.LinkedList
;
6 import be
.nikiroo
.jvcard
.Card
;
7 import be
.nikiroo
.jvcard
.i18n
.Trans
;
8 import be
.nikiroo
.jvcard
.tui
.KeyAction
;
9 import be
.nikiroo
.jvcard
.tui
.UiColors
;
10 import be
.nikiroo
.jvcard
.tui
.KeyAction
.DataType
;
11 import be
.nikiroo
.jvcard
.tui
.KeyAction
.Mode
;
12 import be
.nikiroo
.jvcard
.tui
.UiColors
.Element
;
13 import be
.nikiroo
.jvcard
.tui
.panes
.MainContentList
.TextPart
;
15 import com
.googlecode
.lanterna
.input
.KeyType
;
17 public class ContactList
extends MainContentList
{
20 private List
<String
> formats
= new LinkedList
<String
>();
21 private int selectedFormat
= -1;
22 private String format
= "";
24 public ContactList(Card card
) {
25 super(UiColors
.Element
.CONTACT_LINE
,
26 UiColors
.Element
.CONTACT_LINE_SELECTED
);
28 // TODO: should get that in an INI file
29 formats
.add("NICKNAME@3|FN@+|EMAIL@30");
30 formats
.add("FN@+|EMAIL@40");
37 * Change the currently displayed contacts card.
40 * the new {@link Card}
42 public void setCard(Card card
) {
47 for (int i
= 0; i
< card
.getContacts().size(); i
++) {
48 addItem("[contact line]");
56 public String
getExitWarning() {
57 if (card
!= null && card
.isDirty()) {
58 return "Some of your contact information is not saved";
64 public List
<KeyAction
> getKeyBindings() {
65 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
68 actions
.add(new KeyAction(Mode
.CONTACT_DETAILS
, 'e',
69 Trans
.StringId
.KEY_ACTION_EDIT_CONTACT
) {
71 public Object
getObject() {
72 int index
= getSelectedIndex();
73 return card
.getContacts().get(index
);
76 actions
.add(new KeyAction(Mode
.CONTACT_DETAILS
, KeyType
.Enter
,
77 Trans
.StringId
.KEY_ACTION_VIEW_CONTACT
) {
79 public Object
getObject() {
80 int index
= getSelectedIndex();
81 return card
.getContacts().get(index
);
84 actions
.add(new KeyAction(Mode
.SWICTH_FORMAT
, KeyType
.Tab
,
85 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
87 public boolean onAction() {
97 public DataType
getDataType() {
102 public Mode
getMode() {
103 return Mode
.CONTACT_LIST
;
107 public String
getTitle() {
108 // TODO Auto-generated method stub
113 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
115 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
117 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
118 : Element
.CONTACT_LINE
;
119 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
120 : Element
.CONTACT_LINE_SEPARATOR
;
122 // TODO: width/separator to check
123 String separator
= " ┃ ";
124 width
-= (format
.split("\\|").length
+ 1) * separator
.length();
125 String
[] array
= card
.getContacts().get(index
).toStringArray(format
,
128 // we could use: " ", "┃", "│"...
129 for (String str
: array
) {
130 parts
.add(new TextPart(str
, el
));
131 parts
.add(new TextPart(separator
, elSep
));
134 if (parts
.size() > 0)
135 parts
.remove(parts
.get(parts
.size() - 1));
140 private void switchFormat() {
141 if (formats
.size() == 0)
145 if (selectedFormat
>= formats
.size()) {
149 format
= formats
.get(selectedFormat
);