X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2Fpanes%2FContactDetails.java;h=1d6beb9998bf01b461fb4590746edf1bb4d13868;hb=aecb3399b756d2ba04223bc6f553999fce73f9fb;hp=090cf142dbbaf65fa717f5e9adae73b75100a1d9;hpb=1c03abafc3987d93fa682e7b8758e51bed8a4faf;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java index 090cf14..1d6beb9 100644 --- a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java +++ b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java @@ -4,6 +4,8 @@ import java.awt.Image; import java.io.ByteArrayInputStream; import java.util.LinkedList; import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; import javax.imageio.ImageIO; import javax.xml.bind.DatatypeConverter; @@ -11,7 +13,9 @@ import javax.xml.bind.DatatypeConverter; import be.nikiroo.jvcard.Contact; import be.nikiroo.jvcard.Data; import be.nikiroo.jvcard.TypeInfo; -import be.nikiroo.jvcard.i18n.Trans; +import be.nikiroo.jvcard.resources.Bundles; +import be.nikiroo.jvcard.resources.StringUtils; +import be.nikiroo.jvcard.resources.Trans; import be.nikiroo.jvcard.tui.ImageTextControl; import be.nikiroo.jvcard.tui.KeyAction; import be.nikiroo.jvcard.tui.KeyAction.DataType; @@ -20,6 +24,7 @@ import be.nikiroo.jvcard.tui.UiColors; import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.gui2.BorderLayout; +import com.googlecode.lanterna.gui2.Borders; import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.LinearLayout; @@ -34,8 +39,11 @@ public class ContactDetails extends MainContent { private boolean fullscreenImage; private Panel infoPanel; private Label note; + ResourceBundle map; public ContactDetails(Contact contact) { + map = Bundles.getBundle("display"); + BorderLayout blayout = new BorderLayout(); setLayoutManager(blayout); @@ -57,8 +65,10 @@ public class ContactDetails extends MainContent { setContact(contact); - addComponent(top, BorderLayout.Location.TOP); - addComponent(notePanel, BorderLayout.Location.CENTER); + addComponent(top.withBorder(Borders.doubleLineBevel()), + BorderLayout.Location.TOP); + addComponent(notePanel.withBorder(Borders.singleLineBevel()), + BorderLayout.Location.CENTER); } /** @@ -81,25 +91,102 @@ public class ContactDetails extends MainContent { name = contact.getPreferredDataValue("N"); } - // TODO: i18n + do it properly infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NAME .createLabel(name)); - infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NORMAL .createLabel("")); - infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NORMAL - .createLabel("Phone: " - + contact.getPreferredDataValue("TEL"))); - infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NORMAL - .createLabel("eMail: " - + contact.getPreferredDataValue("EMAIL"))); + + // List of infos: + int labelSize = -1; + try { + labelSize = Integer.parseInt(map + .getString("CONTACT_DETAILS_LABEL_WIDTH")); + + } catch (NumberFormatException e) { + e.printStackTrace(); + labelSize = -1; + } catch (MissingResourceException e) { + labelSize = -1; + } + + String infoFormat = ""; + try { + infoFormat = map.getString("CONTACT_DETAILS_INFO"); + } catch (MissingResourceException e) { + e.printStackTrace(); + } + + 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))); + } + } + // end of list + infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NORMAL .createLabel("")); String notes = contact.getPreferredDataValue("NOTE"); if (notes == null) notes = ""; - note.setText(notes.replaceAll("\\\\n", "\n")); + note.setText(notes); Data photo = contact.getPreferredData("PHOTO"); if (photo != null) { @@ -142,7 +229,6 @@ public class ContactDetails extends MainContent { public List getKeyBindings() { List actions = new LinkedList(); - // TODO actions.add(new KeyAction(Mode.NONE, KeyType.Tab, Trans.StringId.KEY_ACTION_SWITCH_FORMAT) { @Override @@ -174,9 +260,9 @@ public class ContactDetails extends MainContent { return false; } }); - // TODO: add "normal" edit and remove this one into RAW edit - actions.add(new KeyAction(Mode.CONTACT_DETAILS_RAW, 'e', - Trans.StringId.KEY_ACTION_EDIT_CONTACT) { + // TODO: add "normal" edit + actions.add(new KeyAction(Mode.CONTACT_DETAILS_RAW, 'r', + Trans.StringId.KEY_ACTION_EDIT_CONTACT_RAW) { @Override public Object getObject() { return contact; @@ -235,7 +321,7 @@ public class ContactDetails extends MainContent { } else { // TODO: configure size? int w = getSize().getColumns() - 40; - int h = getSize().getRows() - 5; + int h = getSize().getRows() - 9; if (w <= 0 || h <= 0) return null;