X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2Fpanes%2FContactDetails.java;h=aa838cb6d9339cc8d57a6e91dbefe743d827ae22;hb=30a4aa17f2141ad80a23447ee2e6303f6c9ef995;hp=4cbbdf7d38e2e27a6264880123c647d3fd2f7410;hpb=3634193b7a8927e68a3ae3d38fff4f6bd36c4ee5;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java index 4cbbdf7..aa838cb 100644 --- a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java +++ b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java @@ -1,15 +1,11 @@ package be.nikiroo.jvcard.tui.panes; 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; - import be.nikiroo.jvcard.Contact; import be.nikiroo.jvcard.Data; import be.nikiroo.jvcard.TypeInfo; @@ -39,10 +35,33 @@ public class ContactDetails extends MainContent { private boolean fullscreenImage; private Panel infoPanel; private Label note; - ResourceBundle map; + + // from .properties file: + private int labelSize = -1; + private String infoFormat = ""; + // public ContactDetails(Contact contact) { - map = Bundles.getBundle("display"); + // Get the .properties info: + ResourceBundle map = Bundles.getBundle("display"); + + try { + labelSize = Integer.parseInt(map + .getString("CONTACT_DETAILS_LABEL_WIDTH")); + + } catch (NumberFormatException e) { + e.printStackTrace(); + labelSize = -1; + } catch (MissingResourceException e) { + labelSize = -1; + } + + try { + infoFormat = map.getString("CONTACT_DETAILS_INFO"); + } catch (MissingResourceException e) { + e.printStackTrace(); + } + // BorderLayout blayout = new BorderLayout(); setLayoutManager(blayout); @@ -86,36 +105,12 @@ public class ContactDetails extends MainContent { infoPanel.removeAllComponents(); String name = contact.getPreferredDataValue("FN"); - if (name == null || name.length() == 0) { - // TODO format it ourself - name = contact.getPreferredDataValue("N"); - } - infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NAME .createLabel(name)); infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NORMAL .createLabel("")); // 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 @@ -151,23 +146,25 @@ public class ContactDetails extends MainContent { if (all) { for (Data data : contact.getData(field)) { if (data.isPreferred()) { - infoPanel - .addComponent(el.createLabel(StringUtils - .padString(label, labelSize) - + contact - .getPreferredDataValue(field))); + infoPanel.addComponent(el + .createLabel(StringUtils.padString( + label, labelSize) + + data.toString())); } else { infoPanel - .addComponent(UiColors.Element.VIEW_CONTACT_NORMAL.createLabel(StringUtils - .padString(label, labelSize) - + contact - .getPreferredDataValue(field))); + .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) - + contact.getPreferredDataValue(field))); + .padString(label, labelSize) + val)); } } else { String label = info; @@ -184,13 +181,12 @@ public class ContactDetails extends MainContent { 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) { TypeInfo encoding = null; - for (int index = 0; index < photo.size(); index++) { - TypeInfo info = photo.get(index); + for (TypeInfo info : photo) { if (info.getName() != null) { if (info.getName().equalsIgnoreCase("ENCODING")) encoding = info; @@ -203,10 +199,7 @@ public class ContactDetails extends MainContent { && encoding.getValue().equalsIgnoreCase("b")) { try { - image = ImageIO.read(new ByteArrayInputStream( - DatatypeConverter.parseBase64Binary(photo - .getValue()))); - image.toString(); + image = StringUtils.toImage(photo.getValue()); } catch (Exception e) { System.err.println("Cannot parse image for contact: " + contact.getPreferredDataValue("UID")); @@ -319,7 +312,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;