|
|
|
@ -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; |
|
|
|
@ -32,54 +33,44 @@ public final class MainInterfaceController { |
|
|
|
|
|
|
|
|
|
public JFXTextArea message; |
|
|
|
|
|
|
|
|
|
OcrTool ocrTool=null; |
|
|
|
|
|
|
|
|
|
History history=new History(); |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
public MainInterfaceController(){ |
|
|
|
|
public MainInterfaceController() { |
|
|
|
|
history.loadHistory(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MainConfig mainConfig; |
|
|
|
|
VoiceConfig voiceConfig; |
|
|
|
|
|
|
|
|
|
public void bindProperties(){ |
|
|
|
|
public void bindProperties() { |
|
|
|
|
nameChoose.selectedProperty().bindBidirectional(mainConfig.nameChooseProperty()); |
|
|
|
|
|
|
|
|
|
numbChoose.selectedProperty().bind(mainConfig.nameChooseProperty().not()); |
|
|
|
@ -90,67 +81,64 @@ public final class MainInterfaceController { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setImg(InputStream stream){ |
|
|
|
|
public void setImg(InputStream stream) { |
|
|
|
|
mainView.setImage(new Image(stream)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setUpConfig(ConfigLoader configLoader){ |
|
|
|
|
mainConfig=configLoader.readConfigFromFile("files"+ File.separator +"Config.json"); |
|
|
|
|
voiceConfig=configLoader.readVoiceConfigFromFile("files"+ File.separator +"VoiceConfig.json"); |
|
|
|
|
public void setUpConfig(ConfigLoader configLoader) { |
|
|
|
|
mainConfig = configLoader.readConfigFromFile("files" + File.separator + "Config.json"); |
|
|
|
|
voiceConfig = configLoader.readVoiceConfigFromFile("files" + File.separator + "VoiceConfig.json"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
|
void showProgramInfo(ActionEvent event) { |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("程序信息",new ProgramInfoPaneController(rootPane)); |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("程序信息", new ProgramInfoPaneController(rootPane)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
|
void showNameManger(ActionEvent event) { |
|
|
|
|
|
|
|
|
|
if (selector.isWorkerRunning()){ |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("(・。・)","安排中......\n为保证运行的稳定,此时还不能进行该操作哦。"); |
|
|
|
|
if (selector.isWorkerRunning()) { |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("(・。・)", "安排中......\n为保证运行的稳定,此时还不能进行该操作哦。"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
NameManagerPaneController nameManagerPaneController =new NameManagerPaneController(data,rootPane,ocrTool); |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("名单管理",nameManagerPaneController); |
|
|
|
|
NameManagerPaneController nameManagerPaneController = new NameManagerPaneController(data, rootPane, ocrTool); |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("名单管理", nameManagerPaneController); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
|
void showNunberSetting(ActionEvent event) { |
|
|
|
|
|
|
|
|
|
if (selector.isWorkerRunning()){ |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("(・。・)","安排中......\n为保证运行的稳定,此时还不能进行该操作哦。"); |
|
|
|
|
if (selector.isWorkerRunning()) { |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("(・。・)", "安排中......\n为保证运行的稳定,此时还不能进行该操作哦。"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
NumberSettingsPaneController numberSettingsPaneController =new NumberSettingsPaneController(data); |
|
|
|
|
NumberSettingsPaneController numberSettingsPaneController = new NumberSettingsPaneController(data); |
|
|
|
|
numberSettingsPaneController.bindProperties(mainConfig); |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("调整数字",numberSettingsPaneController); |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("调整数字", numberSettingsPaneController); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Logger log= LogManager.getLogger(); |
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
|
void miniMode(ActionEvent event) { |
|
|
|
|
FXMLLoader loader=new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/MiniPane.fxml")); |
|
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/MiniPane.fxml")); |
|
|
|
|
Parent parent; |
|
|
|
|
try { |
|
|
|
|
parent=loader.load(); |
|
|
|
|
parent = loader.load(); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
log.error("Error in loading MiniPane Fxml:"+e); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Scene miniScene=new Scene(parent,300,134); |
|
|
|
|
Stage miniStage=new Stage(); |
|
|
|
|
Scene miniScene = new Scene(parent, 300, 134); |
|
|
|
|
Stage miniStage = new Stage(); |
|
|
|
|
miniStage.setScene(miniScene); |
|
|
|
|
miniStage.initStyle(StageStyle.UNDECORATED); |
|
|
|
|
|
|
|
|
|
MiniPaneController miniPaneController=loader.getController(); |
|
|
|
|
MiniPaneController miniPaneController = loader.getController(); |
|
|
|
|
miniPaneController.setBase(data, mainConfig, selector); |
|
|
|
|
|
|
|
|
|
Stage currentStage=(Stage)anPaiBtn.getScene().getWindow(); |
|
|
|
|
Stage currentStage = (Stage) anPaiBtn.getScene().getWindow(); |
|
|
|
|
miniPaneController.setOldStage(currentStage); |
|
|
|
|
|
|
|
|
|
miniPaneController.setCurrentStage(miniStage); |
|
|
|
@ -165,7 +153,7 @@ public final class MainInterfaceController { |
|
|
|
|
@FXML |
|
|
|
|
void showSettings(ActionEvent event) { |
|
|
|
|
|
|
|
|
|
SettingsPaneController settingsPaneController =new SettingsPaneController(); |
|
|
|
|
SettingsPaneController settingsPaneController = new SettingsPaneController(); |
|
|
|
|
|
|
|
|
|
settingsPaneController.setToggleGroup(); |
|
|
|
|
settingsPaneController.bindProperties(mainConfig); |
|
|
|
@ -176,27 +164,21 @@ public final class MainInterfaceController { |
|
|
|
|
|
|
|
|
|
settingsPaneController.setData(data); |
|
|
|
|
|
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("更多设置",settingsPaneController); |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("更多设置", settingsPaneController); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
|
void showHistory(ActionEvent event) { |
|
|
|
|
|
|
|
|
|
HistoryPaneController historyPaneController =new HistoryPaneController(history,rootPane); |
|
|
|
|
HistoryPaneController historyPaneController = new HistoryPaneController(history, rootPane); |
|
|
|
|
|
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("历史记录",historyPaneController); |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOneBtn("历史记录", historyPaneController); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Random random=new Random(); |
|
|
|
|
|
|
|
|
|
Data data =new Data(); |
|
|
|
|
|
|
|
|
|
Selector selector =new Selector(); |
|
|
|
|
|
|
|
|
|
public void init(){ |
|
|
|
|
public void init() { |
|
|
|
|
|
|
|
|
|
selector.initialVariable(mainConfig, data, history, upperLabel.textProperty(), downLabel.textProperty()); |
|
|
|
|
selector.addStoppedEventListener((observableValue, oldValue, stop)->{ |
|
|
|
|
selector.addStoppedEventListener((observableValue, oldValue, stop) -> { |
|
|
|
|
if (stop) { |
|
|
|
|
anPaiBtn.setText("安排一下"); |
|
|
|
|
nameChoose.setDisable(false); |
|
|
|
@ -212,42 +194,42 @@ public final class MainInterfaceController { |
|
|
|
|
@FXML |
|
|
|
|
void anPai() { |
|
|
|
|
|
|
|
|
|
if(selector.isWorkerRunning()){ |
|
|
|
|
if (selector.isWorkerRunning()) { |
|
|
|
|
selector.forceStop(); |
|
|
|
|
anPaiBtn.setText("安排一下"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(mainConfig.getRandomCount()) { |
|
|
|
|
mainConfig.setMaxTotalCount(100+random.nextInt(151)); |
|
|
|
|
if (mainConfig.getRandomCount()) { |
|
|
|
|
mainConfig.setMaxTotalCount(100 + random.nextInt(151)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(mainConfig.getNameChoose()){ |
|
|
|
|
if (mainConfig.getNameChoose()) { |
|
|
|
|
runNameMode(); |
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
runNumberMode(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setToggleGroup(){ |
|
|
|
|
ToggleGroup toggleGroup =new ToggleGroup(); |
|
|
|
|
public void setToggleGroup() { |
|
|
|
|
ToggleGroup toggleGroup = new ToggleGroup(); |
|
|
|
|
nameChoose.setToggleGroup(toggleGroup); |
|
|
|
|
numbChoose.setToggleGroup(toggleGroup); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void runNameMode(){ |
|
|
|
|
private void runNameMode() { |
|
|
|
|
|
|
|
|
|
if(data.isEmpty()){ |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("哦霍~","现在名单还是空的捏~请前往名单管理添加名字 或 使用数字挑选法。"); |
|
|
|
|
if (data.isEmpty()) { |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("哦霍~", "现在名单还是空的捏~请前往名单管理添加名字 或 使用数字挑选法。"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(data.compareNameIgnoreList() && mainConfig.getPassSelectedResult()){ |
|
|
|
|
if (data.compareNameIgnoreList() && mainConfig.getPassSelectedResult()) { |
|
|
|
|
|
|
|
|
|
if(mainConfig.getEqualMode()) { |
|
|
|
|
if (mainConfig.getEqualMode()) { |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部名字都被点完啦!\n要把名字的忽略列表重置吗?", e -> data.clearNameIgnoreList()); |
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("啊?", "全部名字都被点完啦!\n请多添加几个名字 或 点击“机会均等”的“重置”按钮。"); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
@ -258,29 +240,29 @@ public final class MainInterfaceController { |
|
|
|
|
selector.run(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void runNumberMode(){ |
|
|
|
|
private void runNumberMode() { |
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
int minNumber=Integer.parseInt(mainConfig.getMinNumber()); |
|
|
|
|
int maxNumber=Integer.parseInt(mainConfig.getMaxNumber()); |
|
|
|
|
int minNumber = Integer.parseInt(mainConfig.getMinNumber()); |
|
|
|
|
int maxNumber = Integer.parseInt(mainConfig.getMaxNumber()); |
|
|
|
|
|
|
|
|
|
if(maxNumber-minNumber <= 0){ |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("嗯哼?","数字要前小后大啊~"); |
|
|
|
|
if (maxNumber - minNumber <= 0) { |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("嗯哼?", "数字要前小后大啊~"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(data.getNumberIgnoreListSize() >= (maxNumber-minNumber+1) && mainConfig.getPassSelectedResult()){ |
|
|
|
|
if(mainConfig.getEqualMode()) { |
|
|
|
|
if (data.getNumberIgnoreListSize() >= (maxNumber - minNumber + 1) && mainConfig.getPassSelectedResult()) { |
|
|
|
|
if (mainConfig.getEqualMode()) { |
|
|
|
|
new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部数字都被点完啦!\n要把数字的忽略列表重置吗?", e -> data.clearNumberIgnoreList()); |
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("啊?", "全部数字都被点完啦!\n请扩大数字范围 或 点击“机会均等”的“重置”按钮。"); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("嗯哼?","输入个有效的数字啊~"); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
new DialogMaker(rootPane).createMessageDialog("嗯哼?", "输入个有效的数字啊~"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|