Compare commits
2 Commits
40f556d0e1
...
6837781383
| Author | SHA1 | Date | |
|---|---|---|---|
| 6837781383 | |||
| 68f39aa834 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
/.claude
|
||||
/CLAUDE.md
|
||||
/AGENTS.md
|
||||
/logs
|
||||
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
|
||||
18
pom.xml
18
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.imyeyu.fx.ui</groupId>
|
||||
<artifactId>timi-fx-ui</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
@ -19,7 +19,7 @@
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.fx</groupId>
|
||||
<artifactId>timi-fx</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.fx.icon</groupId>
|
||||
@ -29,7 +29,7 @@
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.lang</groupId>
|
||||
<artifactId>timi-lang</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
</dependency>
|
||||
<!-- 演示程序依赖 -->
|
||||
<dependency>
|
||||
@ -41,13 +41,13 @@
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.network</groupId>
|
||||
<artifactId>timi-network</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.config</groupId>
|
||||
<artifactId>timi-config</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -59,7 +59,13 @@
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.inject</groupId>
|
||||
<artifactId>timi-inject</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.5.24</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
313
src/main/java/com/imyeyu/fx/ui/components/LabelTips.java
Normal file
313
src/main/java/com/imyeyu/fx/ui/components/LabelTips.java
Normal file
@ -0,0 +1,313 @@
|
||||
package com.imyeyu.fx.ui.components;
|
||||
|
||||
import com.imyeyu.fx.ui.TimiFXUI;
|
||||
import com.imyeyu.utils.Time;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.LongProperty;
|
||||
import javafx.beans.property.SimpleLongProperty;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.util.Duration;
|
||||
|
||||
/**
|
||||
* 提示标签,可以临时显示提示内容,经过指定时间后自动恢复原内容。
|
||||
* <p>
|
||||
* 此组件是线程安全的,可以从任意线程调用 {@link #tips(String)} 方法。
|
||||
* 如果在提示期间再次调用 tips 方法,会重置计时器并显示新的提示内容,
|
||||
* 恢复时仍然恢复为最初的原始内容。
|
||||
* </p>
|
||||
*
|
||||
* <pre>{@code
|
||||
* LabelTips label = new LabelTips("默认内容");
|
||||
* label.tips("操作成功!"); // 使用默认 3 秒
|
||||
* label.tips("保存完成!", 5000); // 指定 5 秒
|
||||
* }</pre>
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2025-01-14
|
||||
*/
|
||||
public class LabelTips extends Label implements TimiFXUI.Colorful {
|
||||
|
||||
/** 默认提示持续时间(毫秒) */
|
||||
public static final long DEFAULT_DURATION = Time.S * 5;
|
||||
|
||||
/** 信息提示颜色 */
|
||||
public static final Paint INFO_TEXT_FILL = BLUE;
|
||||
|
||||
/** 警告提示颜色 */
|
||||
public static final Paint WARN_TEXT_FILL = ORANGE;
|
||||
|
||||
/** 错误提示颜色 */
|
||||
public static final Paint ERROR_TEXT_FILL = RED;
|
||||
|
||||
/** 提示持续时间(毫秒) */
|
||||
protected LongProperty duration;
|
||||
|
||||
/** 原始内容,提示结束后恢复 */
|
||||
private volatile String originalText;
|
||||
|
||||
/** 原始颜色,提示结束后恢复 */
|
||||
private volatile Paint originalTextFill;
|
||||
|
||||
/** 定时器,用于恢复原内容 */
|
||||
private PauseTransition transition;
|
||||
|
||||
/** 同步锁 */
|
||||
private final Object lock = new Object();
|
||||
|
||||
/** 默认构造器 */
|
||||
public LabelTips() {
|
||||
this("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准构造器
|
||||
*
|
||||
* @param text 标签初始文本
|
||||
*/
|
||||
public LabelTips(String text) {
|
||||
super(text);
|
||||
this.duration = new SimpleLongProperty(DEFAULT_DURATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示提示内容,使用默认持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
*/
|
||||
public void tips(String content) {
|
||||
tips(content, duration.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示提示内容,指定持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param millis 持续时间(毫秒)
|
||||
*/
|
||||
public void tips(String content, long millis) {
|
||||
tips(content, Duration.millis(millis));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示提示内容,指定持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param duration 持续时间
|
||||
*/
|
||||
public void tips(String content, Duration duration) {
|
||||
tips(content, duration, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示提示内容,指定持续时间与颜色
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param duration 持续时间
|
||||
* @param textFill 文本颜色
|
||||
*/
|
||||
public void tips(String content, Duration duration, Paint textFill) {
|
||||
if (Platform.isFxApplicationThread()) {
|
||||
doTips(content, duration, textFill);
|
||||
} else {
|
||||
Platform.runLater(() -> doTips(content, duration, textFill));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示信息提示内容,使用默认持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
*/
|
||||
public void info(String content) {
|
||||
info(content, duration.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示信息提示内容,指定持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param millis 持续时间(毫秒)
|
||||
*/
|
||||
public void info(String content, long millis) {
|
||||
info(content, Duration.millis(millis));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示信息提示内容,指定持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param duration 持续时间
|
||||
*/
|
||||
public void info(String content, Duration duration) {
|
||||
tips(content, duration, INFO_TEXT_FILL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示警告提示内容,使用默认持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
*/
|
||||
public void warn(String content) {
|
||||
warn(content, duration.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示警告提示内容,指定持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param millis 持续时间(毫秒)
|
||||
*/
|
||||
public void warn(String content, long millis) {
|
||||
warn(content, Duration.millis(millis));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示警告提示内容,指定持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param duration 持续时间
|
||||
*/
|
||||
public void warn(String content, Duration duration) {
|
||||
tips(content, duration, WARN_TEXT_FILL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示错误提示内容,使用默认持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
*/
|
||||
public void error(String content) {
|
||||
error(content, duration.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示错误提示内容,指定持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param millis 持续时间(毫秒)
|
||||
*/
|
||||
public void error(String content, long millis) {
|
||||
error(content, Duration.millis(millis));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示错误提示内容,指定持续时间
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param duration 持续时间
|
||||
*/
|
||||
public void error(String content, Duration duration) {
|
||||
tips(content, duration, ERROR_TEXT_FILL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行提示逻辑,必须在 FX 线程调用
|
||||
*
|
||||
* @param content 提示内容
|
||||
* @param duration 持续时间
|
||||
*/
|
||||
private void doTips(String content, Duration duration, Paint textFill) {
|
||||
synchronized (lock) {
|
||||
// 停止之前的定时器
|
||||
if (transition != null) {
|
||||
transition.stop();
|
||||
}
|
||||
|
||||
// 仅在首次调用时保存原始内容
|
||||
if (originalText == null) {
|
||||
originalText = getText();
|
||||
originalTextFill = getTextFill();
|
||||
}
|
||||
|
||||
// 设置提示内容
|
||||
setText(content);
|
||||
if (textFill != null) {
|
||||
setTextFill(textFill);
|
||||
} else {
|
||||
setTextFill(originalTextFill);
|
||||
}
|
||||
|
||||
// 创建定时器
|
||||
transition = new PauseTransition(duration);
|
||||
transition.setOnFinished(e -> {
|
||||
synchronized (lock) {
|
||||
setText(originalText);
|
||||
setTextFill(originalTextFill);
|
||||
originalText = null;
|
||||
originalTextFill = null;
|
||||
transition = null;
|
||||
}
|
||||
});
|
||||
transition.play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即恢复原始内容,取消正在进行的提示
|
||||
*/
|
||||
public void restore() {
|
||||
if (Platform.isFxApplicationThread()) {
|
||||
doRestore();
|
||||
} else {
|
||||
Platform.runLater(this::doRestore);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行恢复逻辑,必须在 FX 线程调用
|
||||
*/
|
||||
private void doRestore() {
|
||||
synchronized (lock) {
|
||||
if (transition != null) {
|
||||
transition.stop();
|
||||
transition = null;
|
||||
}
|
||||
if (originalText != null) {
|
||||
setText(originalText);
|
||||
setTextFill(originalTextFill);
|
||||
originalText = null;
|
||||
originalTextFill = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前是否正在显示提示
|
||||
*
|
||||
* @return 如果正在显示提示返回 true
|
||||
*/
|
||||
public boolean isTipping() {
|
||||
synchronized (lock) {
|
||||
return originalText != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认提示持续时间
|
||||
*
|
||||
* @return 持续时间(毫秒),默认 {@value #DEFAULT_DURATION}
|
||||
*/
|
||||
public long getDuration() {
|
||||
return duration.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认提示持续时间
|
||||
*
|
||||
* @param millis 持续时间(毫秒)
|
||||
*/
|
||||
public void setDuration(long millis) {
|
||||
this.duration.set(millis);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取持续时间属性
|
||||
*
|
||||
* @return 持续时间属性
|
||||
*/
|
||||
public LongProperty durationProperty() {
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
@ -150,7 +150,7 @@ public abstract class VersionLabel<T> extends VBox implements TimiFXUI, TimiFXUI
|
||||
|
||||
@Override
|
||||
protected void onException(Throwable e) {
|
||||
version.setText(TimiFXUI.MULTILINGUAL.textArgs("version.fail", nowVersion));
|
||||
version.setText(TimiFXUI.MULTILINGUAL.text("version.fail"));
|
||||
version.setOnMouseClicked(event -> checkVersion(nowVersion));
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ public abstract class AbstractAlertFile extends AbstractAlert implements TimiFXU
|
||||
if (file.exists()) {
|
||||
tree.selectItem(file);
|
||||
} else {
|
||||
AlertTips.error(this, TimiFXUI.MULTILINGUAL.textArgs("file.tips.not_found_target", absolutePath.getText()));
|
||||
AlertTips.error(this, TimiFXUI.MULTILINGUAL.text("file.tips.not_found_target"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,20 +1,17 @@
|
||||
package com.imyeyu.fx.ui.examples;
|
||||
|
||||
import com.imyeyu.inject.InjectApp;
|
||||
import javafx.application.Application;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.imyeyu.config.ConfigLoader;
|
||||
import com.imyeyu.fx.config.BindingsConfig;
|
||||
import com.imyeyu.fx.ui.TimiFXUI;
|
||||
import com.imyeyu.fx.ui.examples.bean.Config;
|
||||
import com.imyeyu.fx.ui.examples.ctrl.Main;
|
||||
import com.imyeyu.inject.TimiInject;
|
||||
import com.imyeyu.inject.annotation.TimiInjectApplication;
|
||||
import com.imyeyu.java.bean.Language;
|
||||
import com.imyeyu.lang.multi.ResourcesMultilingual;
|
||||
|
||||
import java.util.Map;
|
||||
import javafx.application.Application;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* TimiFX 示例程序
|
||||
@ -36,31 +33,23 @@ public class TimiFXExamples {
|
||||
private static ConfigLoader<Config> configLoader;
|
||||
|
||||
@Getter
|
||||
private static InjectApp injectApp;
|
||||
public static TimiInject inject;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
injectApp = new InjectApp(TimiFXExamples.class);
|
||||
{
|
||||
configLoader = new ConfigLoader<>("TimiFXExamples.yaml", Config.class);
|
||||
for (Map.Entry<Class<?>, BindingsConfig.PropertyConverter<?, ?>> item : BindingsConfig.DEFAULT_CONVERTER_MAP.entrySet()) {
|
||||
configLoader.addConverter(item.getKey(), item.getValue());
|
||||
}
|
||||
configLoader.addConverter(ObjectProperty.class, BindingsConfig.OBJECT);
|
||||
BindingsConfig.addAllFXConverter(configLoader);
|
||||
config = configLoader.load();
|
||||
|
||||
ResourcesMultilingual multilingual = TimiFXUI.MULTILINGUAL;
|
||||
multilingual.addAll("lang/timi-fx-ui/%s.lang");
|
||||
multilingual.addAll("lang/%s.lang");
|
||||
multilingual.setActivated(Language.zh_CN);
|
||||
multilingual.setActivated(Language.Enum.zh_CN);
|
||||
|
||||
// 禁止系统 DPI 缩放
|
||||
System.setProperty("prism.allowhidpi", "false");
|
||||
System.setProperty("glass.win.minHiDPI", "1");
|
||||
}
|
||||
Application.launch(Main.class);
|
||||
} catch (Exception e) {
|
||||
log.error("fatal error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package com.imyeyu.fx.ui.examples.bean;
|
||||
|
||||
import com.imyeyu.java.bean.Language;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import lombok.Data;
|
||||
import com.imyeyu.java.bean.Language;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
@ -12,7 +12,7 @@ import com.imyeyu.java.bean.Language;
|
||||
@Data
|
||||
public class Config {
|
||||
|
||||
private ObjectProperty<Language> language;
|
||||
private ObjectProperty<Language.Enum> language;
|
||||
|
||||
private DoubleProperty width;
|
||||
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
package com.imyeyu.fx.ui.examples.component;
|
||||
|
||||
import com.imyeyu.fx.ui.TimiFXUI;
|
||||
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
|
||||
import com.imyeyu.fx.ui.examples.service.PageService;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import com.imyeyu.inject.annotation.StaticInject;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
|
||||
/**
|
||||
@ -13,12 +9,8 @@ import javafx.scene.layout.BorderPane;
|
||||
* @author 夜雨
|
||||
* @since 2022-08-26 14:55
|
||||
*/
|
||||
@StaticInject
|
||||
public abstract class AbstractPane extends BorderPane implements TimiFXUI {
|
||||
|
||||
@Inject
|
||||
private static PageService pageService;
|
||||
|
||||
/** 显示时触发,UI 线程 */
|
||||
protected void onShow() {
|
||||
// 子类实现
|
||||
@ -29,15 +21,6 @@ public abstract class AbstractPane extends BorderPane implements TimiFXUI {
|
||||
// 子类实现
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转页面
|
||||
*
|
||||
* @param page 页面
|
||||
*/
|
||||
protected final void toPage(SidebarItem page) {
|
||||
pageService.to(page);
|
||||
}
|
||||
|
||||
/** 显示面板事件,由调用者触发,通常是侧边导航 */
|
||||
public final void show() {
|
||||
onShow();
|
||||
|
||||
@ -2,9 +2,9 @@ package com.imyeyu.fx.ui.examples.component;
|
||||
|
||||
import com.imyeyu.fx.ui.TimiFXUI;
|
||||
import com.imyeyu.fx.ui.examples.component.sidebar.Sidebar;
|
||||
import com.imyeyu.fx.ui.examples.service.PageService;
|
||||
import com.imyeyu.inject.annotation.Component;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import com.imyeyu.inject.annotation.InvokeForInjected;
|
||||
import com.imyeyu.inject.annotation.PostConstruct;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
|
||||
/**
|
||||
@ -16,15 +16,26 @@ import javafx.scene.layout.BorderPane;
|
||||
@Component
|
||||
public class RootLayout extends BorderPane implements TimiFXUI {
|
||||
|
||||
@Inject
|
||||
private Sidebar sidebar;
|
||||
private final Sidebar sidebar;
|
||||
private final PageService pageService;
|
||||
|
||||
public RootLayout() {
|
||||
public RootLayout(Sidebar sidebar, PageService pageService) {
|
||||
this.sidebar = sidebar;
|
||||
this.pageService = pageService;
|
||||
setBorder(Stroke.TOP);
|
||||
}
|
||||
|
||||
@InvokeForInjected
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
setLeft(sidebar);
|
||||
pageService.activatedPageProperty().addListener((obs, prev, now) -> {
|
||||
if (now != null && now.getIOCPage() instanceof AbstractPane pane) {
|
||||
pane.show();
|
||||
setCenter(pane);
|
||||
}
|
||||
if (prev != null && prev.getIOCPage() instanceof AbstractPane pane) {
|
||||
pane.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@ import com.imyeyu.fx.ui.TimiFXUI;
|
||||
import com.imyeyu.fx.ui.components.Navigation;
|
||||
import com.imyeyu.fx.ui.examples.service.PageService;
|
||||
import com.imyeyu.inject.annotation.Component;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
|
||||
/**
|
||||
@ -16,10 +15,8 @@ import javafx.scene.control.ToggleButton;
|
||||
@Component
|
||||
public class Sidebar extends Navigation {
|
||||
|
||||
@Inject
|
||||
private PageService pageService;
|
||||
public Sidebar(PageService pageService) {
|
||||
|
||||
public Sidebar() {
|
||||
Item welcome = new Item(SidebarItem.WELCOME);
|
||||
Item style = new Item(SidebarItem.STYLE);
|
||||
Item extendTools = new Item(SidebarItem.EXTEND_TOOLS);
|
||||
@ -37,25 +34,7 @@ public class Sidebar extends Navigation {
|
||||
addGroup(TimiFXUI.MULTILINGUAL.text("animation"), interpolator, smoothScroll);
|
||||
|
||||
// 组件
|
||||
SidebarItem[] components = {
|
||||
SidebarItem.CHECK_BOX_PICKER,
|
||||
SidebarItem.DATE_TIME_PICKER,
|
||||
SidebarItem.EDITABLE_TABLE_CELL,
|
||||
SidebarItem.FILE_TREE_VIEW,
|
||||
SidebarItem.ICON_BUTTON,
|
||||
SidebarItem.ICON_PICKER,
|
||||
SidebarItem.LABEL_PROGRESS_BAR,
|
||||
SidebarItem.NAVIGATION,
|
||||
SidebarItem.NUMBER_FIELD,
|
||||
SidebarItem.PROGRESS_SLIDER,
|
||||
SidebarItem.SELECTABLE_LABEL,
|
||||
SidebarItem.TEXT_AREA_EDITOR,
|
||||
SidebarItem.TITLE_LABEL,
|
||||
SidebarItem.TOGGLE_ICON,
|
||||
SidebarItem.X_PAGINATION,
|
||||
SidebarItem.X_TAB_PANE,
|
||||
SidebarItem.X_TREE_VIEW
|
||||
};
|
||||
SidebarItem[] components = {SidebarItem.CHECK_BOX_PICKER, SidebarItem.DATE_TIME_PICKER, SidebarItem.EDITABLE_TABLE_CELL, SidebarItem.FILE_TREE_VIEW, SidebarItem.ICON_BUTTON, SidebarItem.ICON_PICKER, SidebarItem.LABEL_PROGRESS_BAR, SidebarItem.NAVIGATION, SidebarItem.NUMBER_FIELD, SidebarItem.PROGRESS_SLIDER, SidebarItem.SELECTABLE_LABEL, SidebarItem.TEXT_AREA_EDITOR, SidebarItem.TITLE_LABEL, SidebarItem.TOGGLE_ICON, SidebarItem.X_PAGINATION, SidebarItem.X_TAB_PANE, SidebarItem.X_TREE_VIEW};
|
||||
Item[] componentItems = new Item[components.length];
|
||||
for (int i = 0; i < componentItems.length; i++) {
|
||||
componentItems[i] = new Item(components[i]);
|
||||
|
||||
@ -155,6 +155,6 @@ public enum SidebarItem {
|
||||
|
||||
/** @return 从 TimiInject 控制反转对象获取该页面 */
|
||||
public Node getIOCPage() {
|
||||
return TimiFXExamples.getInjectApp().injector().di(page);
|
||||
return TimiFXExamples.getInject().getBean(page);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,13 @@
|
||||
package com.imyeyu.fx.ui.examples.ctrl;
|
||||
|
||||
import com.imyeyu.fx.inject.FXTimiInject;
|
||||
import com.imyeyu.fx.ui.components.TrayFX;
|
||||
import com.imyeyu.fx.ui.examples.TimiFXExamples;
|
||||
import com.imyeyu.fx.ui.examples.component.sidebar.Sidebar;
|
||||
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
|
||||
import com.imyeyu.fx.ui.examples.service.PageService;
|
||||
import com.imyeyu.fx.ui.examples.view.ViewMain;
|
||||
import com.imyeyu.inject.TimiInject;
|
||||
import com.imyeyu.inject.annotation.IOCReturn;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import com.imyeyu.inject.annotation.SuperInject;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.awt.SplashScreen;
|
||||
@ -20,7 +18,6 @@ import java.awt.SplashScreen;
|
||||
* @author 夜雨
|
||||
* @since 2022-05-03 15:43
|
||||
*/
|
||||
@SuperInject
|
||||
public class Main extends ViewMain {
|
||||
|
||||
@Inject
|
||||
@ -38,7 +35,7 @@ public class Main extends ViewMain {
|
||||
public void start(Stage stage) {
|
||||
this.stage = stage;
|
||||
|
||||
TimiInject.run(TimiFXExamples.getInjectApp()).ioc(this);
|
||||
TimiFXExamples.inject = FXTimiInject.run(TimiFXExamples.class, this, stage);
|
||||
super.start(stage);
|
||||
|
||||
sidebar.setSelected(SidebarItem.WELCOME);
|
||||
@ -58,10 +55,4 @@ public class Main extends ViewMain {
|
||||
trayFX.remove();
|
||||
stage.close();
|
||||
}
|
||||
|
||||
/** 主窗体 */
|
||||
@IOCReturn
|
||||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
package com.imyeyu.fx.ui.examples.service;
|
||||
|
||||
import com.imyeyu.fx.ui.examples.component.AbstractPane;
|
||||
import com.imyeyu.fx.ui.examples.component.RootLayout;
|
||||
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import com.imyeyu.inject.annotation.Service;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 页面服务
|
||||
@ -16,13 +12,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* @author 夜雨
|
||||
* @since 2021-12-26 10:57
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PageService {
|
||||
|
||||
@Inject
|
||||
private RootLayout root;
|
||||
|
||||
private SidebarItem prev;
|
||||
|
||||
private final ObjectProperty<SidebarItem> activatedPageProperty;
|
||||
@ -31,13 +23,6 @@ public class PageService {
|
||||
activatedPageProperty = new SimpleObjectProperty<>();
|
||||
activatedPageProperty.addListener((obs, prev, now) -> {
|
||||
this.prev = prev;
|
||||
if (now != null && now.getIOCPage() instanceof AbstractPane pane) {
|
||||
pane.show();
|
||||
root.setCenter(pane);
|
||||
}
|
||||
if (prev != null && prev.getIOCPage() instanceof AbstractPane pane) {
|
||||
pane.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,8 @@ import com.imyeyu.fx.ui.TimiFXUI;
|
||||
import com.imyeyu.fx.ui.components.TrayFX;
|
||||
import com.imyeyu.fx.ui.examples.TimiFXExamples;
|
||||
import com.imyeyu.fx.ui.examples.bean.Config;
|
||||
import com.imyeyu.inject.annotation.IOCReturn;
|
||||
import com.imyeyu.inject.annotation.Bean;
|
||||
import com.imyeyu.inject.annotation.Configuration;
|
||||
import javafx.scene.image.Image;
|
||||
|
||||
/**
|
||||
@ -13,19 +14,19 @@ import javafx.scene.image.Image;
|
||||
* @author 夜雨
|
||||
* @since 2022-08-26 15:23
|
||||
*/
|
||||
@com.imyeyu.inject.annotation.Resources
|
||||
@Configuration
|
||||
public class Resources implements TimiFXUI {
|
||||
|
||||
public static final Image ICON_X64 = new Image(RESOURCE + "icon.png", 64, 64, true, false);
|
||||
|
||||
/** @return 配置 */
|
||||
@IOCReturn
|
||||
@Bean
|
||||
public Config config() {
|
||||
return TimiFXExamples.getConfig();
|
||||
}
|
||||
|
||||
/** @return 托盘 */
|
||||
@IOCReturn
|
||||
@Bean
|
||||
public TrayFX trayFX() {
|
||||
return TrayFX.getInstance();
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
|
||||
import com.imyeyu.fx.ui.examples.ctrl.Main;
|
||||
import com.imyeyu.fx.utils.AnimationRenderer;
|
||||
import com.imyeyu.fx.utils.Column;
|
||||
import com.imyeyu.inject.TimiInject;
|
||||
import com.imyeyu.inject.annotation.Component;
|
||||
import com.imyeyu.io.IO;
|
||||
import com.imyeyu.utils.OS;
|
||||
@ -154,7 +153,7 @@ fps.valueProperty().addListener((obs, o, newFps) -> {
|
||||
String jar = IO.getJarAbsolutePath(getClass());
|
||||
// 重启
|
||||
try {
|
||||
TimiFX.doRestart(TimiFXExamples.getInjectApp().injector().di(Main.class), jre + param + jar);
|
||||
TimiFX.doRestart(TimiFXExamples.getInject().getBean(Main.class), jre + param + jar);
|
||||
} catch (Exception ex) {
|
||||
AlertTips.error(getScene().getWindow(), TimiFXUI.MULTILINGUAL.text("tips.restart.error"));
|
||||
}
|
||||
|
||||
@ -9,8 +9,7 @@ import com.imyeyu.fx.ui.examples.bean.Config;
|
||||
import com.imyeyu.fx.ui.examples.component.AbstractDemoPane;
|
||||
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
|
||||
import com.imyeyu.inject.annotation.Component;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import com.imyeyu.inject.annotation.InvokeForInjected;
|
||||
import com.imyeyu.inject.annotation.PostConstruct;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.Label;
|
||||
@ -27,12 +26,11 @@ import javafx.scene.layout.VBox;
|
||||
@Component
|
||||
public class BindingsConfigDemo extends AbstractDemoPane {
|
||||
|
||||
@Inject
|
||||
private Config config;
|
||||
|
||||
private final Config config;
|
||||
private final Label stageSize, interpolatorDuration;
|
||||
|
||||
public BindingsConfigDemo() {
|
||||
public BindingsConfigDemo(Config config) {
|
||||
this.config = config;
|
||||
title.setText(SidebarItem.BINDING_CONFIG.getText());
|
||||
document.sync("https://doc.imyeyu.net/timi-fx/net/imyeyu/timifx/config/BindingsConfig.html");
|
||||
source.sync("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/java/net/imyeyu/timifx/config/BindingsConfig.java");
|
||||
@ -95,8 +93,8 @@ BindingsConfig.cfg(config).bindDoubleProperty(duration, Config.section("Interpol
|
||||
}});
|
||||
}
|
||||
|
||||
@InvokeForInjected
|
||||
private void config() {
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
stageSize.textProperty().bind(Bindings.createStringBinding(() -> "[%s, %s]".formatted(config.getWidth().get(), config.getHeight().get()), config.getWidth(), config.getHeight()));
|
||||
interpolatorDuration.textProperty().bind(config.getInterpolator().getDuration().asString());
|
||||
}
|
||||
|
||||
@ -13,14 +13,11 @@ import com.imyeyu.fx.ui.examples.component.TimiVersionLabel;
|
||||
import com.imyeyu.fx.ui.examples.ctrl.Main;
|
||||
import com.imyeyu.fx.ui.examples.util.Resources;
|
||||
import com.imyeyu.fx.utils.Column;
|
||||
import com.imyeyu.inject.TimiInject;
|
||||
import com.imyeyu.inject.annotation.Component;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import com.imyeyu.inject.annotation.InvokeForInjected;
|
||||
import com.imyeyu.inject.annotation.PostConstruct;
|
||||
import com.imyeyu.io.IO;
|
||||
import com.imyeyu.java.bean.Language;
|
||||
import com.imyeyu.utils.OS;
|
||||
import com.imyeyu.utils.Time;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
@ -31,11 +28,8 @@ import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 欢迎页
|
||||
*
|
||||
@ -45,15 +39,11 @@ import java.util.Date;
|
||||
@Component
|
||||
public class Welcome extends AbstractPane implements OS.FileSystem {
|
||||
|
||||
@Inject
|
||||
private Config config;
|
||||
private final Config config;
|
||||
private final ComboBox<Language.Enum> language;
|
||||
|
||||
@Inject
|
||||
private Stage stage;
|
||||
|
||||
private final ComboBox<Language> language;
|
||||
|
||||
public Welcome() {
|
||||
public Welcome(Config config) {
|
||||
this.config = config;
|
||||
Label title = new Label(TimiFXUI.MULTILINGUAL.text("fx.example.title"), new ImageView(Resources.ICON_X64));
|
||||
title.setMaxWidth(Double.MAX_VALUE);
|
||||
title.setAlignment(Pos.CENTER);
|
||||
@ -76,16 +66,16 @@ public class Welcome extends AbstractPane implements OS.FileSystem {
|
||||
labelLang.setTextFill(Colorful.GRAY);
|
||||
|
||||
language = new ComboBox<>();
|
||||
language.getItems().addAll(Language.values());
|
||||
language.getItems().addAll(Language.Enum.values());
|
||||
language.setConverter(new StringConverter<>() {
|
||||
|
||||
@Override
|
||||
public String toString(Language language) {
|
||||
return language.getName();
|
||||
public String toString(Language.Enum language) {
|
||||
return language.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language fromString(String string) {
|
||||
public Language.Enum fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@ -95,13 +85,13 @@ public class Welcome extends AbstractPane implements OS.FileSystem {
|
||||
license.setTextAlignment(TextAlignment.CENTER);
|
||||
|
||||
// 开发者
|
||||
Label develop = new Label(TimiFXUI.MULTILINGUAL.textArgs("developer.arg", "夜雨"));
|
||||
Label develop = new Label(TimiFXUI.MULTILINGUAL.text("developer.arg"));
|
||||
develop.setAlignment(Pos.CENTER);
|
||||
TextFlower blog = new TextFlower().matcher(TimiFXUI.MULTILINGUAL.text("blog"));
|
||||
blog.setTextAlignment(TextAlignment.CENTER);
|
||||
Label copyright = new Label(TimiFXUI.MULTILINGUAL.textArgs("copyright", "夜雨", Time.yearFull.format(new Date())));
|
||||
Label copyright = new Label(TimiFXUI.MULTILINGUAL.text("copyright"));
|
||||
copyright.setAlignment(Pos.CENTER);
|
||||
Label versionTimiFX = new Label(TimiFXUI.MULTILINGUAL.textArgs("fx.example.welcome.version.timifx", "0.0.1"));
|
||||
Label versionTimiFX = new Label(TimiFXUI.MULTILINGUAL.text("fx.example.welcome.version.timifx"));
|
||||
TimiVersionLabel version = new TimiVersionLabel(TimiFXExamples.VERSION, TimiFXExamples.class.getSimpleName()) {{
|
||||
version.setGraphic(new Label(TimiFXUI.MULTILINGUAL.text("fx.example.welcome.version")));
|
||||
}};
|
||||
@ -145,8 +135,8 @@ public class Welcome extends AbstractPane implements OS.FileSystem {
|
||||
}});
|
||||
}
|
||||
|
||||
@InvokeForInjected
|
||||
private void injected() {
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
language.valueProperty().bind(config.getLanguage());
|
||||
|
||||
// 修改语言
|
||||
@ -163,7 +153,7 @@ public class Welcome extends AbstractPane implements OS.FileSystem {
|
||||
String jar = IO.getJarAbsolutePath(getClass());
|
||||
// 重启
|
||||
try {
|
||||
TimiFX.doRestart(TimiFXExamples.getInjectApp().injector().di(Main.class), jre + param + jar);
|
||||
TimiFX.doRestart(TimiFXExamples.getInject().getBean(Main.class), jre + param + jar);
|
||||
} catch (Exception ex) {
|
||||
AlertTips.error(this, TimiFXUI.MULTILINGUAL.text("tips.restart.error"));
|
||||
}
|
||||
|
||||
@ -8,8 +8,7 @@ import com.imyeyu.fx.ui.examples.component.animation.InterpolatorPane;
|
||||
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
|
||||
import com.imyeyu.fx.utils.SmoothScroll;
|
||||
import com.imyeyu.inject.annotation.Component;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import com.imyeyu.inject.annotation.InvokeForInjected;
|
||||
import com.imyeyu.inject.annotation.PostConstruct;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
@ -32,12 +31,11 @@ import javafx.util.StringConverter;
|
||||
@Component
|
||||
public class InterpolatorDemo extends AbstractDemoPane {
|
||||
|
||||
@Inject
|
||||
private Config config;
|
||||
|
||||
private final Config config;
|
||||
private final Slider duration;
|
||||
|
||||
public InterpolatorDemo() {
|
||||
public InterpolatorDemo(Config config) {
|
||||
this.config = config;
|
||||
title.setText(SidebarItem.INTERPOLATOR.getText());
|
||||
document.sync("https://doc.imyeyu.net/timi-fx/net/imyeyu/timifx/bean/Interpolators.html");
|
||||
source.sync("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/java/net/imyeyu/timifx/bean/Interpolators.java");
|
||||
@ -125,8 +123,8 @@ public class InterpolatorDemo extends AbstractDemoPane {
|
||||
});
|
||||
}
|
||||
|
||||
@InvokeForInjected
|
||||
private void config() {
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
duration.valueProperty().bindBidirectional(config.getInterpolator().getDuration());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.imyeyu.fx.ui.examples.view.pages.animation;
|
||||
|
||||
import com.imyeyu.fx.TimiFX;
|
||||
import com.imyeyu.fx.task.RunAsyncScheduled;
|
||||
import com.imyeyu.fx.ui.TimiFXUI;
|
||||
import com.imyeyu.fx.ui.examples.component.AbstractDemoPane;
|
||||
@ -21,6 +22,7 @@ import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.input.ScrollEvent;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
@ -10,8 +10,8 @@ import com.imyeyu.fx.ui.examples.component.AbstractDemoPane;
|
||||
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
|
||||
import com.imyeyu.fx.ui.examples.ctrl.Main;
|
||||
import com.imyeyu.inject.annotation.Component;
|
||||
import com.imyeyu.inject.annotation.Inject;
|
||||
import com.imyeyu.inject.annotation.InvokeForInjected;
|
||||
import com.imyeyu.inject.annotation.PostConstruct;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.control.Button;
|
||||
@ -30,18 +30,17 @@ import java.awt.TrayIcon;
|
||||
* @author 夜雨
|
||||
* @since 2022-09-01 14:39
|
||||
*/
|
||||
@Component
|
||||
public class TrayFXDemo extends AbstractDemoPane {
|
||||
|
||||
@Inject
|
||||
private Main main;
|
||||
|
||||
@Inject
|
||||
private TrayFX trayFX;
|
||||
|
||||
private final Main main;
|
||||
private final Stage stage;
|
||||
private final TrayFX trayFX;
|
||||
private final Button show, hide;
|
||||
|
||||
public TrayFXDemo() {
|
||||
public TrayFXDemo(Main main, Stage stage, TrayFX trayFX) {
|
||||
this.main = main;
|
||||
this.stage = stage;
|
||||
this.trayFX = trayFX;
|
||||
title.setText(SidebarItem.TRAY.getText());
|
||||
document.sync("https://doc.imyeyu.net/timi-fx/net/imyeyu/timifx/util/TrayFX.html");
|
||||
source.sync("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/java/net/imyeyu/timifx/util/TrayFX.java");
|
||||
@ -103,7 +102,7 @@ public class TrayFXDemo extends AbstractDemoPane {
|
||||
});
|
||||
}
|
||||
|
||||
@InvokeForInjected
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
show.disableProperty().bind(trayFX.showingProperty());
|
||||
hide.disableProperty().bind(trayFX.showingProperty().not());
|
||||
@ -111,7 +110,7 @@ public class TrayFXDemo extends AbstractDemoPane {
|
||||
MenuItem show = new MenuItem(TimiFXUI.MULTILINGUAL.text("show"));
|
||||
MenuItem exit = new MenuItem(TimiFXUI.MULTILINGUAL.text("exit"), TimiFXIcon.fromName("FAIL", Colorful.RED));
|
||||
|
||||
show.setOnAction(e -> TimiFX.requestTop(main.getStage()));
|
||||
show.setOnAction(e -> TimiFX.requestTop(stage));
|
||||
exit.setOnAction(e -> main.stop());
|
||||
|
||||
trayFX.addMenu(0, show, TimiFXUI.sep(), exit);
|
||||
|
||||
Reference in New Issue
Block a user