- String name = " " + data.getName() + " ";
- String value = null;
-
- StringBuilder valueBuilder = new StringBuilder(" ");
- switch (mode) {
- case 0:
- valueBuilder.append(data.getValue());
- if (data.getGroup() != null && data.getGroup().length() > 0) {
- valueBuilder.append("(");
- valueBuilder.append(data.getGroup());
- valueBuilder.append(")");
- }
- break;
- case 1:
- for (TypeInfo type : data.getTypes()) {
- if (valueBuilder.length() > 1)
- valueBuilder.append(", ");
- valueBuilder.append(type.getName());
- valueBuilder.append(": ");
- valueBuilder.append(type.getValue());
+ //
+
+ BorderLayout blayout = new BorderLayout();
+ setLayoutManager(blayout);
+
+ top = new Panel();
+ blayout = new BorderLayout();
+ top.setLayoutManager(blayout);
+
+ infoPanel = new Panel();
+ infoPanel.setLayoutManager(new LinearLayout(Direction.VERTICAL));
+ top.addComponent(infoPanel, BorderLayout.Location.CENTER);
+
+ Panel notePanel = new Panel();
+ notePanel.setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
+
+ notePanel.addComponent(UiColors.Element.VIEW_CONTACT_NOTES_TITLE
+ .createLabel("Notes:"));
+ note = UiColors.Element.VIEW_CONTACT_NORMAL.createLabel("");
+ notePanel.addComponent(note);
+
+ setContact(contact);
+
+ addComponent(top.withBorder(Borders.doubleLineBevel()),
+ BorderLayout.Location.TOP);
+ addComponent(notePanel.withBorder(Borders.singleLineBevel()),
+ BorderLayout.Location.CENTER);
+ }
+
+ /**
+ * Change the enclosed {@link Contact} from this {@link ContactDetails}.
+ * Also re-set the image.
+ *
+ * @param contact
+ * the new {@link Contact}
+ */
+ public void setContact(Contact contact) {
+ this.contact = contact;
+ image = null;
+
+ if (contact != null) {
+ infoPanel.removeAllComponents();
+
+ String name = contact.getPreferredDataValue("FN");
+ infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NAME
+ .createLabel(name));
+ infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NORMAL
+ .createLabel(""));
+
+ // List of infos:
+ String[] infos = infoFormat.split("\\|");
+ for (String info : infos) {
+ // # - "=FIELD" will take the preferred value for this field
+ // # - "+FIELD" will take the preferred value for this field and
+ // highlight it
+ // # - "#FIELD" will take all the values with this field's name
+ // # - "*FIELD" will take all the values with this field's name,
+ // highlighting the preferred one
+ // #
+
+ boolean hl = false;
+ boolean all = false;
+ if (info.contains("+") || info.contains("#"))
+ hl = true;
+ if (info.contains("*") || info.contains("#"))
+ all = true;
+
+ if (all || hl || info.contains("=")) {
+ UiColors.Element el = hl ? UiColors.Element.VIEW_CONTACT_HIGHLIGHT
+ : UiColors.Element.VIEW_CONTACT_NORMAL;
+
+ int index = info.indexOf('=');
+ if (index < 0)
+ index = info.indexOf('+');
+ if (index < 0)
+ index = info.indexOf('#');
+ if (index < 0)
+ index = info.indexOf('*');
+
+ String label = info.substring(0, index);
+ String field = info.substring(index + 1);
+
+ if (all) {
+ for (Data data : contact.getData(field)) {
+ if (data.isPreferred()) {
+ infoPanel.addComponent(el
+ .createLabel(StringUtils.padString(
+ label, labelSize)
+ + data.toString()));
+ } else {
+ infoPanel
+ .addComponent(UiColors.Element.VIEW_CONTACT_NORMAL
+ .createLabel(StringUtils
+ .padString(label,
+ labelSize)
+ + data.toString()));
+ }
+ }
+ } else {
+ String val = contact.getPreferredDataValue(field);
+ if (val == null)
+ val = "";
+ infoPanel.addComponent(el.createLabel(StringUtils
+ .padString(label, labelSize) + val));
+ }
+ } else {
+ String label = info;
+ infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NORMAL
+ .createLabel(StringUtils
+ .padString(label, labelSize)));
+ }