1 package be
.nikiroo
.jvcard
.tui
.panes
;
3 import java
.util
.LinkedList
;
6 import com
.googlecode
.lanterna
.input
.KeyType
;
8 import be
.nikiroo
.jvcard
.Contact
;
9 import be
.nikiroo
.jvcard
.Data
;
10 import be
.nikiroo
.jvcard
.TypeInfo
;
11 import be
.nikiroo
.jvcard
.i18n
.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
.StringUtils
;
16 import be
.nikiroo
.jvcard
.tui
.UiColors
.Element
;
18 public class ContactDetails
extends MainContentList
{
19 private Contact contact
;
22 public ContactDetails(Contact contact
) {
25 this.contact
= contact
;
28 for (int i
= 0; i
< contact
.getContent().size(); i
++) {
29 addItem("[detail line]");
34 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
36 // TODO: from ini file?
39 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
40 : Element
.CONTACT_LINE
;
41 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
42 : Element
.CONTACT_LINE_SEPARATOR
;
43 Element elDirty
= (focused
&& selected
) ? Element
.CONTACT_LINE_DIRTY_SELECTED
44 : Element
.CONTACT_LINE_DIRTY
;
46 Data data
= contact
.getContent().get(index
);
48 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
50 parts
.add(new TextPart(" ", el
));
51 parts
.add(new TextPart("*", elDirty
));
53 parts
.add(new TextPart(" ", elSep
));
55 String name
= " " + data
.getName() + " ";
58 StringBuilder valueBuilder
= new StringBuilder(" ");
61 valueBuilder
.append(data
.getValue());
62 if (data
.getGroup() != null && data
.getGroup().length() > 0) {
63 valueBuilder
.append("(");
64 valueBuilder
.append(data
.getGroup());
65 valueBuilder
.append(")");
69 for (TypeInfo type
: data
.getTypes()) {
70 if (valueBuilder
.length() > 1)
71 valueBuilder
.append(", ");
72 valueBuilder
.append(type
.getName());
73 valueBuilder
.append(": ");
74 valueBuilder
.append(type
.getValue());
78 valueBuilder
.append(" ");
80 value
= valueBuilder
.toString();
82 name
= StringUtils
.padString(name
, SIZE_COL_1
);
83 value
= StringUtils
.padString(value
, width
- SIZE_COL_1
84 - getSeparator().length() - 2);
86 parts
.add(new TextPart(name
, el
));
87 parts
.add(new TextPart(getSeparator(), elSep
));
88 parts
.add(new TextPart(value
, el
));
94 public DataType
getDataType() {
99 public String
getExitWarning() {
100 // TODO Auto-generated method stub
105 public List
<KeyAction
> getKeyBindings() {
106 // TODO Auto-generated method stub
107 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
110 actions
.add(new KeyAction(Mode
.EDIT_DETAIL
, 'd', Trans
.StringId
.DUMMY
) {
112 public Object
getObject() {
113 return contact
.getContent().get(getSelectedIndex());
116 actions
.add(new KeyAction(Mode
.NONE
, KeyType
.Tab
,
117 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
119 public boolean onAction() {
132 public Mode
getMode() {
133 return Mode
.CONTACT_DETAILS
;
137 public String
getTitle() {
140 if (contact
!= null) {
141 title
= contact
.getPreferredDataValue("FN");
142 if (title
== null || title
.length() == 0)
143 title
= contact
.getPreferredDataValue("N");
150 public String
move(int x
, int y
) {
151 // TODO Auto-generated method stub