v1.2.0更新

1. 设计代码模块文件,导入IDE后可快速生成符合JavaFX-Plus编程规范的FXPlusController、FXPlusWindow、FXPlusApplication、FXPlusFXML文件
2. 完善多窗口切换功能,可携带数据跳转
3. 新增注解@FXWindow中的icon属性,传入String类型的图标URL,可为窗口标题栏增设图标
4. 完善JavaFX-Plus生命周期
5. 新增日志log模块
6. 新增语言国际化操作
7. 新增测试生命周期LifeDemo示例和测试国际化的LanguageDemo示例代码
8. 规范化代码和更新README
This commit is contained in:
yangsuiyu
2020-05-04 15:13:58 +08:00
parent 7c807d4b39
commit b48325cd63
147 changed files with 2888 additions and 456 deletions

View File

@@ -4,21 +4,20 @@ import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
import cn.edu.scau.biubiusuisui.exception.NotFXWindowException;
import cn.edu.scau.biubiusuisui.utils.StringUtils;
import javafx.scene.Scene;
import cn.edu.scau.biubiusuisui.log.FXPlusLoggerFactory;
import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
import cn.edu.scau.biubiusuisui.utils.ResourceBundleUtil;
import cn.edu.scau.biubiusuisui.utils.StringUtil;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
/**
* @Author jack
* @Date:2019/6/25 5:51
*/
/**
* In JavaFX-Plus Framework Controller
@@ -28,7 +27,16 @@ import java.util.Map;
* M means model which is base cn.edu.scau.biubiusuisui.entity in your program
* Every BaseController has a name which is used for identifying different <strong>instance</strong>
*/
/**
* @author jack
* @author suisui
* @version 1.0
* @date 2019/6/25 5:51
* @since JavaFX2.0 JDK1.8
*/
public class FXBaseController extends Pane {
private static IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(FXBaseController.class);
protected String name = "";
private Stage stage;
@@ -37,8 +45,8 @@ public class FXBaseController extends Pane {
/**
* @Author: yangsuiyu
* @Descriptions: 用于携带信息数据
* @description 用于携带信息数据
* @version 1.2
*/
private Map<String, Object> query = new HashMap<>();
private Map<String, Object> param = new HashMap<>();
@@ -49,6 +57,7 @@ public class FXBaseController extends Pane {
public FXBaseController() {
FXController fxController = null;
FXWindow fxWindow = null;
Annotation[] annotations = getClass().getAnnotations();
// Find FXController cn.edu.scau.biubiusuisui.annotation
for (Annotation annotation : annotations) {
@@ -59,42 +68,119 @@ public class FXBaseController extends Pane {
}
// 添加赋予是否为窗口的逻辑
if (annotation.annotationType().equals(FXWindow.class)) {
fxWindow = (FXWindow) annotation;
isWindow = true;
}
}
//load fxml file to show panel in scene builder
if (isController && FXPlusApplication.IS_SCENE_BUILDER == true) {
FXMLLoaderPlus fxmlLoader = new FXMLLoaderPlus(getClass().getClassLoader().getResource(fxController.path()));
logger.info("loading the FXML file of " + this.getName());
URL location = getClass().getClassLoader().getResource(fxController.path());
String fxmlBaseName = StringUtil.getFilePathInResources(fxController.path());
ResourceBundle resourceBundle = ResourceBundleUtil.getResourceBundle(fxmlBaseName, fxController.locale());
FXMLLoaderPlus fxmlLoader = new FXMLLoaderPlus(location);
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
fxmlLoader.setShow(true);
fxmlLoader.setResources(resourceBundle);
try {
// 加载前
onLoad();
fxmlLoader.load();
} catch (IOException e) {
logger.error(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
}
}
public void initialize() {
/**
* @description 相当于onReady, 页面渲染完后的操作
* @version 1.2
*/
public void initialize() throws Exception {
}
/**
* 在显示Stage之前的操作
* @description 初始化onShow, onHide, onClose的生命周期
* @version 1.2
*/
public void beforeShowStage() {
public final void initLifeCycle() {
logger.info("init the life cycle of " + this.getName());
this.stage.setOnShowing(event -> {
try {
onShow();
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
});
this.stage.setOnCloseRequest(event -> {
try {
onClose();
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
});
// 监听最小化窗口
this.stage.iconifiedProperty().addListener((observable, oldValue, newValue) -> {
try {
if (newValue) { //最小化
onHide();
} else {
onShow(); //取消最小化
}
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
});
}
/**
* @description 在加载页面之前的操作
* @version 1.2
*/
public void onLoad() throws Exception {
}
/**
* @description 在显示页面之前的操作
* @version 1.2
*/
public void onShow() throws Exception {
}
/**
* @description 在关闭窗口之前的操作
* @version 1.2
*/
public void onClose() throws Exception {
}
/**
* @description 在隐藏窗口之前的操作
* @version 1.2
*/
public void onHide() throws Exception {
}
/**
* 唤起舞台
*/
public void showStage() {
this.beforeShowStage();
if (isWindow) {
this.stage.show();
}
}
public void showAndWait() {
if (isWindow) {
this.stage.showAndWait();
}
}
@@ -107,18 +193,21 @@ public class FXBaseController extends Pane {
}
}
public void showAndWait() {
this.beforeShowStage();
/**
* @description 最小化
* @version 1.2
*/
public void hideStage() {
if (isWindow) {
this.stage.showAndWait();
this.stage.setIconified(true);
}
}
public String getName() {
if ("".equals(name) || name == null) { // 原本无“name == null”判断条件会出错
return StringUtils.getBaseClassName(getClass().getSimpleName());
return StringUtil.getBaseClassName(getClass().getSimpleName());
} else {
return StringUtils.getBaseClassName(getClass().getSimpleName()) + "#" + name;
return StringUtil.getBaseClassName(getClass().getSimpleName()) + "#" + name;
}
}

View File

@@ -6,8 +6,10 @@ import javafx.beans.property.Property;
/**
* 将Controller中的JavaFX的field包装成FXFieldWrapper
*
* @Author jack
* @Date:2019/6/28 10:03
* @author jack
* @version 1.0
* @date 2019/6/28 10:03
* @since JavaFX2.0 JDK1.8
*/
public class FXFieldWrapper {

View File

@@ -5,8 +5,11 @@ import java.lang.reflect.Method;
/**
* This class is base cn.edu.scau.biubiusuisui.entity for queue message(or signal)
* you mush save the instance and method which means who will run this method
* @Author jack
* @Date:2019/6/26 15:39
*
* @author jack
* @version 1.0
* @date 2019/6/26 15:39
* @since JavaFX2.0 JDK1.8
*/
public class FXMethodEntity {

View File

@@ -12,8 +12,10 @@ import java.util.concurrent.ConcurrentHashMap;
* Context is use for storing Controller
* In addition,you can store an instance into Session to use it everywhere
*
* @Author jack
* @Date:2019/6/26 12:28
* @author jack
* @version 1.0
* @date 2019/6/26 12:28
* @since JavaFX2.0 JDK1.8
*/
public class FXPlusContext {

View File

@@ -0,0 +1,67 @@
package cn.edu.scau.biubiusuisui.entity;
/**
* @author suisui
* @version 1.2
* @description JavaFX的Locale枚举类型
* @date 2020/5/3 10:47
* @since JDK1.8 JavaFX2.0
*/
public enum FXPlusLocale {
/**
* 不设置
*/
NONE,
/**
* 简体中文
*/
SIMPLIFIED_CHINESE,
/**
* 繁体中文
*/
TRADITIONAL_CHINESE,
/**
* English 英语
*/
ENGLISH,
/**
* American 美语
*/
AMERICAN,
/**
* Le français 法语
*/
FRANCE,
/**
* Deutsch 德语
*/
GERMANY,
/**
* lingua italiana 意大利语
*/
ITALIAN,
/**
* 日本人 日语
*/
JAPANESE,
/**
* 한국어 韩语
*/
KOREAN,
}

View File

@@ -4,10 +4,11 @@ import java.util.HashMap;
import java.util.Map;
/**
* @author suiyu_yang
* @author suisui
* @version 1.2
* @description 跳转窗口携带的参数
* @date 2020/4/6 18:06
* @email suiyu_yang@163.com
* @since JavaFX2.0 JDK1.8
*/
public class FXRedirectParam {
private String toController;