1 package be
.nikiroo
.jvcard
.tui
.panes
;
3 import java
.util
.LinkedList
;
6 import be
.nikiroo
.jvcard
.Card
;
7 import be
.nikiroo
.jvcard
.Contact
;
8 import be
.nikiroo
.jvcard
.i18n
.Trans
;
9 import be
.nikiroo
.jvcard
.tui
.KeyAction
;
10 import be
.nikiroo
.jvcard
.tui
.UiColors
;
11 import be
.nikiroo
.jvcard
.tui
.KeyAction
.DataType
;
12 import be
.nikiroo
.jvcard
.tui
.KeyAction
.Mode
;
13 import be
.nikiroo
.jvcard
.tui
.UiColors
.Element
;
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 //TODO: save? [y/n] instead
59 return "Some of your contact information is not saved; ignore? [Y/N]";
66 public List
<KeyAction
> getKeyBindings() {
67 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
71 actions
.add(new KeyAction(Mode
.NONE
, 'd', Trans
.StringId
.DUMMY
) {
73 public boolean onAction() {
75 int index
= getSelectedIndex();
76 Contact c
= card
.getContacts().get(index
);
81 actions
.add(new KeyAction(Mode
.CONTACT_DETAILS
, 'e',
82 Trans
.StringId
.KEY_ACTION_EDIT_CONTACT
) {
84 public Object
getObject() {
85 int index
= getSelectedIndex();
86 return card
.getContacts().get(index
);
89 actions
.add(new KeyAction(Mode
.CONTACT_DETAILS
, KeyType
.Enter
,
90 Trans
.StringId
.KEY_ACTION_VIEW_CONTACT
) {
92 public Object
getObject() {
93 int index
= getSelectedIndex();
94 return card
.getContacts().get(index
);
97 actions
.add(new KeyAction(Mode
.SWICTH_FORMAT
, KeyType
.Tab
,
98 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
100 public boolean onAction() {
110 public DataType
getDataType() {
111 return DataType
.CARD
;
115 public Mode
getMode() {
116 return Mode
.CONTACT_LIST
;
120 public String
getTitle() {
122 return card
.getName();
129 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
131 Contact c
= card
.getContacts().get(index
);
133 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
134 : Element
.CONTACT_LINE
;
135 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
136 : Element
.CONTACT_LINE_SEPARATOR
;
137 Element elDirty
= (focused
&& selected
) ? Element
.CONTACT_LINE_DIRTY_SELECTED
138 : Element
.CONTACT_LINE_DIRTY
;
140 width
-= 2; // dirty mark space
142 // we could use: " ", "┃", "│"...
143 String
[] array
= c
.toStringArray(format
, "┃", " ", width
);
145 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
147 parts
.add(new TextPart(" ", el
));
148 parts
.add(new TextPart("*", elDirty
));
150 parts
.add(new TextPart(" ", elSep
));
153 boolean separator
= false;
154 for (String str
: array
) {
155 parts
.add(new TextPart(str
, (separator ? elSep
: el
)));
156 separator
= !separator
;
162 private void switchFormat() {
163 if (formats
.size() == 0)
167 if (selectedFormat
>= formats
.size()) {
171 format
= formats
.get(selectedFormat
);