Skip to content

Commit

Permalink
Support volume range in emboss dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
joeha480 committed Mar 19, 2019
1 parent ebb7553 commit 2628443
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/application/ui/preview/EmbossController.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public EmbossController() {
((RangeToggle)t2.getUserData()).toggleRange();
});
volumes.textProperty().addListener((o, v1, v2)->{
if (!v2.matches("([1-9]\\d*)?")) {
if (!v2.matches("([1-9]\\d*(-([1-9]\\d*)?)?)?")) {
volumes.setText(v1);
}
});
Expand Down Expand Up @@ -230,14 +230,22 @@ private Range getRange() throws FailedToGetRangeException {
if ("".equals(value)) {
throw new FailedToGetRangeException(Messages.ERROR_EMPTY_VOLUME_NUMBER.localize());
}
Range vr;
try {
vr = Range.parseRange(value);
if (vr.getTo()==Integer.MAX_VALUE) {
vr = new Range(vr.getFrom(), book.getVolumes());
}
} catch (IllegalArgumentException e) {
throw new FailedToGetRangeException(Messages.ERROR_FAILED_TO_PARSE_PAGE_RANGE.localize(value));
}
try {
int v = Integer.parseInt(value);
if (v<1) {
if (vr.getFrom()<1) {
throw new FailedToGetRangeException(Messages.ERROR_VOLUME_NUMBER_LESS_THAN_ONE.localize());
} else if (v>book.getVolumes()) {
throw new FailedToGetRangeException(Messages.ERROR_VOLUME_NUMBER_OUT_OF_RANGE.localize(v, book.getVolumes()));
} else if (vr.getTo()>book.getVolumes()) {
throw new FailedToGetRangeException(Messages.ERROR_VOLUME_NUMBER_OUT_OF_RANGE.localize(vr.getTo(), book.getVolumes()));
} else {
return new Range(book.getFirstPage(v), book.getLastPage(v));
return new Range(book.getFirstPage(vr.getFrom()), book.getLastPage(vr.getTo()));
}
} catch (NumberFormatException e) {
throw new FailedToGetRangeException(Messages.ERROR_FAILED_TO_PARSE_VOLUME_NUMBER.localize(value));
Expand Down
3 changes: 1 addition & 2 deletions src/application/ui/preview/EmbossTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class EmbossTask extends Task<Void> {

@Override
protected Void call() throws Exception {
//TODO: include range (requires release of pef-tools v2.3.0)
logger.info("About to emboss " + (copies>1?copies + " copies ":"") + "on " + deviceName + " with alignment " + align);
logger.info("About to emboss " + (copies>1?copies + " copies ":"") + "on " + deviceName + " with alignment " + align + " and range " + range);
if (FeatureSwitch.EMBOSSING.isOn()) {
for (int i=0; i<copies; i++) {
try (InputStream iss = url.openStream()) {
Expand Down

0 comments on commit 2628443

Please sign in to comment.