parent
e58fbeb3a0
commit
79521e8700
@ -0,0 +1,42 @@
|
||||
package com.example.jmacro.wjdr;
|
||||
|
||||
import com.example.jmacro.wjdr.demo.DemoThread;
|
||||
import com.example.jmacro.wjdr.ui.FXMLUtil;
|
||||
import com.example.jmacro.wjdr.util.ResourceUtil;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* UI入口
|
||||
*/
|
||||
public class JMainApplication extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
stage.setTitle("无限工具");
|
||||
stage.setMinWidth(400);
|
||||
stage.setMinHeight(300);
|
||||
FXMLLoader mainLoader = FXMLUtil.load("main.fxml");
|
||||
stage.setScene(new Scene(mainLoader.getRoot()));
|
||||
stage.centerOnScreen();
|
||||
stage.show();
|
||||
stage.setOnCloseRequest(event -> {
|
||||
stage.close();
|
||||
System.exit(0);
|
||||
});
|
||||
// 设置图标
|
||||
Image icon = new Image(ResourceUtil.getInput("/icon.png"));
|
||||
stage.getIcons().add(icon);
|
||||
// 展示UI
|
||||
stage.show();
|
||||
// 启动服务
|
||||
JMainService.start();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.example.jmacro.wjdr;
|
||||
|
||||
import com.example.jmacro.wjdr.base.ScreenRect;
|
||||
import com.example.jmacro.wjdr.util.Capture;
|
||||
import com.example.jmacro.wjdr.util.Logger;
|
||||
import javafx.fxml.FXML;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
|
||||
public class JMainController {
|
||||
|
||||
/**
|
||||
* 截图
|
||||
*/
|
||||
@FXML
|
||||
private void onCapture() throws AWTException {
|
||||
ScreenRect screen = JMainService.getInstance().getThread().getScreen();
|
||||
File legend = JMainService.getInstance().getMacro().getLegend();
|
||||
if (screen == null) {
|
||||
Logger.error("请等待窗口定位");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
new Capture(screen.getLeft(), screen.getTop(), legend);
|
||||
} catch (AWTException awtException) {
|
||||
awtException.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package com.example.jmacro.wjdr;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import com.example.jmacro.wjdr.demo.DemoThread;
|
||||
import com.example.jmacro.wjdr.util.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 主线程
|
||||
*
|
||||
* @author wangbing
|
||||
* @version 0.0.1
|
||||
* @since 1.8
|
||||
*/
|
||||
public class JMainService {
|
||||
|
||||
private static JMainService instance;
|
||||
|
||||
private JMacroThread thread;
|
||||
|
||||
private JMainService() throws AWTException {
|
||||
// 脚本初始化
|
||||
Logger.info("初始化脚本");
|
||||
jMacro = new JMacro();
|
||||
thread = new DemoThread(jMacro);
|
||||
}
|
||||
|
||||
public static synchronized JMainService getInstance() throws AWTException {
|
||||
if (instance == null) {
|
||||
JMainService.instance = new JMainService();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public JMacroThread getThread() {
|
||||
return thread;
|
||||
}
|
||||
|
||||
public JMacro getMacro() {
|
||||
return jMacro;
|
||||
}
|
||||
|
||||
/**
|
||||
* 脚本对象
|
||||
*/
|
||||
private final JMacro jMacro;
|
||||
|
||||
/**
|
||||
* 服务运行状态
|
||||
*/
|
||||
private boolean run;
|
||||
|
||||
public static void start() throws AWTException {
|
||||
// 启动服务
|
||||
Logger.info("启动服务");
|
||||
JMainService.getInstance().run = true;
|
||||
// 启动后台线程
|
||||
JMainService.getInstance().serviceThread.start();
|
||||
}
|
||||
|
||||
public static void stop() throws AWTException {
|
||||
Logger.info("停止服务");
|
||||
JMainService.getInstance().run = false;
|
||||
JMainService.getInstance().serviceThread.interrupt();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图例路径
|
||||
*
|
||||
* @param legend 图例路径
|
||||
*/
|
||||
public void setLegend(File legend) {
|
||||
if (this.jMacro != null) {
|
||||
this.jMacro.setLegend(legend);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务线程
|
||||
*/
|
||||
public Thread serviceThread = new Thread() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (run) {
|
||||
ThreadUtil.sleep(1000);
|
||||
if (thread == null) {
|
||||
Logger.error("脚本线程未设置");
|
||||
continue;
|
||||
}
|
||||
thread.run();
|
||||
// 立即执行
|
||||
// if (noDelay) {
|
||||
// if (schedule != null) {
|
||||
// schedule.cancel(true);
|
||||
// }
|
||||
//
|
||||
// noDelay = false;
|
||||
// Logger.info("启动线程");
|
||||
// schedule = TaskUtil.schedule(new MacroThread(jMacro), 0, TimeUnit.SECONDS);
|
||||
// continue;
|
||||
// }
|
||||
// if (schedule != null) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if (DateUtil.isIn(DateUtil.date(), DateUtil.parse(workStart), DateUtil.parse(workEnd))) {
|
||||
// int delay = RandomUtil.randomInt(5, 20);
|
||||
// Logger.info("等待{}分钟后,重新启动线程", delay);
|
||||
// schedule = TaskUtil.schedule(new MacroThread(jMacro), delay, TimeUnit.MINUTES);
|
||||
// }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 启动入口
|
||||
*/
|
||||
public static void main(String[] args) throws AWTException {
|
||||
new JMainService().start();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.example.jmacro.wjdr.task;
|
||||
package com.example.jmacro.wjdr.demo.task;
|
||||
|
||||
import com.example.jmacro.wjdr.JMacro;
|
||||
import com.example.jmacro.wjdr.base.ScreenRect;
|
@ -1,4 +1,4 @@
|
||||
package com.example.jmacro.wjdr.task;
|
||||
package com.example.jmacro.wjdr.demo.task;
|
||||
|
||||
import com.example.jmacro.wjdr.JMacro;
|
||||
import com.example.jmacro.wjdr.base.ScreenRect;
|
@ -1,4 +1,4 @@
|
||||
package com.example.jmacro.wjdr.task;
|
||||
package com.example.jmacro.wjdr.demo.task;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.example.jmacro.wjdr.JMacro;
|
@ -1,4 +1,4 @@
|
||||
package com.example.jmacro.wjdr.task;
|
||||
package com.example.jmacro.wjdr.demo.task;
|
||||
|
||||
import com.example.jmacro.wjdr.JMacro;
|
||||
import com.example.jmacro.wjdr.base.ScreenRect;
|
@ -0,0 +1,31 @@
|
||||
package com.example.jmacro.wjdr.ui;
|
||||
|
||||
import com.example.jmacro.wjdr.util.ResourceUtil;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* FXML工具
|
||||
*/
|
||||
public class FXMLUtil {
|
||||
|
||||
/**
|
||||
* 加载FXMLLoader
|
||||
*
|
||||
* @param fxml 资源路径
|
||||
* @return
|
||||
*/
|
||||
public static FXMLLoader load(String fxml) throws IOException {
|
||||
if (!fxml.startsWith("classpath:")) {
|
||||
fxml = "classpath:" + fxml;
|
||||
}
|
||||
URL resource = ResourceUtil.getURL(fxml);
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(resource);
|
||||
fxmlLoader.load();
|
||||
return fxmlLoader;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.example.jmacro.wjdr.util;
|
||||
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* 资源工具
|
||||
*/
|
||||
public class ResourceUtil extends cn.hutool.core.io.resource.ResourceUtil {
|
||||
|
||||
/**
|
||||
* 获取资源输入流,以/开始
|
||||
*
|
||||
* @return 资源路径
|
||||
*/
|
||||
public static InputStream getInput(String resourceLocation) {
|
||||
if (resourceLocation.startsWith("/")) {
|
||||
resourceLocation = "/" + resourceLocation;
|
||||
}
|
||||
ClassPathResource classPathResource = new ClassPathResource(resourceLocation);
|
||||
return classPathResource.getStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源路径
|
||||
*
|
||||
* @param resourceLocation 资源
|
||||
*/
|
||||
public static URL getURL(String resourceLocation) throws FileNotFoundException {
|
||||
if (resourceLocation.startsWith("classpath:")) {
|
||||
String path = resourceLocation.substring("classpath:".length());
|
||||
ClassLoader cl = FXMLLoader.getDefaultClassLoader();
|
||||
URL url = cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path);
|
||||
if (url == null) {
|
||||
String description = "class path resource [" + path + "]";
|
||||
throw new FileNotFoundException(description + " cannot be resolved to URL because it does not exist");
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return new URL(resourceLocation);
|
||||
} catch (MalformedURLException var6) {
|
||||
try {
|
||||
return (new File(resourceLocation)).toURI().toURL();
|
||||
} catch (MalformedURLException var5) {
|
||||
throw new FileNotFoundException("Resource location [" + resourceLocation + "] is neither a URL not a well-formed file path");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Separator?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<AnchorPane prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/10.0.2-internal"
|
||||
xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.jmacro.wjdr.JMainController">
|
||||
<children>
|
||||
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="400.0" AnchorPane.leftAnchor="0.0"
|
||||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="60.0" text="工具"/>
|
||||
<Button mnemonicParsing="false" prefHeight="30.0" prefWidth="80.0" text="采集图例" onMouseClicked="#onCapture">
|
||||
<HBox.margin>
|
||||
<Insets/>
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</HBox>
|
||||
<Separator opacity="0.5" prefHeight="1.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0"
|
||||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0"/>
|
||||
<GridPane layoutX="71.0" layoutY="139.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
|
||||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="41.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||
</rowConstraints>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
Loading…
Reference in new issue