X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2Fpanes%2FContactDetails.java;h=2137bd885b1588312590eb15183037a554d6a801;hb=24e66f8322565f83abd73cfddb6838cbd0f52f58;hp=2ea8a9724b80cf6ac777cb37fc75ea08ae7f328c;hpb=7671a2499e6f0d6c8e0765b36c18c1e89bc457c5;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java index 2ea8a97..2137bd8 100644 --- a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java +++ b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java @@ -7,24 +7,26 @@ import java.util.List; import be.nikiroo.jvcard.Contact; import be.nikiroo.jvcard.Data; import be.nikiroo.jvcard.TypeInfo; -import be.nikiroo.jvcard.resources.StringUtils; -import be.nikiroo.jvcard.resources.bundles.DisplayBundle; -import be.nikiroo.jvcard.resources.enums.DisplayOption; -import be.nikiroo.jvcard.resources.enums.ColorOption; -import be.nikiroo.jvcard.resources.enums.StringId; +import be.nikiroo.jvcard.resources.ColorOption; +import be.nikiroo.jvcard.resources.DisplayBundle; +import be.nikiroo.jvcard.resources.DisplayOption; +import be.nikiroo.jvcard.resources.StringId; import be.nikiroo.jvcard.tui.ImageTextControl; import be.nikiroo.jvcard.tui.KeyAction; import be.nikiroo.jvcard.tui.KeyAction.DataType; import be.nikiroo.jvcard.tui.KeyAction.Mode; import be.nikiroo.jvcard.tui.UiColors; +import be.nikiroo.utils.StringUtils; +import be.nikiroo.utils.ui.ImageUtilsAwt; 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; import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.TextBox; +import com.googlecode.lanterna.gui2.TextBox.Style; import com.googlecode.lanterna.input.KeyType; public class ContactDetails extends MainContent { @@ -34,7 +36,7 @@ public class ContactDetails extends MainContent { private Image image; private boolean fullscreenImage; private Panel infoPanel; - private Label note; + private TextBox note; // from .properties file: private int labelSize = -1; @@ -66,8 +68,12 @@ public class ContactDetails extends MainContent { notePanel.addComponent(UiColors.createLabel( ColorOption.VIEW_CONTACT_NOTES_TITLE, "Notes:")); - note = UiColors.createLabel(ColorOption.VIEW_CONTACT_NORMAL, ""); + // 10000x10000 is probably enough or "max" + note = new TextBox(new TerminalSize(10000, 10000), Style.MULTI_LINE); + note.setReadOnly(true); notePanel.addComponent(note); + note.setVerticalFocusSwitching(false); + note.setHorizontalFocusSwitching(false); setContact(contact); @@ -110,22 +116,27 @@ public class ContactDetails extends MainContent { boolean hl = false; boolean all = false; - if (info.contains("+") || info.contains("#")) + if (info.contains("+") || info.contains("#")) { hl = true; - if (info.contains("*") || info.contains("#")) + } + 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) + if (index < 0) { index = info.indexOf('+'); - if (index < 0) + } + if (index < 0) { index = info.indexOf('#'); - if (index < 0) + } + if (index < 0) { index = info.indexOf('*'); + } String label = info.substring(0, index); String field = info.substring(index + 1); @@ -146,8 +157,9 @@ public class ContactDetails extends MainContent { } } else { String val = contact.getPreferredDataValue(field); - if (val == null) + if (val == null) { val = ""; + } infoPanel.addComponent(UiColors.createLabel(el, StringUtils.padString(label, labelSize) + val)); } @@ -164,8 +176,9 @@ public class ContactDetails extends MainContent { ColorOption.VIEW_CONTACT_NORMAL, "")); String notes = contact.getPreferredDataValue("NOTE"); - if (notes == null) + if (notes == null) { notes = ""; + } note.setText(notes); Data photo = contact.getPreferredData("PHOTO"); @@ -182,9 +195,14 @@ public class ContactDetails extends MainContent { if (encoding != null && encoding.getValue() != null && encoding.getValue().equalsIgnoreCase("b")) { - try { - image = StringUtils.toImage(photo.getValue()); + be.nikiroo.utils.Image img = new be.nikiroo.utils.Image( + photo.getValue()); + try { + image = ImageUtilsAwt.fromImage(img); + } finally { + img.close(); + } } catch (Exception e) { System.err.println("Cannot parse image for contact: " + contact.getPreferredDataValue("UID")); @@ -264,15 +282,17 @@ public class ContactDetails extends MainContent { private void setImage(Image image) { this.image = image; - if (txtImage != null && top.containsComponent(txtImage)) + if (txtImage != null && top.containsComponent(txtImage)) { top.removeComponent(txtImage); + } TerminalSize size = getTxtSize(); if (size != null) { - if (txtImage != null) + if (txtImage != null) { txtImage.setSize(size); - else + } else { txtImage = new ImageTextControl(image, size); + } } if (size != null) { @@ -293,15 +313,16 @@ public class ContactDetails extends MainContent { && getSize().getRows() > 0) { if (fullscreenImage) { return getSize(); - } else { - // TODO: configure size? - int w = getSize().getColumns() - 40; - int h = getSize().getRows() - 9; - if (w <= 0 || h <= 0) - return null; + } - return new TerminalSize(w, h); + // TODO: configure size? + int w = getSize().getColumns() - 40; + int h = getSize().getRows() - 9; + if (w <= 0 || h <= 0) { + return null; } + + return new TerminalSize(w, h); } return null;