# gui-shell-core **Repository Path**: qq1134380223/gui-shell-core ## Basic Information - **Project Name**: gui-shell-core - **Description**: 写一些普通的java 函数,再给他们加上一些注解,这个框架会为带有注解的函数创建一个可视化的调用界面。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2023-01-21 - **Last Updated**: 2025-10-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: GUI, shell ## README # GUI SHELL ## 简介 一个类似于spring-shell的框架,不同之处在于这个框架生成gui界面。 ## quick start 导入依赖 ```xml io.gitee.qq1134380223 gui-shell-core 2.0.5.RELEASE ``` 此框架依赖javafx类库,由于不同版本的jdk对javafx类库的包含情况不一样,请根据下表判断您的jdk是否支持此框架以及是否需要额外引入 ```javafx-fxml```依赖 | jdk版本 | 是否支持 | 是否需要导入```javafx-fxml```依赖 | |-------------------|------|---------------------------| | ≥ 11 | 是 | 是 | | ≤ oracle jdk8u441 | 是 | 否 | | ≥ oracle jdk8u451 | 否 | - | | open jdk8 | 否 | - | | <8 | 否 | - | 如果根据上表,你需要导入javafx依赖,使用下方的maven 坐标引入依赖,如果你的java版本足够高,那么你可以使用更高版本的javafx-fxml依赖。 ```xml org.openjfx javafx-fxml 17 ``` 编写TestMethodGroup ```java @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupMethod(value = "嗨", desc = "点击执行功能按钮,然后这个方法的输出将会输出到结果输出区") public String hi() { return "hi!"; } } ``` 编写主方法 ```java import io.gitee.qq1134380223.guishellcore.application.GuiShellApplication; import java.util.Locale; public class Main { static void main(String[] args) { GuiShellApplication.setLang(Locale.CHINESE.getLanguage());// 目前仅支持中文、英文 GuiShellApplication.setFuncGroups(new TestMethodGroup());//此方法可传入多个带有@GuiShellGroup注解的类的实例 GuiShellApplication.setTitle("测试窗口标题"); GuiShellApplication.runApplication(); } } ``` 运行主方法,你会看到这个界面 ![image-20250914173353259](./README.assets/image-20250914173353259.png) 展开右侧的列表中的“测试功能组”,选择“嗨”,然后点击“执行功能”按钮,这时```hi()```方法的的返回值就会显示在结果输出区。 ![image-20250914173816316](./README.assets/image-20250914173816316.png) ① 窗口标题由```GuiShellApplication.setTitle```设置。 ② ```TestMethodGroup```的```@GuiShellGroup```注解值。 ③ ```hi()```的注解```@GuiShellGroupMethod```的value值,这个值是“功能名称”。 ④ 选择了“嗨”这个功能后,点击“执行功能”按钮时会执行 ```hi()```方法,返回值会显示在结果输出区。 ⑤ 功能说明,来自于```hi()```的注解```@GuiShellGroupMethod```的desc值,这个值是“功能说明”。 你可以在```TestMethodGroup```中添加多个注解有```@GuiShellGroupMethod```的```public``` 方法。注意,框架并不要求多个方法的```@GuiShellGroupMethod```的value值必须各不相同,只是如果你写相同的value值,会在使用的过程中无法区分两个value相同的方法。 ```@GuiShellGroup```注解的value值并不要求必须不同,但相同的value会让使用过程中难以区分两个同名的功能组。 ## 参数 方法可以有参数,框架会为参数生成对应的输入组件。现在修改```TestMethodGroup```的```hi()```方法 ```java import io.gitee.qq1134380223.guishellcore.annotation.Param; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupMethod(value = "嗨", desc = "点击执行功能按钮,然后这个函数的输出将会输出到结果输出区") public String hi(@Param("姓名") String name) { return "hi! " + name; } } ``` 重新运行程序并选择“嗨”功能,可以看到参数输入区出现一个输入姓名的输入框,输入姓名并点击执行功能。 ![image-20250914174201386](./README.assets/image-20250914174201386.png) ① 输入框前的参数名称来自于```@Param```的value值 ② 执行功能时,框架会将输入框中的值传入```hi```方法 框架能为大部分类型生成人性化的输入组件,但并非所有,框架支持的参数类型包括在以下列表中: | 类型 | 对应的输入组件 | |:---------------------------------------------------------------------------------------------------------------------------------------:|:--------------------:| | int,Integer
float,Float
double,Double
long,Long
short,Short
byte,Byte
String
BigDecimal | 输入框 | | boolean,Boolean | 勾选框 | | @Choices String | 下拉框 | | File | 文件选择器 | | @Directory File | 目录选择器 | | @SaveLocation File | 文件保存选择器 | | Date
LocalDateTime
LocalDate
ZoneDateTime
Instant
OffsetDateTime
OffsetTime
Year
Month
MonthDay | 输入框(带有格式提示) | | 受支持类型的数组 | 可增加减少的受支持类型的输入组件 | | POJO | 一组给有setter的字段赋值的输入组件 | ### @Choices String 单选框 修改一下功能 ```java import io.gitee.qq1134380223.guishellcore.annotation.Choices; import io.gitee.qq1134380223.guishellcore.annotation.Param; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupMethod(value = "嗨", desc = "点击执行功能按钮,然后这个函数的输出将会输出到结果输出区") public String hi(@Param("问候语") @Choices({"hi", "hello"}) String greeting, @Param("姓名") String name) { return greeting + " " + name; } } ``` 效果如图: ![image-20250914174328383](./README.assets/image-20250914174328383.png) ### File 文件输入框 ```java @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupMethod("输入一个文件") public File getAFile(@Param("文件") File file) { return file; } } ``` 运行测试: ![image-20250914174433852](./README.assets/image-20250914174433852.png) 选择文件然后点击执行功能: ![image-20250914174936053](./README.assets/image-20250914174936053.png) ### @Directory File 目录输入框 ```java import io.gitee.qq1134380223.guishellcore.annotation.Directory; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupMethod("输入一个目录") public File getAFile(@Param("目录") @Directory File file) { return file; } } ``` 运行测试: ![img_10.png](./README.assets/image-20250914175112310.png) ### @SaveLocation File 保存位置选框 ```java import io.gitee.qq1134380223.guishellcore.annotation.Directory; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupMethod("输入一个保存位置") public File getAFile(@Param("保存位置") @SaveLocation File file) { return file; } } ``` 运行测试: ![image-20250914175316994](./README.assets/image-20250914175316994.png) ### pojo组合输入框 定义一个pojo类型参数 ```java import io.gitee.qq1134380223.guishellcore.annotation.Choices; import io.gitee.qq1134380223.guishellcore.annotation.Param; @Data //lombok public class Student { @Param("姓名") String name; @Param("年龄") int year; @Param("性别") @Choices({"男", "女", "其他"}) String gender; } ``` 写一个方法 ```java import io.gitee.qq1134380223.guishellcore.annotation.Choices; import io.gitee.qq1134380223.guishellcore.annotation.Param; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupMethod(value = "输入一个学生信息") public Student hi(@Param("学生信息") Student student) { return student; } } ``` 运行测试: ![image-20250914180100968](./README.assets/image-20250914180100968.png) > 注意POJO 类的字段不要直接或间接引用其本身类型的字段,比如A类的a字段为A类,或A类的a字段为B类,但是B的b字段为A类,框架不会也不可能递归地为它产生输入组件。 ### 数组类型参数 以学生信息为例 ```java import io.gitee.qq1134380223.guishellcore.annotation.Choices; import io.gitee.qq1134380223.guishellcore.annotation.Param; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupMethod(value = "输入一群学生信息") public Student[] hi(@Param("学生信息") Student[] students) { return students; } } ``` 运行测试: ![image-20250914180212991](./README.assets/image-20250914180212991.png) ## 返回值 ### File类型的返回值 在有支持资源管理器的操作系统中,结果输出区会为File类型的返回值生成一个“在资源管理查看”的按钮,点击可打开文件所在目录。 ![image-20250914174936053](./README.assets/image-20250914174936053.png) ### void 类型返回值 会输出“功能已执行” ### 其他类型的返回值 这个框架会尽量地使用json格式数据表达返回的对象。 ## 属性 ```java import io.gitee.qq1134380223.guishellcore.annotation.Choices; import io.gitee.qq1134380223.guishellcore.annotation.GuiShellGroupProperty; import io.gitee.qq1134380223.guishellcore.annotation.Param; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupProperty("字段属性") int i = 0; public int getI() {//字段属性必须有getter return i; } @GuiShellGroupProperty("方法属性") public int getIp1() {//方法属性必须public且无参 return i + 1; } @GuiShellGroupMethod(value = "改变属性") public void hi() { i++; } } ``` 每次点击“执行功能”属性区都会刷新并更新属性的值。 ![image-20250914180515776](./README.assets/image-20250914180515776.png) ### File类型的属性 例子: ```java import io.gitee.qq1134380223.guishellcore.annotation.Directory; import io.gitee.qq1134380223.guishellcore.annotation.GuiShellGroupProperty; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupProperty("目录") File dir; public File getDir() { return dir; } @GuiShellGroupMethod("输入一个目录") public void getAFile(@Param("目录") @Directory File file) { dir = file; } } ``` 对于File类型的属性,在windows操作系统下,会为其生成一个“在资源管理器中查看”或“打开目录”的按钮。 ![image-20250914180613255](./README.assets/image-20250914180613255.png) ### 其他类型的属性 对于其他类型的属性,框架会尽量以json的格式展示其内容。 以Student类为例子: ```java import io.gitee.qq1134380223.guishellcore.annotation.Choices; import io.gitee.qq1134380223.guishellcore.annotation.GuiShellGroupProperty; import io.gitee.qq1134380223.guishellcore.annotation.Param; @GuiShellGroup("测试功能组") public class TestMethodGroup { @GuiShellGroupProperty("学生信息") Student student; public Student getStudent() { return student; } @GuiShellGroupMethod(value = "输入一个学生信息") public void hi(@Param("学生信息") Student student) { this.student = student; } } ``` 效果如图: ![image-20250914180759011](./README.assets/image-20250914180759011.png) ## 耗时任务 如果一个```@GuiShellGroupMethod```或```@GuiShellGroupProperty```的函数是耗时任务,可以为其加上```@Async``` 注解,这样在执行耗时任务的时候就会输出“计算中...”,在计算过后显示计算结果。 示例: ```java @GuiShellGroup("耗时任务") public class Test { @GuiShellGroupMethod("耗时任务") @Async public void test() { //耗时任务的代码 } } ``` ## 整合Spring Boot 整合springboot的步骤如下 1. 创建springboot 项目 2. 引入gui-shell-core依赖 3. 编写功能组类,并加上```@Component```注解 注意gui-shell-core依赖中包含springboot的启动配置,无需手动调用```GuiShellApplication.runApplication``` 使用spring boot 的ioc功能,你能向功能组中注入你需要的bean,比如dao,service等 > 本框架支持springboot 2.x.x和3.x.x ### 配置窗口标题 在application.properties中配置 ```properties guishell.title=你的标题 guishell.lang=en # 目前仅支持zh、en ```