more import fixes

This commit is contained in:
Craig Raw 2020-08-21 10:08:43 +02:00
parent af525797ff
commit d49f85fe5b
3 changed files with 5 additions and 16 deletions

View file

@ -125,7 +125,7 @@ public class TitledDescriptionPane extends TitledPane {
contentBox.setPadding(new Insets(10, 30, 10, 30));
double width = TextUtils.computeTextWidth(details.getFont(), message, 0.0D);
double numLines = Math.max(1, width / 400);
double numLines = Math.max(1, Math.ceil(width / 400d));
//Handle long words like txids
OptionalDouble maxWordLength = Arrays.stream(message.split(" ")).mapToDouble(word -> TextUtils.computeTextWidth(details.getFont(), message, 0.0D)).max();

View file

@ -266,20 +266,7 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
@Override
public boolean isEncrypted(File file) {
if(FileType.BINARY.equals(IOUtils.getFileType(file))) {
try {
try(Scanner s = new Scanner(file)) {
if(s.hasNextLine() && s.nextLine().equals("{")) {
return false;
}
}
return true;
} catch(FileNotFoundException e) {
//Can't happen
}
}
return false;
return (FileType.BINARY.equals(IOUtils.getFileType(file)));
}
@Override

View file

@ -7,7 +7,7 @@ public class IOUtils {
public static FileType getFileType(File file) {
try {
String type = Files.probeContentType(file.toPath());
if (type == null) {
if(type == null) {
if(file.getName().toLowerCase().endsWith("txn") || file.getName().toLowerCase().endsWith("psbt")) {
return FileType.TEXT;
}
@ -17,6 +17,8 @@ public class IOUtils {
String line = br.readLine();
if(line.startsWith("01000000") || line.startsWith("cHNid")) {
return FileType.TEXT;
} else if(line.startsWith("{")) {
return FileType.JSON;
}
}
}