update to latest nikiroo-utils master
authorNiki Roo <niki@nikiroo.be>
Sun, 3 Mar 2019 11:07:17 +0000 (12:07 +0100)
committerNiki Roo <niki@nikiroo.be>
Sun, 3 Mar 2019 11:07:17 +0000 (12:07 +0100)
libs/nikiroo-utils-4.4.5-sources.jar [moved from libs/nikiroo-utils-2.0.0-sources.jar with 55% similarity]
src/be/nikiroo/jvcard/launcher/Main.java
src/be/nikiroo/jvcard/tui/panes/ContactDetails.java

similarity index 55%
rename from libs/nikiroo-utils-2.0.0-sources.jar
rename to libs/nikiroo-utils-4.4.5-sources.jar
index 26cad686d38e5fc964c55cf896bcea20a91b9fc0..de86d02b70e504647af64bed3763af3e960347e2 100644 (file)
Binary files a/libs/nikiroo-utils-2.0.0-sources.jar and b/libs/nikiroo-utils-4.4.5-sources.jar differ
index 0860fec1bd6f3a858cf6cb1e6fafebef7b7a9514..61287b3df8c486b10b1c36a0556ba115399fdb7f 100644 (file)
@@ -1,17 +1,13 @@
 package be.nikiroo.jvcard.launcher;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.net.Socket;
 import java.nio.charset.Charset;
 import java.util.LinkedList;
 import java.util.List;
 
-import javax.imageio.ImageIO;
-
 import be.nikiroo.jvcard.Card;
 import be.nikiroo.jvcard.Contact;
 import be.nikiroo.jvcard.Data;
@@ -26,6 +22,8 @@ import be.nikiroo.jvcard.resources.DisplayOption;
 import be.nikiroo.jvcard.resources.RemoteBundle;
 import be.nikiroo.jvcard.resources.StringId;
 import be.nikiroo.jvcard.resources.TransBundle;
+import be.nikiroo.utils.IOUtils;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.ImageUtils;
 import be.nikiroo.utils.StringUtils;
 import be.nikiroo.utils.Version;
@@ -40,6 +38,7 @@ import be.nikiroo.utils.resources.Bundles;
  * 
  */
 public class Main {
+       /** The name of the program */
        static public final String APPLICATION_TITLE = "jVcard";
 
        static private final int ERR_NO_FILE = 1;
@@ -353,14 +352,11 @@ public class Main {
                                                                }
 
                                                                String b64;
-                                                               InputStream in = null;
+                                                               Image img = new Image(IOUtils.toByteArray(f));
                                                                try {
-                                                                       in = new FileInputStream(f);
-                                                                       b64 = ImageUtils.toBase64(in);
+                                                                       b64 = img.toBase64();
                                                                } finally {
-                                                                       if (in != null) {
-                                                                               in.close();
-                                                                       }
+                                                                       img.close();
                                                                }
 
                                                                // remove previous photos:
@@ -400,10 +396,10 @@ public class Main {
                                                        String filename = contact.toString(format, "");
                                                        File f = new File(dir, filename + ".png");
                                                        System.out.println("Saving " + f);
+                                                       Image img = new Image(photo.getValue());
                                                        try {
-                                                               ImageIO.write(
-                                                                               ImageUtils.fromBase64(photo.getValue()),
-                                                                               "png", f);
+                                                               ImageUtils.getInstance().saveAsImage(img, f,
+                                                                               "png");
                                                        } catch (IOException e) {
                                                                System.err.println(trans(
                                                                                StringId.CLI_ERR_CANNOT_SAVE_PHOTO,
index 791d57c6944f801680c23523c430a88ec103dc5e..2137bd885b1588312590eb15183037a554d6a801 100644 (file)
@@ -16,8 +16,8 @@ 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.ImageUtils;
 import be.nikiroo.utils.StringUtils;
+import be.nikiroo.utils.ui.ImageUtilsAwt;
 
 import com.googlecode.lanterna.TerminalSize;
 import com.googlecode.lanterna.gui2.BorderLayout;
@@ -196,7 +196,13 @@ public class ContactDetails extends MainContent {
                                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"));