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
) {
24 this.contact
= contact
;
27 for (int i
= 0; i
< contact
.size(); i
++) {
28 addItem("[detail line]");
33 public DataType
getDataType() {
38 public List
<KeyAction
> getKeyBindings() {
39 // TODO Auto-generated method stub
40 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
43 actions
.add(new KeyAction(Mode
.ASK_USER
, KeyType
.Enter
,
44 Trans
.StringId
.DUMMY
) {
46 public Object
getObject() {
47 return contact
.get(getSelectedIndex());
51 public String
getQuestion() {
52 Data data
= getData();
54 return data
.getName();
61 public String
getDefaultAnswer() {
62 Data data
= getData();
64 return data
.getValue();
71 public String
callback(String answer
) {
72 Data data
= getData();
74 data
.setValue(answer
);
79 return "Cannot modify value";
82 actions
.add(new KeyAction(Mode
.NONE
, KeyType
.Tab
,
83 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
85 public boolean onAction() {
98 public String
getTitle() {
101 if (contact
!= null) {
102 title
= contact
.getPreferredDataValue("FN");
103 if (title
== null || title
.length() == 0)
104 title
= contact
.getPreferredDataValue("N");
111 public String
move(int x
, int y
) {
112 // TODO Auto-generated method stub
117 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
119 // TODO: from ini file?
122 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
123 : Element
.CONTACT_LINE
;
124 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
125 : Element
.CONTACT_LINE_SEPARATOR
;
126 Element elDirty
= (focused
&& selected
) ? Element
.CONTACT_LINE_DIRTY_SELECTED
127 : Element
.CONTACT_LINE_DIRTY
;
129 Data data
= contact
.get(index
);
131 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
132 if (data
.isDirty()) {
133 parts
.add(new TextPart(" ", el
));
134 parts
.add(new TextPart("*", elDirty
));
136 parts
.add(new TextPart(" ", elSep
));
138 String name
= " " + data
.getName() + " ";
141 StringBuilder valueBuilder
= new StringBuilder(" ");
144 valueBuilder
.append(data
.getValue());
145 if (data
.getGroup() != null && data
.getGroup().length() > 0) {
146 valueBuilder
.append("(");
147 valueBuilder
.append(data
.getGroup());
148 valueBuilder
.append(")");
152 for (int indexType
= 0; indexType
< data
.size(); indexType
++) {
153 TypeInfo type
= data
.get(indexType
);
154 if (valueBuilder
.length() > 1)
155 valueBuilder
.append(", ");
156 valueBuilder
.append(type
.getName());
157 valueBuilder
.append(": ");
158 valueBuilder
.append(type
.getValue());
162 valueBuilder
.append(" ");
164 value
= valueBuilder
.toString();
166 name
= StringUtils
.sanitize(name
, UiColors
.getInstance().isUnicode());
167 value
= StringUtils
.sanitize(value
, UiColors
.getInstance().isUnicode());
169 name
= StringUtils
.padString(name
, SIZE_COL_1
);
170 value
= StringUtils
.padString(value
, width
- SIZE_COL_1
171 - getSeparator().length() - 2);
173 parts
.add(new TextPart(name
, el
));
174 parts
.add(new TextPart(getSeparator(), elSep
));
175 parts
.add(new TextPart(value
, el
));