refactor(scan): 重构扫描功能配置方式
- 新增全局设置对象,保存扫描参数 - 修改设置设备操作函数,仅保存参数而不直接设置 - 在开始扫描时应用全局设置到扫描源 - 更新扫描源类,增加双面扫描参数
This commit is contained in:
parent
5cee6f61e9
commit
a7bede2ee3
|
@ -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<File> fileList = source.scan();
|
||||
List<String> 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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue