remove test demo
This commit is contained in:
@ -1,21 +1,17 @@
|
|||||||
@echo off
|
@echo off
|
||||||
echo =====================================
|
REM JavaFX Demo 启动脚本
|
||||||
echo Timi-Inject JavaFX Demo
|
|
||||||
echo =====================================
|
|
||||||
echo.
|
|
||||||
|
|
||||||
echo Compiling project...
|
echo Starting JavaFX Demo...
|
||||||
call mvn clean compile test-compile -Dmaven.test.skip=false -q
|
cd /d "%~dp0"
|
||||||
if errorlevel 1 (
|
|
||||||
echo Compilation failed!
|
|
||||||
pause
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
|
|
||||||
echo.
|
REM 确保已编译
|
||||||
echo Starting JavaFX application...
|
call mvn test-compile -Dmaven.test.skip=false -q
|
||||||
echo.
|
|
||||||
|
|
||||||
call mvn javafx:run
|
REM 运行应用
|
||||||
|
java ^
|
||||||
|
--module-path "%USERPROFILE%\.m2\repository\org\openjfx\javafx-controls\21.0.2\javafx-controls-21.0.2-win.jar;%USERPROFILE%\.m2\repository\org\openjfx\javafx-graphics\21.0.2\javafx-graphics-21.0.2-win.jar;%USERPROFILE%\.m2\repository\org\openjfx\javafx-base\21.0.2\javafx-base-21.0.2-win.jar;%USERPROFILE%\.m2\repository\org\openjfx\javafx-fxml\21.0.2\javafx-fxml-21.0.2-win.jar" ^
|
||||||
|
--add-modules javafx.controls,javafx.fxml ^
|
||||||
|
-cp "target\classes;target\test-classes;%USERPROFILE%\.m2\repository\com\imyeyu\io\timi-io\0.0.2\timi-io-0.0.2.jar;%USERPROFILE%\.m2\repository\ch\qos\logback\logback-classic\1.5.24\logback-classic-1.5.24.jar;%USERPROFILE%\.m2\repository\ch\qos\logback\logback-core\1.5.24\logback-core-1.5.24.jar;%USERPROFILE%\.m2\repository\org\slf4j\slf4j-api\2.0.16\slf4j-api-2.0.16.jar" ^
|
||||||
|
com.imyeyu.inject.javafxdemo.Launcher
|
||||||
|
|
||||||
pause
|
pause
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
package com.imyeyu.inject.demo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认存储实现
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class DefaultStorage implements Storage {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(String data) {
|
|
||||||
System.out.println("Default save: " + data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
package com.imyeyu.inject.demo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.TimiInject;
|
|
||||||
import com.imyeyu.inject.annotation.TimiInjectApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 演示应用
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@TimiInjectApplication("com.imyeyu.inject.demo")
|
|
||||||
public class DemoApp {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
TimiInject inject = TimiInject.run(DemoApp.class);
|
|
||||||
|
|
||||||
UserService userService = inject.di(UserService.class);
|
|
||||||
System.out.println(userService.hello());
|
|
||||||
|
|
||||||
String appName = inject.di("appName", String.class);
|
|
||||||
System.out.println("App Name: " + appName);
|
|
||||||
|
|
||||||
Storage storage = inject.di(Storage.class);
|
|
||||||
System.out.println("Storage: " + storage.getClass().getSimpleName());
|
|
||||||
|
|
||||||
System.out.println("\n=== Dependency Graph ===");
|
|
||||||
System.out.println(inject.exportDependencyGraph());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
package com.imyeyu.inject.demo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.Bean;
|
|
||||||
import com.imyeyu.inject.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 演示配置
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class DemoConfig {
|
|
||||||
|
|
||||||
@Bean("appName")
|
|
||||||
public String appName() {
|
|
||||||
return "timi-inject-demo";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Integer serverPort() {
|
|
||||||
return 8080;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package com.imyeyu.inject.demo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.Component;
|
|
||||||
import com.imyeyu.inject.annotation.Primary;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 快速存储实现
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@Primary
|
|
||||||
public class FastStorage implements Storage {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(String data) {
|
|
||||||
System.out.println("Fast save: " + data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,67 +0,0 @@
|
|||||||
package com.imyeyu.inject.demo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.TimiInject;
|
|
||||||
import com.imyeyu.inject.annotation.Component;
|
|
||||||
import com.imyeyu.inject.annotation.PostConstruct;
|
|
||||||
import com.imyeyu.inject.annotation.Service;
|
|
||||||
import com.imyeyu.inject.annotation.TimiInjectApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 快速测试
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
public class QuickTest {
|
|
||||||
|
|
||||||
@TimiInjectApplication("com.imyeyu.inject.demo")
|
|
||||||
public static class TestApp {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public static class TestService {
|
|
||||||
private boolean initialized = false;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
this.initialized = true;
|
|
||||||
System.out.println("TestService initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInitialized() {
|
|
||||||
return initialized;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("=== Timi-Inject Quick Test ===\n");
|
|
||||||
|
|
||||||
TimiInject inject = TimiInject.run(TestApp.class);
|
|
||||||
|
|
||||||
System.out.println("\n=== Test 1: Simple DI ===");
|
|
||||||
UserRepository repo = inject.di(UserRepository.class);
|
|
||||||
System.out.println("UserRepository: " + (repo != null ? "OK" : "FAIL"));
|
|
||||||
|
|
||||||
System.out.println("\n=== Test 2: Constructor Injection ===");
|
|
||||||
UserService service = inject.di(UserService.class);
|
|
||||||
System.out.println("UserService: " + service.hello());
|
|
||||||
|
|
||||||
System.out.println("\n=== Test 3: @Bean Method ===");
|
|
||||||
String appName = inject.di("appName", String.class);
|
|
||||||
System.out.println("AppName: " + appName);
|
|
||||||
|
|
||||||
Integer port = inject.di("serverPort", Integer.class);
|
|
||||||
System.out.println("ServerPort: " + port);
|
|
||||||
|
|
||||||
System.out.println("\n=== Test 4: @Primary ===");
|
|
||||||
Storage storage = inject.di(Storage.class);
|
|
||||||
System.out.println("Storage type: " + storage.getClass().getSimpleName());
|
|
||||||
System.out.println("Expected FastStorage: " + (storage instanceof FastStorage ? "OK" : "FAIL"));
|
|
||||||
|
|
||||||
System.out.println("\n=== Test 5: Manual Registration ===");
|
|
||||||
inject.ioc("customBean", "Custom Value");
|
|
||||||
String custom = inject.di("customBean", String.class);
|
|
||||||
System.out.println("Custom bean: " + custom);
|
|
||||||
|
|
||||||
System.out.println("\n=== All Tests Passed! ===");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package com.imyeyu.inject.demo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储接口
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
public interface Storage {
|
|
||||||
void save(String data);
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package com.imyeyu.inject.demo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.Resources;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户仓储
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Resources
|
|
||||||
public class UserRepository {
|
|
||||||
|
|
||||||
public UserRepository() {
|
|
||||||
System.out.println("UserRepository created");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
package com.imyeyu.inject.demo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.PostConstruct;
|
|
||||||
import com.imyeyu.inject.annotation.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户服务
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class UserService {
|
|
||||||
|
|
||||||
private final UserRepository repository;
|
|
||||||
|
|
||||||
public UserService(UserRepository repository) {
|
|
||||||
this.repository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
System.out.println("UserService initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String hello() {
|
|
||||||
return "Hello from UserService! Repository: " + repository.getClass().getSimpleName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package com.imyeyu.inject.javafxdemo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.Bean;
|
|
||||||
import com.imyeyu.inject.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JavaFX 应用配置
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class FxConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public DateTimeFormatter dateTimeFormatter() {
|
|
||||||
return DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean("appTitle")
|
|
||||||
public String appTitle() {
|
|
||||||
return "Timi-Inject JavaFX Demo";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean("version")
|
|
||||||
public String version() {
|
|
||||||
return "0.0.2";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,65 +0,0 @@
|
|||||||
package com.imyeyu.inject.javafxdemo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.TimiInject;
|
|
||||||
import com.imyeyu.inject.annotation.Import;
|
|
||||||
import com.imyeyu.inject.annotation.TimiInjectApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JavaFX Demo 功能测试(非 GUI 测试)
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
public class FxDemoTest {
|
|
||||||
|
|
||||||
@TimiInjectApplication("com.imyeyu.inject.javafxdemo")
|
|
||||||
@Import(FxConfig.class)
|
|
||||||
public static class TestApp {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("=== JavaFX Demo Component Test ===\n");
|
|
||||||
|
|
||||||
// 启动 IOC 容器(使用测试专用应用类,避免依赖 JavaFX Application)
|
|
||||||
TimiInject inject = TimiInject.run(TestApp.class);
|
|
||||||
|
|
||||||
// 测试 1: 配置 Bean
|
|
||||||
System.out.println("=== Test 1: Configuration Beans ===");
|
|
||||||
String appTitle = inject.di("appTitle", String.class);
|
|
||||||
String version = inject.di("version", String.class);
|
|
||||||
System.out.println("App Title: " + appTitle);
|
|
||||||
System.out.println("Version: " + version);
|
|
||||||
|
|
||||||
// 测试 2: UserService
|
|
||||||
System.out.println("\n=== Test 2: UserService ===");
|
|
||||||
UserService userService = inject.di(UserService.class);
|
|
||||||
System.out.println("Initial users: " + userService.getAllUsers());
|
|
||||||
System.out.println("User count: " + userService.getUserCount());
|
|
||||||
System.out.println("Current time: " + userService.getCurrentTime());
|
|
||||||
|
|
||||||
userService.addUser("TestUser");
|
|
||||||
System.out.println("After adding TestUser: " + userService.getAllUsers());
|
|
||||||
|
|
||||||
// 测试 3: MessageService
|
|
||||||
System.out.println("\n=== Test 3: MessageService ===");
|
|
||||||
MessageService messageService = inject.di(MessageService.class);
|
|
||||||
System.out.println(messageService.getWelcomeMessage());
|
|
||||||
System.out.println(messageService.getSuccessMessage("Test action"));
|
|
||||||
System.out.println(messageService.getErrorMessage("Test error"));
|
|
||||||
|
|
||||||
// 测试 4: 验证 MainController 可以被注入(但不实例化,避免 JavaFX 依赖)
|
|
||||||
System.out.println("\n=== Test 4: MainController Bean Definition ===");
|
|
||||||
boolean hasController = inject.exportDependencyGraph().contains("MainController");
|
|
||||||
System.out.println("MainController registered: " + (hasController ? "OK" : "FAIL"));
|
|
||||||
|
|
||||||
// 测试 5: 依赖图
|
|
||||||
System.out.println("\n=== Test 5: Dependency Graph ===");
|
|
||||||
String graph = inject.exportDependencyGraph();
|
|
||||||
System.out.println(graph);
|
|
||||||
|
|
||||||
System.out.println("\n=== All Tests Passed! ===");
|
|
||||||
System.out.println("\nTo run the full JavaFX GUI application, use:");
|
|
||||||
System.out.println(" mvn javafx:run");
|
|
||||||
System.out.println(" or");
|
|
||||||
System.out.println(" run-javafx-demo.bat");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
package com.imyeyu.inject.javafxdemo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.TimiInject;
|
|
||||||
import com.imyeyu.inject.annotation.Import;
|
|
||||||
import com.imyeyu.inject.annotation.TimiInjectApplication;
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Parent;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JavaFX 应用入口
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@TimiInjectApplication("com.imyeyu.inject.javafxdemo")
|
|
||||||
@Import(FxConfig.class)
|
|
||||||
public class FxMain extends Application {
|
|
||||||
|
|
||||||
private static TimiInject inject;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// 启动 IOC 容器
|
|
||||||
inject = TimiInject.run(FxMain.class);
|
|
||||||
|
|
||||||
// 启动 JavaFX 应用
|
|
||||||
launch(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage primaryStage) throws Exception {
|
|
||||||
// 创建 FXMLLoader 并设置控制器工厂
|
|
||||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/javafxdemo/main.fxml"));
|
|
||||||
loader.setControllerFactory(type -> inject.di(type));
|
|
||||||
|
|
||||||
Parent root = loader.load();
|
|
||||||
|
|
||||||
Scene scene = new Scene(root, 600, 400);
|
|
||||||
primaryStage.setTitle("Timi-Inject JavaFX Demo");
|
|
||||||
primaryStage.setScene(scene);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取 IOC 容器实例
|
|
||||||
*/
|
|
||||||
public static TimiInject getInject() {
|
|
||||||
return inject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,135 +0,0 @@
|
|||||||
package com.imyeyu.inject.javafxdemo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.Controller;
|
|
||||||
import com.imyeyu.inject.annotation.PostConstruct;
|
|
||||||
import com.imyeyu.inject.annotation.Scope;
|
|
||||||
import com.imyeyu.inject.annotation.ScopeType;
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.control.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主界面控制器
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Controller
|
|
||||||
@Scope(ScopeType.PROTOTYPE)
|
|
||||||
public class MainController {
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Label welcomeLabel;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Label timeLabel;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Label countLabel;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TextField usernameField;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private ListView<String> userListView;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TextArea logArea;
|
|
||||||
|
|
||||||
private final UserService userService;
|
|
||||||
private final MessageService messageService;
|
|
||||||
private final ObservableList<String> userList = FXCollections.observableArrayList();
|
|
||||||
|
|
||||||
public MainController(UserService userService, MessageService messageService) {
|
|
||||||
this.userService = userService;
|
|
||||||
this.messageService = messageService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
log("MainController initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
public void initialize() {
|
|
||||||
// 设置欢迎消息
|
|
||||||
welcomeLabel.setText(messageService.getWelcomeMessage());
|
|
||||||
|
|
||||||
// 加载用户列表
|
|
||||||
refreshUserList();
|
|
||||||
|
|
||||||
// 更新时间
|
|
||||||
updateTime();
|
|
||||||
|
|
||||||
log("UI initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void handleAddUser() {
|
|
||||||
String username = usernameField.getText().trim();
|
|
||||||
if (username.isEmpty()) {
|
|
||||||
showError("Please enter a username");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
userService.addUser(username);
|
|
||||||
refreshUserList();
|
|
||||||
usernameField.clear();
|
|
||||||
log(messageService.getSuccessMessage("User added"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
showError(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void handleRemoveUser() {
|
|
||||||
String selectedUser = userListView.getSelectionModel().getSelectedItem();
|
|
||||||
if (selectedUser == null) {
|
|
||||||
showError("Please select a user to remove");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
userService.removeUser(selectedUser);
|
|
||||||
refreshUserList();
|
|
||||||
log(messageService.getSuccessMessage("User removed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void handleRefresh() {
|
|
||||||
refreshUserList();
|
|
||||||
updateTime();
|
|
||||||
log("Refreshed");
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void handleClearLog() {
|
|
||||||
logArea.clear();
|
|
||||||
log("Log cleared");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshUserList() {
|
|
||||||
userList.clear();
|
|
||||||
userList.addAll(userService.getAllUsers());
|
|
||||||
userListView.setItems(userList);
|
|
||||||
countLabel.setText("Total Users: " + userService.getUserCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTime() {
|
|
||||||
timeLabel.setText("Current Time: " + userService.getCurrentTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showError(String message) {
|
|
||||||
log(messageService.getErrorMessage(message));
|
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
|
||||||
alert.setTitle("Error");
|
|
||||||
alert.setHeaderText(null);
|
|
||||||
alert.setContentText(message);
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void log(String message) {
|
|
||||||
String timestamp = userService.getCurrentTime();
|
|
||||||
logArea.appendText(String.format("[%s] %s%n", timestamp, message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
package com.imyeyu.inject.javafxdemo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.Qualifier;
|
|
||||||
import com.imyeyu.inject.annotation.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息服务
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class MessageService {
|
|
||||||
|
|
||||||
private final String appTitle;
|
|
||||||
private final String version;
|
|
||||||
|
|
||||||
public MessageService(@Qualifier("appTitle") String appTitle,
|
|
||||||
@Qualifier("version") String version) {
|
|
||||||
this.appTitle = appTitle;
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWelcomeMessage() {
|
|
||||||
return String.format("Welcome to %s v%s!", appTitle, version);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSuccessMessage(String action) {
|
|
||||||
return action + " successfully!";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrorMessage(String error) {
|
|
||||||
return "Error: " + error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
package com.imyeyu.inject.javafxdemo;
|
|
||||||
|
|
||||||
import com.imyeyu.inject.annotation.PostConstruct;
|
|
||||||
import com.imyeyu.inject.annotation.Service;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户服务
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class UserService {
|
|
||||||
|
|
||||||
private final DateTimeFormatter dateTimeFormatter;
|
|
||||||
private final List<String> users = new ArrayList<>();
|
|
||||||
|
|
||||||
public UserService(DateTimeFormatter dateTimeFormatter) {
|
|
||||||
this.dateTimeFormatter = dateTimeFormatter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
users.add("Admin");
|
|
||||||
users.add("User1");
|
|
||||||
users.add("User2");
|
|
||||||
System.out.println("UserService initialized with " + users.size() + " users");
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getAllUsers() {
|
|
||||||
return new ArrayList<>(users);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addUser(String username) {
|
|
||||||
if (username == null || username.isBlank()) {
|
|
||||||
throw new IllegalArgumentException("Username cannot be empty");
|
|
||||||
}
|
|
||||||
if (users.contains(username)) {
|
|
||||||
throw new IllegalArgumentException("User already exists");
|
|
||||||
}
|
|
||||||
users.add(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeUser(String username) {
|
|
||||||
users.remove(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCurrentTime() {
|
|
||||||
return LocalDateTime.now().format(dateTimeFormatter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getUserCount() {
|
|
||||||
return users.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
|
||||||
<?import javafx.scene.control.*?>
|
|
||||||
<?import javafx.scene.layout.*?>
|
|
||||||
|
|
||||||
<BorderPane xmlns="http://javafx.com/javafx"
|
|
||||||
xmlns:fx="http://javafx.com/fxml"
|
|
||||||
fx:controller="com.imyeyu.inject.javafxdemo.MainController"
|
|
||||||
prefHeight="400.0" prefWidth="600.0">
|
|
||||||
|
|
||||||
<!-- 顶部区域 -->
|
|
||||||
<top>
|
|
||||||
<VBox spacing="10" style="-fx-background-color: #2196F3; -fx-padding: 20;">
|
|
||||||
<Label fx:id="welcomeLabel" style="-fx-text-fill: white; -fx-font-size: 18; -fx-font-weight: bold;"/>
|
|
||||||
<Label fx:id="timeLabel" style="-fx-text-fill: white; -fx-font-size: 12;"/>
|
|
||||||
<Label fx:id="countLabel" style="-fx-text-fill: white; -fx-font-size: 12;"/>
|
|
||||||
</VBox>
|
|
||||||
</top>
|
|
||||||
|
|
||||||
<!-- 中心区域 -->
|
|
||||||
<center>
|
|
||||||
<SplitPane dividerPositions="0.5" BorderPane.margin="10">
|
|
||||||
<!-- 左侧:用户列表 -->
|
|
||||||
<VBox spacing="10">
|
|
||||||
<Label text="User Management" style="-fx-font-size: 14; -fx-font-weight: bold;"/>
|
|
||||||
|
|
||||||
<HBox spacing="10">
|
|
||||||
<TextField fx:id="usernameField" promptText="Enter username" HBox.hgrow="ALWAYS"/>
|
|
||||||
<Button text="Add" onAction="#handleAddUser" style="-fx-background-color: #4CAF50; -fx-text-fill: white;"/>
|
|
||||||
</HBox>
|
|
||||||
|
|
||||||
<ListView fx:id="userListView" VBox.vgrow="ALWAYS"/>
|
|
||||||
|
|
||||||
<HBox spacing="10">
|
|
||||||
<Button text="Remove Selected" onAction="#handleRemoveUser"
|
|
||||||
style="-fx-background-color: #f44336; -fx-text-fill: white;" HBox.hgrow="ALWAYS"/>
|
|
||||||
<Button text="Refresh" onAction="#handleRefresh"
|
|
||||||
style="-fx-background-color: #2196F3; -fx-text-fill: white;" HBox.hgrow="ALWAYS"/>
|
|
||||||
</HBox>
|
|
||||||
|
|
||||||
<padding>
|
|
||||||
<Insets top="10" right="10" bottom="10" left="10"/>
|
|
||||||
</padding>
|
|
||||||
</VBox>
|
|
||||||
|
|
||||||
<!-- 右侧:日志区域 -->
|
|
||||||
<VBox spacing="10">
|
|
||||||
<HBox>
|
|
||||||
<Label text="Operation Log" style="-fx-font-size: 14; -fx-font-weight: bold;" HBox.hgrow="ALWAYS"/>
|
|
||||||
<Button text="Clear Log" onAction="#handleClearLog" style="-fx-font-size: 10;"/>
|
|
||||||
</HBox>
|
|
||||||
|
|
||||||
<TextArea fx:id="logArea" editable="false" VBox.vgrow="ALWAYS"
|
|
||||||
style="-fx-font-family: 'Consolas', monospace; -fx-font-size: 11;"/>
|
|
||||||
|
|
||||||
<padding>
|
|
||||||
<Insets top="10" right="10" bottom="10" left="10"/>
|
|
||||||
</padding>
|
|
||||||
</VBox>
|
|
||||||
</SplitPane>
|
|
||||||
</center>
|
|
||||||
|
|
||||||
<!-- 底部区域 -->
|
|
||||||
<bottom>
|
|
||||||
<HBox spacing="10" style="-fx-background-color: #f5f5f5; -fx-padding: 10;">
|
|
||||||
<Label text="Powered by Timi-Inject" style="-fx-font-size: 10; -fx-text-fill: #666;"/>
|
|
||||||
<Region HBox.hgrow="ALWAYS"/>
|
|
||||||
<Label text="IOC/DI Framework Demo" style="-fx-font-size: 10; -fx-text-fill: #666;"/>
|
|
||||||
</HBox>
|
|
||||||
</bottom>
|
|
||||||
</BorderPane>
|
|
||||||
Reference in New Issue
Block a user