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
;
13 import com
.googlecode
.lanterna
.input
.KeyType
;
15 public class ContactList
extends MainContentList
{
18 private List
<String
> formats
= new LinkedList
<String
>();
19 private int selectedFormat
= -1;
20 private String format
= "";
22 public ContactList(Card card
) {
23 super(UiColors
.Element
.CONTACT_LINE
,
24 UiColors
.Element
.CONTACT_LINE_SELECTED
);
26 // TODO: should get that in an INI file
27 formats
.add("NICKNAME@3|FN@+|EMAIL@30");
28 formats
.add("FN@+|EMAIL@40");
35 * Change the currently displayed contacts card.
38 * the new {@link Card}
40 public void setCard(Card card
) {
45 for (int i
= 0; i
< card
.getContacts().size(); i
++) {
46 addItem("[contact line]");
54 public String
getExitWarning() {
55 if (card
!= null && card
.isDirty()) {
56 return "Some of your contact information is not saved";
62 public List
<KeyAction
> getKeyBindings() {
63 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
66 actions
.add(new KeyAction(Mode
.CONTACT_DETAILS
, 'e',
67 Trans
.StringId
.KEY_ACTION_EDIT_CONTACT
) {
69 public Object
getObject() {
70 int index
= getSelectedIndex();
71 return card
.getContacts().get(index
);
74 actions
.add(new KeyAction(Mode
.CONTACT_DETAILS
, KeyType
.Enter
,
75 Trans
.StringId
.KEY_ACTION_VIEW_CONTACT
) {
77 public Object
getObject() {
78 int index
= getSelectedIndex();
79 return card
.getContacts().get(index
);
82 actions
.add(new KeyAction(Mode
.SWICTH_FORMAT
, KeyType
.Tab
,
83 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
85 public boolean onAction() {
95 public DataType
getDataType() {
100 public Mode
getMode() {
101 return Mode
.CONTACT_LIST
;
105 public String
getTitle() {
106 // TODO Auto-generated method stub
111 protected String
getLabel(int index
, int width
) {
112 // we could use: " ", "┃", "│"...
113 return card
.getContacts().get(index
).toString(format
, " ┃ ", width
);
116 private void switchFormat() {
117 if (formats
.size() == 0)
121 if (selectedFormat
>= formats
.size()) {
125 format
= formats
.get(selectedFormat
);