X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2Fpanes%2FContactDetails.java;h=825be1a40f9515a013e7e19459da9e67b522ab5a;hb=f04d8b1c4c3ed29d4d23cc076f307ef455b2dcb6;hp=1fad960e46730006273c8ab47943fab1a85eb11d;hpb=bcb54330afff6a443ab43ee3d38cc7f863c701b7;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java index 1fad960..825be1a 100644 --- a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java +++ b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java @@ -1,154 +1,73 @@ package be.nikiroo.jvcard.tui.panes; -import java.util.LinkedList; +import java.awt.Image; +import java.util.Base64; import java.util.List; -import com.googlecode.lanterna.input.KeyType; +import javax.swing.ImageIcon; 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.tui.ImageText; 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.StringUtils; -import be.nikiroo.jvcard.tui.UiColors.Element; -public class ContactDetails extends MainContentList { - private Contact contact; - private int mode; - - public ContactDetails(Contact contact) { - super(null, null); - - this.contact = contact; - this.mode = 0; - - for (int i = 0; i < contact.getContent().size(); i++) { - addItem("[detail line]"); - } - } - - @Override - protected List 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; +import com.googlecode.lanterna.TerminalSize; +import com.googlecode.lanterna.gui2.BorderLayout; +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.TextBox; - Data data = contact.getContent().get(index); - - List parts = new LinkedList(); - 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()); - } - break; - } - valueBuilder.append(" "); - - value = valueBuilder.toString(); - - name = StringUtils.padString(name, SIZE_COL_1); - value = StringUtils.padString(value, width - SIZE_COL_1 - - getSeparator().length() - 2); - - parts.add(new TextPart(name, el)); - parts.add(new TextPart(getSeparator(), elSep)); - parts.add(new TextPart(value, el)); - - return parts; - }; +public class ContactDetails extends MainContent { + private Contact contact; @Override public DataType getDataType() { return DataType.DATA; } - @Override - public String getExitWarning() { - // TODO Auto-generated method stub - return null; - } - @Override public List getKeyBindings() { // TODO Auto-generated method stub - List actions = new LinkedList(); - - // TODO: add, remove - actions.add(new KeyAction(Mode.EDIT_DETAIL, 'd', Trans.StringId.DUMMY) { - @Override - public Object getObject() { - return contact.getContent().get(getSelectedIndex()); - } - }); - actions.add(new KeyAction(Mode.NONE, KeyType.Tab, - Trans.StringId.KEY_ACTION_SWITCH_FORMAT) { - @Override - public boolean onAction() { - mode++; - if (mode > 1) - mode = 0; - - return false; - } - }); - - return actions; + return null; } - @Override - public Mode getMode() { - return Mode.CONTACT_DETAILS; - } + public ContactDetails(Contact contact) { + this.contact = contact; - @Override - public String getTitle() { - String title = null; + BorderLayout blayout = new BorderLayout(); + setLayoutManager(blayout); + Panel top = new Panel(); if (contact != null) { - title = contact.getPreferredDataValue("FN"); - if (title == null || title.length() == 0) - title = contact.getPreferredDataValue("N"); + Data photo = contact.getPreferredData("PHOTO"); + if (photo != null) { + TypeInfo encoding = null; + TypeInfo type = null; + for (TypeInfo info : photo.getTypes()) { + if (info.getName() != null) { + if (info.getName().equalsIgnoreCase("ENCODING")) + encoding = info; + if (info.getName().equalsIgnoreCase("TYPE")) + type = info; + } + } + + if (encoding != null && encoding.getValue() != null + && encoding.getValue().equalsIgnoreCase("b")) { + + Image img = new ImageIcon(Base64.getDecoder().decode( + photo.getValue())).getImage(); + + TerminalSize size = new TerminalSize(40, 20); + size = new TerminalSize(120, 50); + + String str = new ImageText(img, size).getText(); + top.addComponent(new TextBox(size, str)); + } + } } - return title; - } - - @Override - public String move(int x, int y) { - // TODO Auto-generated method stub - return null; + addComponent(top, BorderLayout.Location.TOP); } }