You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.5 KiB
147 lines
3.5 KiB
package xyz.wbsite.jmacro;
|
|
|
|
import xyz.wbsite.jmacro.base.Legend;
|
|
import xyz.wbsite.jmacro.base.ViewRect;
|
|
import xyz.wbsite.jmacro.tool.Measure;
|
|
import xyz.wbsite.jmacro.tool.PickLegend;
|
|
import xyz.wbsite.jmacro.tool.PickPoint;
|
|
import xyz.wbsite.jmacro.tool.PickRect;
|
|
import xyz.wbsite.jmacro.util.DialogUtil;
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.image.ImageView;
|
|
|
|
import java.awt.*;
|
|
import java.util.concurrent.Semaphore;
|
|
|
|
/**
|
|
* UI控制器
|
|
*
|
|
* @author wangbing
|
|
* @version 0.0.1
|
|
* @since 1.8
|
|
*/
|
|
public class JMainController {
|
|
|
|
@FXML
|
|
private Button start;
|
|
@FXML
|
|
private Button stop;
|
|
@FXML
|
|
private Button capture;
|
|
@FXML
|
|
private ImageView preview;
|
|
|
|
private Semaphore semaphore = new Semaphore(1);
|
|
|
|
/**
|
|
* 采点
|
|
*/
|
|
@FXML
|
|
public void pickPoint() {
|
|
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
|
|
if (screen == null) {
|
|
DialogUtil.alert("未定位到视口,请稍后再试!");
|
|
return;
|
|
}
|
|
try {
|
|
new PickPoint(screen.getLeft(), screen.getTop());
|
|
} catch (AWTException awtException) {
|
|
awtException.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 采区
|
|
*/
|
|
@FXML
|
|
public void pickRect() {
|
|
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
|
|
if (screen == null) {
|
|
DialogUtil.alert("未定位到视口,请稍后再试!");
|
|
return;
|
|
}
|
|
try {
|
|
new PickRect(screen.getLeft(), screen.getTop());
|
|
} catch (AWTException awtException) {
|
|
awtException.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 采图
|
|
*/
|
|
@FXML
|
|
public void pickLegend() {
|
|
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
|
|
if (screen == null) {
|
|
DialogUtil.alert("未定位到视口,请稍后再试!");
|
|
return;
|
|
}
|
|
try {
|
|
new PickLegend(screen.getLeft(), screen.getTop(), Legend.getDefaultBase());
|
|
} catch (AWTException awtException) {
|
|
awtException.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 测量
|
|
*/
|
|
@FXML
|
|
public void measure() {
|
|
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
|
|
if (screen == null) {
|
|
DialogUtil.alert("未定位到视口,请稍后再试!");
|
|
return;
|
|
}
|
|
try {
|
|
new Measure(screen.getLeft(), screen.getTop());
|
|
} catch (AWTException awtException) {
|
|
awtException.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 运行服务
|
|
*/
|
|
@FXML
|
|
public void onStart() {
|
|
boolean start = JMainService.start();
|
|
this.start.setDisable(start);
|
|
this.stop.setDisable(!start);
|
|
}
|
|
|
|
/**
|
|
* 停止服务
|
|
*/
|
|
@FXML
|
|
public void onStop() {
|
|
boolean stop = JMainService.stop();
|
|
this.start.setDisable(!stop);
|
|
this.stop.setDisable(stop);
|
|
this.preview.setImage(null);
|
|
}
|
|
|
|
/**
|
|
* 预览
|
|
*
|
|
* @param image
|
|
*/
|
|
public void preview(Image image) {
|
|
try {
|
|
if (!JMainService.getInstance().run) {
|
|
return;
|
|
}
|
|
semaphore.acquire();
|
|
preview.setImage(image);
|
|
Thread.sleep(500);
|
|
semaphore.release();
|
|
} catch (InterruptedException e) {
|
|
semaphore.release();
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|