上传备份

wjdr
王兵 1 year ago
parent 5416b9301e
commit ab2cb90095

@ -2,7 +2,6 @@ package com.example.jmacro.wjdr;
import com.example.jmacro.wjdr.base.ViewPoint;
import com.example.jmacro.wjdr.base.ViewRect;
import com.example.jmacro.wjdr.wjdr.MacroForWJDR;
import com.example.jmacro.wjdr.ui.FXMLUtil;
import com.example.jmacro.wjdr.util.Logger;
import com.example.jmacro.wjdr.util.ResourceUtil;
@ -68,7 +67,18 @@ public class JMainApplication extends Application {
});
// 服务初始化
JMainService.init(new MacroForWJDR(), new File("legend"));
JMainService.init(new JMacro() {
@Override
public ViewRect focus() {
return new ViewRect(0, 0, 500, 500);
}
@Override
public void run() {
findLegend(of(0,0,159,168), "电脑", 0.99);
findLegend(of(100,100,200,200), "电脑2", 0.99);
}
}, new File("legend"));
}
public static void main(String[] args) {

@ -2,8 +2,9 @@ package com.example.jmacro.wjdr;
import com.example.jmacro.wjdr.base.Legend;
import com.example.jmacro.wjdr.base.ViewRect;
import com.example.jmacro.wjdr.tool.Capture;
import com.example.jmacro.wjdr.tool.Location;
import com.example.jmacro.wjdr.tool.PickLegend;
import com.example.jmacro.wjdr.tool.PickPoint;
import com.example.jmacro.wjdr.tool.PickRect;
import com.example.jmacro.wjdr.util.DialogUtil;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
@ -30,41 +31,58 @@ public class JMainController {
private ImageView preview;
/**
*
*
*/
@FXML
public void onCapture() {
public void pickPoint() {
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
if (screen == null) {
DialogUtil.alert("未定位到视口,请稍后再试!");
return;
}
try {
new Capture(screen.getLeft(), screen.getTop(), Legend.getDefaultBase());
new PickPoint(screen.getLeft(), screen.getTop());
} catch (AWTException awtException) {
awtException.printStackTrace();
}
}
/**
*
*
*/
@FXML
public void onLocation() {
public void pickRect() {
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
if (screen == null) {
DialogUtil.alert("未定位到视口,请稍后再试!");
return;
}
try {
new Location(screen.getLeft(), screen.getTop());
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 onStart() {
@ -74,7 +92,7 @@ public class JMainController {
}
/**
*
*
*/
@FXML
public void onStop() {

@ -30,7 +30,7 @@ import java.util.prefs.Preferences;
* @version 0.0.1
* @since 1.8
*/
public class Capture extends JFrame {
public class PickLegend extends JFrame {
private static final String LAST_PATH = "capture.last.path";
@ -80,14 +80,14 @@ public class Capture extends JFrame {
* @param originY y
* @throws AWTException
*/
public Capture(int originX, int originY, File path) throws AWTException {
public PickLegend(int originX, int originY, File path) throws AWTException {
this();
this.originX = originX;
this.originY = originY;
this.preferences.put(LAST_PATH, path.isDirectory() ? path.getAbsolutePath() : path.getParent());
}
public Capture() throws AWTException {
public PickLegend() throws AWTException {
init();
}
@ -97,6 +97,7 @@ public class Capture extends JFrame {
setUndecorated(true);
setAlwaysOnTop(true);
setBackground(mask);
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
// 初始化偏好设置
preferences = Preferences.userRoot().node(this.getClass().getName());
@ -260,6 +261,6 @@ public class Capture extends JFrame {
*/
public static void main(String[] args) throws AWTException {
// 运行坐标图例截图工具
new Capture(5, 5, new File("legend"));
new PickLegend(5, 5, new File("legend"));
}
}

@ -22,7 +22,7 @@ import java.awt.image.BufferedImage;
* @version 0.0.1
* @since 1.8
*/
public class Location extends JFrame {
public class PickPoint extends JFrame {
/**
* x
@ -59,13 +59,13 @@ public class Location extends JFrame {
* @param originY y
* @throws AWTException
*/
public Location(int originX, int originY) throws AWTException {
public PickPoint(int originX, int originY) throws AWTException {
this();
this.originX = originX;
this.originY = originY;
}
public Location() throws AWTException {
public PickPoint() throws AWTException {
init();
}
@ -106,7 +106,7 @@ public class Location extends JFrame {
Logger.info("坐标色值:[#{}]", hexColor);
Logger.info("用法示例:");
Logger.info("1、坐标点击mouseLeftClick(of({},{}));", x - originX, y - originY);
Logger.info("1、点击坐标mouseLeftClick(of({},{}));", x - originX, y - originY);
Logger.info("2、色值比对matchColor(of({},{},{}));", x - originX, y - originY, hexColor);
Logger.info("=========================坐标采集=========================");
@ -177,6 +177,6 @@ public class Location extends JFrame {
*/
public static void main(String[] args) throws AWTException {
// 运行坐标图例截图工具
new Location(5, 5);
new PickPoint(5, 5);
}
}

@ -0,0 +1,215 @@
package com.example.jmacro.wjdr.tool;
import cn.hutool.log.StaticLog;
import com.example.jmacro.wjdr.util.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class PickRect extends JFrame {
/**
* x
*/
private int originX;
/**
* y
*/
private int originY;
/**
*
*/
private BufferedImage capture;
/**
*
*/
private final Color mask = new Color(0, 0, 0, 0.2f);
/**
* 线
*/
private final Stroke focusWindow = new BasicStroke(1.0f);
/**
*
*/
private final Point start = new Point(0, 0);
/**
*
*/
private final Point end = new Point(0, 0);
/**
*
*
* @param originX x
* @param originY y
* @throws AWTException
*/
public PickRect(int originX, int originY) throws AWTException {
this();
this.originX = originX;
this.originY = originY;
}
public PickRect() throws AWTException {
init();
}
private void init() throws AWTException {
setExtendedState(Frame.MAXIMIZED_BOTH);
setLocation(0, 0);//位置
setUndecorated(true);
setAlwaysOnTop(true);
setBackground(mask);
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
// 获取屏幕截图
Robot robot = new Robot();
Toolkit tk = Toolkit.getDefaultToolkit();
capture = robot.createScreenCapture(new Rectangle(0, 0, tk.getScreenSize().width, tk.getScreenSize().height));
// 监听窗口关闭
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// 关闭应用时要释放资源
dispose();
System.exit(0);//0正常退出1非正常退出
}
});
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
start.setLocation(e.getX(), e.getY());
end.setLocation(e.getX(), e.getY());
Logger.info("起始坐标:{}", start);
repaint();
}
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
end.setLocation(e.getX(), e.getY());
int left = getCaptureX();
int top = getCaptureY();
int right = getCaptureX() + getCaptureWidth();
int bottom = getCaptureY() + getCaptureHeight();
Logger.info("=========================区域采集=========================");
Logger.info("屏幕区域:[{},{},{},{}]", left, top, right, bottom);
Logger.info("相对区域:[{},{},{},{}]", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("用法示例:");
Logger.info("1、区域点击mouseLeftClick(of({},{},{},{}));", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("2、区域查找findLegend(of({},{},{},{}), \"按钮\", 0.99);", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("=========================区域采集=========================");
close();
}
});
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
super.mouseDragged(e);
end.setLocation(e.getX(), e.getY());
repaint();
}
});
addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_ESCAPE: {
StaticLog.info("exit.");
close();
}
break;
}
}
});
setVisible(true);
}
@Override
public void doLayout() {
super.doLayout();
}
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(capture, 0, 0, capture.getWidth(), capture.getHeight(), this);
// 在背景图上加个蒙层
g2d.setColor(mask);
g2d.fillRect(0, 0, capture.getWidth(), capture.getHeight());
int w = getCaptureWidth();
int h = getCaptureHeight();
if (w > 0 && h > 0) {
g2d.setStroke(focusWindow);
g2d.setColor(Color.green);
g2d.drawRect(getCaptureX(), getCaptureY(), w, h);
}
}
public int getCaptureX() {
return (int) Math.min(start.getX(), end.getX());
}
public int getCaptureY() {
return (int) Math.min(start.getY(), end.getY());
}
public int getCaptureWidth() {
return (int) Math.abs(start.getX() - end.getX());
}
public int getCaptureHeight() {
return (int) Math.abs(start.getY() - end.getY());
}
public void close() {
setVisible(false);
dispose();
}
/**
*
*
* @param args
* @throws AWTException
*/
public static void main(String[] args) throws AWTException {
// 运行坐标图例截图工具
new PickRect(5, 5);
}
}

@ -17,8 +17,8 @@
</Label>
<HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="46.0" prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="35.0">
<children>
<Button fx:id="start" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onStart" prefHeight="30.0" prefWidth="60.0" text="开始F1" />
<Button fx:id="stop" disable="true" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onStop" prefHeight="30.0" prefWidth="60.0" text="停止F2">
<Button fx:id="start" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onStart" prefHeight="30.0" prefWidth="80.0" text="开始F1" />
<Button fx:id="stop" disable="true" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onStop" prefHeight="30.0" prefWidth="80.0" text="停止F2">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
@ -28,33 +28,39 @@
<Insets left="6.0" />
</padding>
</HBox>
<Label contentDisplay="CENTER" layoutY="86.0" prefHeight="35.0" prefWidth="60.0" text="编排工具" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="80.0">
<Label contentDisplay="CENTER" layoutY="86.0" prefHeight="35.0" prefWidth="60.0" text="辅助工具" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="80.0">
<padding>
<Insets left="10.0" />
</padding>
</Label>
<HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="126.0" prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="115.0">
<children>
<Button fx:id="capture" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onCapture" prefHeight="30.0" prefWidth="60.0" text="采图" />
<Button fx:id="location" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onLocation" prefHeight="30.0" prefWidth="60.0" text="采点">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin></Button>
<Button focusTraversable="false" mnemonicParsing="false" onMouseClicked="#pickPoint" prefHeight="30.0" prefWidth="50.0" text="采点" />
<Button focusTraversable="false" mnemonicParsing="false" onMouseClicked="#pickRect" prefHeight="30.0" prefWidth="50.0" text="采区">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Button>
<Button focusTraversable="false" mnemonicParsing="false" onMouseClicked="#pickLegend" prefHeight="30.0" prefWidth="50.0" text="采图">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Button>
</children>
<padding>
<Insets left="6.0" />
</padding>
</HBox>
<Pane layoutX="6.0" layoutY="200.0" style="-fx-border-color: #ddd;" AnchorPane.bottomAnchor="6.0" AnchorPane.leftAnchor="6.0" AnchorPane.rightAnchor="6.0" AnchorPane.topAnchor="200.0">
<AnchorPane layoutX="6.0" AnchorPane.bottomAnchor="6.0" AnchorPane.leftAnchor="6.0" AnchorPane.rightAnchor="6.0" AnchorPane.topAnchor="0.0">
<children>
<ImageView fx:id="preview" pickOnBounds="true" preserveRatio="true">
<viewport>
<Rectangle2D height="100.0" width="188.0" />
</viewport>
</ImageView>
<ImageView fx:id="preview" pickOnBounds="true" preserveRatio="true">
<viewport>
<Rectangle2D height="100.0" width="188.0" />
</viewport>
</ImageView>
</children>
</Pane>
<Label layoutX="40.0" layoutY="165.0" prefHeight="35.0" prefWidth="200.0" text="区域预览" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="160.0">
</AnchorPane>
<Label layoutX="40.0" layoutY="165.0" prefHeight="35.0" prefWidth="200.0" text="焦点预览" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<padding>
<Insets left="6.0" />
</padding>

Loading…
Cancel
Save

Powered by TurnKey Linux.