|
|
|
@ -12,21 +12,19 @@ import de.srsoftware.belegscanner.model.api.Page;
@@ -12,21 +12,19 @@ import de.srsoftware.belegscanner.model.api.Page;
|
|
|
|
|
import de.srsoftware.belegscanner.model.api.Project; |
|
|
|
|
import de.srsoftware.tools.gui.DateChooser; |
|
|
|
|
import de.srsoftware.tools.gui.SelectComboBox; |
|
|
|
|
import org.json.JSONArray; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.text.html.Option; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.net.URI; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Locale; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.Vector; |
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
import static de.srsoftware.belegscanner.Application.t; |
|
|
|
@ -56,6 +54,7 @@ public class Worker {
@@ -56,6 +54,7 @@ public class Worker {
|
|
|
|
|
private ImproveSelector improveSelector; |
|
|
|
|
private RotationSelector rotationSelector; |
|
|
|
|
private TypeSelector typeSelector; |
|
|
|
|
private Map<String,Set<String>> samples = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Worker(Configuration config) { |
|
|
|
@ -75,6 +74,13 @@ public class Worker {
@@ -75,6 +74,13 @@ public class Worker {
|
|
|
|
|
return config.getOrCreate("profiles",new JSONObject()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Set<String> getSamples(String varName) { |
|
|
|
|
var set = samples.get(varName); |
|
|
|
|
if (set == null) set = new HashSet<>(); |
|
|
|
|
LOG.debug("Worker.getSamples(\"{}\") → {}",varName,set); |
|
|
|
|
return set; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String getType() { |
|
|
|
|
return type; |
|
|
|
|
} |
|
|
|
@ -188,13 +194,14 @@ public class Worker {
@@ -188,13 +194,14 @@ public class Worker {
|
|
|
|
|
|
|
|
|
|
private void saveProfile() { |
|
|
|
|
var prefix = String.join(".","profiles",profile,""); |
|
|
|
|
|
|
|
|
|
addSamples(); |
|
|
|
|
Map.of( |
|
|
|
|
"path",rawPath, |
|
|
|
|
"size",Map.of("height",dimension.height,"width",dimension.width), |
|
|
|
|
"resolution",resolution, |
|
|
|
|
"improvements", Map.of("brightness",improveBrightness,"drop_page",removePageOnStitching), |
|
|
|
|
"rotation",rotationAngle, |
|
|
|
|
"samples", samples, |
|
|
|
|
"target_type",type) |
|
|
|
|
.entrySet() |
|
|
|
|
.forEach(e -> config.set(prefix+e.getKey(),e.getValue())); |
|
|
|
@ -205,6 +212,16 @@ public class Worker {
@@ -205,6 +212,16 @@ public class Worker {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void addSamples() { |
|
|
|
|
toolbar.additionalFields().forEach(entry -> addSample(entry.getKey(), entry.getValue())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void addSample(String key, String value) { |
|
|
|
|
var set = samples.get(key); |
|
|
|
|
if (set == null) samples.put(key, set = new HashSet<>()); |
|
|
|
|
set.add(value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void performScan(){ |
|
|
|
|
LOG.debug("scan()"); |
|
|
|
|
var project = docTable.getProject(resolvedPath).orElseGet(() -> docTable.createProject(resolvedPath)); |
|
|
|
@ -469,6 +486,7 @@ public class Worker {
@@ -469,6 +486,7 @@ public class Worker {
|
|
|
|
|
LOG.debug("setCat({}})",newProfile); |
|
|
|
|
profile = newProfile; |
|
|
|
|
var prefix = String.join(".","profiles",profile,""); |
|
|
|
|
|
|
|
|
|
Optional.ofNullable((String)config.get(prefix+"path")).ifPresent(path -> { |
|
|
|
|
pathPicker.setText(path); |
|
|
|
|
setPath(path); |
|
|
|
@ -501,6 +519,19 @@ public class Worker {
@@ -501,6 +519,19 @@ public class Worker {
|
|
|
|
|
typeSelector.set(t); |
|
|
|
|
type = t; |
|
|
|
|
}); |
|
|
|
|
Optional.ofNullable(config.get(prefix+"samples")).filter(o -> o instanceof JSONObject json).map(JSONObject.class::cast).ifPresent(this::processSamples); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void processSamples(JSONObject json) { |
|
|
|
|
samples.clear(); |
|
|
|
|
for (String key : json.keySet()){ |
|
|
|
|
if (json.get(key) instanceof JSONArray arr){ |
|
|
|
|
var set = new HashSet<String>(); |
|
|
|
|
arr.toList().stream().filter(o -> o instanceof String).map(String.class::cast).forEach(set::add); |
|
|
|
|
samples.put(key,set); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
LOG.debug("processSamples({}),json → {}",json,samples); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|