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
.UiColors
;
14 import be
.nikiroo
.jvcard
.tui
.KeyAction
.DataType
;
15 import be
.nikiroo
.jvcard
.tui
.KeyAction
.Mode
;
16 import be
.nikiroo
.jvcard
.tui
.StringUtils
;
17 import be
.nikiroo
.jvcard
.tui
.UiColors
.Element
;
19 public class ContactDetailsRaw
extends MainContentList
{
20 private Contact contact
;
23 public ContactDetailsRaw(Contact contact
) {
26 this.contact
= contact
;
29 for (int i
= 0; i
< contact
.getContent().size(); i
++) {
30 addItem("[detail line]");
35 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
37 // TODO: from ini file?
40 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
41 : Element
.CONTACT_LINE
;
42 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
43 : Element
.CONTACT_LINE_SEPARATOR
;
44 Element elDirty
= (focused
&& selected
) ? Element
.CONTACT_LINE_DIRTY_SELECTED
45 : Element
.CONTACT_LINE_DIRTY
;
47 Data data
= contact
.getContent().get(index
);
49 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
51 parts
.add(new TextPart(" ", el
));
52 parts
.add(new TextPart("*", elDirty
));
54 parts
.add(new TextPart(" ", elSep
));
56 String name
= " " + data
.getName() + " ";
59 StringBuilder valueBuilder
= new StringBuilder(" ");
62 valueBuilder
.append(data
.getValue());
63 if (data
.getGroup() != null && data
.getGroup().length() > 0) {
64 valueBuilder
.append("(");
65 valueBuilder
.append(data
.getGroup());
66 valueBuilder
.append(")");
70 for (TypeInfo type
: data
.getTypes()) {
71 if (valueBuilder
.length() > 1)
72 valueBuilder
.append(", ");
73 valueBuilder
.append(type
.getName());
74 valueBuilder
.append(": ");
75 valueBuilder
.append(type
.getValue());
79 valueBuilder
.append(" ");
81 value
= valueBuilder
.toString();
83 name
= StringUtils
.sanitize(name
, UiColors
.getInstance().isUnicode());
84 value
= StringUtils
.sanitize(value
, UiColors
.getInstance().isUnicode());
86 name
= StringUtils
.padString(name
, SIZE_COL_1
);
87 value
= StringUtils
.padString(value
, width
- SIZE_COL_1
88 - getSeparator().length() - 2);
90 parts
.add(new TextPart(name
, el
));
91 parts
.add(new TextPart(getSeparator(), elSep
));
92 parts
.add(new TextPart(value
, el
));
98 public DataType
getDataType() {
103 public List
<KeyAction
> getKeyBindings() {
104 // TODO Auto-generated method stub
105 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
108 actions
.add(new KeyAction(Mode
.EDIT_DETAIL
, 'd', Trans
.StringId
.DUMMY
) {
110 public Object
getObject() {
111 return contact
.getContent().get(getSelectedIndex());
114 actions
.add(new KeyAction(Mode
.NONE
, KeyType
.Tab
,
115 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
117 public boolean onAction() {
130 public String
getTitle() {
133 if (contact
!= null) {
134 title
= contact
.getPreferredDataValue("FN");
135 if (title
== null || title
.length() == 0)
136 title
= contact
.getPreferredDataValue("N");
143 public String
move(int x
, int y
) {
144 // TODO Auto-generated method stub