import be.nikiroo.jvcard.tui.KeyAction.DataType;
import be.nikiroo.jvcard.tui.KeyAction.Mode;
import be.nikiroo.jvcard.tui.UiColors;
-import be.nikiroo.utils.ImageUtils;
import be.nikiroo.utils.StringUtils;
+import be.nikiroo.utils.ui.ImageUtilsAwt;
import com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.gui2.BorderLayout;
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);
}
} else {
String val = contact.getPreferredDataValue(field);
- if (val == null)
+ if (val == null) {
val = "";
+ }
infoPanel.addComponent(UiColors.createLabel(el,
StringUtils.padString(label, labelSize) + val));
}
ColorOption.VIEW_CONTACT_NORMAL, ""));
String notes = contact.getPreferredDataValue("NOTE");
- if (notes == null)
+ if (notes == null) {
notes = "";
+ }
note.setText(notes);
Data photo = contact.getPreferredData("PHOTO");
if (encoding != null && encoding.getValue() != null
&& encoding.getValue().equalsIgnoreCase("b")) {
-
try {
- image = ImageUtils.fromBase64(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"));
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) {
&& 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;