生成代码文件夹选择
This commit is contained in:
parent
26395251f8
commit
00b58e8e52
@ -1,5 +1,6 @@
|
|||||||
package ink.wgink.code.factory;
|
package ink.wgink.code.factory;
|
||||||
|
|
||||||
|
import ink.wgink.code.factory.controller.LoginController;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
@ -20,8 +21,10 @@ import javafx.stage.Stage;
|
|||||||
public class StartUp extends Application {
|
public class StartUp extends Application {
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/route/main.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/route/login.fxml"));
|
||||||
primaryStage.setScene(new Scene(fxmlLoader.load()));
|
primaryStage.setScene(new Scene(fxmlLoader.load()));
|
||||||
|
LoginController loginController = fxmlLoader.getController();
|
||||||
|
loginController.setPrimaryStage(primaryStage);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ import javafx.scene.control.TableColumn;
|
|||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
import javafx.stage.DirectoryChooser;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -70,6 +72,7 @@ public class GenerateController implements Initializable {
|
|||||||
private TableVO tableVO;
|
private TableVO tableVO;
|
||||||
private FieldService fieldService;
|
private FieldService fieldService;
|
||||||
private GenerateService generateService;
|
private GenerateService generateService;
|
||||||
|
private Stage fieldStage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
@ -130,8 +133,13 @@ public class GenerateController implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void onRefreshClick(ActionEvent actionEvent) {
|
public void onRefreshClick(ActionEvent actionEvent) throws IOException {
|
||||||
this.fieldService.showField();
|
this.fieldService.showField();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFieldStage(Stage fieldStage) {
|
||||||
|
this.fieldStage = fieldStage;
|
||||||
|
fieldService.setFieldStage(fieldStage);
|
||||||
|
generateService.setFieldStage(fieldStage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package ink.wgink.code.factory.controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: LoadingController
|
||||||
|
* @Description:
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/3/11 20:33
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
public class LoadingController {
|
||||||
|
}
|
@ -1,12 +1,20 @@
|
|||||||
package ink.wgink.code.factory.controller;
|
package ink.wgink.code.factory.controller;
|
||||||
|
|
||||||
import com.sun.javafx.robot.impl.FXRobotHelper;
|
import com.sun.javafx.robot.impl.FXRobotHelper;
|
||||||
|
import ink.wgink.code.factory.utils.MsgUtil;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.concurrent.Service;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.PasswordField;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -22,14 +30,60 @@ import java.io.IOException;
|
|||||||
**/
|
**/
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
||||||
|
public final static String DEFAULT_USERNAME = "admin";
|
||||||
|
public final static String DEFAULT_PASSWORD = "aaa111!!!";
|
||||||
@FXML
|
@FXML
|
||||||
private Button clickButton;
|
private TextField usernameField;
|
||||||
|
@FXML
|
||||||
|
private PasswordField passwordField;
|
||||||
|
private Stage primaryStage;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void onAction(ActionEvent actionEvent) throws IOException {
|
public void onLoginClick(ActionEvent actionEvent) throws IOException {
|
||||||
Scene scene = new Scene(FXMLLoader.load(getClass().getResource("/route/main.fxml")), 400, 300);
|
if (StringUtils.isBlank(usernameField.getText())) {
|
||||||
Stage stage = FXRobotHelper.getStages().get(0);
|
MsgUtil.errorAlert("用户名不能为空");
|
||||||
stage.setScene(scene);
|
return;
|
||||||
}
|
}
|
||||||
|
if (StringUtils.isBlank(passwordField.getText())) {
|
||||||
|
MsgUtil.errorAlert("密码不能为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!StringUtils.equalsIgnoreCase(DEFAULT_USERNAME, usernameField.getText())
|
||||||
|
|| !StringUtils.equals(DEFAULT_PASSWORD, passwordField.getText())) {
|
||||||
|
MsgUtil.errorAlert("用户名或密码错误");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MsgUtil.loading(primaryStage);
|
||||||
|
new Service<Integer>() {
|
||||||
|
@Override
|
||||||
|
protected Task<Integer> createTask() {
|
||||||
|
return new Task<Integer>() {
|
||||||
|
@Override
|
||||||
|
protected Integer call() throws Exception {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
primaryStage.close();
|
||||||
|
MsgUtil.closeNewLoading();
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/route/main.fxml"));
|
||||||
|
final Stage stage = new Stage();
|
||||||
|
stage.setScene(new Scene(fxmlLoader.load()));
|
||||||
|
MainController mainController = fxmlLoader.getController();
|
||||||
|
mainController.setMainStage(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPrimaryStage(Stage primaryStage) {
|
||||||
|
this.primaryStage = primaryStage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -53,6 +53,7 @@ public class MainController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private TableView dbTableTableView;
|
private TableView dbTableTableView;
|
||||||
private TableService tableService;
|
private TableService tableService;
|
||||||
|
private Stage mainStage;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +74,7 @@ public class MainController implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void onConnectDatabase(ActionEvent event) {
|
public void onConnectDatabase(ActionEvent event) throws IOException {
|
||||||
String dbUrl = dbUrlField.getText();
|
String dbUrl = dbUrlField.getText();
|
||||||
if (StringUtils.isBlank(dbUrl)) {
|
if (StringUtils.isBlank(dbUrl)) {
|
||||||
MsgUtil.errorAlert("数据库地址不能为空");
|
MsgUtil.errorAlert("数据库地址不能为空");
|
||||||
@ -99,6 +100,7 @@ public class MainController implements Initializable {
|
|||||||
MsgUtil.errorAlert("数据库密码不能为空");
|
MsgUtil.errorAlert("数据库密码不能为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tableService.connectionDatabase(dbUrl, dbPort, dbName, dbUsername, dbPassword);
|
tableService.connectionDatabase(dbUrl, dbPort, dbName, dbUsername, dbPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,4 +160,8 @@ public class MainController implements Initializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMainStage(Stage mainStage) {
|
||||||
|
this.mainStage = mainStage;
|
||||||
|
this.tableService.setMainStage(mainStage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import ink.wgink.code.factory.enums.ColumnIsNullableEnum;
|
|||||||
import ink.wgink.code.factory.enums.FormFieldTypeEnum;
|
import ink.wgink.code.factory.enums.FormFieldTypeEnum;
|
||||||
import ink.wgink.code.factory.enums.PropertyTypeEnum;
|
import ink.wgink.code.factory.enums.PropertyTypeEnum;
|
||||||
import ink.wgink.code.factory.manager.JdbcManager;
|
import ink.wgink.code.factory.manager.JdbcManager;
|
||||||
|
import ink.wgink.code.factory.utils.MsgUtil;
|
||||||
import ink.wgink.code.factory.utils.WStringUtil;
|
import ink.wgink.code.factory.utils.WStringUtil;
|
||||||
import ink.wgink.code.factory.vos.FieldVO;
|
import ink.wgink.code.factory.vos.FieldVO;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
@ -12,8 +13,10 @@ import javafx.collections.ObservableList;
|
|||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -44,6 +47,7 @@ public class FieldService {
|
|||||||
private ObservableList<FieldVO> fields = FXCollections.observableArrayList();
|
private ObservableList<FieldVO> fields = FXCollections.observableArrayList();
|
||||||
private TableView tableView;
|
private TableView tableView;
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
private Stage fieldStage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表单字段类型
|
* 表单字段类型
|
||||||
@ -89,7 +93,8 @@ public class FieldService {
|
|||||||
return PropertyTypeEnum.STRING.getValue();
|
return PropertyTypeEnum.STRING.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showField() {
|
public void showField() throws IOException {
|
||||||
|
MsgUtil.loading(fieldStage);
|
||||||
new Service<Integer>() {
|
new Service<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -133,6 +138,7 @@ public class FieldService {
|
|||||||
@Override
|
@Override
|
||||||
protected void succeeded() {
|
protected void succeeded() {
|
||||||
tableView.setItems(fields);
|
tableView.setItems(fields);
|
||||||
|
MsgUtil.closeNewLoading();
|
||||||
super.succeeded();
|
super.succeeded();
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
@ -188,4 +194,8 @@ public class FieldService {
|
|||||||
|
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFieldStage(Stage fieldStage) {
|
||||||
|
this.fieldStage = fieldStage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,16 @@ import freemarker.template.Configuration;
|
|||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
import ink.wgink.code.factory.utils.DateUtil;
|
import ink.wgink.code.factory.utils.DateUtil;
|
||||||
|
import ink.wgink.code.factory.utils.MsgUtil;
|
||||||
import ink.wgink.code.factory.utils.WStringUtil;
|
import ink.wgink.code.factory.utils.WStringUtil;
|
||||||
import ink.wgink.code.factory.vos.FieldVO;
|
import ink.wgink.code.factory.vos.FieldVO;
|
||||||
import ink.wgink.code.factory.vos.GenerateVO;
|
import ink.wgink.code.factory.vos.GenerateVO;
|
||||||
import ink.wgink.code.factory.vos.TableVO;
|
import ink.wgink.code.factory.vos.TableVO;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
|
import javafx.stage.DirectoryChooser;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@ -36,6 +40,7 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class GenerateService {
|
public class GenerateService {
|
||||||
|
|
||||||
|
private Stage fieldStage;
|
||||||
private TableView tableView;
|
private TableView tableView;
|
||||||
Configuration freemarkerConfiguration = new Configuration(Configuration.getVersion());
|
Configuration freemarkerConfiguration = new Configuration(Configuration.getVersion());
|
||||||
|
|
||||||
@ -46,7 +51,13 @@ public class GenerateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateCode(TableVO tableVO, GenerateVO generateVO) throws IOException, TemplateException {
|
public void generateCode(TableVO tableVO, GenerateVO generateVO) throws IOException, TemplateException {
|
||||||
String outFolder = "/Users/wanggeng/Desktop/UploadFiles/code/";
|
// 选择文件夹
|
||||||
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
|
File outFolderFile = directoryChooser.showDialog(fieldStage);
|
||||||
|
if (outFolderFile == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String outFolder = outFolderFile.getPath();
|
||||||
// 无前缀表名
|
// 无前缀表名
|
||||||
String tableFullName = tableVO.getTableName();
|
String tableFullName = tableVO.getTableName();
|
||||||
String tableNameWithoutPrefix = tableFullName.replaceFirst(generateVO.getTablePrefix(), "");
|
String tableNameWithoutPrefix = tableFullName.replaceFirst(generateVO.getTablePrefix(), "");
|
||||||
@ -105,6 +116,7 @@ public class GenerateService {
|
|||||||
dtoCode("/normal/pojo/dto.ftl", String.format("%s/pojo/dtos", outFolder, lowerTableName), firstUpperTableName, dataModel);
|
dtoCode("/normal/pojo/dto.ftl", String.format("%s/pojo/dtos", outFolder, lowerTableName), firstUpperTableName, dataModel);
|
||||||
poCode("/normal/pojo/po.ftl", String.format("%s/pojo/pos", outFolder, lowerTableName), firstUpperTableName, dataModel);
|
poCode("/normal/pojo/po.ftl", String.format("%s/pojo/pos", outFolder, lowerTableName), firstUpperTableName, dataModel);
|
||||||
voCode("/normal/pojo/vo.ftl", String.format("%s/pojo/vos", outFolder, lowerTableName), firstUpperTableName, dataModel);
|
voCode("/normal/pojo/vo.ftl", String.format("%s/pojo/vos", outFolder, lowerTableName), firstUpperTableName, dataModel);
|
||||||
|
MsgUtil.alert(Alert.AlertType.CONFIRMATION, "生成成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -442,4 +454,8 @@ public class GenerateService {
|
|||||||
template.process(dataModel, out);
|
template.process(dataModel, out);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFieldStage(Stage fieldStage) {
|
||||||
|
this.fieldStage = fieldStage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package ink.wgink.code.factory.service;
|
package ink.wgink.code.factory.service;
|
||||||
|
|
||||||
import ink.wgink.code.factory.manager.JdbcManager;
|
import ink.wgink.code.factory.manager.JdbcManager;
|
||||||
|
import ink.wgink.code.factory.utils.MsgUtil;
|
||||||
import ink.wgink.code.factory.vos.TableVO;
|
import ink.wgink.code.factory.vos.TableVO;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -24,6 +27,7 @@ import java.util.Map;
|
|||||||
**/
|
**/
|
||||||
public class TableService {
|
public class TableService {
|
||||||
|
|
||||||
|
private Stage mainStage;
|
||||||
private TableView dbTableTableView;
|
private TableView dbTableTableView;
|
||||||
private ObservableList<TableVO> tableVOObservableList = FXCollections.observableArrayList();
|
private ObservableList<TableVO> tableVOObservableList = FXCollections.observableArrayList();
|
||||||
|
|
||||||
@ -40,12 +44,13 @@ public class TableService {
|
|||||||
* @param dbUsername 数据库用户名
|
* @param dbUsername 数据库用户名
|
||||||
* @param dbPassword 数据库密码
|
* @param dbPassword 数据库密码
|
||||||
*/
|
*/
|
||||||
public void connectionDatabase(String dbUrl, String dbPort, String dbName, String dbUsername, String dbPassword) {
|
public void connectionDatabase(String dbUrl, String dbPort, String dbName, String dbUsername, String dbPassword) throws IOException {
|
||||||
JdbcManager.getInstance().setDatabaseInfo(dbUrl, dbPort, dbName, dbUsername, dbPassword);
|
JdbcManager.getInstance().setDatabaseInfo(dbUrl, dbPort, dbName, dbUsername, dbPassword);
|
||||||
showTable();
|
showTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showTable() {
|
private void showTable() throws IOException {
|
||||||
|
MsgUtil.loading(mainStage);
|
||||||
new Service<Integer>() {
|
new Service<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
protected Task<Integer> createTask() {
|
protected Task<Integer> createTask() {
|
||||||
@ -69,12 +74,15 @@ public class TableService {
|
|||||||
@Override
|
@Override
|
||||||
protected void succeeded() {
|
protected void succeeded() {
|
||||||
dbTableTableView.setItems(tableVOObservableList);
|
dbTableTableView.setItems(tableVOObservableList);
|
||||||
|
MsgUtil.closeNewLoading();
|
||||||
super.succeeded();
|
super.succeeded();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMainStage(Stage mainStage) {
|
||||||
|
this.mainStage = mainStage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,11 @@ import javafx.beans.property.ReadOnlyStringProperty;
|
|||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import javafx.concurrent.Worker;
|
import javafx.concurrent.Worker;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.geometry.Rectangle2D;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.Alert.AlertType;
|
import javafx.scene.control.Alert.AlertType;
|
||||||
@ -19,11 +22,13 @@ import javafx.scene.layout.HBox;
|
|||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
|
import javafx.stage.Screen;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.StageStyle;
|
import javafx.stage.StageStyle;
|
||||||
|
|
||||||
import javax.xml.soap.Text;
|
import javax.xml.soap.Text;
|
||||||
import java.util.Stack;
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
@ -37,6 +42,8 @@ import java.util.Stack;
|
|||||||
**/
|
**/
|
||||||
public class MsgUtil {
|
public class MsgUtil {
|
||||||
|
|
||||||
|
public final static List<Stage> LOADING_LIST = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误
|
* 错误
|
||||||
*
|
*
|
||||||
@ -53,7 +60,6 @@ public class MsgUtil {
|
|||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
public static void alert(Alert.AlertType alertType, String msg) {
|
public static void alert(Alert.AlertType alertType, String msg) {
|
||||||
|
|
||||||
Alert alert = new Alert(alertType, msg, ButtonType.CLOSE);
|
Alert alert = new Alert(alertType, msg, ButtonType.CLOSE);
|
||||||
alert.setTitle("提示");
|
alert.setTitle("提示");
|
||||||
alert.getDialogPane().setPrefWidth(150);
|
alert.getDialogPane().setPrefWidth(150);
|
||||||
@ -61,63 +67,43 @@ public class MsgUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提醒
|
* 等待
|
||||||
*
|
*
|
||||||
* @param msg
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void msg(final String msg) {
|
public static void loading(Stage parentStage) throws IOException {
|
||||||
HBox hBox = new HBox();
|
FXMLLoader fxmlLoader = new FXMLLoader(MsgUtil.class.getResource("/route/loading.fxml"));
|
||||||
hBox.setPadding(new Insets(5, 5, 5, 5));
|
Stage stage = new Stage(StageStyle.TRANSPARENT);
|
||||||
hBox.setAlignment(Pos.CENTER);
|
stage.setScene(new Scene(fxmlLoader.load()));
|
||||||
|
stage.initModality(Modality.APPLICATION_MODAL);
|
||||||
Label label = new Label(msg);
|
stage.setAlwaysOnTop(true);
|
||||||
label.setId("msgLabel");
|
if (parentStage != null) {
|
||||||
hBox.getChildren().add(label);
|
stage.setX(parentStage.getX() + (parentStage.getWidth() - 200) / 2);
|
||||||
Stage stage = new Stage(StageStyle.UNDECORATED);
|
stage.setY(parentStage.getY() + (parentStage.getHeight() - 100) / 2);
|
||||||
stage.setScene(new Scene(hBox));
|
}
|
||||||
stage.show();
|
stage.show();
|
||||||
|
LOADING_LIST.add(0, stage);
|
||||||
// Platform.runLater(() -> {
|
|
||||||
// // 子线程更新主线程UI的代码
|
|
||||||
// stage.close();
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
|
|
||||||
// 这种方式提倡,call中编写代码,successed方法中填写刷新UI的操作,
|
|
||||||
Service<String> service = new Service<String>() {
|
|
||||||
@Override
|
|
||||||
protected Task<String> createTask() {
|
|
||||||
return new Task<String>() {
|
|
||||||
@Override
|
|
||||||
protected String call() throws Exception {
|
|
||||||
Thread.sleep(2000);
|
|
||||||
return "success";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
protected void scheduled() {
|
* 关闭最新的Loading
|
||||||
// 任务开始, 填写刷新UI的操作
|
*/
|
||||||
super.scheduled();
|
public static void closeNewLoading() {
|
||||||
|
if (LOADING_LIST.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOADING_LIST.get(0).close();
|
||||||
|
LOADING_LIST.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
protected void running() {
|
* 关闭全部Loading
|
||||||
// 任务执行
|
*/
|
||||||
super.running();
|
public static void closeAllLoading() {
|
||||||
}
|
for (Stage stage : LOADING_LIST) {
|
||||||
|
|
||||||
// 任务成功之后,关闭提示
|
|
||||||
@Override
|
|
||||||
protected void succeeded() {
|
|
||||||
// 任务执行成功
|
|
||||||
stage.close();
|
stage.close();
|
||||||
super.succeeded();
|
|
||||||
}
|
}
|
||||||
};
|
LOADING_LIST.clear();
|
||||||
}
|
|
||||||
};
|
|
||||||
service.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
BIN
src/main/resources/assets/images/loading.gif
Normal file
BIN
src/main/resources/assets/images/loading.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 187 KiB |
22
src/main/resources/route/loading.fxml
Normal file
22
src/main/resources/route/loading.fxml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.image.*?>
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<AnchorPane prefHeight="100.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ink.wgink.code.factory.controller.LoadingController">
|
||||||
|
<children>
|
||||||
|
<HBox layoutX="200.0" layoutY="150.0" prefHeight="100.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<children>
|
||||||
|
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../assets/images/loading.gif" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
@ -10,40 +10,64 @@
|
|||||||
|
|
||||||
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ink.wgink.code.factory.controller.LoginController">
|
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ink.wgink.code.factory.controller.LoginController">
|
||||||
<children>
|
<children>
|
||||||
<GridPane alignment="CENTER" hgap="5.0" layoutX="200.0" layoutY="140.0" vgap="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<BorderPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<center>
|
||||||
|
<GridPane alignment="CENTER" hgap="10.0" vgap="10.0" BorderPane.alignment="CENTER">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="10.0" prefWidth="49.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="10.0" prefWidth="49.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="158.0" minWidth="10.0" prefWidth="151.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="205.0" minWidth="10.0" prefWidth="181.0" />
|
||||||
</columnConstraints>
|
</columnConstraints>
|
||||||
<rowConstraints>
|
<rowConstraints>
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
<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>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="4">
|
<Label alignment="CENTER" prefWidth="50.0" style="-fx-font-weight: bold;" text="用户名" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
|
||||||
<children>
|
<GridPane.margin>
|
||||||
<Button mnemonicParsing="false" onAction="#onAction" text="点击" />
|
<Insets />
|
||||||
|
</GridPane.margin>
|
||||||
|
</Label>
|
||||||
|
<Label alignment="CENTER" prefWidth="50.0" style="-fx-font-weight: bold;" text="密 码" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
|
||||||
|
<TextField fx:id="usernameField" alignment="CENTER" prefHeight="23.0" prefWidth="116.0" promptText="输入用户名" style="-fx-font-weight: bold;" text="admin" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
|
<PasswordField fx:id="passwordField" alignment="CENTER" promptText="输入密码" style="-fx-font-weight: bold;" text="aaa111!!!" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
<opaqueInsets>
|
||||||
<Label text="用户名" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />
|
<Insets />
|
||||||
<Label text="密码" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
|
</opaqueInsets>
|
||||||
<TextField prefHeight="23.0" prefWidth="116.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
<padding>
|
||||||
<PasswordField GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
<Insets left="10.0" right="10.0" />
|
||||||
<Label text="欢迎" GridPane.columnIndex="1">
|
</padding>
|
||||||
|
</GridPane>
|
||||||
|
</center>
|
||||||
|
<top>
|
||||||
|
<HBox BorderPane.alignment="CENTER">
|
||||||
|
<children>
|
||||||
|
<Label alignment="CENTER" prefWidth="230.0" style="-fx-font-weight: bold; -fx-font-size: 20px;" text="欢迎使用3.0代码生成器">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="20.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
<Insets left="15.0" right="15.0" top="15.0" />
|
||||||
</padding>
|
</padding>
|
||||||
<opaqueInsets>
|
</HBox>
|
||||||
|
</top>
|
||||||
|
<bottom>
|
||||||
|
<HBox BorderPane.alignment="CENTER">
|
||||||
|
<children>
|
||||||
|
<Button mnemonicParsing="false" onAction="#onLoginClick" prefWidth="230.0" text="登 录">
|
||||||
|
<HBox.margin>
|
||||||
<Insets />
|
<Insets />
|
||||||
</opaqueInsets>
|
</HBox.margin>
|
||||||
</GridPane>
|
</Button>
|
||||||
|
</children>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
|
||||||
|
</padding>
|
||||||
|
</HBox>
|
||||||
|
</bottom>
|
||||||
|
</BorderPane>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
Loading…
Reference in New Issue
Block a user