diff --git a/src/main/java/org/aohe/control/Operational.java b/src/main/java/org/aohe/control/Operational.java index 9312143..c1f57bf 100644 --- a/src/main/java/org/aohe/control/Operational.java +++ b/src/main/java/org/aohe/control/Operational.java @@ -19,6 +19,8 @@ public class Operational { //是否使用系统UI private static Boolean isSystemUI = false; + private static JSONObject settings = new JSONObject(); + public static String selectOperational(String path) { JSONObject json = JSONObject.parse(path); @@ -181,28 +183,30 @@ public class Operational { * @return R */ public static R setDeviceOperations(JSONObject map){ - try { - TwainSource twainSource = Twain.getSourceManager().getSource(); - // 先约定为三种参数 DPI,色彩模式,进纸模式 - if(map.get("dpi") !=null){ - twainSource.setResolution(map.getDouble("dpi")); - } - if(map.get("color") !=null){ - twainSource.setCapability(Twain.ICAP_PIXELTYPE, map.getInteger("color")); - } - if(map.get("paper") !=null){ - twainSource.setCapability(Twain.CAP_FEEDERENABLED, map.getBooleanValue("paper")); - } - if(map.get("duple") != null){ - twainSource.setCapability(Twain.CAP_DUPLEXENABLED, map.getBooleanValue("duple")); - } - if(map.get("systemUI") != null){ - isSystemUI = map.getBooleanValue("systemUI"); - } +// try { +// TwainSource twainSource = Twain.getSourceManager().getSource(); +// // 先约定为三种参数 DPI,色彩模式,进纸模式 +// if(map.get("dpi") !=null){ +// twainSource.setResolution(map.getDouble("dpi")); +// } +// if(map.get("color") !=null){ +// twainSource.setCapability(Twain.ICAP_PIXELTYPE, map.getInteger("color")); +// } +// if(map.get("paper") !=null){ +// twainSource.setCapability(Twain.CAP_FEEDERENABLED, map.getBooleanValue("paper")); +// } +// if(map.get("duple") != null){ +// twainSource.setCapability(Twain.CAP_DUPLEXENABLED, map.getBooleanValue("duple")); +// } +// if(map.get("systemUI") != null){ +// isSystemUI = map.getBooleanValue("systemUI"); +// } +// +// } catch (TwainException e) { +// throw new RuntimeException(e); +// } + settings.putAll(map); - } catch (TwainException e) { - throw new RuntimeException(e); - } return R.ok(); } @@ -226,8 +230,8 @@ public class Operational { */ public static R startScan(String name, boolean systemUI ) { Source source = new Source(); + initSettings(source); source.setName(name); - source.setSystemUI(systemUI); List fileList = source.scan(); List base64Files = new ArrayList<>(); for (File file : fileList){ @@ -236,6 +240,31 @@ public class Operational { return R.ok(base64Files); } + private static void initSettings(Source source) { + if(settings.get("dpi") !=null){ + source.setDpi(settings.getDouble("dpi")); + } + if(settings.get("color") !=null){ + Integer color = settings.getInteger("color"); + if (color == 0){ + source.setColor(Source.ColorMode.BW); + }else if (color == 1){ + source.setColor(Source.ColorMode.GRAYSCALE); + }else if (color == 2){ + source.setColor(Source.ColorMode.COLOR); + } + } + if(settings.get("paper") !=null){ + source.setAutoDocumentFeeder(settings.getBooleanValue("paper")); + } + if(settings.get("duple") != null){ + source.setDuple(settings.getBooleanValue("duple")); + } + if(settings.get("systemUI") != null){ + source.setSystemUI(settings.getBooleanValue("systemUI")); + } + } + /** * 打开接口 * @return twSource diff --git a/src/main/java/org/aohe/scan/Source.java b/src/main/java/org/aohe/scan/Source.java index 62f1867..8fdc84b 100644 --- a/src/main/java/org/aohe/scan/Source.java +++ b/src/main/java/org/aohe/scan/Source.java @@ -21,6 +21,7 @@ public class Source implements TwainListener { private ColorMode color = ColorMode.GRAYSCALE; private boolean autoDocumentFeeder = true; private boolean systemUI = true; + private boolean duple = false; private String name; @@ -72,6 +73,13 @@ public class Source implements TwainListener { this.systemUI = systemUI; } + public boolean isDuple() { + return duple; + } + + public void setDuple(boolean duple) { + this.duple = duple; + } @Override public void update(TwainIOMetadata.Type type, TwainIOMetadata metadata) { // System.out.println(type + " -> " + metadata.getState() + ": " + metadata.getStateStr()); @@ -107,6 +115,7 @@ public class Source implements TwainListener { } source.setCapability(Twain.CAP_FEEDERENABLED, autoDocumentFeeder ? 1 : 0); + source.setCapability(Twain.CAP_DUPLEXENABLED, duple); } } catch (TwainException e) { e.printStackTrace();