1 package be
.nikiroo
.jvcard
.tui
.panes
;
3 import java
.util
.LinkedList
;
6 import be
.nikiroo
.jvcard
.Contact
;
7 import be
.nikiroo
.jvcard
.Data
;
8 import be
.nikiroo
.jvcard
.TypeInfo
;
9 import be
.nikiroo
.jvcard
.i18n
.Trans
;
10 import be
.nikiroo
.jvcard
.tui
.KeyAction
;
11 import be
.nikiroo
.jvcard
.tui
.KeyAction
.DataType
;
12 import be
.nikiroo
.jvcard
.tui
.KeyAction
.Mode
;
13 import be
.nikiroo
.jvcard
.tui
.StringUtils
;
14 import be
.nikiroo
.jvcard
.tui
.UiColors
;
15 import be
.nikiroo
.jvcard
.tui
.UiColors
.Element
;
17 import com
.googlecode
.lanterna
.input
.KeyType
;
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
.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
.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 (int indexType
= 0; indexType
< data
.size(); indexType
++) {
71 TypeInfo type
= data
.get(indexType
);
72 if (valueBuilder
.length() > 1)
73 valueBuilder
.append(", ");
74 valueBuilder
.append(type
.getName());
75 valueBuilder
.append(": ");
76 valueBuilder
.append(type
.getValue());
80 valueBuilder
.append(" ");
82 value
= valueBuilder
.toString();
84 name
= StringUtils
.sanitize(name
, UiColors
.getInstance().isUnicode());
85 value
= StringUtils
.sanitize(value
, UiColors
.getInstance().isUnicode());
87 name
= StringUtils
.padString(name
, SIZE_COL_1
);
88 value
= StringUtils
.padString(value
, width
- SIZE_COL_1
89 - getSeparator().length() - 2);
91 parts
.add(new TextPart(name
, el
));
92 parts
.add(new TextPart(getSeparator(), elSep
));
93 parts
.add(new TextPart(value
, el
));
99 public DataType
getDataType() {
100 return DataType
.DATA
;
104 public List
<KeyAction
> getKeyBindings() {
105 // TODO Auto-generated method stub
106 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
109 actions
.add(new KeyAction(Mode
.ASK_USER
, KeyType
.Enter
,
110 Trans
.StringId
.DUMMY
) {
112 public Object
getObject() {
113 return contact
.get(getSelectedIndex());
117 public String
getQuestion() {
118 Data data
= getData();
120 return data
.getName();
127 public String
getDefaultAnswer() {
128 Data data
= getData();
130 return data
.getValue();
137 public String
callback(String answer
) {
138 Data data
= getData();
140 data
.setValue(answer
);
145 return "Cannot modify value";
148 actions
.add(new KeyAction(Mode
.NONE
, KeyType
.Tab
,
149 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
151 public boolean onAction() {
164 public String
getTitle() {
167 if (contact
!= null) {
168 title
= contact
.getPreferredDataValue("FN");
169 if (title
== null || title
.length() == 0)
170 title
= contact
.getPreferredDataValue("N");
177 public String
move(int x
, int y
) {
178 // TODO Auto-generated method stub