- @Override
- protected List<TextPart> getLabel(int index, int width, boolean selected,
- boolean focused) {
- // TODO: from ini file?
- int SIZE_COL_1 = 15;
-
- Element el = (focused && selected) ? Element.CONTACT_LINE_SELECTED
- : Element.CONTACT_LINE;
- Element elSep = (focused && selected) ? Element.CONTACT_LINE_SEPARATOR_SELECTED
- : Element.CONTACT_LINE_SEPARATOR;
- Element elDirty = (focused && selected) ? Element.CONTACT_LINE_DIRTY_SELECTED
- : Element.CONTACT_LINE_DIRTY;
-
- Data data = contact.getContent().get(index);
-
- List<TextPart> parts = new LinkedList<TextPart>();
- if (data.isDirty()) {
- parts.add(new TextPart(" ", el));
- parts.add(new TextPart("*", elDirty));
- } else {
- parts.add(new TextPart(" ", elSep));
- }
- 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());
+ /**
+ * 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.createLabel(
+ ColorOption.VIEW_CONTACT_NAME, name));
+ infoPanel.addComponent(UiColors.createLabel(
+ ColorOption.VIEW_CONTACT_NORMAL, ""));
+
+ // 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("=")) {
+ ColorOption el = hl ? ColorOption.VIEW_CONTACT_HIGHLIGHT
+ : ColorOption.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) {
+ Data pref = contact.getPreferredData(field);
+ for (Data data : contact.getData(field)) {
+ if (data == pref) {
+ infoPanel.addComponent(UiColors.createLabel(el,
+ StringUtils.padString(label, labelSize)
+ + data.toString()));
+ } else {
+ infoPanel.addComponent(UiColors.createLabel(
+ ColorOption.VIEW_CONTACT_NORMAL,
+ StringUtils.padString(label, labelSize)
+ + data.toString()));
+ }
+ }
+ } else {
+ String val = contact.getPreferredDataValue(field);
+ if (val == null)
+ val = "";
+ infoPanel.addComponent(UiColors.createLabel(el,
+ StringUtils.padString(label, labelSize) + val));
+ }
+ } else {
+ String label = info;
+ infoPanel.addComponent(UiColors.createLabel(
+ ColorOption.VIEW_CONTACT_NORMAL,
+ StringUtils.padString(label, labelSize)));
+ }