Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a7efd76c6 | ||
|
|
96a58bcda5 | ||
|
|
34ddd6f26e | ||
|
|
38dc53b484 | ||
|
|
547c036cdb | ||
|
|
a69651447c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.idea
|
||||
*.iml
|
||||
@@ -85,13 +85,13 @@ The framework is not the framework for beautifying UI, but to simplify the step
|
||||
- [ ] Data valication
|
||||
- [ ] Optimize performance
|
||||
|
||||
## ~~Maven Repository~~
|
||||
## Maven Repository
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.gitee.Biubiuyuyu</groupId>
|
||||
<artifactId>javafx-plus</artifactId>
|
||||
<version>1.0.0-RELEASE</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
- [ ] 键盘事件绑定
|
||||
- [ ] 优化性能
|
||||
|
||||
## ~~Maven仓库地址~~
|
||||
## Maven仓库地址
|
||||
|
||||
maven仓库中的JavaFX-Plus版本是较旧版本,建议使用最新发行版。
|
||||
|
||||
@@ -93,7 +93,7 @@ maven仓库中的JavaFX-Plus版本是较旧版本,建议使用最新发行版
|
||||
<dependency>
|
||||
<groupId>com.gitee.Biubiuyuyu</groupId>
|
||||
<artifactId>javafx-plus</artifactId>
|
||||
<version>1.0.0-RELEASE</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
## Git地址
|
||||
|
||||
73
pom.xml
73
pom.xml
@@ -7,7 +7,7 @@
|
||||
|
||||
<groupId>com.gitee.Biubiuyuyu</groupId>
|
||||
<artifactId>javafx-plus</artifactId>
|
||||
<version>1.2.0-RELEASE</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<!-- packaging为pom时,不会加载resources 故注释-->
|
||||
<!-- <packaging>pom</packaging>-->
|
||||
|
||||
@@ -19,30 +19,27 @@
|
||||
|
||||
<description>this is javafx framework that simplified coding</description>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>javafx-plus</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>javafx-plus</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<properties>
|
||||
<cglib.version>3.1</cglib.version>
|
||||
<junit.version>4.13.1</junit.version>
|
||||
<slf4j-log4j12.version>1.7.21</slf4j-log4j12.version>
|
||||
<tomcat.version>9.0.48</tomcat.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<commons-io.version>2.11.0</commons-io.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- 第三方动态代理库 -->
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib</artifactId>
|
||||
<version>3.1</version>
|
||||
<version>${cglib.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Junit单元测试 -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -50,15 +47,39 @@
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.21</version>
|
||||
<version>${slf4j-log4j12.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<version>9.0.29</version>
|
||||
<version>${tomcat.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>javafx-plus</id>
|
||||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>javafx-plus</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<build>
|
||||
<!--配置Maven 对resource文件 过滤 -->
|
||||
<resources>
|
||||
@@ -104,19 +125,11 @@
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Source -->
|
||||
<!-- Source 开源 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -126,6 +139,14 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Javadoc -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
||||
@@ -12,6 +12,7 @@ import cn.edu.scau.biubiusuisui.utils.ClassUtil;
|
||||
import cn.edu.scau.biubiusuisui.utils.FileUtil;
|
||||
import cn.edu.scau.biubiusuisui.utils.LogUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -25,7 +26,6 @@ import java.util.Set;
|
||||
*/
|
||||
public class FXPlusApplication {
|
||||
private static final IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(FXPlusApplication.class);
|
||||
// Application
|
||||
|
||||
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
|
||||
|
||||
@@ -37,7 +37,11 @@ public class FXPlusApplication {
|
||||
|
||||
public static void start(Class clazz, BeanBuilder beanBuilder) {
|
||||
logger.info("starting JavaFX-Plus Application");
|
||||
try {
|
||||
logger.info("\n" + FileUtil.readFileFromResources("banner.txt"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.error("\n read classpath:banner.txt error, you can ignore it");
|
||||
}
|
||||
// 初始化日志路径
|
||||
LogUtil.initLog4jBase();
|
||||
|
||||
@@ -56,15 +60,15 @@ public class FXPlusApplication {
|
||||
for (String dir : sets) {
|
||||
logger.info("scanning directory: " + dir);
|
||||
ClassUtil classUtil = new ClassUtil();
|
||||
List<String> temps = classUtil.scanAllClassName(dir);
|
||||
for (String className : temps) {
|
||||
List<String> temps = null;
|
||||
try {
|
||||
temps = classUtil.scanAllClassName(dir);
|
||||
for (String className : temps) {
|
||||
logger.info("loading class: " + className);
|
||||
loadFXPlusClass(className, beanBuilder);
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (UnsupportedEncodingException | ClassNotFoundException exception) {
|
||||
logger.error("{}", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import cn.edu.scau.biubiusuisui.function.DragWindowHandlerImpl;
|
||||
import cn.edu.scau.biubiusuisui.log.FXPlusLoggerFactory;
|
||||
import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
|
||||
import cn.edu.scau.biubiusuisui.utils.FileUtil;
|
||||
import cn.edu.scau.biubiusuisui.utils.IFxPlusConstants;
|
||||
import cn.edu.scau.biubiusuisui.utils.ResourceBundleUtil;
|
||||
import cn.edu.scau.biubiusuisui.utils.StringUtil;
|
||||
import javafx.event.EventHandler;
|
||||
@@ -18,6 +19,7 @@ import javafx.stage.Stage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
@@ -249,8 +251,8 @@ public class FXBaseController extends Pane {
|
||||
} else {
|
||||
logger.warn("the icon file has not existed");
|
||||
}
|
||||
} catch (ProtocolNotSupport protocolNotSupport) {
|
||||
logger.error(protocolNotSupport.getMessage(), protocolNotSupport);
|
||||
} catch (ProtocolNotSupport | UnsupportedEncodingException exception) {
|
||||
logger.error(exception.getMessage(), exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,7 +283,7 @@ public class FXBaseController extends Pane {
|
||||
if ("".equals(name) || name == null) { // 原本无“name == null”判断条件,会出错
|
||||
return StringUtil.getBaseClassName(getClass().getSimpleName());
|
||||
} else {
|
||||
return StringUtil.getBaseClassName(getClass().getSimpleName()) + "#" + name;
|
||||
return StringUtil.getBaseClassName(getClass().getSimpleName()) + IFxPlusConstants.CONTROLLER_NAME_SEPARATOR + name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,13 @@ import java.lang.reflect.Method;
|
||||
* @since JavaFX2.0 JDK1.8
|
||||
*/
|
||||
public class FXMethodEntity {
|
||||
|
||||
/**
|
||||
* 所属Controller
|
||||
*/
|
||||
private FXBaseController fxBaseController;
|
||||
|
||||
/**
|
||||
* 实际方法
|
||||
*/
|
||||
private Method method;
|
||||
|
||||
public FXMethodEntity(FXBaseController fxBaseController, Method method) {
|
||||
|
||||
@@ -33,6 +33,8 @@ public class FXPlusContext {
|
||||
controllers = new LinkedList<>();
|
||||
}
|
||||
controllers.add(fxBaseController);
|
||||
// @since 1.2.1 fix: 没有将controller真正注册到context的异常
|
||||
controllerContext.put(fxBaseController.getName(), controllers);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,19 @@ import java.util.Map;
|
||||
* @since JavaFX2.0 JDK1.8
|
||||
*/
|
||||
public class FXRedirectParam {
|
||||
/**
|
||||
* 跳转的目标Controller
|
||||
*/
|
||||
private String toController;
|
||||
/**
|
||||
* query方式的参数, like: helloController?name=JavaFx-Plus&msg=helloWorld
|
||||
* the map will store: { name -> JavaFx-Plus, msg -> helloWorld}
|
||||
*/
|
||||
private Map<String, Object> query = new HashMap<>();
|
||||
|
||||
/**
|
||||
* param方式的参数,会以map方式传递给目标Controller
|
||||
*/
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
public FXRedirectParam(String toController) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package cn.edu.scau.biubiusuisui.log;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* @author suisui
|
||||
* @version 1.2
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.edu.scau.biubiusuisui.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
@@ -22,7 +23,14 @@ public class ClassUtil {
|
||||
classLoader = getClass().getClassLoader();
|
||||
}
|
||||
|
||||
private List<String> getAllFXControllerClassName(String base, List<String> nameList) {
|
||||
/**
|
||||
* 获取所有FxController的类名
|
||||
*
|
||||
* @param base 基础目录路径
|
||||
* @param nameList 类名列表
|
||||
* @return 所有FXController的类名列表
|
||||
*/
|
||||
private List<String> getAllFXControllerClassName(String base, List<String> nameList) throws UnsupportedEncodingException {
|
||||
String splashPath = StringUtil.dotToSplash(base);
|
||||
URL url = classLoader.getResource(splashPath);
|
||||
String filePath = StringUtil.getRootPath(url);
|
||||
@@ -42,7 +50,7 @@ public class ClassUtil {
|
||||
return nameList;
|
||||
}
|
||||
|
||||
public List<String> scanAllClassName(String base) {
|
||||
public List<String> scanAllClassName(String base) throws UnsupportedEncodingException {
|
||||
return getAllFXControllerClassName(base, new LinkedList<>());
|
||||
}
|
||||
|
||||
@@ -62,7 +70,9 @@ public class ClassUtil {
|
||||
}
|
||||
|
||||
private static List<String> readFromDirectory(String path) {
|
||||
if (path == null) return null;
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
return readFromFileDirectory(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@ package cn.edu.scau.biubiusuisui.utils;
|
||||
import cn.edu.scau.biubiusuisui.exception.ProtocolNotSupport;
|
||||
import cn.edu.scau.biubiusuisui.log.FXPlusLoggerFactory;
|
||||
import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
|
||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
/**
|
||||
* @author jack
|
||||
@@ -33,12 +35,28 @@ public class FileUtil {
|
||||
* @param filePath
|
||||
* @return
|
||||
* @description 读取resources文件夹下的file,相对于resources的文件路径,如 resources/config.conf 则只需 config.conf
|
||||
* @since 1.2.0 update: 使用getResourcesAsStream读取,屏蔽jar包读取障碍
|
||||
*/
|
||||
public static String readFileFromResources(String filePath) {
|
||||
URL url = FileUtil.class.getClassLoader().getResource(filePath);
|
||||
if (url != null) {
|
||||
String path = StringUtil.getRootPath(url);
|
||||
return readFile(path);
|
||||
public static String readFileFromResources(String filePath) throws UnsupportedEncodingException {
|
||||
InputStream is = FileUtil.class.getClassLoader().getResourceAsStream(filePath);
|
||||
if (is == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuffer content = new StringBuffer();
|
||||
try (
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(inputStreamReader);
|
||||
) {
|
||||
String temp;
|
||||
while ((temp = br.readLine()) != null) {
|
||||
// 一次读入一行数据
|
||||
content.append(temp + "\r\n");
|
||||
}
|
||||
return content.toString();
|
||||
} catch (IOException e) {
|
||||
logger.error("reading file error", e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -59,8 +77,7 @@ public class FileUtil {
|
||||
content.append(temp + "\r\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
logger.error("reading file error", e);
|
||||
}
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.edu.scau.biubiusuisui.utils;
|
||||
|
||||
/**
|
||||
* @author suisui
|
||||
* @version 1.2.0
|
||||
* <p> Description: JavaFx-Plus常量 </p>
|
||||
* @time 2021/9/5 10:36 下午
|
||||
*/
|
||||
public interface IFxPlusConstants {
|
||||
/**
|
||||
* 项目默认编码 UTF-8
|
||||
*/
|
||||
String DEFAULT_CHARSET = "UTF-8";
|
||||
/**
|
||||
* FXController名称分隔符
|
||||
*/
|
||||
String CONTROLLER_NAME_SEPARATOR = "#";
|
||||
}
|
||||
@@ -2,8 +2,11 @@ package cn.edu.scau.biubiusuisui.utils;
|
||||
|
||||
import cn.edu.scau.biubiusuisui.log.FXPlusLoggerFactory;
|
||||
import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
/**
|
||||
* @author jack
|
||||
@@ -11,20 +14,20 @@ import java.net.URL;
|
||||
* @version 1.0
|
||||
* @date 2019/6/25 3:46
|
||||
* @since JavaFX2.0 JDK1.8
|
||||
* @since 1.3.0 add:继承StringUtils
|
||||
*/
|
||||
public class StringUtil {
|
||||
public class StringUtil extends StringUtils {
|
||||
private static IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(StringUtil.class);
|
||||
|
||||
private StringUtil() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* "file:/home/whf/cn/fh" -> "/home/whf/cn/fh"
|
||||
* "jar:file:/home/whf/foo.jar!cn/fh" -> "/home/whf/foo.jar"
|
||||
*/
|
||||
public static String getRootPath(URL url) {
|
||||
String fileUrl = url.getFile();
|
||||
public static String getRootPath(URL url) throws UnsupportedEncodingException {
|
||||
String fileUrl = URLDecoder.decode(url.getFile(),IFxPlusConstants.DEFAULT_CHARSET);
|
||||
int pos = fileUrl.indexOf('!');
|
||||
|
||||
if (-1 == pos) {
|
||||
@@ -51,7 +54,6 @@ public class StringUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String splashToDot(String name) {
|
||||
|
||||
return name.replaceAll("/", "\\.");
|
||||
}
|
||||
|
||||
@@ -63,7 +65,6 @@ public class StringUtil {
|
||||
if (-1 != pos) {
|
||||
return name.substring(0, pos);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -76,7 +77,6 @@ public class StringUtil {
|
||||
public static String trimURI(String uri) {
|
||||
String trimmed = uri.substring(1);
|
||||
int splashIndex = trimmed.indexOf('/');
|
||||
|
||||
return trimmed.substring(splashIndex);
|
||||
}
|
||||
|
||||
@@ -103,8 +103,7 @@ public class StringUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String toInstanceName(String name) {
|
||||
String result = name.substring(0, 1).toLowerCase().concat(name.substring(1));
|
||||
return result;
|
||||
return name.substring(0, 1).toLowerCase().concat(name.substring(1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,8 +113,7 @@ public class StringUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String toClassName(String name) {
|
||||
String result = name.substring(0, 1).toUpperCase().concat(name.substring(1));
|
||||
return result;
|
||||
return name.substring(0, 1).toUpperCase().concat(name.substring(1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user