可携带数据跳转
1. 新增可携带数据跳转的功能 2. 完善README 3. 修改示例
This commit is contained in:
205
README.en.md
205
README.en.md
@@ -32,7 +32,6 @@ Language: [中文](README.md)
|
|||||||
- [Specification](#specification)
|
- [Specification](#specification)
|
||||||
- [How to Use](#how-to-use)
|
- [How to Use](#how-to-use)
|
||||||
- [Example Code](#example-code)
|
- [Example Code](#example-code)
|
||||||
- [Deficiencies](#deficiencies)
|
|
||||||
|
|
||||||
[How to Use JavaFX-Plus](#how-to-use-javafX-plus)
|
[How to Use JavaFX-Plus](#how-to-use-javafX-plus)
|
||||||
|
|
||||||
@@ -452,58 +451,117 @@ In JavaFX application, we always need to switch between multiple windows, such a
|
|||||||
|
|
||||||
#### Specification
|
#### Specification
|
||||||
|
|
||||||
The JavaFX-Plus stipulates that if we need an annotated with `@FXRedirect` method to handle redirection, the return value must be Stirng property and return the name of registered Controller. For example, if we need redirecting to login success interface whose conttroller named SuccessController, we should write `return "SuccessController"` in the method handling redirection.
|
The JavaFX-Plus stipulates that if we need an annotated with `@FXRedirect` method to handle redirection, the return value must be Stirng property or FXRedirectParam class, which all should provide the name of registered Controller. For example, if we need redirecting to login success interface whose controller named SuccessController, we should write `return "SuccessController"` in the method handling redirection. But the way above had not transfer data to anothor stage. If we need to transfer data to anothor stage, we should return url or FXRedirectParam, the usage has follows:
|
||||||
|
|
||||||
#### How to Use
|
#### How to Use
|
||||||
|
|
||||||
1. The usage of annotation `FXRedirect` as shown follows:
|
1. The usage of annotation `FXRedirect` as shown follows:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@FXRedirect
|
@FXRedirect
|
||||||
public String redirectToRegister() {
|
public String redirectToRegister() {
|
||||||
return "RegisterController";
|
return "RegisterController";
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@FXRedirect(close = false)
|
@FXRedirect(close = false) //test popup
|
||||||
public String redirectToDialog() {
|
public String redirectToDialog() {
|
||||||
return "DialogController";
|
return "DialogController";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //redirect to success page with query url
|
||||||
|
public String redirectToSuccessWithQuery() {
|
||||||
|
return "SuccessController?username=" + usernameTF.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //redirect to success page with param
|
||||||
|
public FXRedirectParam redirectToSuccessWithParam() {
|
||||||
|
//SuccessController is the name of controller which is redirected to
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController");
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //redirect to success page with query and param
|
||||||
|
public FXRedirectParam redirectToSuccessWithAll() {
|
||||||
|
//SuccessController is the name of controller which is redirected to
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController");
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
params.addQuery("token", new Date().toString());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The boolean value of close marks that if close the current window, and the default value is true, which means that the current window will be closed when redirecting to anothor window.
|
The boolean value of close marks that if close the current window, and the default value is true, which means that the current window will be closed when redirecting to anothor window.
|
||||||
|
|
||||||
|
If we need to transform data to another controller when redirecting to it, we can choose to return URL string, for example `return "SuccessController?name=JavaFX&password=Plus"`, or return class `FXRedirectParam` provided by JavaFX-Plus, with this way, we can choose addParam() or addQuery to transform parameters data according to your needs.
|
||||||
|
|
||||||
2. Create the login Controller
|
2. Create the login Controller
|
||||||
|
|
||||||
```java
|
1. Firstly, we design an API of data which transforms from LoginController to SuccessController, which as follows:
|
||||||
@FXController(path = "redirectDemo/login.fxml")
|
|
||||||
@FXWindow(title = "redirectDemo", mainStage = true)
|
|
||||||
public class LoginController extends FXBaseController {
|
|
||||||
|
|
||||||
@FXML
|
```java
|
||||||
private TextField usernameTF;
|
username: the name of user to login
|
||||||
|
password: the password of user to login
|
||||||
|
token: a token to login
|
||||||
|
```
|
||||||
|
|
||||||
@FXML
|
The example code :
|
||||||
private PasswordField passwordPF;
|
|
||||||
|
|
||||||
@FXML
|
```java
|
||||||
public void registerClick() {
|
@FXController(path = "redirectDemo/login.fxml")
|
||||||
redirectToRegister();
|
@FXWindow(title = "redirectDemo", mainStage = true)
|
||||||
}
|
public class LoginController extends FXBaseController {
|
||||||
|
@FXML
|
||||||
@FXRedirect
|
private TextField usernameTF;
|
||||||
public String redirectToRegister() {
|
@FXML
|
||||||
return "RegisterController";
|
private PasswordField passwordPF;
|
||||||
}
|
|
||||||
|
@FXML
|
||||||
@FXML
|
public void registerClick() { //click the "register" button
|
||||||
@FXRedirect(close = false)
|
redirectToRegister();
|
||||||
public String redirectToDialog() {
|
}
|
||||||
return "DialogController";
|
|
||||||
}
|
@FXRedirect
|
||||||
}
|
public String redirectToRegister() { //redirect to register page
|
||||||
|
return "RegisterController";
|
||||||
```
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect(close = false) //popup
|
||||||
|
public String redirectToDialog() {
|
||||||
|
return "DialogController";
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //redirect to success page with query url
|
||||||
|
public String redirectToSuccessWithQuery() {
|
||||||
|
return "SuccessController?username=" + usernameTF.getText() + "&password=" + passwordPF.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //redirect to success page with param
|
||||||
|
public FXRedirectParam redirectToSuccessWithParam() {
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController");
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
params.addParam("password", passwordPF.getText());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //redirect to success page with query and param
|
||||||
|
public FXRedirectParam redirectToSuccessWithAll() {
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController");
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
params.addParam("password", passwordPF.getText());
|
||||||
|
params.addQuery("token", new Date().toString());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
3. Design the Controller which will be redirected to.
|
3. Design the Controller which will be redirected to.
|
||||||
|
|
||||||
@@ -513,8 +571,10 @@ The JavaFX-Plus stipulates that if we need an annotated with `@FXRedirect` metho
|
|||||||
public class RegisterController extends FXBaseController {
|
public class RegisterController extends FXBaseController {
|
||||||
@FXML
|
@FXML
|
||||||
private TextField usernameTF;
|
private TextField usernameTF;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField emailTF;
|
private TextField emailTF;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PasswordField passwordPF;
|
private PasswordField passwordPF;
|
||||||
|
|
||||||
@@ -523,7 +583,14 @@ The JavaFX-Plus stipulates that if we need an annotated with `@FXRedirect` metho
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void registerClick() {
|
public void registerClick() {
|
||||||
|
if (validate()) { //validate(): validate that if a user can register
|
||||||
|
UserEntity userEntity = new UserEntity();
|
||||||
|
userEntity.setUsername(usernameTF.getText());
|
||||||
|
userEntity.setPassword(passwordPF.getText());
|
||||||
|
userEntity.setEmail(emailTF.getText());
|
||||||
|
// TODO register
|
||||||
|
redirectToRegisterSuccess(userEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -535,6 +602,13 @@ The JavaFX-Plus stipulates that if we need an annotated with `@FXRedirect` metho
|
|||||||
public String redirectToLogin() {
|
public String redirectToLogin() {
|
||||||
return "LoginController";
|
return "LoginController";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXRedirect
|
||||||
|
public FXRedirectParam redirectToRegisterSuccess(UserEntity userEntity) {
|
||||||
|
FXRedirectParam fxRedirectParam = new FXRedirectParam("SuccessController");
|
||||||
|
fxRedirectParam.addParam("user", userEntity);
|
||||||
|
return fxRedirectParam;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -545,7 +619,52 @@ The JavaFX-Plus stipulates that if we need an annotated with `@FXRedirect` metho
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
4. When we redirect to another controller, we need to process the data. We can override the method of `beforeShowStage` in FXBaseController, which will be revoked before the revoke of `showStage()`. FXBaseController includes `query` and `param` fields, which storage the transformed data in the redirection.
|
||||||
|
|
||||||
|
```java
|
||||||
|
@FXController(path = "redirectDemo/success.fxml")
|
||||||
|
@FXWindow(title = "success")
|
||||||
|
public class SuccessController extends FXBaseController implements Initializable {
|
||||||
|
@FXML
|
||||||
|
private Label title;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label usernameLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label passwordLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label tokenLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect
|
||||||
|
public String redirectToLogin() {
|
||||||
|
return "LoginController";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeShowStage() {
|
||||||
|
if (this.getQuery().get("showType") != null) {
|
||||||
|
String showType = (String) this.getQuery().get("showType");
|
||||||
|
if (showType.equals("1")) { //register
|
||||||
|
title.setText("Register Success");
|
||||||
|
if (this.getParam().get("user") != null) {
|
||||||
|
UserEntity userEntity = (UserEntity) this.getParam().get("user");
|
||||||
|
usernameLabel.setText(userEntity.getUsername());
|
||||||
|
passwordLabel.setText(userEntity.getPassword());
|
||||||
|
}
|
||||||
|
} else { //login ,username and password will be transformed with param
|
||||||
|
title.setText("Login Success");
|
||||||
|
if (this.getParam().size() > 1) {
|
||||||
|
usernameLabel.setText(String.valueOf(this.getParam().get("username")));
|
||||||
|
passwordLabel.setText(String.valueOf(this.getParam().get("password")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### Example Code
|
#### Example Code
|
||||||
|
|
||||||
@@ -557,11 +676,13 @@ The example code is stored at `cn.edu.scau.biubiusuisui.example.redirectDemo`, a
|
|||||||
|
|
||||||
2. popup an window as a dialog(do not close the current window)
|
2. popup an window as a dialog(do not close the current window)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
3. redirect to another window with data
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
#### Deficiencies
|
|
||||||
|
|
||||||
Currently, the JavaFX-Plus does not support the redirection to windows with data, but support redrecting to another window with nothing.
|
|
||||||
|
|
||||||
## How to Use JavaFX-Plus
|
## How to Use JavaFX-Plus
|
||||||
|
|
||||||
@@ -577,7 +698,7 @@ Currently, the JavaFX-Plus does not support the redirection to windows with data
|
|||||||
| @FXField | to mark a field in java bean marked by @FXEntity to be reflected to Property type | | |
|
| @FXField | to mark a field in java bean marked by @FXEntity to be reflected to Property type | | |
|
||||||
| @FXSender | to mark a method as sending signal method | name | not necessary, renames the signal |
|
| @FXSender | to mark a method as sending signal method | name | not necessary, renames the signal |
|
||||||
| @FXReceiver | to mark a method as receiving signal method | name | necessary, marks the subscribed signal |
|
| @FXReceiver | to mark a method as receiving signal method | name | necessary, marks the subscribed signal |
|
||||||
| @FXRedirect | to mark a method that can redirect to anthor window | close | not necessary, the boolean value marks if close current window; the return value of this method should be the name of redrecting Controller |
|
| @FXRedirect | to mark a method that can redirect to anthor window | close | not necessary, the boolean value marks if close current window; the return value of this method should be the name of redrecting Controller or FXRedirectParam class. |
|
||||||
|
|
||||||
### Two Factories and A Context
|
### Two Factories and A Context
|
||||||
|
|
||||||
|
|||||||
BIN
README.en/redirect_with_data_en.gif
Normal file
BIN
README.en/redirect_with_data_en.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 MiB |
186
README.md
186
README.md
@@ -40,7 +40,6 @@
|
|||||||
- [规定](#规定)
|
- [规定](#规定)
|
||||||
- [使用方法](#使用方法)
|
- [使用方法](#使用方法)
|
||||||
- [示例演示](#示例演示)
|
- [示例演示](#示例演示)
|
||||||
- [不足之处](#不足之处)
|
|
||||||
|
|
||||||
[框架的使用](#框架的使用)
|
[框架的使用](#框架的使用)
|
||||||
|
|
||||||
@@ -199,7 +198,6 @@ public class MainController extends FXBaseController {
|
|||||||
*/
|
*/
|
||||||
@FXReceiver(name = "TopBarController:sendToMain")
|
@FXReceiver(name = "TopBarController:sendToMain")
|
||||||
public void handleTopBar(String msg) {
|
public void handleTopBar(String msg) {
|
||||||
// TODO: 2019/12/8
|
|
||||||
// 处理导航栏的点击事件
|
// 处理导航栏的点击事件
|
||||||
outTA.appendText(msg + "\n");
|
outTA.appendText(msg + "\n");
|
||||||
}
|
}
|
||||||
@@ -474,61 +472,118 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
|
|
||||||
#### 规定
|
#### 规定
|
||||||
|
|
||||||
本框架规定,当需要使用`@FXRedirect`标记函数处理重定向时,函数必须是返回String类型的函数,且返回已注册的Controller名,如需要重定向至登录成功界面,控制器为`SuccessController`,则需要写上`return "SuccessController"。
|
本框架规定,当需要使用`@FXRedirect`标记函数处理重定向时,函数必须是返回`String`或`FXRedirectParam`类型的函数,均需要提供已注册的Controller名,例如需要重定向至登录成功界面,控制器为`SuccessController`,则需要写上`return "SuccessController"`,此时并未携带相关数据,如需携带数据可使用返回URL的方式或返回`FXRedirectParam`,参考以下用法。
|
||||||
|
|
||||||
#### 使用方法
|
#### 使用方法
|
||||||
|
|
||||||
1. `FXRedirect`注解的使用如下:
|
1. `FXRedirect`注解的使用如下:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@FXRedirect
|
@FXRedirect
|
||||||
public String redirectToRegister() {
|
public String redirectToRegister() {
|
||||||
return "RegisterController";
|
return "RegisterController";
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@FXRedirect(close = false) //测试弹窗
|
@FXRedirect(close = false) //测试弹窗
|
||||||
public String redirectToDialog() {
|
public String redirectToDialog() {
|
||||||
return "DialogController";
|
return "DialogController";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //登录成功 Query方式
|
||||||
|
public String redirectToSuccessWithQuery() {
|
||||||
|
return "SuccessController?username=" + usernameTF.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //登录成功 Param方式
|
||||||
|
public FXRedirectParam redirectToSuccessWithParam() {
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController"); //需要跳转至Controller的名称
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //登录成功 两种方式混合
|
||||||
|
public FXRedirectParam redirectToSuccessWithAll() {
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController"); //需要跳转至Controller的名称
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
params.addQuery("token", new Date().toString());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
close是标明是否需要关闭当前的窗口,默认为true,即默认当跳转另一个窗口时关闭当前窗口。
|
close是标明是否需要关闭当前的窗口,默认为true,即默认当跳转另一个窗口时关闭当前窗口。
|
||||||
|
|
||||||
|
如果需要携带数据跳转至另一窗口,可选择使用返回URL字符串,如:`return "SuccessController?name=JavaFX&password=Plus"`的形式,或返回JavaFX-Plus提供的`FXRedirectParam`类,根据数据传递方式选择addParam()或addQuery()两种方式进行添加参数数据操作。
|
||||||
|
|
||||||
2. 创建程序初始界面Controller,此处举例为登录界面
|
2. 创建程序初始界面Controller,此处举例为登录界面
|
||||||
|
|
||||||
|
首先我们设计LoginController和SuccessController之间的数据接口如下:
|
||||||
|
|
||||||
|
```java
|
||||||
|
username: 用户名
|
||||||
|
password: 用户密码
|
||||||
|
token: 令牌 //设计用于两种方式传递数据
|
||||||
|
```
|
||||||
|
|
||||||
|
代码如下:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@FXController(path = "redirectDemo/login.fxml")
|
@FXController(path = "redirectDemo/login.fxml")
|
||||||
@FXWindow(title = "redirectDemo", mainStage = true)
|
@FXWindow(title = "redirectDemo", mainStage = true)
|
||||||
public class LoginController extends FXBaseController {
|
public class LoginController extends FXBaseController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField usernameTF;
|
private TextField usernameTF;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PasswordField passwordPF;
|
private PasswordField passwordPF;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void registerClick() {
|
public void registerClick() { //点击“注册”
|
||||||
System.out.println("点击注册.....");
|
|
||||||
redirectToRegister();
|
redirectToRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXRedirect
|
@FXRedirect
|
||||||
public String redirectToRegister() {
|
public String redirectToRegister() { //重定向至注册界面
|
||||||
return "RegisterController";
|
return "RegisterController";
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@FXRedirect(close = false) //测试弹窗
|
@FXRedirect(close = false) //弹窗
|
||||||
public String redirectToDialog() {
|
public String redirectToDialog() {
|
||||||
return "DialogController";
|
return "DialogController";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //登录成功 Query方式
|
||||||
|
public String redirectToSuccessWithQuery() {
|
||||||
|
return "SuccessController?username=" + usernameTF.getText() + "&password=" + passwordPF.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect //登录成功 Param方式
|
||||||
|
public FXRedirectParam redirectToSuccessWithParam() {
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController");
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
params.addParam("password", passwordPF.getText());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect
|
||||||
|
public FXRedirectParam redirectToSuccessWithAll() {
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController");
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
params.addParam("password", passwordPF.getText());
|
||||||
|
params.addQuery("token", new Date().toString());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. 编写需要跳转的界面Controller,比如登录时,尚无账号跳转至注册界面和测试弹窗的Controller
|
3. 编写需要跳转的界面Controller,比如登录时,尚无账号跳转至注册界面(不弹窗)和测试弹窗的Controller
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@FXController(path = "redirectDemo/register.fxml")
|
@FXController(path = "redirectDemo/register.fxml")
|
||||||
@@ -536,8 +591,10 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
public class RegisterController extends FXBaseController {
|
public class RegisterController extends FXBaseController {
|
||||||
@FXML
|
@FXML
|
||||||
private TextField usernameTF;
|
private TextField usernameTF;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField emailTF;
|
private TextField emailTF;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PasswordField passwordPF;
|
private PasswordField passwordPF;
|
||||||
|
|
||||||
@@ -546,7 +603,14 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void registerClick() {
|
public void registerClick() {
|
||||||
|
if (validate()) { //validate()为校验能否注册函数
|
||||||
|
UserEntity userEntity = new UserEntity();
|
||||||
|
userEntity.setUsername(usernameTF.getText());
|
||||||
|
userEntity.setPassword(passwordPF.getText());
|
||||||
|
userEntity.setEmail(emailTF.getText());
|
||||||
|
// TODO 注册操作
|
||||||
|
redirectToRegisterSuccess(userEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -558,6 +622,13 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
public String redirectToLogin() {
|
public String redirectToLogin() {
|
||||||
return "LoginController";
|
return "LoginController";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXRedirect
|
||||||
|
public FXRedirectParam redirectToRegisterSuccess(UserEntity userEntity) {
|
||||||
|
FXRedirectParam fxRedirectParam = new FXRedirectParam("SuccessController");
|
||||||
|
fxRedirectParam.addParam("user", userEntity);
|
||||||
|
return fxRedirectParam;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -568,7 +639,52 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
4. 在携带数据跳转至另一Controller后,需要对传入数据进行处理,此时需要重写FXBaseController中的`beforeShowStage()`函数,此函数将在某一Controller的`showStage()`之前执行,即在Controller显示之前进行处理数据等相关操作。FXBaseController中包含`query`和`param`两个属性,用于存储重定向中的传递数据。
|
||||||
|
|
||||||
|
```java
|
||||||
|
@FXController(path = "redirectDemo/success.fxml")
|
||||||
|
@FXWindow(title = "success")
|
||||||
|
public class SuccessController extends FXBaseController implements Initializable {
|
||||||
|
@FXML
|
||||||
|
private Label title;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label usernameLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label passwordLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label tokenLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect
|
||||||
|
public String redirectToLogin() {
|
||||||
|
return "LoginController";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeShowStage() {
|
||||||
|
if (this.getQuery().get("showType") != null) {
|
||||||
|
String showType = (String) this.getQuery().get("showType");
|
||||||
|
if (showType.equals("1")) { //注册
|
||||||
|
title.setText("注册成功");
|
||||||
|
if (this.getParam().get("user") != null) {
|
||||||
|
UserEntity userEntity = (UserEntity) this.getParam().get("user");
|
||||||
|
usernameLabel.setText(userEntity.getUsername());
|
||||||
|
passwordLabel.setText(userEntity.getPassword());
|
||||||
|
}
|
||||||
|
} else { //登录 ,登录时username和password以param方式传递
|
||||||
|
title.setText("登录成功");
|
||||||
|
if (this.getParam().size() > 1) {
|
||||||
|
usernameLabel.setText(String.valueOf(this.getParam().get("username")));
|
||||||
|
passwordLabel.setText(String.valueOf(this.getParam().get("password")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### 示例演示
|
#### 示例演示
|
||||||
|
|
||||||
@@ -582,26 +698,28 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
#### 不足之处
|
3. 携带数据跳转窗口
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
暂未实现携带数据的窗口跳转,目前只实现纯粹跳转到另一个Controller。
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 框架的使用
|
## 框架的使用
|
||||||
### 内置注解
|
### 内置注解
|
||||||
|
|
||||||
| 名字 | 作用 | 参数 | 备注 |
|
| 名字 | 作用 | 参数 | 备注 |
|
||||||
| ------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ---------------------------------------- |
|
| ------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
|
||||||
| @FXData | 标明这个普通bean要装配成javafxBean | fx_id | 重新命名 |
|
| @FXData | 标明这个普通bean要装配成javafxBean | fx_id | 重新命名 |
|
||||||
| @FXScan | 扫描@FXEntity和@FXController注解标记的类 | 要扫描的目录 | 默认值是当前目录之下所有 |
|
| @FXScan | 扫描@FXEntity和@FXController注解标记的类 | 要扫描的目录 | 默认值是当前目录之下所有 |
|
||||||
| @FXController | 标记这个类为控件 | path:fxml文件地址 | 无 |
|
| @FXController | 标记这个类为控件 | path:fxml文件地址 | 无 |
|
||||||
| @FXWindow | 标记这个控件要以单独窗口显示 | 1. title 设置窗口名字<br/>2. mainStage 标记是否为主舞台<br/>3. preHeight, preWidth 预设长宽度<br/>4. minHeight, minWidth 最小长宽度<br/>5. resizable, draggable 设置可拉伸可拖拽<br/>6. style 设置StageStyle | 无 |
|
| @FXWindow | 标记这个控件要以单独窗口显示 | 1. title 设置窗口名字<br/>2. mainStage 标记是否为主舞台<br/>3. preHeight, preWidth 预设长宽度<br/>4. minHeight, minWidth 最小长宽度<br/>5. resizable, draggable 设置可拉伸可拖拽<br/>6. style 设置StageStyle | 无 |
|
||||||
| @FXEntity | 标记JavaBean系统会自动识别@FXField然后包装JavaBean为JavaFXBean | 重命名 | |
|
| @FXEntity | 标记JavaBean系统会自动识别@FXField然后包装JavaBean为JavaFXBean | 重命名 | |
|
||||||
| @FXField | 代表这个属性要映射为Property属性 | | |
|
| @FXField | 代表这个属性要映射为Property属性 | | |
|
||||||
| @FXSender | 信号发送者 | name:重命名信号 | |
|
| @FXSender | 信号发送者 | name:重命名信号 | |
|
||||||
| @FXReceiver | 信号接收函数 | name:订阅的发射者函数名 | 不可空 |
|
| @FXReceiver | 信号接收函数 | name:订阅的发射者函数名 | 不可空 |
|
||||||
| @FXRedirect | 标记函数为重定向函数 | close:是否关闭当前窗口 | 返回值为某个使用了FXView注解的Controller |
|
| @FXRedirect | 标记函数为重定向函数 | close:是否关闭当前窗口 | 返回值为某个使用了FXView注解的Controller名或JavaFX-Plus提供的FXRedirectParam类 |
|
||||||
|
|
||||||
### 两个工厂和一个context
|
### 两个工厂和一个context
|
||||||
|
|
||||||
|
|||||||
BIN
README/image-20200407003220469.png
Normal file
BIN
README/image-20200407003220469.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
BIN
README/redirect_with_data.gif
Normal file
BIN
README/redirect_with_data.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 MiB |
@@ -1159,7 +1159,7 @@ public class FXMLLoaderPlus {
|
|||||||
if (fields != null) {
|
if (fields != null) {
|
||||||
try {
|
try {
|
||||||
for (Field f : fields) {
|
for (Field f : fields) {
|
||||||
if(baseController!=null) {
|
if (baseController != null) {
|
||||||
f.set(baseController, value);
|
f.set(baseController, value);
|
||||||
}
|
}
|
||||||
f.set(controller, value);
|
f.set(controller, value);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import cn.edu.scau.biubiusuisui.factory.FXBuilder;
|
|||||||
import cn.edu.scau.biubiusuisui.factory.FXControllerFactory;
|
import cn.edu.scau.biubiusuisui.factory.FXControllerFactory;
|
||||||
import cn.edu.scau.biubiusuisui.function.FXWindowParser;
|
import cn.edu.scau.biubiusuisui.function.FXWindowParser;
|
||||||
import cn.edu.scau.biubiusuisui.utils.ClassUtils;
|
import cn.edu.scau.biubiusuisui.utils.ClassUtils;
|
||||||
import javafx.application.Application;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -22,7 +21,7 @@ public class FXPlusApplication {
|
|||||||
|
|
||||||
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
|
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
|
||||||
|
|
||||||
private static BeanBuilder DEFALUT_BEAN_FACTORY = new FXBuilder();
|
private static BeanBuilder DEFAULT_BEAN_FACTORY = new FXBuilder();
|
||||||
|
|
||||||
private static BeanBuilder beanBuilder;
|
private static BeanBuilder beanBuilder;
|
||||||
|
|
||||||
@@ -56,7 +55,7 @@ public class FXPlusApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void start(Class clazz) {
|
public static void start(Class clazz) {
|
||||||
start(clazz, DEFALUT_BEAN_FACTORY);
|
start(clazz, DEFAULT_BEAN_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadFXPlusClass(String className, BeanBuilder beanBuilder) throws ClassNotFoundException {
|
private static void loadFXPlusClass(String className, BeanBuilder beanBuilder) throws ClassNotFoundException {
|
||||||
|
|||||||
@@ -4,12 +4,16 @@ import cn.edu.scau.biubiusuisui.annotation.FXController;
|
|||||||
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
||||||
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
|
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
|
||||||
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
|
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
|
||||||
|
import cn.edu.scau.biubiusuisui.exception.NotFXWindowException;
|
||||||
import cn.edu.scau.biubiusuisui.utils.StringUtils;
|
import cn.edu.scau.biubiusuisui.utils.StringUtils;
|
||||||
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author jack
|
* @Author jack
|
||||||
@@ -31,6 +35,14 @@ public class FXBaseController extends Pane {
|
|||||||
private boolean isController = false;
|
private boolean isController = false;
|
||||||
private boolean isWindow = false;
|
private boolean isWindow = false;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: yangsuiyu
|
||||||
|
* @Descriptions: 用于携带信息数据
|
||||||
|
*/
|
||||||
|
private Map<String, Object> query = new HashMap<>();
|
||||||
|
private Map<String, Object> param = new HashMap<>();
|
||||||
|
|
||||||
public FXBaseController(String name) {
|
public FXBaseController(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@@ -40,6 +52,7 @@ public class FXBaseController extends Pane {
|
|||||||
Annotation[] annotations = getClass().getAnnotations();
|
Annotation[] annotations = getClass().getAnnotations();
|
||||||
// Find FXController cn.edu.scau.biubiusuisui.annotation
|
// Find FXController cn.edu.scau.biubiusuisui.annotation
|
||||||
for (Annotation annotation : annotations) {
|
for (Annotation annotation : annotations) {
|
||||||
|
// 是否Controller
|
||||||
if (annotation.annotationType().equals(FXController.class)) {
|
if (annotation.annotationType().equals(FXController.class)) {
|
||||||
fxController = (FXController) annotation;
|
fxController = (FXController) annotation;
|
||||||
isController = true;
|
isController = true;
|
||||||
@@ -55,7 +68,6 @@ public class FXBaseController extends Pane {
|
|||||||
fxmlLoader.setRoot(this);
|
fxmlLoader.setRoot(this);
|
||||||
fxmlLoader.setController(this);
|
fxmlLoader.setController(this);
|
||||||
fxmlLoader.setShow(true);
|
fxmlLoader.setShow(true);
|
||||||
// System.out.println("?");
|
|
||||||
try {
|
try {
|
||||||
fxmlLoader.load();
|
fxmlLoader.load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -68,12 +80,21 @@ public class FXBaseController extends Pane {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在显示Stage之前的操作
|
||||||
|
*/
|
||||||
|
public void beforeShowStage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 唤起舞台
|
* 唤起舞台
|
||||||
*/
|
*/
|
||||||
public void showStage() {
|
public void showStage() {
|
||||||
|
this.beforeShowStage();
|
||||||
if (isWindow) {
|
if (isWindow) {
|
||||||
this.stage.show();
|
this.stage.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +107,13 @@ public class FXBaseController extends Pane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showAndWait() {
|
||||||
|
this.beforeShowStage();
|
||||||
|
if (isWindow) {
|
||||||
|
this.stage.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if ("".equals(name) || name == null) { // 原本无“name == null”判断条件,会出错
|
if ("".equals(name) || name == null) { // 原本无“name == null”判断条件,会出错
|
||||||
return StringUtils.getBaseClassName(getClass().getSimpleName());
|
return StringUtils.getBaseClassName(getClass().getSimpleName());
|
||||||
@@ -122,4 +150,19 @@ public class FXBaseController extends Pane {
|
|||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getQuery() {
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getParam() {
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuery(Map<String, Object> query) {
|
||||||
|
this.query = query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParam(Map<String, Object> param) {
|
||||||
|
this.param = param;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class FXPlusContext {
|
|||||||
private static Map<Object, FXEntityProxy> beanMap = new ConcurrentHashMap<>(); // Object注册为FXEntityObject
|
private static Map<Object, FXEntityProxy> beanMap = new ConcurrentHashMap<>(); // Object注册为FXEntityObject
|
||||||
|
|
||||||
|
|
||||||
public static void addController(FXBaseController fxBaseController) {
|
public static void registerController(FXBaseController fxBaseController) {
|
||||||
List<FXBaseController> controllers = controllerContext.get(fxBaseController.getName());
|
List<FXBaseController> controllers = controllerContext.get(fxBaseController.getName());
|
||||||
if (controllers == null) {
|
if (controllers == null) {
|
||||||
controllers = new LinkedList<>();
|
controllers = new LinkedList<>();
|
||||||
@@ -33,9 +33,6 @@ public class FXPlusContext {
|
|||||||
controllers.add(fxBaseController);
|
controllers.add(fxBaseController);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<FXBaseController> getControllers(String key) {
|
|
||||||
return controllerContext.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FXEntityProxy getProxyByBeanObject(Object object) {
|
public static FXEntityProxy getProxyByBeanObject(Object object) {
|
||||||
return beanMap.get(object);
|
return beanMap.get(object);
|
||||||
@@ -45,6 +42,10 @@ public class FXPlusContext {
|
|||||||
beanMap.put(object, fxEntityProxy);
|
beanMap.put(object, fxEntityProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<FXBaseController> getControllers(String key) {
|
||||||
|
return controllerContext.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
public static Property getEntityPropertyByName(Object object, String fieldName) {
|
public static Property getEntityPropertyByName(Object object, String fieldName) {
|
||||||
return getProxyByBeanObject(object).getPropertyByFieldName(fieldName);
|
return getProxyByBeanObject(object).getPropertyByFieldName(fieldName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package cn.edu.scau.biubiusuisui.entity;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author suiyu_yang
|
||||||
|
* @description 跳转窗口携带的参数
|
||||||
|
* @date 2020/4/6 18:06
|
||||||
|
* @email suiyu_yang@163.com
|
||||||
|
*/
|
||||||
|
public class FXRedirectParam {
|
||||||
|
private String toController;
|
||||||
|
private Map<String, Object> query = new HashMap<>();
|
||||||
|
private Map<String, Object> params = new HashMap<>();
|
||||||
|
|
||||||
|
public FXRedirectParam(String toController) {
|
||||||
|
this.toController = toController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToController() {
|
||||||
|
return toController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToController(String toController) {
|
||||||
|
this.toController = toController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getQueryMap() {
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addParam(String key, Object param) {
|
||||||
|
this.params.put(key, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getParam(String key) {
|
||||||
|
return this.params.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addQuery(String key, Object param) {
|
||||||
|
this.query.put(key, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getOneQuery(String key) {
|
||||||
|
return this.query.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,16 +2,13 @@ package cn.edu.scau.biubiusuisui.example.bindDemo;
|
|||||||
|
|
||||||
import cn.edu.scau.biubiusuisui.annotation.FXBind;
|
import cn.edu.scau.biubiusuisui.annotation.FXBind;
|
||||||
import cn.edu.scau.biubiusuisui.annotation.FXController;
|
import cn.edu.scau.biubiusuisui.annotation.FXController;
|
||||||
import cn.edu.scau.biubiusuisui.annotation.FXData;
|
|
||||||
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
||||||
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.PasswordField;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -38,18 +35,34 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private Label userPswLabel;
|
private Label userPswLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label ageLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label enableLabel;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField usernameTF;
|
private TextField usernameTF;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PasswordField pswPF;
|
private PasswordField pswPF;
|
||||||
|
|
||||||
@FXData
|
@FXML
|
||||||
@FXBind({
|
private TextField ageTF;
|
||||||
"name=${usernameTF.text}",
|
|
||||||
"password=${pswPF.text}"
|
@FXML
|
||||||
})
|
private ToggleGroup enableButtons;
|
||||||
private User user = new User();
|
|
||||||
|
//
|
||||||
|
// @FXData
|
||||||
|
// @FXBind({
|
||||||
|
// "name=${usernameTF.text}",
|
||||||
|
// "password=${pswPF.text}",
|
||||||
|
// "age=${ageTF.text}",
|
||||||
|
// "isEnable=${enableButtons.getSelectedToggle().getUserData()}"
|
||||||
|
// })
|
||||||
|
// private User user = new User();
|
||||||
|
private UserPropertyEntity user = new UserPropertyEntity();
|
||||||
|
|
||||||
// View bind to Expression
|
// View bind to Expression
|
||||||
@FXML
|
@FXML
|
||||||
@@ -67,10 +80,29 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
@FXBind("text=${@toUk(money.text)}")
|
@FXBind("text=${@toUk(money.text)}")
|
||||||
private Label uk;
|
private Label uk;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
money.setText("0");
|
||||||
|
money.textProperty().addListener(new ChangeListener<String>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||||
|
if (null == newValue || "".equals(newValue)) {
|
||||||
|
money.setText("0");
|
||||||
|
} else if (!newValue.matches("^[0-9]*$")) {
|
||||||
|
money.setText(oldValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void clickToShowInfo() {
|
public void clickToShowInfo() {
|
||||||
|
RadioButton button = (RadioButton) enableButtons.getSelectedToggle();
|
||||||
|
System.out.println(button.getText());
|
||||||
usernameLabel.setText(user.getName());
|
usernameLabel.setText(user.getName());
|
||||||
userPswLabel.setText(user.getPassword());
|
userPswLabel.setText(user.getPassword());
|
||||||
|
ageLabel.setText(Integer.toString(user.getAge()));
|
||||||
|
enableLabel.setText(Boolean.toString(user.getEnable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toUs(String value) {
|
public String toUs(String value) {
|
||||||
@@ -91,18 +123,4 @@ public class MainController extends FXBaseController implements Initializable {
|
|||||||
return String.valueOf(money * percent);
|
return String.valueOf(money * percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
|
||||||
money.setText("0");
|
|
||||||
money.textProperty().addListener(new ChangeListener<String>() {
|
|
||||||
@Override
|
|
||||||
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
|
||||||
if (null == newValue || "".equals(newValue)) {
|
|
||||||
money.setText("0");
|
|
||||||
} else if (!newValue.matches("^[0-9]*$")) {
|
|
||||||
money.setText(oldValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package cn.edu.scau.biubiusuisui.example.bindDemo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author suiyu_yang
|
||||||
|
* @description 详细信息
|
||||||
|
* @date 2020/4/6 00:29
|
||||||
|
* @email suiyu_yang@163.com
|
||||||
|
*/
|
||||||
|
public class Profile {
|
||||||
|
private String birthday;
|
||||||
|
private String address;
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
public String getBirthday() {
|
||||||
|
return birthday;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBirthday(String birthday) {
|
||||||
|
this.birthday = birthday;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAvatar() {
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvatar(String avatar) {
|
||||||
|
this.avatar = avatar;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,11 @@ package cn.edu.scau.biubiusuisui.example.bindDemo;
|
|||||||
import cn.edu.scau.biubiusuisui.annotation.FXEntity;
|
import cn.edu.scau.biubiusuisui.annotation.FXEntity;
|
||||||
import cn.edu.scau.biubiusuisui.annotation.FXField;
|
import cn.edu.scau.biubiusuisui.annotation.FXField;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author jack
|
* @Author yangsuiyu
|
||||||
* @Date:2019/7/27 12:19
|
* @Date:2020/4/5 12:19
|
||||||
*/
|
*/
|
||||||
@FXEntity
|
@FXEntity
|
||||||
public class User {
|
public class User {
|
||||||
@@ -13,6 +15,16 @@ public class User {
|
|||||||
private String name;
|
private String name;
|
||||||
@FXField
|
@FXField
|
||||||
private String password;
|
private String password;
|
||||||
|
@FXField
|
||||||
|
private Integer age;
|
||||||
|
@FXField
|
||||||
|
private List<Double> scores;
|
||||||
|
@FXField
|
||||||
|
private Double gpa;//平均分
|
||||||
|
@FXField
|
||||||
|
private Profile profile;
|
||||||
|
@FXField
|
||||||
|
private boolean isEnable;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@@ -29,4 +41,46 @@ public class User {
|
|||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(Integer age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Double> getScores() {
|
||||||
|
return scores;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addScore(double score) {
|
||||||
|
this.scores.add(score);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Profile getProfile() {
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfile(Profile profile) {
|
||||||
|
this.profile = profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnable() {
|
||||||
|
return isEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnable(boolean enable) {
|
||||||
|
isEnable = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getGpa() {
|
||||||
|
double sum = 0;
|
||||||
|
for (double score : scores) {
|
||||||
|
sum += score;
|
||||||
|
}
|
||||||
|
gpa = sum / scores.size();
|
||||||
|
return gpa;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package cn.edu.scau.biubiusuisui.example.bindDemo;
|
||||||
|
|
||||||
|
import javafx.beans.property.*;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author suiyu_yang
|
||||||
|
* @description User的JavaFXBean
|
||||||
|
* @date 2020/4/6 14:30
|
||||||
|
* @email suiyu_yang@163.com
|
||||||
|
*/
|
||||||
|
public class UserPropertyEntity {
|
||||||
|
private SimpleStringProperty name;
|
||||||
|
private SimpleStringProperty password;
|
||||||
|
private SimpleIntegerProperty age;
|
||||||
|
private SimpleListProperty<Double> scores;
|
||||||
|
private SimpleDoubleProperty gpa;//平均分
|
||||||
|
private SimpleObjectProperty<Profile> profile;
|
||||||
|
private SimpleBooleanProperty enable;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty nameProperty() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name.set(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty passwordProperty() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password.set(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleIntegerProperty ageProperty() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(int age) {
|
||||||
|
this.age.set(age);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableList<Double> getScores() {
|
||||||
|
return scores.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleListProperty<Double> scoresProperty() {
|
||||||
|
return scores;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScores(ObservableList<Double> scores) {
|
||||||
|
this.scores.set(scores);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getGpa() {
|
||||||
|
return gpa.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleDoubleProperty gpaProperty() {
|
||||||
|
return gpa;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGpa(double gpa) {
|
||||||
|
this.gpa.set(gpa);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Profile getProfile() {
|
||||||
|
return profile.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleObjectProperty<Profile> profileProperty() {
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfile(Profile profile) {
|
||||||
|
this.profile.set(profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getEnable() {
|
||||||
|
return enable.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleBooleanProperty enableProperty() {
|
||||||
|
return enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnable(boolean enable) {
|
||||||
|
this.enable.set(enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,9 +10,9 @@ import javafx.stage.Stage;
|
|||||||
* @Date:2019/7/27 1:43
|
* @Date:2019/7/27 1:43
|
||||||
*/
|
*/
|
||||||
@FXScan(base = "cn.edu.scau.biubiusuisui.example.listDemo")
|
@FXScan(base = "cn.edu.scau.biubiusuisui.example.listDemo")
|
||||||
public class Demo extends Application {
|
public class ListDemo extends Application {
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
FXPlusApplication.start(Demo.class);
|
FXPlusApplication.start(ListDemo.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author jack
|
* @Author jack
|
||||||
@@ -35,7 +36,7 @@ public class MainController extends FXBaseController {
|
|||||||
user.addNames("Jack\t" + (count++));
|
user.addNames("Jack\t" + (count++));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList toList(ArrayList list) {
|
public ObservableList toList(List list) {
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.edu.scau.biubiusuisui.annotation.FXEntity;
|
|||||||
import cn.edu.scau.biubiusuisui.annotation.FXField;
|
import cn.edu.scau.biubiusuisui.annotation.FXField;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author jack
|
* @Author jack
|
||||||
@@ -18,7 +19,7 @@ public class User {
|
|||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@FXField
|
@FXField
|
||||||
private ArrayList<String> names = new ArrayList<>();
|
private List<String> names = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public User() {
|
public User() {
|
||||||
@@ -47,7 +48,7 @@ public class User {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getNames() {
|
public List<String> getNames() {
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ public class MainController extends FXBaseController {
|
|||||||
*/
|
*/
|
||||||
@FXReceiver(name = "TopBarController:sendToMain")
|
@FXReceiver(name = "TopBarController:sendToMain")
|
||||||
public void handleTopBar(String msg) {
|
public void handleTopBar(String msg) {
|
||||||
// TODO: 2019/12/8
|
|
||||||
// 处理导航栏的点击事件
|
// 处理导航栏的点击事件
|
||||||
outTA.appendText(msg + "\n");
|
outTA.appendText(msg + "\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,15 @@ import cn.edu.scau.biubiusuisui.annotation.FXController;
|
|||||||
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
|
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
|
||||||
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
||||||
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
||||||
|
import cn.edu.scau.biubiusuisui.entity.FXRedirectParam;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.PasswordField;
|
import javafx.scene.control.PasswordField;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author suiyu_yang
|
* @author suiyu_yang
|
||||||
* @description
|
* @description
|
||||||
@@ -41,9 +46,30 @@ public class LoginController extends FXBaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@FXRedirect //登录成功
|
@FXRedirect //登录成功 Query方式
|
||||||
public String redirectToSuccess() {
|
public String redirectToSuccessWithQuery() {
|
||||||
|
return "SuccessController?showType=0&username=" + usernameTF.getText() + "&password=" + passwordPF.getText();
|
||||||
|
}
|
||||||
|
|
||||||
return "SuccessController";
|
@FXML
|
||||||
|
@FXRedirect //登录成功 Param方式
|
||||||
|
public FXRedirectParam redirectToSuccessWithParam() {
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController");
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
params.addParam("password", passwordPF.getText());
|
||||||
|
params.addQuery("showType", "0");
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
@FXRedirect
|
||||||
|
public FXRedirectParam redirectToSuccessWithAll() {
|
||||||
|
FXRedirectParam params = new FXRedirectParam("SuccessController");
|
||||||
|
params.addParam("username", usernameTF.getText());
|
||||||
|
params.addParam("password", passwordPF.getText());
|
||||||
|
|
||||||
|
params.addQuery("token", new Date().toString());
|
||||||
|
params.addQuery("showType", "0");
|
||||||
|
return params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.edu.scau.biubiusuisui.annotation.FXController;
|
|||||||
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
|
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
|
||||||
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
||||||
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
||||||
|
import cn.edu.scau.biubiusuisui.entity.FXRedirectParam;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.PasswordField;
|
import javafx.scene.control.PasswordField;
|
||||||
@@ -23,6 +24,7 @@ public class RegisterController extends FXBaseController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField emailTF;
|
private TextField emailTF;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PasswordField passwordPF;
|
private PasswordField passwordPF;
|
||||||
|
|
||||||
@@ -36,8 +38,8 @@ public class RegisterController extends FXBaseController {
|
|||||||
userEntity.setUsername(usernameTF.getText());
|
userEntity.setUsername(usernameTF.getText());
|
||||||
userEntity.setPassword(passwordPF.getText());
|
userEntity.setPassword(passwordPF.getText());
|
||||||
userEntity.setEmail(emailTF.getText());
|
userEntity.setEmail(emailTF.getText());
|
||||||
|
redirectToRegisterSuccess(userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -50,6 +52,13 @@ public class RegisterController extends FXBaseController {
|
|||||||
return "LoginController";
|
return "LoginController";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXRedirect
|
||||||
|
public FXRedirectParam redirectToRegisterSuccess(UserEntity userEntity) {
|
||||||
|
FXRedirectParam fxRedirectParam = new FXRedirectParam("SuccessController");
|
||||||
|
fxRedirectParam.addQuery("showType", "1");
|
||||||
|
fxRedirectParam.addParam("user", userEntity);
|
||||||
|
return fxRedirectParam;
|
||||||
|
}
|
||||||
|
|
||||||
// 校验
|
// 校验
|
||||||
private boolean validate() {
|
private boolean validate() {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.edu.scau.biubiusuisui.annotation.FXController;
|
|||||||
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
|
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
|
||||||
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
|
||||||
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
||||||
|
import cn.edu.scau.biubiusuisui.exception.NotFXWindowException;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
@@ -21,12 +22,17 @@ import java.util.ResourceBundle;
|
|||||||
@FXWindow(title = "success")
|
@FXWindow(title = "success")
|
||||||
public class SuccessController extends FXBaseController implements Initializable {
|
public class SuccessController extends FXBaseController implements Initializable {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label title;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label usernameLabel;
|
private Label usernameLabel;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label passwordLabel;
|
private Label passwordLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label tokenLabel;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@FXRedirect
|
@FXRedirect
|
||||||
@@ -34,9 +40,35 @@ public class SuccessController extends FXBaseController implements Initializable
|
|||||||
return "LoginController";
|
return "LoginController";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeShowStage() {
|
||||||
|
if (this.getQuery().get("showType") != null) {
|
||||||
|
String showType = (String) this.getQuery().get("showType");
|
||||||
|
if (showType.equals("1")) { //注册
|
||||||
|
title.setText("注册成功");
|
||||||
|
if (this.getParam().get("user") != null) {
|
||||||
|
UserEntity userEntity = (UserEntity) this.getParam().get("user");
|
||||||
|
usernameLabel.setText(userEntity.getUsername());
|
||||||
|
passwordLabel.setText(userEntity.getPassword());
|
||||||
|
}
|
||||||
|
} else { //登录
|
||||||
|
title.setText("登录成功");
|
||||||
|
// 此处为演示多种方式数据传递才进行多次赋值,实际应用时应根据数据API进行相应的数据获取操作
|
||||||
|
if (this.getQuery().size() > 1) { //query方式传递
|
||||||
|
usernameLabel.setText(String.valueOf(this.getQuery().get("username")));
|
||||||
|
passwordLabel.setText(String.valueOf(this.getQuery().get("password")));
|
||||||
|
tokenLabel.setText(String.valueOf(this.getQuery().get("token")));
|
||||||
|
}
|
||||||
|
if (this.getParam().size() > 1) { //param方式传递
|
||||||
|
usernameLabel.setText(String.valueOf(this.getParam().get("username")));
|
||||||
|
passwordLabel.setText(String.valueOf(this.getParam().get("password")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package cn.edu.scau.biubiusuisui.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author suiyu_yang
|
||||||
|
* @description 不合法URL
|
||||||
|
* @date 2020/4/6 15:59
|
||||||
|
* @email suiyu_yang@163.com
|
||||||
|
*/
|
||||||
|
public class InvalidURLException extends Exception {
|
||||||
|
public InvalidURLException() {
|
||||||
|
super("the url is invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package cn.edu.scau.biubiusuisui.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author suiyu_yang
|
||||||
|
* @description 某Controller不是窗口
|
||||||
|
* @date 2020/4/6 17:10
|
||||||
|
* @email suiyu_yang@163.com
|
||||||
|
*/
|
||||||
|
public class NotFXWindowException extends Exception {
|
||||||
|
public NotFXWindowException() {
|
||||||
|
super("the controller is not a window");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,5 +13,4 @@ public class ChangeParser implements BindParser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ import cn.edu.scau.biubiusuisui.annotation.FXValue;
|
|||||||
import cn.edu.scau.biubiusuisui.exception.NoSuchChangeMethod;
|
import cn.edu.scau.biubiusuisui.exception.NoSuchChangeMethod;
|
||||||
import com.sun.istack.internal.NotNull;
|
import com.sun.istack.internal.NotNull;
|
||||||
import com.sun.javafx.fxml.expression.Expression;
|
import com.sun.javafx.fxml.expression.Expression;
|
||||||
import com.sun.javafx.fxml.expression.VariableExpression;
|
|
||||||
import javafx.beans.property.Property;
|
import javafx.beans.property.Property;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将FXBind中表达式建立绑定
|
* 将FXBind中表达式建立绑定
|
||||||
@@ -24,7 +22,7 @@ import java.util.NoSuchElementException;
|
|||||||
* expression -> bean.field
|
* expression -> bean.field
|
||||||
* <p>
|
* <p>
|
||||||
* FXBind("text=${bean.field})
|
* FXBind("text=${bean.field})
|
||||||
* textProperty 通过 adapter.getModelProeprty --> textProperty实例
|
* textProperty 通过 adapter.getModelProperty --> textProperty实例
|
||||||
* bean 通过namespace 获取,因为bean有FXEntity标签,所以返回包装过后的bean的property
|
* bean 通过namespace 获取,因为bean有FXEntity标签,所以返回包装过后的bean的property
|
||||||
* 最后
|
* 最后
|
||||||
* left.bind(right)
|
* left.bind(right)
|
||||||
@@ -60,7 +58,7 @@ public class ExpressionParser {
|
|||||||
|
|
||||||
private static final String FUNCTION_PREFIX = "@";
|
private static final String FUNCTION_PREFIX = "@";
|
||||||
|
|
||||||
private MyExpressionValue getRightExpreesion(MyBeanAdapter myBeanAdapter, String key, String rightExpression) {
|
private MyExpressionValue getRightExpression(MyBeanAdapter myBeanAdapter, String key, String rightExpression) {
|
||||||
Expression expression = null;
|
Expression expression = null;
|
||||||
if (rightExpression.startsWith(FUNCTION_PREFIX)) {
|
if (rightExpression.startsWith(FUNCTION_PREFIX)) {
|
||||||
expression = getFunctionExpression(rightExpression);
|
expression = getFunctionExpression(rightExpression);
|
||||||
@@ -75,27 +73,27 @@ public class ExpressionParser {
|
|||||||
private Expression getFunctionExpression(String rightExpression) {
|
private Expression getFunctionExpression(String rightExpression) {
|
||||||
Expression expression = null;
|
Expression expression = null;
|
||||||
int indexLeft = rightExpression.indexOf("(");
|
int indexLeft = rightExpression.indexOf("(");
|
||||||
String methodName = rightExpression.substring(1,indexLeft);
|
String methodName = rightExpression.substring(1, indexLeft);
|
||||||
int indexRight = rightExpression.indexOf(")");
|
int indexRight = rightExpression.indexOf(")");
|
||||||
String argString = rightExpression.substring(indexLeft + 1, indexRight);
|
String argString = rightExpression.substring(indexLeft + 1, indexRight);
|
||||||
String[] args = null;
|
String[] args = null;
|
||||||
if(!"".equals(argString.trim())) {
|
if (!"".equals(argString.trim())) {
|
||||||
args = argString.split(",");
|
args = argString.split(",");
|
||||||
}
|
}
|
||||||
Class clazz = targetController.getClass();
|
Class targetClazz = targetController.getClass();
|
||||||
Method[] methods = clazz.getMethods();
|
Method[] methods = targetClazz.getMethods();
|
||||||
Expression[] expressions = null;
|
Expression[] expressionArgs = null;
|
||||||
if(args!=null) {
|
if (args != null) {
|
||||||
expressions = new Expression[args.length];
|
expressionArgs = new Expression[args.length];
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if (!"".equals(args[i].trim())) {
|
if (!"".equals(args[i].trim())) {
|
||||||
expressions[i] = Expression.valueOf(args[i]);
|
expressionArgs[i] = Expression.valueOf(args[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
if (method.getName().equals(methodName)) {
|
if (method.getName().equals(methodName)) {
|
||||||
expression = new FunctionExpression(method, targetController, expressions);
|
expression = new FunctionExpression(method, targetController, expressionArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return expression;
|
return expression;
|
||||||
@@ -120,7 +118,7 @@ public class ExpressionParser {
|
|||||||
ExpressionType expressionType;
|
ExpressionType expressionType;
|
||||||
if (right.startsWith(BIND_PREFIX) && right.endsWith(BIND_SUFIX)) {
|
if (right.startsWith(BIND_PREFIX) && right.endsWith(BIND_SUFIX)) {
|
||||||
int length = right.length();
|
int length = right.length();
|
||||||
right = right.substring(2, length - 1);
|
right = right.substring(2, length - 1); //已经去掉“${”的表达式
|
||||||
expressionType = ExpressionType.DataExpression;
|
expressionType = ExpressionType.DataExpression;
|
||||||
} else {
|
} else {
|
||||||
right = right.substring(1); //#changeMethod -> changeMethod
|
right = right.substring(1); //#changeMethod -> changeMethod
|
||||||
@@ -133,12 +131,16 @@ public class ExpressionParser {
|
|||||||
bindDataExpression(left, right, myBeanAdapter, leftProperty);
|
bindDataExpression(left, right, myBeanAdapter, leftProperty);
|
||||||
break;
|
break;
|
||||||
case ActionExpression:
|
case ActionExpression:
|
||||||
//
|
|
||||||
bindActionExpression(right, leftProperty);
|
bindActionExpression(right, leftProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param right
|
||||||
|
* @param leftProperty
|
||||||
|
* @throws NoSuchChangeMethod
|
||||||
|
* @Description 鼠标事件或键盘事件绑定
|
||||||
|
*/
|
||||||
private void bindActionExpression(String right, Property leftProperty) throws NoSuchChangeMethod {
|
private void bindActionExpression(String right, Property leftProperty) throws NoSuchChangeMethod {
|
||||||
Class clazz = targetController.getClass();
|
Class clazz = targetController.getClass();
|
||||||
Method[] methods = clazz.getMethods();
|
Method[] methods = clazz.getMethods();
|
||||||
@@ -158,8 +160,15 @@ public class ExpressionParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param left
|
||||||
|
* @param right
|
||||||
|
* @param myBeanAdapter
|
||||||
|
* @param leftProperty
|
||||||
|
* @Description 数据绑定
|
||||||
|
*/
|
||||||
private void bindDataExpression(String left, String right, MyBeanAdapter myBeanAdapter, Property leftProperty) {
|
private void bindDataExpression(String left, String right, MyBeanAdapter myBeanAdapter, Property leftProperty) {
|
||||||
MyExpressionValue rightProperty = getRightExpreesion(myBeanAdapter, left, right);
|
MyExpressionValue rightProperty = getRightExpression(myBeanAdapter, left, right);
|
||||||
leftProperty.bind(rightProperty);
|
leftProperty.bind(rightProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ public class FunctionExpression extends Expression {
|
|||||||
|
|
||||||
private Method method;
|
private Method method;
|
||||||
private Object target;
|
private Object target;
|
||||||
private Expression []args;
|
private Expression[] args;
|
||||||
|
|
||||||
public FunctionExpression(Method method, Object target, Expression[]expressions) {
|
public FunctionExpression(Method method, Object target, Expression[] expressions) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.args = expressions;
|
this.args = expressions;
|
||||||
@@ -27,7 +27,7 @@ public class FunctionExpression extends Expression {
|
|||||||
@Override
|
@Override
|
||||||
public List<KeyPath> getArguments() {
|
public List<KeyPath> getArguments() {
|
||||||
List<KeyPath> list = new ArrayList<>();
|
List<KeyPath> list = new ArrayList<>();
|
||||||
if(args !=null) {
|
if (args != null) {
|
||||||
for (Expression expression : args) {
|
for (Expression expression : args) {
|
||||||
list.addAll(expression.getArguments());
|
list.addAll(expression.getArguments());
|
||||||
}
|
}
|
||||||
@@ -38,9 +38,9 @@ public class FunctionExpression extends Expression {
|
|||||||
@Override
|
@Override
|
||||||
public Object evaluate(Object namespace) {
|
public Object evaluate(Object namespace) {
|
||||||
Object result = null;
|
Object result = null;
|
||||||
if(args!=null){
|
if (args != null) {
|
||||||
Object[] values = new Object[args.length];
|
Object[] values = new Object[args.length];
|
||||||
for(int i = 0 ;i<args.length;i++){
|
for (int i = 0; i < args.length; i++) {
|
||||||
values[i] = args[i].evaluate(namespace);
|
values[i] = args[i].evaluate(namespace);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -51,7 +51,7 @@ public class FunctionExpression extends Expression {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}else{
|
} else {
|
||||||
try {
|
try {
|
||||||
result = method.invoke(target);
|
result = method.invoke(target);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MyExpressionValue extends ObservableValueBase<Object> {
|
public class MyExpressionValue extends ObservableValueBase<Object> {
|
||||||
|
|
||||||
// Monitors a namespace for changes along a key path
|
// Monitors a namespace for changes along a key path
|
||||||
private class KeyPathMonitor {
|
private class KeyPathMonitor {
|
||||||
@@ -70,9 +70,9 @@ public class MyExpressionValue extends ObservableValueBase<Object> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void monitor(Object namespace) {
|
public void monitor(Object namespace) {
|
||||||
if (namespace instanceof ObservableList<?>) {
|
if (namespace instanceof ObservableList<?>) {
|
||||||
((ObservableList<Object>)namespace).addListener(listChangeListener);
|
((ObservableList<Object>) namespace).addListener(listChangeListener);
|
||||||
} else if (namespace instanceof ObservableMap<?, ?>) {
|
} else if (namespace instanceof ObservableMap<?, ?>) {
|
||||||
((ObservableMap<String, Object>)namespace).addListener(mapChangeListener);
|
((ObservableMap<String, Object>) namespace).addListener(mapChangeListener);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
MyBeanAdapter namespaceAdapter = new MyBeanAdapter(namespace);
|
MyBeanAdapter namespaceAdapter = new MyBeanAdapter(namespace);
|
||||||
@@ -98,11 +98,11 @@ public class MyExpressionValue extends ObservableValueBase<Object> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void unmonitor() {
|
public void unmonitor() {
|
||||||
if (namespace instanceof ObservableList<?>) {
|
if (namespace instanceof ObservableList<?>) {
|
||||||
((ObservableList<Object>)namespace).removeListener(listChangeListener);
|
((ObservableList<Object>) namespace).removeListener(listChangeListener);
|
||||||
} else if (namespace instanceof ObservableMap<?, ?>) {
|
} else if (namespace instanceof ObservableMap<?, ?>) {
|
||||||
((ObservableMap<String, Object>)namespace).removeListener(mapChangeListener);
|
((ObservableMap<String, Object>) namespace).removeListener(mapChangeListener);
|
||||||
} else if (namespace != null) {
|
} else if (namespace != null) {
|
||||||
MyBeanAdapter namespaceAdapter = (MyBeanAdapter)namespace;
|
MyBeanAdapter namespaceAdapter = (MyBeanAdapter) namespace;
|
||||||
ObservableValue<Object> propertyModel = namespaceAdapter.getPropertyModel(key);
|
ObservableValue<Object> propertyModel = namespaceAdapter.getPropertyModel(key);
|
||||||
|
|
||||||
if (propertyModel != null) {
|
if (propertyModel != null) {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import java.net.URL;
|
|||||||
*/
|
*/
|
||||||
public class FXControllerFactory {
|
public class FXControllerFactory {
|
||||||
|
|
||||||
|
|
||||||
private static final BeanBuilder BEAN_BUILDER = new FXBuilder();
|
private static final BeanBuilder BEAN_BUILDER = new FXBuilder();
|
||||||
private static FXWindowParser fxWindowAnnotationParser = new FXWindowParser();
|
private static FXWindowParser fxWindowAnnotationParser = new FXWindowParser();
|
||||||
|
|
||||||
@@ -136,18 +135,18 @@ public class FXControllerFactory {
|
|||||||
* @param fxBaseControllerProxy 代理对象
|
* @param fxBaseControllerProxy 代理对象
|
||||||
*/
|
*/
|
||||||
private static void register(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
|
private static void register(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
|
||||||
FXPlusContext.addController(fxBaseController); //保存
|
FXPlusContext.registerController(fxBaseController); //保存
|
||||||
MessageQueue.getInstance().registerConsumer(fxBaseController, fxBaseControllerProxy); // 添加进入消息队列 信号功能
|
MessageQueue.getInstance().registerConsumer(fxBaseController, fxBaseControllerProxy); // 添加进入消息队列 信号功能
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为有FXWindow注解的类创建Stage
|
|
||||||
*
|
|
||||||
* @param fxWindow
|
* @param fxWindow
|
||||||
|
* @param clazz
|
||||||
* @param fxBaseControllerProxy
|
* @param fxBaseControllerProxy
|
||||||
* @return
|
* @return
|
||||||
|
* @Description 为有FXWindow注解的类创建Stage
|
||||||
*/
|
*/
|
||||||
private static Stage createWindow(FXWindow fxWindow, FXBaseController fxBaseControllerProxy) {
|
private static Stage createWindow(FXWindow fxWindow, Class clazz, FXBaseController fxBaseControllerProxy) {
|
||||||
Stage stage = new Stage();
|
Stage stage = new Stage();
|
||||||
fxBaseControllerProxy.setStage(stage);
|
fxBaseControllerProxy.setStage(stage);
|
||||||
double preWidth = fxWindow.preWidth() == 0 ? fxBaseControllerProxy.getPrefWidth() : fxWindow.preWidth();
|
double preWidth = fxWindow.preWidth() == 0 ? fxBaseControllerProxy.getPrefWidth() : fxWindow.preWidth();
|
||||||
@@ -156,9 +155,8 @@ public class FXControllerFactory {
|
|||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
fxWindowAnnotationParser.parse(stage, fxBaseControllerProxy, fxWindow);
|
fxWindowAnnotationParser.parse(stage, fxBaseControllerProxy, fxWindow);
|
||||||
|
|
||||||
StageManager.getInstance().registerWindow(fxBaseControllerProxy); //注册舞台
|
StageManager.getInstance().registerWindow(clazz, fxBaseControllerProxy); //注册舞台
|
||||||
if (fxWindow.mainStage() == true) { //当是主舞台时,先show为敬
|
if (fxWindow.mainStage() == true) { //当是主舞台时,先show为敬
|
||||||
// System.out.println("FXControllerFactory: "+(fxControllerProxy.getStage() == null));
|
|
||||||
fxBaseControllerProxy.showStage();
|
fxBaseControllerProxy.showStage();
|
||||||
}
|
}
|
||||||
return stage;
|
return stage;
|
||||||
@@ -206,7 +204,7 @@ public class FXControllerFactory {
|
|||||||
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
|
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
|
||||||
if (fxWindow != null) {
|
if (fxWindow != null) {
|
||||||
FXBaseController fxController = getFXController(clazz, null, BEAN_BUILDER);
|
FXBaseController fxController = getFXController(clazz, null, BEAN_BUILDER);
|
||||||
return createWindow(fxWindow, fxController);
|
return createWindow(fxWindow, clazz, fxController);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -216,7 +214,7 @@ public class FXControllerFactory {
|
|||||||
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
|
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
|
||||||
if (fxWindow != null) {
|
if (fxWindow != null) {
|
||||||
FXBaseController fxController = getFXController(clazz, null, beanBuilder);
|
FXBaseController fxController = getFXController(clazz, null, beanBuilder);
|
||||||
return createWindow(fxWindow, fxController);
|
return createWindow(fxWindow, clazz, fxController);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -226,7 +224,7 @@ public class FXControllerFactory {
|
|||||||
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
|
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
|
||||||
if (fxWindow != null) {
|
if (fxWindow != null) {
|
||||||
FXBaseController fxController = getFXController(clazz, controllerName, BEAN_BUILDER);
|
FXBaseController fxController = getFXController(clazz, controllerName, BEAN_BUILDER);
|
||||||
return createWindow(fxWindow, fxController);
|
return createWindow(fxWindow, clazz, fxController);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -236,7 +234,7 @@ public class FXControllerFactory {
|
|||||||
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
|
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
|
||||||
if (fxWindow != null) {
|
if (fxWindow != null) {
|
||||||
FXBaseController fxController = getFXController(clazz, controllerName, beanBuilder);
|
FXBaseController fxController = getFXController(clazz, controllerName, beanBuilder);
|
||||||
return createWindow(fxWindow, fxController);
|
return createWindow(fxWindow, clazz, fxController);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,22 +37,33 @@ public class FXEntityFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param object 被转换的对象
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static Object wrapFXBean(Object object) {
|
public static Object wrapFXBean(Object object) {
|
||||||
FXEntityProxy fxEntityProxy = new FXEntityProxy();
|
FXEntityProxy fxEntityProxy = new FXEntityProxy();
|
||||||
Object objectProxy = null;
|
Object proxyObject = null;
|
||||||
try {
|
try {
|
||||||
objectProxy = fxEntityProxy.getInstance(object); // 初始化代理类
|
proxyObject = fxEntityProxy.getInstance(object); // 初始化代理类
|
||||||
processFXEntityProxyFields(object, objectProxy, fxEntityProxy); //处理FXEntity上的@FXField
|
processFXEntityProxyFields(object, proxyObject, fxEntityProxy); //处理FXEntity上的@FXField
|
||||||
FXPlusContext.setProxyByBeanObject(objectProxy, fxEntityProxy);
|
FXPlusContext.setProxyByBeanObject(proxyObject, fxEntityProxy);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return objectProxy;
|
return proxyObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processFXEntityProxyFields(Object entity, Object proxy, FXEntityProxy fxEntityProxy) throws IllegalAccessException {
|
/**
|
||||||
|
* @param entityObject 被转换的原Entity对象
|
||||||
|
* @param proxyObject 被转换对象的FXEntityProxy对象
|
||||||
|
* @param fxEntityProxy 被转换对象的FXEntityProxy类
|
||||||
|
* @throws IllegalAccessException
|
||||||
|
* @Description 处理FXEntity中的FXField注解,1. 添加监听 2.赋值FXEntityProxy中的fxFieldWrapperMap
|
||||||
|
*/
|
||||||
|
private static void processFXEntityProxyFields(Object entityObject, Object proxyObject, FXEntityProxy fxEntityProxy) throws IllegalAccessException {
|
||||||
Map<String, FXFieldWrapper> fxFieldWrapperMap = new HashMap<>();
|
Map<String, FXFieldWrapper> fxFieldWrapperMap = new HashMap<>();
|
||||||
Field[] fields = entity.getClass().getDeclaredFields();
|
Field[] fields = entityObject.getClass().getDeclaredFields();
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
Annotation annotation = ClassUtils.getAnnotationInList(FXField.class, field.getDeclaredAnnotations());
|
Annotation annotation = ClassUtils.getAnnotationInList(FXField.class, field.getDeclaredAnnotations());
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
@@ -60,17 +71,19 @@ public class FXEntityFactory {
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
FXField fxField = (FXField) annotation;
|
FXField fxField = (FXField) annotation;
|
||||||
FXFieldWrapper fieldWrapper = new FXFieldWrapper(fxField, field.getType());
|
FXFieldWrapper fieldWrapper = new FXFieldWrapper(fxField, field.getType());
|
||||||
if (field.get(entity) == null) {
|
if (field.get(entityObject) == null) { //没有初始值
|
||||||
property = getFieldDefaultProperty(field);
|
property = getFieldDefaultProperty(field);
|
||||||
} else {
|
} else { //有初始值
|
||||||
property = getFieldProperty(entity, field);
|
property = getFieldProperty(entityObject, field);
|
||||||
}
|
}
|
||||||
if (property != null) {
|
if (property != null) {
|
||||||
|
// 监听
|
||||||
property.addListener((object, oldVal, newVal) -> {
|
property.addListener((object, oldVal, newVal) -> {
|
||||||
if (!fxField.readOnly()) {
|
if (!fxField.readOnly()) {
|
||||||
|
// 判断field.getType()是否为List类型
|
||||||
if (!List.class.isAssignableFrom(field.getType())) {
|
if (!List.class.isAssignableFrom(field.getType())) {
|
||||||
try {
|
try {
|
||||||
field.set(proxy, newVal);
|
field.set(proxyObject, newVal);//赋值
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -78,18 +91,24 @@ public class FXEntityFactory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// 设置属性
|
||||||
fieldWrapper.setProperty(property);
|
fieldWrapper.setProperty(property);
|
||||||
fxFieldWrapperMap.put(field.getName(), fieldWrapper);
|
fxFieldWrapperMap.put(field.getName(), fieldWrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fxEntityProxy.setFxFieldWrapperMap(fxFieldWrapperMap);
|
fxEntityProxy.setFXFieldWrapperMap(fxFieldWrapperMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
private static Property getFieldProperty(Object object, Field field) throws IllegalAccessException {
|
* @param entityObject
|
||||||
|
* @param field
|
||||||
|
* @return
|
||||||
|
* @throws IllegalAccessException
|
||||||
|
* @Description 某一属性中有初始值时
|
||||||
|
*/
|
||||||
|
private static Property getFieldProperty(Object entityObject, Field field) throws IllegalAccessException {
|
||||||
Class type = field.getType();
|
Class type = field.getType();
|
||||||
Object value = field.get(object);
|
Object value = field.get(entityObject);
|
||||||
|
|
||||||
Property property = null;
|
Property property = null;
|
||||||
|
|
||||||
if (Boolean.class.equals(type) || boolean.class.equals(type)) {
|
if (Boolean.class.equals(type) || boolean.class.equals(type)) {
|
||||||
@@ -100,7 +119,7 @@ public class FXEntityFactory {
|
|||||||
property = new SimpleFloatProperty((Float) value);
|
property = new SimpleFloatProperty((Float) value);
|
||||||
} else if (Integer.class.equals(type) || int.class.equals(type)) {
|
} else if (Integer.class.equals(type) || int.class.equals(type)) {
|
||||||
property = new SimpleIntegerProperty((Integer) value);
|
property = new SimpleIntegerProperty((Integer) value);
|
||||||
} else if (Long.class.equals(type) || long.class.equals(property)) {
|
} else if (Long.class.equals(type) || long.class.equals(type)) {
|
||||||
property = new SimpleLongProperty((Long) value);
|
property = new SimpleLongProperty((Long) value);
|
||||||
} else if (String.class.equals(type)) {
|
} else if (String.class.equals(type)) {
|
||||||
property = new SimpleStringProperty((String) value);
|
property = new SimpleStringProperty((String) value);
|
||||||
@@ -112,9 +131,16 @@ public class FXEntityFactory {
|
|||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param field
|
||||||
|
* @return
|
||||||
|
* @throws IllegalAccessException
|
||||||
|
* @Description 某一属性中无初始值
|
||||||
|
*/
|
||||||
private static Property getFieldDefaultProperty(Field field) throws IllegalAccessException {
|
private static Property getFieldDefaultProperty(Field field) throws IllegalAccessException {
|
||||||
Class type = field.getType();
|
Class type = field.getType();
|
||||||
Property property = null;
|
Property property = null;
|
||||||
|
|
||||||
if (Boolean.class.equals(type) || boolean.class.equals(type)) {
|
if (Boolean.class.equals(type) || boolean.class.equals(type)) {
|
||||||
property = new SimpleBooleanProperty();
|
property = new SimpleBooleanProperty();
|
||||||
} else if (Double.class.equals(type) || double.class.equals(type)) {
|
} else if (Double.class.equals(type) || double.class.equals(type)) {
|
||||||
@@ -123,7 +149,7 @@ public class FXEntityFactory {
|
|||||||
property = new SimpleFloatProperty();
|
property = new SimpleFloatProperty();
|
||||||
} else if (Integer.class.equals(type) || int.class.equals(type)) {
|
} else if (Integer.class.equals(type) || int.class.equals(type)) {
|
||||||
property = new SimpleIntegerProperty();
|
property = new SimpleIntegerProperty();
|
||||||
} else if (Long.class.equals(type) || long.class.equals(property)) {
|
} else if (Long.class.equals(type) || long.class.equals(type)) {
|
||||||
property = new SimpleLongProperty();
|
property = new SimpleLongProperty();
|
||||||
} else if (String.class.equals(type)) {
|
} else if (String.class.equals(type)) {
|
||||||
property = new SimpleStringProperty();
|
property = new SimpleStringProperty();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import javafx.stage.Stage;
|
|||||||
/**
|
/**
|
||||||
* @Author jack
|
* @Author jack
|
||||||
* @Date:2019/6/30 10:40
|
* @Date:2019/6/30 10:40
|
||||||
|
* @Description 解析@FXWindow
|
||||||
*/
|
*/
|
||||||
public class FXWindowParser {
|
public class FXWindowParser {
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ public class FXWindowParser {
|
|||||||
|
|
||||||
stage.setTitle(fxWindow.title());
|
stage.setTitle(fxWindow.title());
|
||||||
|
|
||||||
|
// fxWindow的resizable默认为false
|
||||||
if (fxWindow.resizable()) {
|
if (fxWindow.resizable()) {
|
||||||
stage.setResizable(true);
|
stage.setResizable(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ public class MessageQueue {
|
|||||||
return messageQueue;
|
return messageQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fxBaseController
|
||||||
|
* @param fxBaseControllerProxy
|
||||||
|
* @Description 注册消费者,即FXReceiver注解的method
|
||||||
|
*/
|
||||||
public void registerConsumer(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
|
public void registerConsumer(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
|
||||||
Class clazz = fxBaseController.getClass();
|
Class clazz = fxBaseController.getClass();
|
||||||
Method[] methods = clazz.getDeclaredMethods();
|
Method[] methods = clazz.getDeclaredMethods();
|
||||||
@@ -54,6 +59,11 @@ public class MessageQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id
|
||||||
|
* @param msg
|
||||||
|
* @Description 处理消息发送,id为topic,msg为消息
|
||||||
|
*/
|
||||||
public void sendMsg(String id, Object msg) {
|
public void sendMsg(String id, Object msg) {
|
||||||
List<FXMethodEntity> lists = receivers.get(id);
|
List<FXMethodEntity> lists = receivers.get(id);
|
||||||
if (lists != null) {
|
if (lists != null) {
|
||||||
@@ -71,6 +81,7 @@ public class MessageQueue {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
// obj the object the underlying method is invoked from
|
||||||
method.invoke(fxBaseController, msg);
|
method.invoke(fxBaseController, msg);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ public class FXControllerProxy implements MethodInterceptor {
|
|||||||
|
|
||||||
public Object getInstance(FXBaseController target) {
|
public Object getInstance(FXBaseController target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
// System.out.println(target.toString());
|
|
||||||
Enhancer enhancer = new Enhancer();
|
Enhancer enhancer = new Enhancer();
|
||||||
enhancer.setSuperclass(this.target.getClass());
|
enhancer.setSuperclass(this.target.getClass());
|
||||||
enhancer.setCallback(this);
|
enhancer.setCallback(this);
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ public class FXEntityProxy implements MethodInterceptor {
|
|||||||
Object target;
|
Object target;
|
||||||
private Map<String, FXFieldWrapper> fxFieldWrapperMap;
|
private Map<String, FXFieldWrapper> fxFieldWrapperMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param target
|
||||||
|
* @return
|
||||||
|
* @Desciption 通过getInstance获取代理对象
|
||||||
|
*/
|
||||||
public Object getInstance(Object target) {
|
public Object getInstance(Object target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
Enhancer enhancer = new Enhancer();
|
Enhancer enhancer = new Enhancer();
|
||||||
@@ -30,51 +35,53 @@ public class FXEntityProxy implements MethodInterceptor {
|
|||||||
/**
|
/**
|
||||||
* intercept get and set method and
|
* intercept get and set method and
|
||||||
*
|
*
|
||||||
* @param o
|
* @param proxy cglib生成的代理对象
|
||||||
* @param method
|
* @param method 被代理对象的方法
|
||||||
* @param objects
|
* @param args 拦截的方法的入参
|
||||||
* @param methodProxy
|
* @param methodProxy 拦截方法的代理方法
|
||||||
* @return
|
* @return
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
|
* @Descripton 拦截getter, setter, del, cls, add方法
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
Object o1 = methodProxy.invokeSuper(o, objects); //获取该方法运行后的结果
|
Object revokeResult = methodProxy.invokeSuper(proxy, args); //获取该方法运行后的结果
|
||||||
String methodName = method.getName();
|
String methodName = method.getName();
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
if (methodName.length() >= 3) {
|
if (methodName.length() >= 3) {
|
||||||
fieldName = StringUtils.toInstanceName(methodName.substring(3)); // 该method有可能是getter和setter方法,进行处理
|
fieldName = StringUtils.toInstanceName(methodName.substring(3)); // 该method有可能是getter和setter方法,进行处理
|
||||||
} else {
|
} else {
|
||||||
return o1;
|
return revokeResult;
|
||||||
}
|
}
|
||||||
FXFieldWrapper fxFieldWrapper = fxFieldWrapperMap.get(fieldName);
|
FXFieldWrapper fxFieldWrapper = fxFieldWrapperMap.get(fieldName);
|
||||||
Property property = getPropertyByFieldName(fieldName);
|
Property property = getPropertyByFieldName(fieldName);
|
||||||
if (fxFieldWrapper == null || property == null) {
|
if (fxFieldWrapper == null || property == null) { //非属性的getter或setter
|
||||||
return o1;
|
return revokeResult;
|
||||||
}
|
}
|
||||||
Class type = fxFieldWrapper.getType();
|
Class type = fxFieldWrapper.getType();
|
||||||
if (methodName.startsWith("set")) {
|
if (methodName.startsWith("set")) {
|
||||||
if(Boolean.class.equals(type) || boolean.class.equals(type)){
|
if (Boolean.class.equals(type) || boolean.class.equals(type)) {
|
||||||
((SimpleBooleanProperty)property).set((Boolean)objects[0]);
|
((SimpleBooleanProperty) property).set((Boolean) args[0]);
|
||||||
}else if(Double.class.equals(type)||double.class.equals(type)){
|
} else if (Double.class.equals(type) || double.class.equals(type)) {
|
||||||
((SimpleDoubleProperty)property).set((Double)objects[0]);
|
((SimpleDoubleProperty) property).set((Double) args[0]);
|
||||||
}else if (Float.class.equals(type) || float.class.equals(type)){
|
} else if (Float.class.equals(type) || float.class.equals(type)) {
|
||||||
((SimpleFloatProperty)property).set((Float) objects[0]);
|
((SimpleFloatProperty) property).set((Float) args[0]);
|
||||||
}else if(Integer.class.equals(type) || int.class.equals(type)){
|
} else if (Integer.class.equals(type) || int.class.equals(type)) {
|
||||||
((SimpleIntegerProperty)property).set((Integer) objects[0]);
|
((SimpleIntegerProperty) property).set((Integer) args[0]);
|
||||||
}else if(Long.class.equals(type) ||long.class.equals(type)){
|
} else if (Long.class.equals(type) || long.class.equals(type)) {
|
||||||
((SimpleLongProperty)property).set((Long)objects[0]);
|
((SimpleLongProperty) property).set((Long) args[0]);
|
||||||
}else if(String.class.equals(type)){
|
} else if (String.class.equals(type)) {
|
||||||
((SimpleStringProperty)property).set((String)objects[0]);
|
((SimpleStringProperty) property).set((String) args[0]);
|
||||||
}
|
}
|
||||||
}else if (methodName.startsWith("add")){
|
} else if (methodName.startsWith("add")) {
|
||||||
((SimpleListProperty)(property)).add(objects[0]);
|
((SimpleListProperty) (property)).add(args[0]);
|
||||||
}else if(methodName.startsWith("del")){
|
} else if (methodName.startsWith("del")) {
|
||||||
((SimpleListProperty)(property)).remove(objects[0]);
|
((SimpleListProperty) (property)).remove(args[0]);
|
||||||
}else if(methodName.startsWith("cls")){
|
} else if (methodName.startsWith("cls")) {
|
||||||
((SimpleListProperty)(property)).clear();
|
((SimpleListProperty) (property)).clear();
|
||||||
}
|
}
|
||||||
return o1;
|
return revokeResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getTarget() {
|
public Object getTarget() {
|
||||||
@@ -92,11 +99,11 @@ public class FXEntityProxy implements MethodInterceptor {
|
|||||||
return fxFieldWrapperMap.get(name).getProperty();
|
return fxFieldWrapperMap.get(name).getProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, FXFieldWrapper> getFxFieldWrapperMap() {
|
public Map<String, FXFieldWrapper> getFXFieldWrapperMap() {
|
||||||
return fxFieldWrapperMap;
|
return fxFieldWrapperMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFxFieldWrapperMap(Map<String, FXFieldWrapper> fxFieldWrapperMap) {
|
public void setFXFieldWrapperMap(Map<String, FXFieldWrapper> fxFieldWrapperMap) {
|
||||||
this.fxFieldWrapperMap = fxFieldWrapperMap;
|
this.fxFieldWrapperMap = fxFieldWrapperMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package cn.edu.scau.biubiusuisui.stage;
|
package cn.edu.scau.biubiusuisui.stage;
|
||||||
|
|
||||||
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
|
||||||
|
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
|
||||||
|
import cn.edu.scau.biubiusuisui.entity.FXRedirectParam;
|
||||||
|
import cn.edu.scau.biubiusuisui.exception.InvalidURLException;
|
||||||
|
import cn.edu.scau.biubiusuisui.factory.FXControllerFactory;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@@ -14,8 +19,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class StageManager {
|
public class StageManager {
|
||||||
private static StageManager stageManager = null;
|
private static StageManager stageManager = null;
|
||||||
private static Map<String, FXBaseController> windows = new ConcurrentHashMap<>(); //
|
private static Map<String, FXBaseController> initWindows = new ConcurrentHashMap<>();
|
||||||
|
private static Map<String, Class> windowClazz = new ConcurrentHashMap<>();
|
||||||
/**
|
/**
|
||||||
* @author yangsuiyu
|
* @author yangsuiyu
|
||||||
* @description 1.2新增属性
|
* @description 1.2新增属性
|
||||||
@@ -38,22 +43,86 @@ public class StageManager {
|
|||||||
return stageManager;
|
return stageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerWindow(FXBaseController fxBaseControllerProxy) {
|
public void registerWindow(Class clazz, FXBaseController fxBaseControllerProxy) {
|
||||||
if (fxBaseControllerProxy.isWindow()) {
|
fxBaseControllerProxy.getClass().getDeclaredAnnotations();
|
||||||
windows.put(fxBaseControllerProxy.getName(), fxBaseControllerProxy);
|
initWindows.put(fxBaseControllerProxy.getName(), fxBaseControllerProxy);
|
||||||
}
|
windowClazz.put(fxBaseControllerProxy.getName(), clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeStage(String controllerName) {
|
public void closeStage(String controllerName) {
|
||||||
windows.get(controllerName).closeStage();
|
if (initWindows.get(controllerName) != null) {
|
||||||
|
initWindows.get(controllerName).closeStage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 无参数跳转
|
* @param redirectParams
|
||||||
*
|
* @Description 跳转
|
||||||
* @param controller
|
|
||||||
*/
|
*/
|
||||||
public void redirectTo(Object controller) {
|
public void redirectTo(Object redirectParams) {
|
||||||
windows.get(controller).showStage();
|
FXRedirectParam fxRedirectParam = null;
|
||||||
|
if (redirectParams instanceof String) {
|
||||||
|
if (((String) redirectParams).contains("?")) { //有参数,query return "SuccessController?name=ss&psw=111"
|
||||||
|
try {
|
||||||
|
fxRedirectParam = getQueryParamsFromURL((String) redirectParams);
|
||||||
|
} catch (InvalidURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else { //无参数 return "SuccessController"
|
||||||
|
fxRedirectParam = new FXRedirectParam((String) redirectParams);
|
||||||
|
}
|
||||||
|
} else if (redirectParams instanceof FXRedirectParam) { // return FXRedirectParam
|
||||||
|
fxRedirectParam = (FXRedirectParam) redirectParams;
|
||||||
|
}
|
||||||
|
redirectWithParams(fxRedirectParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fxRedirectParam
|
||||||
|
* @Description 携带参数跳转
|
||||||
|
*/
|
||||||
|
private void redirectWithParams(FXRedirectParam fxRedirectParam) {
|
||||||
|
if (fxRedirectParam != null) {
|
||||||
|
String toControllerStr = fxRedirectParam.getToController();
|
||||||
|
FXBaseController toController = initWindows.get(toControllerStr);
|
||||||
|
if (toController != null) {
|
||||||
|
List<FXBaseController> controllers = FXPlusContext.getControllers(toController.getName());
|
||||||
|
// if (controllers.size() > 0) {
|
||||||
|
// FXBaseController newController = controllers.get(controllers.size() - 1);
|
||||||
|
// toController = FXControllerFactory.getFXController(newController.getClass(), toControllerStr);
|
||||||
|
//// registerWindow(, toController);
|
||||||
|
// }
|
||||||
|
toController.setParam(fxRedirectParam.getParams());
|
||||||
|
toController.setQuery(fxRedirectParam.getQueryMap());
|
||||||
|
toController.showStage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RedirectController?num=10&name=suisui -> Map:{"num","10"},{"name","suisui"}
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private FXRedirectParam getQueryParamsFromURL(String url) throws InvalidURLException {
|
||||||
|
String[] items = url.split("\\?");
|
||||||
|
if (items.length != 2) {
|
||||||
|
throw new InvalidURLException();
|
||||||
|
}
|
||||||
|
String leftBase = items[0];
|
||||||
|
String paramsStr = items[1];
|
||||||
|
String[] paramsKV = paramsStr.split("&");
|
||||||
|
|
||||||
|
FXRedirectParam fxRedirectParam = new FXRedirectParam(leftBase);
|
||||||
|
for (int i = 0; i < paramsKV.length; i++) {
|
||||||
|
String params[] = paramsKV[i].split("=");
|
||||||
|
if (params.length != 2) {
|
||||||
|
throw new InvalidURLException();
|
||||||
|
} else {
|
||||||
|
fxRedirectParam.addQuery(params[0], params[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fxRedirectParam;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import javafx.beans.property.Property;
|
|||||||
/**
|
/**
|
||||||
* @Author jack
|
* @Author jack
|
||||||
* @Date:2019/7/28 1:52
|
* @Date:2019/7/28 1:52
|
||||||
|
* @Description:
|
||||||
*/
|
*/
|
||||||
public class BeanUtil {
|
public class BeanUtil {
|
||||||
public static Property getPropertyByName(Object entity, String fieldName){
|
public static Property getPropertyByName(Object entity, String fieldName) {
|
||||||
FXEntityProxy fxEntityProxy = FXPlusContext.getProxyByBeanObject(entity);
|
FXEntityProxy fxEntityProxy = FXPlusContext.getProxyByBeanObject(entity);
|
||||||
if(fxEntityProxy == null){
|
if (fxEntityProxy == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return fxEntityProxy.getFxFieldWrapperMap().get(fieldName).getProperty();
|
return fxEntityProxy.getFXFieldWrapperMap().get(fieldName).getProperty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,14 @@ package cn.edu.scau.biubiusuisui.utils;
|
|||||||
* @Date:2019/6/25 3:46
|
* @Date:2019/6/25 3:46
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import cn.edu.scau.biubiusuisui.exception.InvalidURLException;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
private StringUtils() {
|
private StringUtils() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -93,4 +98,5 @@ public class StringUtils {
|
|||||||
String result = name.substring(0, 1).toUpperCase().concat(name.substring(1));
|
String result = name.substring(0, 1).toUpperCase().concat(name.substring(1));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,11 @@
|
|||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.PasswordField?>
|
<?import javafx.scene.control.PasswordField?>
|
||||||
|
<?import javafx.scene.control.RadioButton?>
|
||||||
<?import javafx.scene.control.Tab?>
|
<?import javafx.scene.control.Tab?>
|
||||||
<?import javafx.scene.control.TabPane?>
|
<?import javafx.scene.control.TabPane?>
|
||||||
<?import javafx.scene.control.TextField?>
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.control.ToggleGroup?>
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
<?import javafx.scene.layout.HBox?>
|
<?import javafx.scene.layout.HBox?>
|
||||||
<?import javafx.scene.layout.Pane?>
|
<?import javafx.scene.layout.Pane?>
|
||||||
@@ -36,47 +38,77 @@
|
|||||||
<content>
|
<content>
|
||||||
<Pane prefHeight="200.0" prefWidth="200.0">
|
<Pane prefHeight="200.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<VBox layoutX="47.0" layoutY="154.0" prefHeight="143.0" prefWidth="353.0">
|
<VBox layoutX="47.0" layoutY="154.0" prefHeight="229.0" prefWidth="353.0">
|
||||||
<children>
|
<children>
|
||||||
<HBox alignment="CENTER" prefHeight="60.0" prefWidth="800.0">
|
<HBox alignment="CENTER" prefHeight="60.0" prefWidth="800.0">
|
||||||
<children>
|
<children>
|
||||||
<Label prefWidth="40.0" text="用户名" />
|
<Label prefWidth="40.0" text="用户名"/>
|
||||||
<TextField fx:id="usernameTF" />
|
<TextField fx:id="usernameTF"/>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER" prefHeight="60.0" prefWidth="800.0">
|
<HBox alignment="CENTER" prefHeight="60.0" prefWidth="800.0">
|
||||||
<children>
|
<children>
|
||||||
<Label prefWidth="40.0" text="密码" />
|
<Label prefWidth="40.0" text="密码"/>
|
||||||
<PasswordField fx:id="pswPF" />
|
<PasswordField fx:id="pswPF"/>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
</children>
|
<HBox alignment="CENTER" prefHeight="60.0" prefWidth="800.0">
|
||||||
|
<children>
|
||||||
|
<Label prefWidth="40.0" text="年龄"/>
|
||||||
|
<TextField fx:id="ageTF"/>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<HBox alignment="CENTER" prefHeight="60.0" prefWidth="353.0" spacing="20.0">
|
||||||
|
<children>
|
||||||
|
<Label prefHeight="40.0" text="是否有效"/>
|
||||||
|
<RadioButton mnemonicParsing="false" text="是">
|
||||||
|
<toggleGroup>
|
||||||
|
<ToggleGroup fx:id="enableButtons"/>
|
||||||
|
</toggleGroup>
|
||||||
|
</RadioButton>
|
||||||
|
<RadioButton mnemonicParsing="false" text="否" toggleGroup="$enableButtons"/>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
<VBox layoutX="381.0" layoutY="124.0" prefHeight="203.0" prefWidth="353.0">
|
<VBox layoutX="381.0" layoutY="124.0" prefHeight="203.0" prefWidth="353.0" spacing="5.0">
|
||||||
<children>
|
<children>
|
||||||
<Label alignment="CENTER" prefHeight="26.0" prefWidth="359.0" text="输入的用户信息" textAlignment="CENTER">
|
<Label alignment="CENTER" prefHeight="26.0" prefWidth="359.0" text="输入的用户信息"
|
||||||
<font>
|
textAlignment="CENTER">
|
||||||
<Font size="20.0" />
|
<font>
|
||||||
</font>
|
<Font size="20.0"/>
|
||||||
</Label>
|
</font>
|
||||||
<HBox alignment="CENTER_LEFT" prefHeight="60.0" prefWidth="800.0">
|
</Label>
|
||||||
<children>
|
<HBox alignment="CENTER_LEFT" prefHeight="60.0" prefWidth="800.0">
|
||||||
<Label prefWidth="60.0" text="用户名:" />
|
<children>
|
||||||
<Label fx:id="usernameLabel" />
|
<Label prefWidth="60.0" text="用户名:"/>
|
||||||
</children>
|
<Label fx:id="usernameLabel"/>
|
||||||
</HBox>
|
</children>
|
||||||
<HBox alignment="CENTER_LEFT" prefHeight="60.0" prefWidth="800.0">
|
</HBox>
|
||||||
<children>
|
<HBox alignment="CENTER_LEFT" prefHeight="60.0" prefWidth="800.0">
|
||||||
<Label prefWidth="60.0" text="密码:" />
|
<children>
|
||||||
<Label fx:id="userPswLabel" />
|
<Label prefWidth="60.0" text="密码:"/>
|
||||||
</children>
|
<Label fx:id="userPswLabel"/>
|
||||||
</HBox>
|
</children>
|
||||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
</HBox>
|
||||||
<children>
|
<HBox alignment="CENTER_LEFT" prefHeight="60.0" prefWidth="800.0">
|
||||||
<Button mnemonicParsing="false" onAction="#clickToShowInfo" text="点击显示" />
|
<children>
|
||||||
</children>
|
<Label prefWidth="60.0" text="年龄:"/>
|
||||||
</HBox>
|
<Label fx:id="ageLabel"/>
|
||||||
</children>
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<HBox alignment="CENTER_LEFT" prefHeight="60.0" prefWidth="800.0">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="enableLabel" prefWidth="60.0" text="是否有效:"/>
|
||||||
|
<Label fx:id="userPswLabel2"/>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
|
<children>
|
||||||
|
<Button mnemonicParsing="false" onAction="#clickToShowInfo" text="点击显示"/>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
</children></Pane>
|
</children></Pane>
|
||||||
</content>
|
</content>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
prefWidth="800.0" type="Pane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1"
|
prefWidth="800.0" type="Pane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="cn.edu.scau.biubiusuisui.example.redirectDemo.LoginController">
|
fx:controller="cn.edu.scau.biubiusuisui.example.redirectDemo.LoginController">
|
||||||
<children>
|
<children>
|
||||||
<VBox alignment="CENTER" layoutX="265.0" layoutY="100.0" prefHeight="300.0" prefWidth="250.0" spacing="10.0">
|
<VBox alignment="CENTER" prefHeight="356.0" prefWidth="800.0" spacing="10.0">
|
||||||
<children>
|
<children>
|
||||||
<Label alignment="CENTER" prefHeight="50.0" prefWidth="250.0" text="登录">
|
<Label alignment="CENTER" prefHeight="50.0" prefWidth="250.0" text="登录">
|
||||||
<font>
|
<font>
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<PasswordField fx:id="passwordPF"/>
|
<PasswordField fx:id="passwordPF"/>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="200.0">
|
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<Label onMouseClicked="#registerClick" prefHeight="50.0" text="还没有账户,去注册" underline="true">
|
<Label onMouseClicked="#registerClick" prefHeight="50.0" text="还没有账户,去注册" underline="true">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
@@ -42,11 +42,20 @@
|
|||||||
</Label>
|
</Label>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="200.0">
|
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<VBox alignment="TOP_RIGHT" prefHeight="54.0" prefWidth="167.0" spacing="10.0">
|
<VBox alignment="CENTER" prefHeight="64.0" prefWidth="810.0" spacing="10.0">
|
||||||
<children>
|
<children>
|
||||||
<Button mnemonicParsing="false" onAction="#redirectToSuccess" text="登录"/>
|
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="5.0">
|
||||||
|
<children>
|
||||||
|
<Button mnemonicParsing="false" onAction="#redirectToSuccessWithQuery"
|
||||||
|
text="query方式登录"/>
|
||||||
|
<Button mnemonicParsing="false" onAction="#redirectToSuccessWithParam"
|
||||||
|
text="param方式登录"/>
|
||||||
|
<Button mnemonicParsing="false" onAction="#redirectToSuccessWithAll"
|
||||||
|
text="混合登录"/>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
<Button mnemonicParsing="false" onAction="#redirectToDialog" text="测试弹窗的按钮"/>
|
<Button mnemonicParsing="false" onAction="#redirectToDialog" text="测试弹窗的按钮"/>
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0"
|
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0"
|
||||||
prefWidth="600.0" type="Pane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1"
|
prefWidth="600.0" type="Pane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="cn.edu.scau.biubiusuisui.example.redirectDemo.SuccessController">
|
fx:controller="cn.edu.scau.biubiusuisui.example.redirectDemo.SuccessController">
|
||||||
<children>
|
<children>
|
||||||
<VBox alignment="CENTER" layoutX="158.0" layoutY="80.0" prefHeight="300.0" prefWidth="250.0" spacing="10.0">
|
<VBox alignment="CENTER" layoutX="158.0" layoutY="80.0" prefHeight="300.0" prefWidth="250.0" spacing="10.0">
|
||||||
<children>
|
<children>
|
||||||
<Label alignment="CENTER" prefHeight="50.0" prefWidth="250.0" text="登录成功">
|
<Label fx:id="title" alignment="CENTER" prefHeight="50.0" prefWidth="250.0" text="登录成功">
|
||||||
<font>
|
<font>
|
||||||
<Font size="27.0"/>
|
<Font size="27.0"/>
|
||||||
</font>
|
</font>
|
||||||
@@ -17,13 +21,19 @@
|
|||||||
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
|
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="用户名:"/>
|
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="用户名:"/>
|
||||||
<Label fx:id="usernameLabel" alignment="CENTER" prefHeight="50.0" prefWidth="150.0"/>
|
<Label fx:id="usernameLabel" alignment="CENTER" prefHeight="50.0" prefWidth="203.0"/>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
|
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="密码:"/>
|
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="密码:"/>
|
||||||
<Label fx:id="passwordLabel" alignment="CENTER" prefHeight="50.0" prefWidth="150.0"/>
|
<Label fx:id="passwordLabel" alignment="CENTER" prefHeight="50.0" prefWidth="205.0"/>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
|
||||||
|
<children>
|
||||||
|
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="Token:"/>
|
||||||
|
<Label fx:id="tokenLabel" alignment="CENTER" prefHeight="50.0" prefWidth="203.0"/>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
</children>
|
</children>
|
||||||
|
|||||||
Reference in New Issue
Block a user