package xyz.wbsite.jmacro; import com.melloware.jintellitype.JIntellitype; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.stage.Stage; import xyz.wbsite.jmacro.ui.FXMLUtil; import xyz.wbsite.jmacro.util.ResourceUtil; import xyz.wbsite.jtask.TaskImpl; import java.awt.event.KeyEvent; import java.io.File; /** * UI入口 * * @author wangbing * @version 0.0.1 * @since 1.8 */ public class JMainApplication extends Application { public static final int F1_SHORTCUT = 1; // 开始快捷键 public static final int F2_SHORTCUT = 2; // 结束快捷键 public static Stage primaryStage; public static JMainController mainController; @Override public void start(Stage stage) throws Exception { stage.setTitle("无限工具"); stage.setMinWidth(400); stage.setMinHeight(300); FXMLLoader mainLoader = FXMLUtil.load("main.fxml"); mainController = mainLoader.getController(); stage.setScene(new Scene(mainLoader.getRoot())); stage.centerOnScreen(); stage.setResizable(false); stage.setOnCloseRequest(event -> { stage.close(); System.exit(0); }); // 设置图标 Image icon = new Image(ResourceUtil.getInput("/icon.png")); stage.getIcons().add(icon); // 展示UI stage.show(); JMainApplication.primaryStage = stage; JIntellitype.getInstance().registerHotKey(F1_SHORTCUT, JIntellitype.MOD_CONTROL, KeyEvent.VK_F1); JIntellitype.getInstance().registerHotKey(F2_SHORTCUT, JIntellitype.MOD_CONTROL, KeyEvent.VK_F2); JIntellitype.getInstance().addHotKeyListener(identifier -> { switch (identifier) { case F1_SHORTCUT: mainController.onStart(); break; case F2_SHORTCUT: mainController.onStop(); break; } }); // 服务初始化 JMainService.init(new TaskImpl(), new File("legend")); } public static void main(String[] args) { launch(args); } }