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 public DataType
getDataType() {
40 public List
<KeyAction
> getKeyBindings() {
41 // TODO Auto-generated method stub
42 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
45 actions
.add(new KeyAction(Mode
.ASK_USER
, KeyType
.Enter
,
46 Trans
.StringId
.DUMMY
) {
48 public Object
getObject() {
49 return contact
.get(getSelectedIndex());
53 public String
getQuestion() {
54 Data data
= getData();
56 return data
.getName();
63 public String
getDefaultAnswer() {
64 Data data
= getData();
66 return data
.getValue();
73 public String
callback(String answer
) {
74 Data data
= getData();
76 data
.setValue(answer
);
81 return "Cannot modify value";
84 actions
.add(new KeyAction(Mode
.NONE
, KeyType
.Tab
,
85 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
87 public boolean onAction() {
100 public String
getTitle() {
103 if (contact
!= null) {
104 title
= contact
.getPreferredDataValue("FN");
105 if (title
== null || title
.length() == 0)
106 title
= contact
.getPreferredDataValue("N");
113 public String
move(int x
, int y
) {
114 // TODO Auto-generated method stub
119 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
121 // TODO: from ini file?
124 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
125 : Element
.CONTACT_LINE
;
126 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
127 : Element
.CONTACT_LINE_SEPARATOR
;
128 Element elDirty
= (focused
&& selected
) ? Element
.CONTACT_LINE_DIRTY_SELECTED
129 : Element
.CONTACT_LINE_DIRTY
;
131 Data data
= contact
.get(index
);
133 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
134 if (data
.isDirty()) {
135 parts
.add(new TextPart(" ", el
));
136 parts
.add(new TextPart("*", elDirty
));
138 parts
.add(new TextPart(" ", elSep
));
140 String name
= " " + data
.getName() + " ";
143 StringBuilder valueBuilder
= new StringBuilder(" ");
146 valueBuilder
.append(data
.getValue());
147 if (data
.getGroup() != null && data
.getGroup().length() > 0) {
148 valueBuilder
.append("(");
149 valueBuilder
.append(data
.getGroup());
150 valueBuilder
.append(")");
154 for (int indexType
= 0; indexType
< data
.size(); indexType
++) {
155 TypeInfo type
= data
.get(indexType
);
156 if (valueBuilder
.length() > 1)
157 valueBuilder
.append(", ");
158 valueBuilder
.append(type
.getName());
159 valueBuilder
.append(": ");
160 valueBuilder
.append(type
.getValue());
164 valueBuilder
.append(" ");
166 value
= valueBuilder
.toString();
168 name
= StringUtils
.sanitize(name
, UiColors
.getInstance().isUnicode());
169 value
= StringUtils
.sanitize(value
, UiColors
.getInstance().isUnicode());
171 name
= StringUtils
.padString(name
, SIZE_COL_1
);
172 value
= StringUtils
.padString(value
, width
- SIZE_COL_1
173 - getSeparator().length() - 2);
175 parts
.add(new TextPart(name
, el
));
176 parts
.add(new TextPart(getSeparator(), elSep
));
177 parts
.add(new TextPart(value
, el
));