无伤大雅的的小修改

main
lensfrex 3 years ago
parent d49c52c70c
commit b446921b42
Signed by: lensfrex
GPG Key ID: 947ADABD8533C476
  1. 7
      Dogename/dogename.iml
  2. 7
      Dogename/pom.xml
  3. 34
      Dogename/src/main/java/log4j2.xml
  4. 10
      Dogename/src/main/java/me/lensferno/dogename/Main.java
  5. 23
      Dogename/src/main/java/me/lensferno/dogename/configs/ConfigLoader.java
  6. 135
      Dogename/src/main/java/me/lensferno/dogename/configs/MainConfig.java
  7. 44
      Dogename/src/main/java/me/lensferno/dogename/configs/VoiceConfig.java
  8. 7
      Dogename/src/main/java/me/lensferno/dogename/controllers/GushiciPaneController.java
  9. 38
      Dogename/src/main/java/me/lensferno/dogename/controllers/HistoryPaneController.java
  10. 6
      Dogename/src/main/java/me/lensferno/dogename/controllers/HitokotoPaneController.java
  11. 46
      Dogename/src/main/java/me/lensferno/dogename/controllers/MainInterfaceController.java
  12. 25
      Dogename/src/main/java/me/lensferno/dogename/controllers/MiniPaneController.java
  13. 40
      Dogename/src/main/java/me/lensferno/dogename/controllers/NameManagerPaneController.java
  14. 11
      Dogename/src/main/java/me/lensferno/dogename/controllers/NumberSettingsPaneController.java
  15. 9
      Dogename/src/main/java/me/lensferno/dogename/controllers/OcrPaneController.java
  16. 30
      Dogename/src/main/java/me/lensferno/dogename/controllers/SettingsPaneController.java
  17. 18
      Dogename/src/main/java/me/lensferno/dogename/controllers/VoiceSettingsPaneController.java
  18. 2
      Dogename/src/main/java/me/lensferno/dogename/controllers/WindowListeners/MoveWindowByMouse.java
  19. 2
      Dogename/src/main/java/me/lensferno/dogename/controllers/WindowListeners/MoveWindowByTouch.java
  20. 115
      Dogename/src/main/java/me/lensferno/dogename/data/Data.java
  21. 23
      Dogename/src/main/java/me/lensferno/dogename/data/History.java
  22. 25
      Dogename/src/main/java/me/lensferno/dogename/sayings/Gushici.java
  23. 30
      Dogename/src/main/java/me/lensferno/dogename/sayings/Hitokoto.java
  24. 5
      Dogename/src/main/java/me/lensferno/dogename/select/Selector.java
  25. 73
      Dogename/src/main/java/me/lensferno/dogename/select/core/Worker.java
  26. 9
      Dogename/src/main/java/me/lensferno/dogename/utils/DialogMaker.java
  27. 5
      Dogename/src/main/java/me/lensferno/dogename/utils/IOUtil.java
  28. 12
      Dogename/src/main/java/me/lensferno/dogename/utils/NetworkUtil.java
  29. 67
      Dogename/src/main/java/me/lensferno/dogename/utils/ocr/ScreenCapture.java
  30. 12
      Dogename/src/main/java/me/lensferno/dogename/voice/Token.java
  31. 31
      Dogename/src/main/java/me/lensferno/dogename/voice/TokenManager.java
  32. 7
      Dogename/src/main/java/me/lensferno/dogename/voice/VoicePlayer.java

@ -13,14 +13,7 @@
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.14" level="project" />
<orderEntry type="library" name="Maven: com.jfoenix:jfoenix:8.0.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.13.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.13.2" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.7" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:4.2.2" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:2.2.2" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.3.50" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.3.50" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: com.baidu.aip:java-sdk:4.12.0" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20160810" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />

@ -52,13 +52,6 @@
<version>8.0.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="error">
<!--先定义所有的appender-->
<appenders>
<!--这个输出控制台的配置-->
<Console name="Console" target="SYSTEM_OUT">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/>
<!--这个都知道是输出日志的格式-->
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %l:%m%n "/>
</Console>
<!--文件会打印出所有信息,这个log每次运行程序会自动清空,由append属性决定,这个也挺有用的,适合临时测试用-->
<File name="log" fileName="log/test.log" append="false">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %l:%m%n "/>
</File>
<!--这个会打印出所有的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFile" fileName="log/app.log"
filePattern="log/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout pattern=" %-5level %class{36} %L %M - %msg%xEx%n"/>
<SizeBasedTriggeringPolicy size="50MB"/>
</RollingFile>
</appenders>
<!--然后定义logger,只有定义了logger并引入的appender,appender才会生效-->
<loggers>
<!--建立一个默认的root的logger-->
<root level="trace">
<appender-ref ref="RollingFile"/>
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>

@ -9,8 +9,6 @@ import me.lensferno.dogename.configs.ConfigLoader;
import me.lensferno.dogename.controllers.MainInterfaceController;
import me.lensferno.dogename.sayings.Gushici;
import me.lensferno.dogename.sayings.Hitokoto;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.lang.management.ManagementFactory;
@ -18,9 +16,9 @@ import java.util.Random;
public class Main extends Application {
Logger log = LogManager.getLogger();
public static void main(String[] args){ launch(args);}
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
@ -45,7 +43,7 @@ public class Main extends Application {
fxmlLoader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/MainInterface.fxml"));
parent = fxmlLoader.load();
} catch (Exception e) {
log.error("Error to load main interface FXML :"+e.toString());
System.out.println("Error to load main interface FXML :" + e);
return;
}

@ -2,29 +2,28 @@ package me.lensferno.dogename.configs;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javafx.beans.property.*;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import me.lensferno.dogename.configs.adapters.BooleanPropertyAdapter;
import me.lensferno.dogename.configs.adapters.DoublePropertyAdapter;
import me.lensferno.dogename.configs.adapters.IntegerPropertyAdapter;
import me.lensferno.dogename.configs.adapters.StringPropertyAdapter;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class ConfigLoader {
Logger log = LogManager.getLogger();
private final String mainConfigLocation = "files" + File.separator + "Config.json";
private final String voiceConfigLocation = "files" + File.separator + "VoiceConfig.json";
//ConfigValuesBean config;
private MainConfig mainConfig;
private VoiceConfig voiceConfig;
private final String mainConfigLocation = "files"+ File.separator+"Config.json";
private final String voiceConfigLocation = "files"+ File.separator+"VoiceConfig.json";
public String getMainConfigLocation() {
return mainConfigLocation;
}
@ -71,7 +70,7 @@ public class ConfigLoader {
}
} catch (Exception e) {
log.error("Error to load config file:"+e+"\nUse Default config.");
System.out.println("Error to load config file:" + e + "\nUse Default config.");
mainConfig = new MainConfig();
writeMainConfigToFile(mainConfigLocation);
@ -116,7 +115,7 @@ public class ConfigLoader {
}
} catch (Exception e) {
log.error("Error to load voice config file:"+e+"\nUse Default voice config.");
System.out.println("Error to load voice config file:" + e + "\nUse Default voice config.");
voiceConfig = new VoiceConfig();
writeVoiceConfigToFile(voiceConfigLocation);
@ -171,7 +170,7 @@ public class ConfigLoader {
IOUtils.write(VoiceConfigtoJSON(this.voiceConfig).getBytes(StandardCharsets.UTF_8), voiceConfigFileStream);
} catch (Exception e) {
log.error("Error in writing all config:"+e);
System.out.println("Error in writing all config:" + e);
}
}
@ -188,7 +187,7 @@ public class ConfigLoader {
IOUtils.write(toJSON(this.mainConfig).getBytes(StandardCharsets.UTF_8), stream);
} catch (Exception e) {
log.error("Error in writing main config:"+e);
System.out.println("Error in writing main config:" + e);
}
}
@ -205,7 +204,7 @@ public class ConfigLoader {
IOUtils.write(VoiceConfigtoJSON(this.voiceConfig).getBytes(StandardCharsets.UTF_8), voiceConfigFileStream);
} catch (Exception e) {
log.error("Error in writing voice config:"+e);
System.out.println("Error in writing voice config:" + e);
}
}

@ -1,55 +1,48 @@
package me.lensferno.dogename.configs;
import com.google.gson.annotations.Expose;
import javafx.beans.property.*;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class MainConfig {
// ---------------------- Default values ---------------------------------------------------------
private final int currentVersion = 3;
@Expose
public static final boolean DEFAULT_NAME_CHOOSE = true;
public static final int METHOD_NAME = 0; // 名字挑选法
public static final int METHOD_NUMBER = 1; // 数字挑选法
public static final int DEFAULT_MAX_TOTAL_COUNT = 120; // 默认轮回次数:120
public static final int DEFAULT_SPEED = 80; // 默认速度:20ms,对应滑动条80的位置
public static final boolean DEFAULT_RANDOM_TIMES = true; // 默认挑选轮回次数是否随机:ture
public static final boolean DEFAULT_IGNORE_PAST = true; // 默认忽略已经点过的名字:ture
public static final boolean DEFAULT_EQUAL_MODE = true; // 默认开启"机会均等"
public static final boolean DEFAULT_NEW_ALGO = true; // 默认使用新算法"Java sec random"
public static final boolean DEFAULT_VOICE_PLAY = true; // 默认使用语音播报
public static final boolean DEFAULT_SHOW_SAYING = true;
private final int currentVersion = 3;
// ----------------------Properties----------------------------------------------------------------
private final SimpleBooleanProperty nameChoose;
private SimpleBooleanProperty nameChoose;
private SimpleBooleanProperty randomCount; // 挑选次数是否随机
private SimpleBooleanProperty passSelectedResult; // 是否忽略已经被点过的名字/数字
private final SimpleBooleanProperty randomCount; // 挑选次数是否随机
private final SimpleBooleanProperty passSelectedResult; // 是否忽略已经被点过的名字/数字
private SimpleIntegerProperty chooseMethod; // 挑选方式: 0->名字挑选法 1->数字挑选法
private SimpleIntegerProperty maxTotalCount; // 挑选轮回次数
private final SimpleIntegerProperty chooseMethod; // 挑选方式: 0->名字挑选法 1->数字挑选法
private final SimpleIntegerProperty maxTotalCount; // 挑选轮回次数
private SimpleIntegerProperty speed; // 速度
private final SimpleIntegerProperty speed; // 速度
private SimpleStringProperty minNumber; // 最小值
private SimpleStringProperty maxNumber; // 最大值
private final SimpleStringProperty minNumber; // 最小值
private final SimpleStringProperty maxNumber; // 最大值
private SimpleBooleanProperty equalMode; // 是否开启"机会均等"
private final SimpleBooleanProperty equalMode; // 是否开启"机会均等"
private SimpleBooleanProperty secureRandom; // 是否使用secure random
private SimpleBooleanProperty voicePlay; // 是否使用语音播报
private final SimpleBooleanProperty secureRandom; // 是否使用secure random
private final SimpleBooleanProperty voicePlay; // 是否使用语音播报
private SimpleBooleanProperty showSaying;
private final SimpleBooleanProperty showSaying;
// -------------------------- 初始化 --------------------------------------------------------------
public MainConfig() {
@ -80,146 +73,146 @@ public class MainConfig {
return nameChoose.get();
}
public SimpleBooleanProperty nameChooseProperty() {
return nameChoose;
}
public void setNameChoose(boolean nameChoose) {
this.nameChoose.set(nameChoose);
}
public boolean getRandomCount() {
return randomCount.get();
public SimpleBooleanProperty nameChooseProperty() {
return nameChoose;
}
public SimpleBooleanProperty randomCountProperty() {
return randomCount;
public boolean getRandomCount() {
return randomCount.get();
}
public void setRandomCount(boolean randomCount) {
this.randomCount.set(randomCount);
}
public boolean getPassSelectedResult() {
return passSelectedResult.get();
public SimpleBooleanProperty randomCountProperty() {
return randomCount;
}
public SimpleBooleanProperty passSelectedResultProperty() {
return passSelectedResult;
public boolean getPassSelectedResult() {
return passSelectedResult.get();
}
public void setPassSelectedResult(boolean passSelectedResult) {
this.passSelectedResult.set(passSelectedResult);
}
public int getChooseMethod() {
return chooseMethod.get();
public SimpleBooleanProperty passSelectedResultProperty() {
return passSelectedResult;
}
public SimpleIntegerProperty chooseMethodProperty() {
return chooseMethod;
public int getChooseMethod() {
return chooseMethod.get();
}
public void setChooseMethod(int chooseMethod) {
this.chooseMethod.set(chooseMethod);
}
public int getMaxTotalCount() {
return maxTotalCount.get();
public SimpleIntegerProperty chooseMethodProperty() {
return chooseMethod;
}
public SimpleIntegerProperty maxTotalCountProperty() {
return maxTotalCount;
public int getMaxTotalCount() {
return maxTotalCount.get();
}
public void setMaxTotalCount(int maxTotalCount) {
this.maxTotalCount.set(maxTotalCount);
}
public int getSpeed() {
return speed.get();
public SimpleIntegerProperty maxTotalCountProperty() {
return maxTotalCount;
}
public SimpleIntegerProperty speedProperty() {
return speed;
public int getSpeed() {
return speed.get();
}
public void setSpeed(int speed) {
this.speed.set(speed);
}
public String getMinNumber() {
return minNumber.get();
public SimpleIntegerProperty speedProperty() {
return speed;
}
public SimpleStringProperty minNumberProperty() {
return minNumber;
public String getMinNumber() {
return minNumber.get();
}
public void setMinNumber(String minNumber) {
this.minNumber.set(minNumber);
}
public String getMaxNumber() {
return maxNumber.get();
public SimpleStringProperty minNumberProperty() {
return minNumber;
}
public SimpleStringProperty maxNumberProperty() {
return maxNumber;
public String getMaxNumber() {
return maxNumber.get();
}
public void setMaxNumber(String maxNumber) {
this.maxNumber.set(maxNumber);
}
public boolean getEqualMode() {
return equalMode.get();
public SimpleStringProperty maxNumberProperty() {
return maxNumber;
}
public SimpleBooleanProperty equalModeProperty() {
return equalMode;
public boolean getEqualMode() {
return equalMode.get();
}
public void setEqualMode(boolean equalMode) {
this.equalMode.set(equalMode);
}
public boolean getSecureRandom() {
return secureRandom.get();
public SimpleBooleanProperty equalModeProperty() {
return equalMode;
}
public SimpleBooleanProperty secureRandomProperty() {
return secureRandom;
public boolean getSecureRandom() {
return secureRandom.get();
}
public void setSecureRandom(boolean secureRandom) {
this.secureRandom.set(secureRandom);
}
public boolean getVoicePlay() {
return voicePlay.get();
public SimpleBooleanProperty secureRandomProperty() {
return secureRandom;
}
public SimpleBooleanProperty voicePlayProperty() {
return voicePlay;
public boolean getVoicePlay() {
return voicePlay.get();
}
public void setVoicePlay(boolean voicePlay) {
this.voicePlay.set(voicePlay);
}
public boolean isShowSaying() {
return showSaying.get();
public SimpleBooleanProperty voicePlayProperty() {
return voicePlay;
}
public SimpleBooleanProperty showSayingProperty() {
return showSaying;
public boolean isShowSaying() {
return showSaying.get();
}
public void setShowSaying(boolean showSaying) {
this.showSaying.set(showSaying);
}
public SimpleBooleanProperty showSayingProperty() {
return showSaying;
}
public int getCurrentConfigVersion() {
return currentVersion;
}

@ -6,15 +6,23 @@ import javafx.fxml.FXML;
public class VoiceConfig {
private String speaker;
private int selectedSpeaker;
public final int DEFAULT_SPEED = 5;
public final int DEFAULT_INTONATION = 5;
//度小宇=1,度小美=0,度逍遥=3,度丫丫=4
//度博文=106,度小童=110,度小萌=111,度米朵=103,度小娇=5
private String speaker;
private int selectedSpeaker;
private final SimpleDoubleProperty speed;
private final SimpleDoubleProperty intonation;
private SimpleDoubleProperty speed;
private SimpleDoubleProperty intonation;
public VoiceConfig() {
selectedSpeaker = 0;
speaker = "1";
speed = new SimpleDoubleProperty(DEFAULT_SPEED);
intonation = new SimpleDoubleProperty(DEFAULT_INTONATION);
}
public String getSpeaker() {
return speaker;
@ -24,16 +32,6 @@ public class VoiceConfig {
this.speaker = speaker;
}
public final int DEFAULT_SPEED=5;
public final int DEFAULT_INTONATION=5;
public VoiceConfig(){
selectedSpeaker=0;
speaker="1";
speed=new SimpleDoubleProperty(DEFAULT_SPEED);
intonation=new SimpleDoubleProperty(DEFAULT_INTONATION);
}
public int getSelectedSpeaker() {
return selectedSpeaker;
}
@ -41,35 +39,35 @@ public class VoiceConfig {
public void setSelectedSpeaker(int selectedSpeaker) {
this.selectedSpeaker = selectedSpeaker;
}
public double getSpeed() {
return speed.get();
}
public SimpleDoubleProperty speedProperty() {
return speed;
}
public void setSpeed(double speed) {
this.speed.set(speed);
}
public double getIntonation() {
return intonation.get();
public SimpleDoubleProperty speedProperty() {
return speed;
}
public SimpleDoubleProperty intonationProperty() {
return intonation;
public double getIntonation() {
return intonation.get();
}
public void setIntonation(double intonation) {
this.intonation.set(intonation);
}
public SimpleDoubleProperty intonationProperty() {
return intonation;
}
@FXML
void showAdvancedVoiceSettings(ActionEvent event) {
}
}

@ -4,13 +4,10 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class GushiciPaneController extends VBox {
Logger log= LogManager.getLogger();
@FXML
public Text contentText;
@ -28,9 +25,7 @@ public class GushiciPaneController extends VBox {
try {
loader.load();
} catch (Exception e) {
log.error("Error to load Gushici pane FXML: "+e.toString());
//e.printStackTrace();
e.printStackTrace();
}
contentText.setText("“" + content + "”");
contentInfo.setText("《" + title + "》" + "——" + author);

@ -1,6 +1,8 @@
package me.lensferno.dogename.controllers;
import com.jfoenix.controls.*;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXListView;
import com.jfoenix.controls.JFXTextField;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
@ -8,18 +10,26 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.data.History;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import me.lensferno.dogename.utils.DialogMaker;
public class HistoryPaneController extends VBox {
Logger log= LogManager.getLogger(HitokotoPaneController.class);
public static final ObservableList<String> shownHistoryList = FXCollections.observableArrayList();
History history;
Pane rootPane;
int pointer = 0;
@FXML
private JFXListView<String> historyList;
public static final ObservableList<String> shownHistoryList = FXCollections.observableArrayList();
@FXML
private JFXTextField searchBar;
@FXML
private JFXButton previousBtn;
@FXML
private JFXButton nextBtn;
public HistoryPaneController(History history, Pane rootPane) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/HistoryPane.fxml"));
@ -35,28 +45,14 @@ public class HistoryPaneController extends VBox {
searchBar.textProperty().addListener((observable, oldValue, newValue) -> pointer = 0);
} catch (Exception e) {
log.error("Error in loading history Fxml:"+e.toString());
e.printStackTrace();
}
}
@FXML
private JFXListView<String> historyList;
@FXML
private JFXTextField searchBar;
@FXML
private JFXButton previousBtn;
@FXML
private JFXButton nextBtn;
private void pointOutSearchResult(int pointer) {
historyList.getSelectionModel().select(pointer);
}
int pointer=0;
@FXML
void upSearch(ActionEvent event) {

@ -5,12 +5,9 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import java.util.logging.Logger;
public class HitokotoPaneController extends VBox {
Logger log=Logger.getLogger("HitokotoPaneLogger");
@FXML
private Text hitokotoContent;
@ -28,8 +25,7 @@ public class HitokotoPaneController extends VBox {
try {
loader.load();
} catch (Exception e) {
log.warning("Error to load Gushici pane FXML: "+e.toString());
//e.printStackTrace();
e.printStackTrace();
}
hitokotoContent.setText("『 " + hitokoto + " 』");
contentInfo.setText("出自:" + from + "  |  作者:" + author + "  |  上传者:" + creator);

@ -1,27 +1,28 @@
package me.lensferno.dogename.controllers;
import com.jfoenix.controls.*;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXRadioButton;
import com.jfoenix.controls.JFXTextArea;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import me.lensferno.dogename.select.Selector;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.configs.ConfigLoader;
import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.select.Selector;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.utils.ocr.OcrTool;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
@ -35,40 +36,33 @@ public final class MainInterfaceController {
OcrTool ocrTool = null;
History history = new History();
MainConfig mainConfig;
VoiceConfig voiceConfig;
Random random = new Random();
Data data = new Data();
Selector selector = new Selector();
@FXML
private Pane rootPane;
@FXML
private JFXRadioButton nameChoose;
@FXML
private JFXButton showHistoryBtn;
@FXML
private JFXRadioButton numbChoose;
@FXML
private JFXButton anPaiBtn;
@FXML
private Pane mainPane;
@FXML
private Label topBar;
@FXML
private JFXButton showNameMangerButton;
@FXML
private Label upperLabel;
@FXML
private ImageView mainView;
@FXML
private JFXButton miniModeBtn;
@FXML
private Label downLabel;
@ -76,9 +70,6 @@ public final class MainInterfaceController {
history.loadHistory();
}
MainConfig mainConfig;
VoiceConfig voiceConfig;
public void bindProperties() {
nameChoose.selectedProperty().bindBidirectional(mainConfig.nameChooseProperty());
@ -104,7 +95,6 @@ public final class MainInterfaceController {
new DialogMaker(rootPane).createDialogWithOneBtn("程序信息", new ProgramInfoPaneController(rootPane));
}
@FXML
void showNameManger(ActionEvent event) {
@ -129,8 +119,6 @@ public final class MainInterfaceController {
}
Logger log= LogManager.getLogger();
@FXML
void miniMode(ActionEvent event) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/MiniPane.fxml"));
@ -138,7 +126,7 @@ public final class MainInterfaceController {
try {
parent = loader.load();
} catch (IOException e) {
log.error("Error in loading MiniPane Fxml:"+e);
e.printStackTrace();
return;
}
@ -187,12 +175,6 @@ public final class MainInterfaceController {
new DialogMaker(rootPane).createDialogWithOneBtn("历史记录", historyPaneController);
}
Random random=new Random();
Data data =new Data();
Selector selector =new Selector();
public void init() {
selector.initialVariable(mainConfig, data, history, upperLabel.textProperty(), downLabel.textProperty());

@ -10,26 +10,30 @@ import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TouchEvent;
import javafx.stage.Stage;
import me.lensferno.dogename.select.Selector;
import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByMouse;
import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByTouch;
import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.select.Selector;
import java.util.Random;
public class MiniPaneController {
Stage oldStage;
Stage currentStage;
Scene currentScene;
StringProperty[] oldTextProperties = null;
@FXML
private Label chosenNameLabel;
@FXML
private JFXButton anPaiBtn;
@FXML
private JFXButton miniModeBtn;
Stage oldStage;
private final Random random = new Random();
private Data data;
private MainConfig mainConfig;
private Selector selector = new Selector();
public Stage getOldStage() {
return oldStage;
@ -39,12 +43,6 @@ public class MiniPaneController {
this.oldStage = oldStage;
}
private Random random = new Random();
private Data data;
Stage currentStage;
Scene currentScene;
public void setCurrentScene(Scene currentScene) {
this.currentScene = currentScene;
}
@ -53,8 +51,6 @@ public class MiniPaneController {
this.currentStage = currentStage;
}
StringProperty[] oldTextProperties = null;
public void setBase(Data data, MainConfig mainConfig, Selector selector) {
this.data = data;
this.mainConfig = mainConfig;
@ -95,9 +91,6 @@ public class MiniPaneController {
miniModeBtn.setOnTouchMoved(touchHandler);
}
private MainConfig mainConfig;
private Selector selector = new Selector();
@FXML
void anPai() {

@ -1,6 +1,8 @@
package me.lensferno.dogename.controllers;
import com.jfoenix.controls.*;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXListView;
import com.jfoenix.controls.JFXTextArea;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
@ -12,23 +14,31 @@ import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.utils.ocr.OcrTool;
import me.lensferno.dogename.utils.Clipboard;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.utils.ocr.OcrTool;
import java.io.File;
import java.util.logging.Logger;
public class NameManagerPaneController extends VBox {
public static final ObservableList<String> shownNameList = FXCollections.observableArrayList();
Data data;
Pane rootPane;
OcrTool ocrTool;
Logger log = Logger.getLogger("NameManagerPaneLOgger");
public static final ObservableList<String> shownNameList = FXCollections.observableArrayList();
@FXML
private JFXListView<String> nameList;
@FXML
private JFXButton deleteAll;
@FXML
private JFXButton addName;
@FXML
private JFXButton deleteName;
@FXML
private JFXTextArea inputName;
public NameManagerPaneController(Data data, Pane rootPane, OcrTool ocrTool) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/NameManagerPane.fxml"));
@ -48,22 +58,6 @@ public class NameManagerPaneController extends VBox {
this.ocrTool = ocrTool;
}
@FXML
private JFXListView<String> nameList;
@FXML
private JFXButton deleteAll;
@FXML
private JFXButton addName;
@FXML
private JFXButton deleteName;
@FXML
private JFXTextArea inputName;
@FXML
void deleteName(ActionEvent event) {
@ -167,7 +161,7 @@ public class NameManagerPaneController extends VBox {
fxmlLoader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/OcrPane.fxml"));
parent = fxmlLoader.load();
} catch (Exception e) {
log.warning("Error to load main interface FXML :"+e.toString());
log.warning("Error to load main interface FXML :" + e);
return;
}

@ -9,6 +9,11 @@ import me.lensferno.dogename.data.Data;
public class NumberSettingsPaneController extends VBox {
Data data;
@FXML
private JFXTextField minValueField;
@FXML
private JFXTextField maxValueField;
public NumberSettingsPaneController(Data data) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/NumberSettingPane.fxml"));
loader.setRoot(this);
@ -21,12 +26,6 @@ public class NumberSettingsPaneController extends VBox {
this.data = data;
}
@FXML
private JFXTextField minValueField;
@FXML
private JFXTextField maxValueField;
public void bindProperties(MainConfig mainConfig) {
minValueField.textProperty().bindBidirectional(mainConfig.minNumberProperty());

@ -3,27 +3,22 @@ package me.lensferno.dogename.controllers;
import com.jfoenix.controls.JFXSpinner;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import me.lensferno.dogename.utils.ocr.ScreenCapture;
import me.lensferno.dogename.utils.Clipboard;
import me.lensferno.dogename.utils.ocr.ScreenCapture;
public class OcrPaneController {
Stage mainStage;
@FXML
private TextArea ocrText;
@FXML
private JFXSpinner loadingSpinner;
Stage mainStage;
public void setMainStage(Stage mainStage) {
this.mainStage = mainStage;
}
@FXML
void addNew() {

@ -9,54 +9,39 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.Data;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import me.lensferno.dogename.utils.DialogMaker;
public class SettingsPaneController extends VBox {
MainConfig mainConfig;
VoiceConfig voiceConfig;
Pane rootPane;
Data data;
@FXML
private JFXCheckBox showSayingBtn;
@FXML
private JFXCheckBox newAlgoBtn;
@FXML
private JFXSlider cycleTimesBar;
@FXML
private JFXCheckBox voicePlayBtn;
@FXML
private JFXSlider speedBar;
@FXML
private JFXCheckBox equalModeBtn;
@FXML
private JFXRadioButton ignoreOnce;
@FXML
private JFXRadioButton chooseOnce;
@FXML
private JFXRadioButton randomTimes;
@FXML
private JFXRadioButton fixedTimes;
MainConfig mainConfig;
VoiceConfig voiceConfig;
Pane rootPane;
Data data;
Logger log = LogManager.getLogger("SettingsPaneControllerLogger");
public SettingsPaneController() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/SettingsPane.fxml"));
@ -65,7 +50,7 @@ public class SettingsPaneController extends VBox {
try {
loader.load();
} catch (Exception e) {
log.warn("Error to load settings pane FXML: "+e.toString());
e.printStackTrace();
}
}
@ -103,8 +88,7 @@ public class SettingsPaneController extends VBox {
showSayingBtn.selectedProperty().bindBidirectional(mainConfig.showSayingProperty());
mainConfig.passSelectedResultProperty().addListener((observable, oldValue, isIgnorePast) -> {
if(!isIgnorePast)
{
if (!isIgnorePast) {
//如果 忽略被点过的名字 被取消后就把机会均等模式的按钮给取消掉
equalModeBtn.setSelected(false);
}

@ -13,25 +13,18 @@ import me.lensferno.dogename.configs.VoiceConfig;
import java.util.logging.Logger;
public class VoiceSettingsPaneController extends VBox {
public static final ObservableList<String> shownSpeakerList = FXCollections.observableArrayList();
private final String[] speakers = {
"1", "0", "3", "4",
"106", "110", "111", "103", "5"};
Logger log = Logger.getLogger("VoiceSettingsPaneControllerLogger");
VoiceConfig voiceConfig = new VoiceConfig();
@FXML
private JFXSlider intonationBar;
@FXML
private JFXComboBox<String> speakerSelectBar;
@FXML
private JFXSlider voiceSpeedBar;
public static final ObservableList<String> shownSpeakerList = FXCollections.observableArrayList();
private final String[] speakers={
"1","0","3","4",
"106","110","111","103","5"};
//度小宇=1,度小美=0,度逍遥=3,度丫丫=4
//度博文=106,度小童=110,度小萌=111,度米朵=103,度小娇=5
@ -42,7 +35,7 @@ public class VoiceSettingsPaneController extends VBox {
try {
loader.load();
} catch (Exception e) {
log.warning("Error to load settings pane FXML: " + e.toString());
log.warning("Error to load settings pane FXML: " + e);
}
if (shownSpeakerList.isEmpty()) {
shownSpeakerList.addAll(
@ -79,7 +72,6 @@ public class VoiceSettingsPaneController extends VBox {
}
}

@ -6,7 +6,7 @@ import javafx.stage.Stage;
public class MoveWindowByMouse implements EventHandler<MouseEvent> {
private Stage primaryStage;
private final Stage primaryStage;
private double oldStageX;
private double oldStageY;
private double oldScreenX;

@ -6,7 +6,7 @@ import javafx.stage.Stage;
public class MoveWindowByTouch implements EventHandler<TouchEvent> {
private Stage primaryStage;
private final Stage primaryStage;
private double oldStageX;
private double oldStageY;
private double oldScreenX;

@ -1,8 +1,6 @@
package me.lensferno.dogename.data;
import com.google.gson.Gson;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.nio.charset.StandardCharsets;
@ -11,19 +9,47 @@ import java.util.*;
public class Data {
Logger log = LogManager.getLogger("dataLogger");
public static final int IGNORELIST_NAME_ONLY = 0;
public static final int IGNORELIST_NUMBER_ONLY = 1;
public static final int IGNORELIST_ALL = 2;
File dataFile;
SecureRandom secRandom = new SecureRandom();
Random random = new Random();
private List<String> nameList;
private final IgnoreList ignoreList = new IgnoreList();
public Data() {
private List<String> nameList;
private IgnoreList ignoreList = new IgnoreList();
dataFile = new File("files" + File.separator + "Namelist.data");
File dataFile;
try {
SecureRandom secRandom = new SecureRandom();
if (!dataFile.exists()) {
dataFile.getParentFile().mkdirs();
dataFile.createNewFile();
nameList = new ArrayList<>();
saveToFile();
return;
}
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(dataFile));
this.nameList = (ArrayList) ois.readObject();
System.out.println(nameList.size() + " names loaded.");
} catch (EOFException EOFe) {
nameList = new ArrayList<>();
System.out.println("Data file is empty.");
saveToFile();
} catch (Exception e) {
nameList = new ArrayList<>();
saveToFile();
System.out.println("Failed to load data file.");
e.printStackTrace();
}
ignoreList.readIgnoreList();
}
public List<String> getNameList() {
return nameList;
@ -35,9 +61,9 @@ public class Data {
FileOutputStream oos = new FileOutputStream(path);
oos.write(new Gson().toJson(nameList).getBytes(StandardCharsets.UTF_8));
oos.close();
log.info("Exported list to:" + path.getPath());
System.out.println("Exported list to:" + path.getPath());
} catch (Exception e) {
log.warn("error in export namelist: " + e.toString());
System.out.println("error in export namelist: " + e);
e.printStackTrace();
}
}
@ -58,9 +84,9 @@ public class Data {
}
nameList = new Gson().fromJson(sb.toString(), List.class);
log.info("Imported list from:" + path.getPath());
System.out.println("Imported list from:" + path.getPath());
} catch (Exception e) {
log.warn("error in import namelist:" + e.toString());
System.out.println("error in import namelist:" + e);
e.printStackTrace();
}
@ -86,56 +112,6 @@ public class Data {
}
public Data() {
if (System.getProperty("os.name").toLowerCase().contains("window"))
dataFile = new File("files\\Namelist.data");
else
dataFile = new File("files/Namelist.data");
File oldDataFile = new File("D:\\dogename\\files\\data");
try {
if (oldDataFile.exists()) {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(oldDataFile));
this.nameList = (ArrayList) ois.readObject();
ois.close();
oldDataFile.delete();
saveToFile();
return;
}
if (!dataFile.exists()) {
dataFile.getParentFile().mkdirs();
dataFile.createNewFile();
nameList = new ArrayList<>();
saveToFile();
return;
}
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(dataFile));
this.nameList = (ArrayList) ois.readObject();
log.info(nameList.size() + " names loaded.");
} catch (EOFException EOFe) {
nameList = new ArrayList<>();
log.warn("Data file is empty.");
saveToFile();
} catch (Exception e) {
nameList = new ArrayList<>();
saveToFile();
log.warn("Failed to load data file.");
e.printStackTrace();
}
ignoreList.readIgnoreList();
}
public void add(String text) {
String[] splitedText;
@ -158,7 +134,6 @@ public class Data {
System.gc();
}
public boolean compareNameIgnoreList() {
return ignoreList.getNameIgnoreListSize() >= nameList.size();
}
@ -177,8 +152,6 @@ public class Data {
return nameList.isEmpty();
}
Random random = new Random();
public String randomGet(boolean secureRandom) {
if (secureRandom)
return nameList.get(secRandom.nextInt(nameList.size()));
@ -237,12 +210,10 @@ public class Data {
class IgnoreList {
private HashSet<String> ignoreNameList = new HashSet<>();
private HashSet<String> ignoreNumberList = new HashSet<>();
private final File nameIgnoreFile = new File("files" + File.separator + "IgnoredNameList.data");
private final File numbIgnoreFile = new File("files" + File.separator + "IgnoredNumberList.data");
private HashSet<String> ignoreNameList = new HashSet<>();
private HashSet<String> ignoreNumberList = new HashSet<>();
public void writeIgnoreList(int switchy) {
switch (switchy) {
@ -279,7 +250,7 @@ public class Data {
public void readIgnoreList() {
readNameIgnoreList();
readNumberIgnoreList();
log.info("There are " + ignoreNameList.size() + " names and " + ignoreNumberList.size() + " numbers ignored.");
System.out.println("There are " + ignoreNameList.size() + " names and " + ignoreNumberList.size() + " numbers ignored.");
}
private void readNameIgnoreList() {
@ -319,11 +290,11 @@ public class Data {
this.ignoreNumberList = (HashSet) ois.readObject();
} catch (EOFException e) {
ignoreNumberList = new HashSet<>();
log.warn("Ignored number list is empty.");
System.out.println("Ignored number list is empty.");
writeIgnoreList(IGNORELIST_NUMBER_ONLY);
} catch (Exception e) {
ignoreNumberList = new HashSet<>();
log.warn("Failed to load ignored number list");
System.out.println("Failed to load ignored number list");
writeIgnoreList(IGNORELIST_NUMBER_ONLY);
e.printStackTrace();
}

@ -1,20 +1,13 @@
package me.lensferno.dogename.data;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.util.ArrayList;
public class History {
Logger log = LogManager.getLogger();
private String HISTORY_FILE;
public static final String separator = File.separator;
ArrayList<String> history;
private String HISTORY_FILE;
public void loadHistory() {
@ -36,11 +29,11 @@ public class History {
} catch (EOFException e) {
history = new ArrayList<>();
log.warn("History file is empty.");
System.out.println("History file is empty.");
writeHistory();
} catch (Exception e) {
history = new ArrayList<>();
log.error("Failed to load history file:"+e.toString());
System.out.println("Failed to load history file:" + e);
e.printStackTrace();
}
}
@ -72,16 +65,8 @@ public class History {
oos.writeObject(history);
oos.close();
} catch (Exception e) {
log.error("Error in writing history file:"+e);
}
System.out.println("Error in writing history file:" + e);
}
public int downSearch(){
return 1;
}
public int upSearch(){
return 1;
}
public void clearHistory() {

@ -5,8 +5,8 @@ import com.google.gson.annotations.SerializedName;
import javafx.application.Platform;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.controllers.GushiciPaneController;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.utils.NetworkUtil;
public class Gushici {
@ -35,6 +35,7 @@ public class Gushici {
type = gushiciData.getType();
Platform.runLater(() -> {
topBar.setText(content + " ——" + author + "《" + title + "》");
topBar.setText(String.format("%s ——%s 《%s》", content, author, title));
if (showOnDialog) {
GushiciPaneController gushiciPaneController = new GushiciPaneController(content, title, author, type);
new DialogMaker(rootPane).createDialogWithOneBtn("每日古诗词", gushiciPaneController);
@ -57,32 +58,36 @@ public class Gushici {
@SerializedName("category")
private String type;//诗歌类型
public void setContent(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public void setTitle(String title) {
this.title = title;
public void setContent(String content) {
this.content = content;
}
public String getTitle() {
return title;
}
public void setAuthor(String author) {
this.author = author;
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setType(String type) {
this.type = type;
public void setAuthor(String author) {
this.author = author;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
}

@ -5,8 +5,8 @@ import com.google.gson.annotations.SerializedName;
import javafx.application.Platform;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.controllers.HitokotoPaneController;
import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.utils.NetworkUtil;
public class Hitokoto {
@ -60,24 +60,20 @@ public class Hitokoto {
private String creator;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setHitokoto(String hitokoto) {
this.hitokoto = hitokoto;
public void setId(int id) {
this.id = id;
}
public String getHitokoto() {
return hitokoto;
}
public void setType(String type) {
this.type = type;
public void setHitokoto(String hitokoto) {
this.hitokoto = hitokoto;
}
/**
@ -143,29 +139,33 @@ public class Hitokoto {
return type;
}
public void setFrom(String from) {
this.from = from;
public void setType(String type) {
this.type = type;
}
public String getFrom() {
return from;
}
public void setAuthor(String author) {
this.author = author;
public void setFrom(String from) {
this.from = from;
}
public String getAuthor() {
return author;
}
public void setCreator(String creator) {
this.creator = creator;
public void setAuthor(String author) {
this.author = author;
}
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
}
}

@ -6,8 +6,8 @@ import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.select.core.Worker;
import me.lensferno.dogename.voice.TokenManager;
import me.lensferno.dogename.voice.VoicePlayer;
@ -62,9 +62,8 @@ public final class Selector {
// ---------------------------------------------------
static class Processor extends AnimationTimer {
private Worker coreWorker;
MainConfig config = null;
private Worker coreWorker;
protected void initialVariable(MainConfig config, VoicePlayer voicePlayer, Data data, History history, StringProperty... labelTexts) {
coreWorker = new Worker(labelTexts, config, data, history, voicePlayer);

@ -3,55 +3,40 @@ package me.lensferno.dogename.select.core;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.StringProperty;
import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.utils.Random;
import me.lensferno.dogename.voice.VoicePlayer;
public final class Worker {
private final Random randomNumber = new Random();
private StringProperty[] labelTexts;
private final SimpleBooleanProperty stoppedIndicator = new SimpleBooleanProperty(true);
private final MainConfig config;
//挑选方法
private final int selectMethod = MainConfig.METHOD_NAME;
private final Data data;
private final History history;
private final VoicePlayer voicePlayer;
private int speed = 0;
//数值范围最大最小值
private final int[] numberRange = new int[2];
private final int MIN_NUMBER = 0;
private final int MAX_NUMBER = 1;
private final Counter counter = new Counter();
private StringProperty[] labelTexts;
private int speed = 0;
//挑选次数和每一轮的挑选次数
private int maxTotalCount = MainConfig.DEFAULT_MAX_TOTAL_COUNT;
private int maxCycleCount = 0;
//已经挑选了多少次
private int totalCount = 0;
private int cycleCount = 0;
private boolean finalResult = true;
private boolean forceStop = false;
private String selectedResult;
private boolean continueSelecting = false;
private int resultLabelId = 0;
private final Counter counter = new Counter();
public Worker(StringProperty[] labelTexts, MainConfig config, Data data, History history, VoicePlayer voicePlayer) {
this.labelTexts = labelTexts;
this.config = config;
@ -150,6 +135,31 @@ public final class Worker {
}
}
public boolean getStoppedIndicator() {
return stoppedIndicator.get();
}
public SimpleBooleanProperty stoppedIndicatorProperty() {
return stoppedIndicator;
}
public void setNumberRange(int minNumber, int maxNumber) {
this.numberRange[MIN_NUMBER] = minNumber;
this.numberRange[MAX_NUMBER] = maxNumber;
}
public void setForceStop(boolean forceStop) {
this.forceStop = forceStop;
}
public void setMaxTotalCount(int maxTotalCount) {
this.maxTotalCount = maxTotalCount;
}
public void setSpeed(int speed) {
this.speed = speed;
}
// 这里有个内部类Counter计数菌
final class Counter {
@ -183,29 +193,4 @@ public final class Worker {
return newResultLabelId;
}
}
public boolean getStoppedIndicator() {
return stoppedIndicator.get();
}
public SimpleBooleanProperty stoppedIndicatorProperty() {
return stoppedIndicator;
}
public void setNumberRange(int minNumber, int maxNumber) {
this.numberRange[MIN_NUMBER] = minNumber;
this.numberRange[MAX_NUMBER] = maxNumber;
}
public void setForceStop(boolean forceStop) {
this.forceStop = forceStop;
}
public void setMaxTotalCount(int maxTotalCount) {
this.maxTotalCount = maxTotalCount;
}
public void setSpeed(int speed) {
this.speed = speed;
}
}

@ -19,14 +19,13 @@ import javafx.scene.text.Text;
public class DialogMaker {
Pane rootPane;
JFXDialog dialog;
public DialogMaker(@NamedArg("rootPane") Pane rootPane) {
this.rootPane = rootPane;
}
JFXDialog dialog;
public void createMessageDialog(@NamedArg("title") String title, @NamedArg("message") String message) {
JFXButton OKButton = new JFXButton("了解!");
OKButton.setFont(Font.font("Microsoft YaHei", FontWeight.BOLD, 12));
@ -69,7 +68,9 @@ public class DialogMaker {
OKButton.setPrefWidth(60);
OKButton.setPrefHeight(30);
OKButton.setTextFill(Paint.valueOf("red"));
OKButton.addEventHandler(ActionEvent.ACTION,e -> {dialog.close();});
OKButton.addEventHandler(ActionEvent.ACTION, e -> {
dialog.close();
});
OKButton.addEventHandler(ActionEvent.ACTION, OKEvent);
Text messageText = new Text(message);

@ -1,6 +1,9 @@
package me.lensferno.dogename.utils;
import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
public class IOUtil {

@ -1,10 +1,10 @@
package me.lensferno.dogename.utils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.URL;
@ -16,8 +16,6 @@ import java.util.zip.InflaterInputStream;
public class NetworkUtil {
private static Logger log = LogManager.getLogger();
public static final String REQUEST_USERAGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67";
public static String getHtml(String address) {
@ -61,12 +59,12 @@ public class NetworkUtil {
is.close();
} catch (Exception e) {
log.error("Error in getting HTML:" + e);
System.out.println("Error in getting HTML:" + e);
return null;
}
if (output)
System.out.println("[INFO]Got:" + sb.toString());
System.out.println("[INFO]Got:" + sb);
return sb.toString();
}

@ -20,10 +20,18 @@ import java.io.File;
public class ScreenCapture {
private OcrTool ocrTool;
private final String cacheImageFileLocation = "caches/image/ocrImageCache.png";
private final SimpleStringProperty result = new SimpleStringProperty();
private final SimpleBooleanProperty end = new SimpleBooleanProperty(true);
private final ImageView screenImageView = new ImageView();
private final Pane rootPane = new Pane();
private final Stage stage = new Stage();
private final int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
private final int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
private final Line MouseLine_X = new Line();
private final Line MouseLine_Y = new Line();
ScreenshotTool screenshotTool = new ScreenshotTool();
private OcrTool ocrTool;
private final Runnable finalEvent = new Runnable() {
@Override
public void run() {
@ -35,18 +43,19 @@ public class ScreenCapture {
result.set(ocrTool.getResult());
}
};
private double dragStartX = 0;
private double dragStartY = 0;
private final SimpleStringProperty result = new SimpleStringProperty();
private final SimpleBooleanProperty end = new SimpleBooleanProperty(true);
private final ImageView screenImageView = new ImageView();
private final Pane rootPane = new Pane();
private final Stage stage = new Stage();
private double dragEndX = 0;
private double dragEndY = 0;
private final int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
private final int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
private double selectedAreaWidth = 0;
private double selectedAreaHeight = 0;
ScreenshotTool screenshotTool = new ScreenshotTool();
private Line Width_Follow;
private Line Height_Follow;
private Line Width_Fixed;
private Line Height_Fixed;
public void startCapture() {
end.set(false);
@ -85,20 +94,6 @@ public class ScreenCapture {
stage.show();
}
private double dragStartX = 0;
private double dragStartY = 0;
private double dragEndX = 0;
private double dragEndY = 0;
private double selectedAreaWidth = 0;
private double selectedAreaHeight = 0;
private Line Width_Follow;
private Line Height_Follow;
private Line Width_Fixed;
private Line Height_Fixed;
private void addEventListeners() {
rootPane.setOnMousePressed(e -> {
dragStartX = e.getX();
@ -181,9 +176,6 @@ public class ScreenCapture {
Height_Follow.layoutYProperty().set(dragStartY);
}
private final Line MouseLine_X = new Line();
private final Line MouseLine_Y = new Line();
private void addMouseLine() {
MouseLine_X.layoutXProperty().set(0);
MouseLine_X.endXProperty().set(screenWidth);
@ -215,8 +207,17 @@ public class ScreenCapture {
Height_Follow.endYProperty().set(selectedAreaHeight);
}
public SimpleStringProperty resultProperty() {
return result;
}
public SimpleBooleanProperty endProperty() {
return end;
}
class ScreenshotTool {
BufferedImage fullscreenBufferedImage;
public Image getFullScreenshotImageData() {
try {
Robot robot = new Robot();
@ -236,12 +237,4 @@ public class ScreenCapture {
ImageIO.write(fullscreenBufferedImage.getSubimage(x, y, width, height), formateName, output);
}
}
public SimpleStringProperty resultProperty() {
return result;
}
public SimpleBooleanProperty endProperty() {
return end;
}
}

@ -34,20 +34,20 @@ aue =6 ,返回为二进制wav文件,具体header信息 Content-Type: audio/w
return System.currentTimeMillis() > expTime;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getAccessToken() {
return accessToken;
}
public void setExpiresIn(long expiresIn) {
this.expiresIn = expiresIn;
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public long getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(long expiresIn) {
this.expiresIn = expiresIn;
}
}

@ -2,8 +2,6 @@ package me.lensferno.dogename.voice;
import com.google.gson.Gson;
import me.lensferno.dogename.utils.NetworkUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.net.HttpURLConnection;
@ -11,25 +9,16 @@ import java.net.URL;
public class TokenManager {
Logger log= LogManager.getLogger();
public static final String separator = File.separator;
private final int TOKEN_NULL = -2;
private final int TOKEN_EXPIRED = -1;
public static final int TOKEN_OK = 0;
public static final int TOKEN_BAD = 1;
private int tokenStatus = TOKEN_OK;
final String API_KEY = "dIHCtamVdD0ERO1yyFir2iI4";
final String SEC_KEY = "HmpBQY3gG4PyZ0cmudnCbMeoMcMejuuW";
final String TOKEN_API_URL = "https://openapi.baidu.com/oauth/2.0/token";
private final int TOKEN_NULL = -2;
private final int TOKEN_EXPIRED = -1;
File tokenFile = new File("API_voice.token");
private int tokenStatus = TOKEN_OK;
private Token token = null;
private void updateTokenStatus(int statusCode) {
@ -95,18 +84,18 @@ public class TokenManager {
//token是空的就返回-2
if (token == null || token.getAccessToken() == null) {
log.info("Token was null");
System.out.println("Token was null");
return -2;
}
//token过期了就返回-1
if (token.isTokenTimeOut()) {
log.info("Token expired.");
System.out.println("Token expired.");
return -1;
}
//正常的话就返回0
log.info("Token OK.");
System.out.println("Token OK.");
return 0;
}
@ -123,7 +112,7 @@ public class TokenManager {
token.setExpTime();
} catch (Exception e) {
log.error("Error to get Token:"+e);
System.out.println("Error to get Token:" + e);
token = null;
}
}
@ -142,7 +131,7 @@ public class TokenManager {
return true;
} catch (Exception e) {
log.info("Network is not available.");
System.out.println("Network is not available.");
return false;
}
}
@ -154,7 +143,7 @@ public class TokenManager {
this.token = (Token) ois.readObject();
ois.close();
} catch (Exception e) {
log.error("Error in loading Token:"+e);
System.out.println("Error in loading Token:" + e);
this.token = null;
}
}
@ -166,7 +155,7 @@ public class TokenManager {
oos.writeObject(token);
oos.close();
} catch (Exception e) {
log.error("Error in writing Token:"+e);
System.out.println("Error in writing Token:" + e);
}
}

@ -14,11 +14,10 @@ public class VoicePlayer {
public static final String separator = File.separator;
private final String VOICE_API = "https://tsn.baidu.com/text2audio";
private VoiceConfig voiceConfig = null;
String cachePath = "caches" + separator + "voice" + separator;
Token token;
StreamPlayer streamPlayer = new StreamPlayer();
private VoiceConfig voiceConfig = null;
public VoicePlayer(Token token, VoiceConfig voiceConfig) {
this.token = token;
@ -90,8 +89,6 @@ public class VoicePlayer {
return success;
}
StreamPlayer streamPlayer = new StreamPlayer();
private void playSound(File file) {
try {
streamPlayer.open(file);

Loading…
Cancel
Save