TITLE_MAIN, TITLE_VARIABLE, TITLE_COUNT, //
ACTION_KEY, ACTION_DESC, //
LINE_MESSAGE, LINE_MESSAGE_ERR, LINE_MESSAGE_QUESTION, LINE_MESSAGE_ANS, //
- CONTACT_LINE, CONTACT_LINE_SEPARATOR, CONTACT_LINE_SELECTED, CONTACT_LINE_SEPARATOR_SELECTED, CONTACT_LINE_DIRTY, CONTACT_LINE_DIRTY_SELECTED;
+ CONTACT_LINE, CONTACT_LINE_SEPARATOR, CONTACT_LINE_SELECTED, CONTACT_LINE_SEPARATOR_SELECTED, CONTACT_LINE_DIRTY, CONTACT_LINE_DIRTY_SELECTED, //
+ VIEW_CONTACT_NAME, VIEW_CONTACT_NORMAL, VIEW_CONTACT_NOTES_TITLE, //
+ ;
/**
* Get the foreground colour of this element.
}
private Label createLabel(Element el, String text) {
+ if (text == null)
+ text = "";
+
Label lbl = new Label(text);
themeLabel(el, lbl);
return lbl;
addEl(Element.TITLE_MAIN, TextColor.ANSI.WHITE, TextColor.ANSI.BLUE);
addEl(Element.TITLE_VARIABLE, TextColor.ANSI.GREEN, TextColor.ANSI.BLUE);
addEl(Element.TITLE_COUNT, TextColor.ANSI.RED, TextColor.ANSI.BLUE);
+ addEl(Element.VIEW_CONTACT_NAME, TextColor.ANSI.BLACK,
+ TextColor.ANSI.WHITE);
+ addEl(Element.VIEW_CONTACT_NORMAL, TextColor.ANSI.WHITE,
+ TextColor.ANSI.BLACK);
+ addEl(Element.VIEW_CONTACT_NOTES_TITLE, TextColor.ANSI.BLACK,
+ TextColor.ANSI.WHITE);
}
private void addEl(Element el, TextColor fore, TextColor back) {
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 com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.gui2.BorderLayout;
+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.input.KeyType;
public class ContactDetails extends MainContent {
private Contact contact;
private Panel top;
- private ImageTextControl txt;
+ private ImageTextControl txtImage;
private Image image;
private boolean fullscreenImage;
+ private Panel infoPanel;
+ private Label note;
public ContactDetails(Contact contact) {
- this.contact = contact;
-
BorderLayout blayout = new BorderLayout();
setLayoutManager(blayout);
top = new Panel();
+ blayout = new BorderLayout();
+ top.setLayoutManager(blayout);
+
+ infoPanel = new Panel();
+ infoPanel.setLayoutManager(new LinearLayout(Direction.VERTICAL));
+ top.addComponent(infoPanel, BorderLayout.Location.CENTER);
+
+ Panel notePanel = new Panel();
+ notePanel.setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
+
+ notePanel.addComponent(UiColors.Element.VIEW_CONTACT_NOTES_TITLE
+ .createLabel("Notes:"));
+ note = UiColors.Element.VIEW_CONTACT_NORMAL.createLabel("");
+ notePanel.addComponent(note);
+
setContact(contact);
+
addComponent(top, BorderLayout.Location.TOP);
+ addComponent(notePanel, BorderLayout.Location.CENTER);
}
+ /**
+ * Change the enclosed {@link Contact} from this {@link ContactDetails}.
+ *
+ * @param contact
+ * the new {@link Contact}
+ */
public void setContact(Contact contact) {
- Image img = null;
+ if (this.contact == contact)
+ return;
+
this.contact = contact;
- if (contact != null) {
+ if (contact == null) {
+ image = null;
+ } else {
+ infoPanel.removeAllComponents();
+
+ String name = contact.getPreferredDataValue("FN");
+ if (name == null || name.length() == 0) {
+ // TODO format it ourself
+ 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")));
+ infoPanel.addComponent(UiColors.Element.VIEW_CONTACT_NORMAL
+ .createLabel(""));
+
+ String notes = contact.getPreferredDataValue("NOTE");
+ if (notes == null)
+ notes = "";
+ note.setText(notes.replaceAll("\\\\n", "\n"));
+
Data photo = contact.getPreferredData("PHOTO");
if (photo != null) {
TypeInfo encoding = null;
if (encoding != null && encoding.getValue() != null
&& encoding.getValue().equalsIgnoreCase("b")) {
- img = new ImageIcon(Base64.getDecoder().decode(
+ image = new ImageIcon(Base64.getDecoder().decode(
photo.getValue())).getImage();
}
}
}
- setImage(img);
+ setImage(image);
}
@Override
Trans.StringId.KEY_ACTION_SWITCH_FORMAT) {
@Override
public boolean onAction() {
- if (txt != null) {
- txt.switchMode();
+ if (txtImage != null) {
+ txtImage.switchMode();
}
return false;
Trans.StringId.KEY_ACTION_INVERT) {
@Override
public boolean onAction() {
- if (txt != null) {
- txt.invertColor();
+ if (txtImage != null) {
+ txtImage.invertColor();
}
return false;
}
/**
- * Set the {@link Image} to render.
+ * Set the {@link Image} to render and refresh it to the current size
+ * constraints.
*
* @param image
* the new {@link Image}
private void setImage(Image image) {
this.image = image;
+ if (txtImage != null && top.containsComponent(txtImage))
+ top.removeComponent(txtImage);
+
TerminalSize size = getTxtSize();
if (size != null) {
- if (txt != null)
- txt.setSize(size);
+ if (txtImage != null)
+ txtImage.setSize(size);
else
- txt = new ImageTextControl(image, size);
+ txtImage = new ImageTextControl(image, size);
}
- if (top.getChildCount() > 0)
- top.removeAllComponents();
+ if (size != null) {
+ top.addComponent(txtImage, BorderLayout.Location.LEFT);
+ }
- if (size != null)
- top.addComponent(txt);
+ invalidate();
}
/**
if (fullscreenImage) {
return getSize();
} else {
- // TODO:
- return new TerminalSize(40, 20);
+ // TODO: configure size?
+ int w = getSize().getColumns() - 40;
+ int h = getSize().getRows() - 5;
+ if (w <= 0 || h <= 0)
+ return null;
+
+ return new TerminalSize(w, h);
}
}
}
}
- @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.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 (int indexType = 0; indexType < data.size(); indexType++) {
- TypeInfo type = data.get(indexType);
- if (valueBuilder.length() > 1)
- valueBuilder.append(", ");
- valueBuilder.append(type.getName());
- valueBuilder.append(": ");
- valueBuilder.append(type.getValue());
- }
- break;
- }
- valueBuilder.append(" ");
-
- value = valueBuilder.toString();
-
- name = StringUtils.sanitize(name, UiColors.getInstance().isUnicode());
- value = StringUtils.sanitize(value, UiColors.getInstance().isUnicode());
-
- 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;
- };
-
@Override
public DataType getDataType() {
return DataType.DATA;
// TODO Auto-generated method stub
return null;
}
+
+ @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.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 (int indexType = 0; indexType < data.size(); indexType++) {
+ TypeInfo type = data.get(indexType);
+ if (valueBuilder.length() > 1)
+ valueBuilder.append(", ");
+ valueBuilder.append(type.getName());
+ valueBuilder.append(": ");
+ valueBuilder.append(type.getValue());
+ }
+ break;
+ }
+ valueBuilder.append(" ");
+
+ value = valueBuilder.toString();
+
+ name = StringUtils.sanitize(name, UiColors.getInstance().isUnicode());
+ value = StringUtils.sanitize(value, UiColors.getInstance().isUnicode());
+
+ 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;
+ };
+
}