mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-09 00:04:55 +00:00
38 lines
966 B
Java
38 lines
966 B
Java
package com.sparrowwallet.sparrow.control;
|
|
|
|
import com.sparrowwallet.drongo.address.Address;
|
|
import com.sparrowwallet.drongo.address.InvalidAddressException;
|
|
import javafx.util.StringConverter;
|
|
|
|
public class AddressStringConverter extends StringConverter<Address> {
|
|
@Override
|
|
public Address fromString(String value) {
|
|
// If the specified value is null or zero-length, return null
|
|
if(value == null) {
|
|
return null;
|
|
}
|
|
|
|
value = value.trim();
|
|
|
|
if (value.length() < 1) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
return Address.fromString(value);
|
|
} catch(InvalidAddressException e) {
|
|
throw new IllegalArgumentException(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String toString(Address value) {
|
|
// If the specified value is null, return a zero-length String
|
|
if(value == null) {
|
|
return "";
|
|
}
|
|
|
|
return value.toString();
|
|
}
|
|
}
|