Speichen von Variablen-Werten implementiert
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>BelegScanner</groupId>
|
||||
<artifactId>BelegScanner</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.1.3</version>
|
||||
|
||||
<name>BelegScanner</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -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 {
|
||||
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 {
|
||||
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 {
|
||||
|
||||
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 {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,10 +10,9 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static de.srsoftware.belegscanner.Application.t;
|
||||
import static javax.swing.BoxLayout.X_AXIS;
|
||||
@@ -28,7 +27,8 @@ public class Toolbar extends JPanel {
|
||||
|
||||
private final SelectComboBox pathPicker, profilePicker;
|
||||
private static final int OFFSET = 2;
|
||||
private class AdditionalInput {
|
||||
|
||||
public class AdditionalInput {
|
||||
private final JPanel panel;
|
||||
private final SelectComboBox input;
|
||||
private boolean required;
|
||||
@@ -79,7 +79,12 @@ public class Toolbar extends JPanel {
|
||||
Arrays.stream(getComponents()).filter(c -> c instanceof JPanel).map(JPanel.class::cast).forEach(p -> p.setBorder(BORDER));
|
||||
}
|
||||
|
||||
|
||||
public Stream<Map.Entry<String, String>> additionalFields() {
|
||||
return additionalInputs.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getValue().required)
|
||||
.map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(),entry.getValue().input.getText()));
|
||||
}
|
||||
|
||||
private SelectComboBox profilePicker() {
|
||||
return new SelectComboBox(worker.getProfiles().keySet()).onUpdateText(worker::loadProfile).onDelete(worker::dropProfile);
|
||||
@@ -153,7 +158,7 @@ public class Toolbar extends JPanel {
|
||||
var additionalInput = additionalInputs.get(varName);
|
||||
if (additionalInput == null) {
|
||||
LOG.debug("Field missing, creating…");
|
||||
var input = new SelectComboBox(new Vector<>());
|
||||
var input = new SelectComboBox(List.of());
|
||||
input.onUpdateText(newText -> worker.resolvePath());
|
||||
JPanel panel = input(varName,input);
|
||||
additionalInputs.put(varName, additionalInput = new AdditionalInput(panel,input,true));
|
||||
@@ -166,6 +171,7 @@ public class Toolbar extends JPanel {
|
||||
add(additionalInput.panel,getComponentCount()-OFFSET);
|
||||
}
|
||||
}
|
||||
additionalInput.input.setElements(worker.getSamples(varName));
|
||||
return additionalInput.input.getText();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="de.srsoftware.belegscanner.gui.Toolbar" level="debug" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="de.srsoftware.belegscanner.Worker" level="debug" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
Reference in New Issue
Block a user