This commit is contained in:
Timi
2026-05-11 21:38:37 +08:00
parent 6837781383
commit 88f3e135ff
37 changed files with 358 additions and 658 deletions

View File

@@ -47,15 +47,15 @@ public class ScreenIdentify extends Stage implements TimiFXUI {
while (c.next()) {
if (c.wasAdded()) {
List<? extends Identify> list = c.getAddedSubList();
for (int i = 0; i < list.size(); i++) {
Rectangle2D r2d = list.get(i).screen.getBounds();
list.get(i).show(this, r2d.getMinX() + 80, r2d.getMinY() + 80);
for (Identify identify : list) {
Rectangle2D r2d = identify.screen.getBounds();
identify.show(this, r2d.getMinX() + 80, r2d.getMinY() + 80);
}
}
if (c.wasRemoved()) {
List<? extends Identify> list = c.getRemoved();
for (int i = 0; i < list.size(); i++) {
list.get(i).hide();
for (Identify identify : list) {
identify.hide();
}
}
}

View File

@@ -12,6 +12,7 @@ import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.TilePane;
import javafx.stage.Popup;
import lombok.Getter;
import java.util.ArrayList;
import java.util.HashMap;
@@ -26,6 +27,8 @@ import java.util.Map;
*/
public class CheckBoxPicker<T> extends TextField implements TimiFXUI {
/** 数据列表 */
@Getter
private final ObservableList<T> items;
private final CheckBoxListPopup<T> checkBoxListPopup;
@@ -65,15 +68,6 @@ public class CheckBoxPicker<T> extends TextField implements TimiFXUI {
return checkBoxListPopup.selectedItems;
}
/**
* 获取数据列表
*
* @return 数据列表
*/
public ObservableList<T> getItems() {
return items;
}
/**
* 复选框列表弹窗
*
@@ -142,8 +136,8 @@ public class CheckBoxPicker<T> extends TextField implements TimiFXUI {
if (c.wasRemoved()) {
// 移除
List<? extends T> list = c.getRemoved();
for (int i = 0; i < list.size(); i++) {
root.getChildren().remove(cache.get(list.get(i)));
for (T t : list) {
root.getChildren().remove(cache.get(t));
}
}
}

View File

@@ -40,13 +40,13 @@ public class ContextMenu extends javafx.scene.control.ContextMenu {
}
private void updateMinWidth(List<MenuItem> items) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i) instanceof Menu menu) {
for (MenuItem item : items) {
if (item instanceof Menu menu) {
if (!menu.getProperties().containsKey(NOT_EXTENDS_FLAG)) {
boolean isItemsMenu = false; // 为 true 时表示子菜单是一般菜单项,继续应用最小宽度
ObservableList<MenuItem> subItems = menu.getItems();
for (int j = 0; j < subItems.size(); j++) {
if (subItems.get(j).getClass().equals(MenuItem.class)) {
for (MenuItem subItem : subItems) {
if (subItem.getClass().equals(MenuItem.class)) {
isItemsMenu = true;
break;
}
@@ -56,7 +56,7 @@ public class ContextMenu extends javafx.scene.control.ContextMenu {
}
}
} else {
items.get(i).setStyle(STYLE_TEMPLATE.formatted(getMinWidth(), getMinWidth()));
item.setStyle(STYLE_TEMPLATE.formatted(getMinWidth(), getMinWidth()));
}
}
}

View File

@@ -22,6 +22,7 @@ import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;
import javafx.util.StringConverter;
import lombok.Getter;
import java.time.LocalDate;
import java.time.LocalTime;
@@ -36,7 +37,8 @@ public class DateTimePicker extends Region implements TimiFXUI, TimiFXUI.Colorfu
private static final String STYLE_CLASS = "date-time-picker";
/** 选择器 */
/** 日期选择器 */
@Getter
private final DatePicker datePicker;
/** 当前值 */
@@ -270,13 +272,4 @@ public class DateTimePicker extends Region implements TimiFXUI, TimiFXUI.Colorfu
public LongProperty valueProperty() {
return value;
}
/**
* 获取日期选择器
*
* @return 日期选择器
*/
public DatePicker getDatePicker() {
return datePicker;
}
}

View File

@@ -115,7 +115,7 @@ public class FileTreeView extends XTreeView<File> implements TimiFXUI.Colorful {
menuRefresh.disableProperty().bind(Bindings.createBooleanBinding(() -> {
List<TreeItem<File>> items = getSelectionModel().getSelectedItems();
// 没有选择、多选、选的不是文件时禁用
return items == null || items.size() != 1 || items.get(0).getValue().isFile();
return items == null || items.size() != 1 || items.getFirst().getValue().isFile();
}, getSelectionModel().selectedItemProperty()));
menuRefresh.setOnAction(e -> refreshItem(getSelectionModel().getSelectedItem()));
@@ -126,8 +126,8 @@ public class FileTreeView extends XTreeView<File> implements TimiFXUI.Colorful {
if (items.isEmpty()) {
return true;
}
for (int i = 0; i < items.size(); i++) {
if (roots.contains(items.get(i).getValue())) {
for (TreeItem<File> item : items) {
if (roots.contains(item.getValue())) {
return true;
}
}
@@ -168,8 +168,8 @@ public class FileTreeView extends XTreeView<File> implements TimiFXUI.Colorful {
});
// 默认磁盘根目录
for (int i = 0; i < roots.size(); i++) {
getRoots().add(new FileItem(roots.get(i)));
for (File root : roots) {
getRoots().add(new FileItem(root));
}
}
@@ -237,8 +237,8 @@ public class FileTreeView extends XTreeView<File> implements TimiFXUI.Colorful {
@Override
protected TreeItem<File> call() {
List<File> items = files.stream().map(TreeItem::getValue).toList();
for (int i = 0; i < items.size(); i++) {
IO.destroy(items.get(i));
for (File file : items) {
IO.destroy(file);
}
// 查找最高级节点刷新
int l = Integer.MAX_VALUE;
@@ -319,16 +319,16 @@ public class FileTreeView extends XTreeView<File> implements TimiFXUI.Colorful {
parent = new File("./").getAbsoluteFile();
}
do {
selectDeque.add(0, parent);
selectDeque.addFirst(parent);
} while ((parent = parent.getParentFile()) != null);
if (TimiJava.isNotEmpty(selectDeque)) {
ObservableList<TreeItem<File>> roots = getRoots();
for (int i = 0; i < roots.size(); i++) {
roots.get(i).setExpanded(false);
if (roots.get(i).getValue().equals(selectDeque.get(0))) {
selectDeque.remove(0);
roots.get(i).setExpanded(true);
for (TreeItem<File> root : roots) {
root.setExpanded(false);
if (root.getValue().equals(selectDeque.getFirst())) {
selectDeque.removeFirst();
root.setExpanded(true);
if (TimiJava.isEmpty(selectDeque)) {
break;
}
@@ -439,13 +439,13 @@ public class FileTreeView extends XTreeView<File> implements TimiFXUI.Colorful {
// 过滤
list:
for (int i = 0; i < fileList.size(); i++) {
for (int j = 0; j < itemFilters.size(); j++) {
if (!itemFilters.get(j).handler(fileList.get(i))) {
for (File file : fileList) {
for (CallbackArgReturn<File, Boolean> itemFilter : itemFilters) {
if (!itemFilter.handler(file)) {
continue list;
}
}
fileItems.add(new FileItem(fileList.get(i)));
fileItems.add(new FileItem(file));
}
}
return fileItems;
@@ -453,11 +453,11 @@ public class FileTreeView extends XTreeView<File> implements TimiFXUI.Colorful {
getChildren().setAll(items);
if (TimiJava.isNotEmpty(selectDeque)) {
File file = selectDeque.remove(0);
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getValue().equals(file)) {
if (items.get(i).getValue().isDirectory()) {
items.get(i).setExpanded(true);
File file = selectDeque.removeFirst();
for (FileItem item : items) {
if (item.getValue().equals(file)) {
if (item.getValue().isDirectory()) {
item.setExpanded(true);
}
break;
}

View File

@@ -120,8 +120,6 @@ public class IconPicker extends TextField implements TimiFXUI {
*/
private static class IconPickerPopup extends Stage {
private static final String SEARCH_API = "https://api.timiserver.imyeyu.net/icon/search/label";
final ToggleGroup group;
final List<ToggleIcon> icons;
final Map<String, Character> nameMapping = TimiFXIcon.getNameMapping();

View File

@@ -6,6 +6,8 @@ import javafx.beans.property.StringProperty;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.StackPane;
import lombok.Getter;
import lombok.Setter;
/**
* 标签进度。如果继承进度组件使用反射注入标签组件时,在设置标签文本会导致标签消失
@@ -13,17 +15,19 @@ import javafx.scene.layout.StackPane;
* @author 夜雨
* @since 2022-08-09 10:48
*/
@Getter
public class LabelProgressBar extends StackPane {
private static final String STYLE_CLASS = "label-progress-bar";
/** 标签 */
/** 标签组件 */
protected final Label label;
/** 进度 */
/** 进度组件 */
protected final ProgressBar bar;
/** 标签转换 */
/** 标签转换回调,进度变换时触发回调 */
@Setter
protected CallbackArgReturn<Double, String> converter;
/** 默认构造 */
@@ -73,15 +77,6 @@ public class LabelProgressBar extends StackPane {
return label.textProperty();
}
/**
* 获取标签组件
*
* @return 标签组件
*/
public Label getLabel() {
return label;
}
/**
* 设置进度值
*
@@ -108,31 +103,4 @@ public class LabelProgressBar extends StackPane {
public DoubleProperty progressProperty() {
return bar.progressProperty();
}
/**
* 获取进度组件
*
* @return 进度组件
*/
public ProgressBar getBar() {
return bar;
}
/**
* 获取标签转换回调
*
* @return 转换回调
*/
public CallbackArgReturn<Double, String> getConverter() {
return converter;
}
/**
* 设置标签转换回调,进度变换时触发回调
*
* @param converter 标签转换回调
*/
public void setConverter(CallbackArgReturn<Double, String> converter) {
this.converter = converter;
}
}

View File

@@ -16,6 +16,7 @@ import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import lombok.Getter;
import java.util.List;
@@ -27,7 +28,8 @@ import java.util.List;
*/
public class Navigation extends ScrollPane implements TimiFXUI {
/** 导航列表 */
/** 导航数据列表 */
@Getter
protected final ObservableList<ToggleButton> items;
/** 已选中监听 */
@@ -62,7 +64,7 @@ public class Navigation extends ScrollPane implements TimiFXUI {
selectedItem.set(btn);
}
});
ObservableList<Node> childrens = root.getChildren();
ObservableList<Node> children = root.getChildren();
// 响应 TimiFXUI
items.addListener((ListChangeListener<ToggleButton>) c -> {
@@ -70,54 +72,54 @@ public class Navigation extends ScrollPane implements TimiFXUI {
if (c.wasAdded()) {
// 添加
List<? extends ToggleButton> list = c.getAddedSubList();
for (int i = 0; i < list.size(); i++) {
list.get(i).setMaxWidth(Double.MAX_VALUE);
list.get(i).getStyleClass().setAll(CSS.MINECRAFT, "navigation-button");
list.get(i).addEventFilter(MouseEvent.MOUSE_PRESSED, TimiFX.EVENT_CONSUME_TG_BTN);
for (ToggleButton toggleButton : list) {
toggleButton.setMaxWidth(Double.MAX_VALUE);
toggleButton.getStyleClass().setAll(CSS.MINECRAFT, "navigation-button");
toggleButton.addEventFilter(MouseEvent.MOUSE_PRESSED, TimiFX.EVENT_CONSUME_TG_BTN);
if (list.get(i).getProperties().get("OWNER") instanceof TitledPane pane) {
if (toggleButton.getProperties().get("OWNER") instanceof TitledPane pane) {
// 存在所属组
if (!childrens.contains(pane)) {
if (!children.contains(pane)) {
// 未添加组
childrens.add(pane);
children.add(pane);
}
if (pane.getContent() instanceof VBox box) {
box.getChildren().add(list.get(i));
box.getChildren().add(toggleButton);
}
} else {
// 单独项
if (!childrens.isEmpty()) {
if (childrens.get(childrens.size() - 1) instanceof TitledPane) {
if (!children.isEmpty()) {
if (children.getLast() instanceof TitledPane) {
// 上一项是组导航,添加上边框
list.get(i).getStyleClass().add("after-group");
toggleButton.getStyleClass().add("after-group");
}
}
childrens.add(list.get(i));
children.add(toggleButton);
}
// 归组
group.getToggles().add(list.get(i));
group.getToggles().add(toggleButton);
}
return;
}
if (c.wasRemoved()) {
// 移除
List<? extends ToggleButton> list = c.getRemoved();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getProperties().get("OWNER") instanceof TitledPane pane) {
for (ToggleButton toggleButton : list) {
if (toggleButton.getProperties().get("OWNER") instanceof TitledPane pane) {
// 存在所属组
if (pane.getContent() instanceof VBox box) {
box.getChildren().remove(list.get(i));
box.getChildren().remove(toggleButton);
if (box.getChildren().isEmpty()) {
// 该组已没有列表项
childrens.remove(box);
children.remove(box);
}
}
} else {
// 单独项
childrens.remove(list.get(i));
children.remove(toggleButton);
}
// 从组移除
group.getToggles().remove(list.get(i));
group.getToggles().remove(toggleButton);
}
}
}
@@ -185,9 +187,9 @@ public class Navigation extends ScrollPane implements TimiFXUI {
pane.setExpanded(isExpanded);
pane.getStyleClass().add("group-pane");
for (int i = 0; i < buttons.length; i++) {
buttons[i].getProperties().put("OWNER", pane);
items.add(buttons[i]);
for (ToggleButton button : buttons) {
button.getProperties().put("OWNER", pane);
items.add(button);
}
return pane;
}
@@ -231,13 +233,4 @@ public class Navigation extends ScrollPane implements TimiFXUI {
public ObjectProperty<ToggleButton> selectedItem() {
return selectedItem;
}
/**
* 获取导航数据列表
*
* @return 导航数据列表
*/
public ObservableList<ToggleButton> getItems() {
return items;
}
}

View File

@@ -56,7 +56,7 @@ public class NumberField extends TextField {
addEventFilter(KeyEvent.KEY_PRESSED, e -> isBackSpace = e.getCode() == KeyCode.BACK_SPACE);
setTextFormatter(new TextFormatter<>(c -> {
String newText = c.getControlNewText();
if (!newText.equals("")) {
if (TimiJava.isNotEmpty(newText)) {
if (newText.equals("+") || newText.equals("-")) {
return c;
}

View File

@@ -45,7 +45,7 @@ public class ProgressSlider extends Slider implements TimiFXUI {
pb.progressProperty().bind(valueProperty().subtract(minProperty()).divide(maxProperty().subtract(minProperty())));
pb.prefWidthProperty().bind(track.widthProperty());
pb.setMouseTransparent(true);
track.getChildren().add(0, pb);
track.getChildren().addFirst(pb);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}

View File

@@ -90,7 +90,7 @@ public class SelectableLabel extends TextArea implements TimiFXUI, TimiFXUI.Colo
bindTextStyle(paragraphNodes.getChildren());
widthProperty().addListener((obs, oldValue, newValue) -> {
if (oldValue.doubleValue() < newValue.doubleValue()) {
if (paragraphNodes.getChildren().get(0) instanceof Text text) {
if (paragraphNodes.getChildren().getFirst() instanceof Text text) {
setPrefHeight(Utils.computeTextHeight(getFont(), getText(), getWidth(), text.getBoundsType()));
}
}
@@ -108,8 +108,8 @@ public class SelectableLabel extends TextArea implements TimiFXUI, TimiFXUI.Colo
* @param list 文本节点,必须是 {@link Text}
*/
private void bindTextStyle(List<? extends Node> list) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof Text text) {
for (Node node : list) {
if (node instanceof Text text) {
text.fillProperty().bind(textFillProperty);
text.textAlignmentProperty().bind(textAlignmentProperty);
}

View File

@@ -47,6 +47,7 @@ import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Path;
import javafx.scene.text.Text;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
@@ -61,28 +62,36 @@ public class TextAreaEditor extends TextArea implements TimiFXUI {
private static final String STYLE_CLASS = "text-area-editor";
/** 主要控制区,此面板在 {@link #header} 的中部 */
/** 控制区面板,此面板在 */
@Getter
protected final HBox ctrl;
/** 顶部控制区 */
/** 顶部控制区面板 */
@Getter
protected final BorderPane header;
/** 撤销按钮 */
@Getter
protected final IconButton undo;
/** 重做按钮 */
@Getter
protected final IconButton redo;
/** 复制按钮 */
@Getter
protected final IconButton copy;
/** 剪切按钮 */
@Getter
protected final IconButton cut;
/** 粘贴按钮 */
@Getter
protected final IconButton paste;
/** 换行按钮 */
@Getter
protected final ToggleIcon wrap;
/** 显示行号 */
@@ -269,7 +278,7 @@ public class TextAreaEditor extends TextArea implements TimiFXUI {
Group paragraphNodes = Ref.getClassFieldValue(skin, TextAreaSkin.class, "paragraphNodes", Group.class);
Callback lineNumberParser = () -> {
wraps.clear();
if (isWrapText() && paragraphNodes.getChildren().get(0) instanceof Text text) {
if (isWrapText() && paragraphNodes.getChildren().getFirst() instanceof Text text) {
// 计算段落被渲染换行数
double wrappingWidth = scrollPane.getWidth() - 12;
for (int i = 0, l = getParagraphs().size(); i < l; i++) {
@@ -319,78 +328,6 @@ public class TextAreaEditor extends TextArea implements TimiFXUI {
return skin;
}
/**
* 获取控制区面板,此面板在 {@link #getHeader()} 的中部
*
* @return 控制区面板
*/
public HBox getCtrl() {
return ctrl;
}
/**
* 获取顶部控制区面板
*
* @return 顶部控制区面板
*/
public BorderPane getHeader() {
return header;
}
/**
* 获取撤销按钮
*
* @return 撤销按钮
*/
public IconButton getUndo() {
return undo;
}
/**
* 获取重做按钮
*
* @return 重做按钮
*/
public IconButton getRedo() {
return redo;
}
/**
* 获取复制按钮
*
* @return 复制按钮
*/
public IconButton getCopy() {
return copy;
}
/**
* 获取剪切按钮
*
* @return 剪切按钮
*/
public IconButton getCut() {
return cut;
}
/**
* 获取粘贴按钮
*
* @return 粘贴按钮
*/
public IconButton getPaste() {
return paste;
}
/**
* 获取换行按钮
*
* @return 换行按钮
*/
public ToggleIcon getWrap() {
return wrap;
}
/**
* 获取是否显示行号
*
@@ -767,7 +704,7 @@ public class TextAreaEditor extends TextArea implements TimiFXUI {
@Override
protected void layoutChildren(double contentX, double contentY, double contentWidth, double contentHeight) {
getChildren().get(0).resizeRelocate(contentX, contentY, contentWidth, contentHeight);
getChildren().getFirst().resizeRelocate(contentX, contentY, contentWidth, contentHeight);
}
}
}

View File

@@ -16,6 +16,8 @@ import javafx.scene.control.skin.TextFieldSkin;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import lombok.Getter;
import lombok.Setter;
/**
* 复杂文本域编辑器 {@link TextAreaEditor} 的文本框显示方式,需要时弹出文本域编辑器
@@ -25,10 +27,13 @@ import javafx.stage.Stage;
*/
public class TextAreaEditorField extends TextField implements TimiFXUI {
/** 显示编辑器事件 */
/** 显示编辑器回调事件,触发时窗体并未显示 */
@Getter
@Setter
private CallbackArg<Stage> onShowEditorEvent;
/** 编辑器窗 */
/** 编辑器窗 */
@Getter
private final EditorStage editorStage;
/** 标题 */
@@ -93,33 +98,6 @@ public class TextAreaEditorField extends TextField implements TimiFXUI {
return skin;
}
/**
* 获取显示编辑器回调事件
*
* @return 显示编辑器回调事件
*/
public CallbackArg<Stage> getOnShowEditorEvent() {
return onShowEditorEvent;
}
/**
* 设置显示编辑器回调事件,触发时窗体并未显示
*
* @param onShowEditorEvent 显示编辑器回调事件
*/
public void setOnShowEditorEvent(CallbackArg<Stage> onShowEditorEvent) {
this.onShowEditorEvent = onShowEditorEvent;
}
/**
* 获取编辑器的弹窗
*
* @return 编辑器弹窗
*/
public EditorStage getEditorStage() {
return editorStage;
}
/**
* 获取编辑器标题
*
@@ -151,7 +129,7 @@ public class TextAreaEditorField extends TextField implements TimiFXUI {
* 编辑器弹窗
*
* @author 夜雨
* @since 2022-07-26 16:54
* @since 2022-07-26 16:54
*/
public static class EditorStage extends Stage {

View File

@@ -125,7 +125,7 @@ public class TextFlower extends TextFlow implements TimiFXUI {
* @return 本实例
*/
public TextFlower asLink(String link) {
Node text = getChildren().remove(getChildren().size() - 1);
Node text = getChildren().removeLast();
if (text instanceof Text t) {
getChildren().add(new XHyperlink(t.getText(), link));
}
@@ -156,7 +156,7 @@ public class TextFlower extends TextFlow implements TimiFXUI {
* 富文本匹配
*
* @author 夜雨
* @since 2022-10-10 11:23
* @since 2022-10-10 11:23
*/
private static class RichMatcher {
@@ -164,7 +164,7 @@ public class TextFlower extends TextFlow implements TimiFXUI {
* 匹配正则
*
* @author 夜雨
* @since 2022-10-10 11:58
* @since 2022-10-10 11:58
*/
private enum Regex {
@@ -185,7 +185,7 @@ public class TextFlower extends TextFlow implements TimiFXUI {
* 重点内容样式
*
* @author 夜雨
* @since 2022-10-10 11:58
* @since 2022-10-10 11:58
*/
private enum Style {
@@ -199,11 +199,11 @@ public class TextFlower extends TextFlow implements TimiFXUI {
static Style fromMatcher(String matcher) {
Style[] values = values();
for (int i = 0; i < values.length; i++) {
String[] matches = values[i].matches;
for (int j = 0; j < matches.length; j++) {
if (matches[j].equalsIgnoreCase(matcher)) {
return values[i];
for (Style value : values) {
String[] matches = value.matches;
for (String match : matches) {
if (match.equalsIgnoreCase(matcher)) {
return value;
}
}
}
@@ -315,10 +315,10 @@ public class TextFlower extends TextFlow implements TimiFXUI {
} else {
Text text = new Text(value.substring(sp + 1).trim());
String[] styles = value.substring(0, sp).trim().split(" ");
for (int i = 0; i < styles.length; i++) {
Style style = Style.fromMatcher(styles[i]);
for (String s : styles) {
Style style = Style.fromMatcher(s);
if (style == null) {
text.setFill(Paint.valueOf(styles[i]));
text.setFill(Paint.valueOf(s));
} else {
if (style == Style.UNDERLINE) {
text.setUnderline(true);

View File

@@ -1,6 +1,5 @@
package com.imyeyu.fx.ui.components;
import com.imyeyu.fx.TimiFX;
import com.imyeyu.fx.ui.TimiFXUI;
import com.sun.javafx.scene.control.LabeledText;
import javafx.beans.binding.Bindings;
@@ -57,7 +56,7 @@ public class TitleLabel extends Label implements TimiFXUI {
line.setHeight(1);
line.fillProperty().bind(lineColor);
line.translateYProperty().bind(heightProperty().multiply(.5).subtract(1));
Node node = skin.getChildren().get(0);
Node node = skin.getChildren().getFirst();
if (node instanceof LabeledText text) {
line.widthProperty().bind(Bindings.createDoubleBinding(() -> {
double textWidth = text.getLayoutBounds().getWidth();
@@ -69,11 +68,11 @@ public class TitleLabel extends Label implements TimiFXUI {
}, spacing, text.layoutBoundsProperty()));
}
skin.getChildren().addListener((ListChangeListener<Node>) c -> {
if (skin.getChildren().get(0) != line) {
skin.getChildren().add(0, line);
if (skin.getChildren().getFirst() != line) {
skin.getChildren().addFirst(line);
}
});
skin.getChildren().add(0, line);
skin.getChildren().addFirst(line);
}
return defaultSkin;
}
@@ -81,7 +80,7 @@ public class TitleLabel extends Label implements TimiFXUI {
/**
* 获取当前分割线颜色
*
* @return 分割线颜色,默认 {@link TimiFX.Colorful#BORDER}
* @return 分割线颜色,默认 {@link TimiFXUI.Colorful#BORDER}
*/
public Paint getLineColor() {
return lineColor.get();

View File

@@ -18,6 +18,7 @@ import javafx.scene.layout.StackPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import lombok.Getter;
import javax.swing.SwingUtilities;
import java.awt.Image;
@@ -54,10 +55,16 @@ public final class TrayFX implements TimiFXUI {
/** 菜单寄主窗体 */
private final Stage stage;
/** 根节点,修改这个节点的内容可以完全自定义右键菜单内容 */
@Getter
private final StackPane root;
/** 菜单进行修改 */
@Getter
private final ContextMenu menu;
/** 托盘对象 */
@Getter
private final SystemTray tray;
/** 文本提示 */
@@ -70,6 +77,7 @@ public final class TrayFX implements TimiFXUI {
private final ObjectProperty<Image> icon;
/** 托盘图标 */
@Getter
private TrayIcon trayIcon;
private final List<CallbackArg<Stage>> showMenuListeners;
@@ -157,30 +165,12 @@ public final class TrayFX implements TimiFXUI {
* @param menu 菜单
*/
public void addMenu(int sort, MenuItem... menu) {
for (int i = 0; i < menu.length; i++) {
menu[i].getProperties().put(SORT_KEY, sort);
for (MenuItem menuItem : menu) {
menuItem.getProperties().put(SORT_KEY, sort);
}
this.menu.getItems().addAll(menu);
}
/**
* 获取菜单进行修改(添加菜单建议通过 {@link #addMenu(int, MenuItem...)},可以手动排序
*
* @return 菜单
*/
public ContextMenu getMenu() {
return menu;
}
/**
* 获取根节点,修改这个节点的内容可以完全自定义右键菜单内容
*
* @return 根节点
*/
public StackPane getRoot() {
return root;
}
/**
* 显示图标到托盘
*
@@ -209,8 +199,8 @@ public final class TrayFX implements TimiFXUI {
@Override
public void mouseReleased(MouseEvent e) {
Platform.runLater(() -> {
for (int i = 0; i < clickListeners.size(); i++) {
clickListeners.get(i).handler(e);
for (CallbackArg<MouseEvent> clickListener : clickListeners) {
clickListener.handler(e);
}
if (SwingUtilities.isRightMouseButton(e)) {
Point p = e.getLocationOnScreen();
@@ -224,8 +214,8 @@ public final class TrayFX implements TimiFXUI {
menu.setY(p.getY());
menu.show(stage);
stage.sizeToScene();
for (int i = 0; i < showMenuListeners.size(); i++) {
showMenuListeners.get(i).handler(stage);
for (CallbackArg<Stage> showMenuListener : showMenuListeners) {
showMenuListener.handler(stage);
}
}
});
@@ -374,22 +364,4 @@ public final class TrayFX implements TimiFXUI {
public void addShowMenuListener(CallbackArg<Stage> listener) {
showMenuListeners.add(listener);
}
/**
* 获取托盘图标
*
* @return 托盘图标
*/
public TrayIcon getTrayIcon() {
return trayIcon;
}
/**
* 获取托盘对象
*
* @return 托盘对象
*/
public SystemTray getTray() {
return tray;
}
}

View File

@@ -11,6 +11,9 @@ import javafx.scene.Cursor;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.awt.Desktop;
import java.io.IOException;
@@ -30,6 +33,7 @@ public abstract class VersionLabel<T> extends VBox implements TimiFXUI, TimiFXUI
* @author 夜雨
* @since 2022-11-27 16:13
*/
@AllArgsConstructor
protected enum Status {
/** 一般 */
@@ -44,23 +48,12 @@ public abstract class VersionLabel<T> extends VBox implements TimiFXUI, TimiFXUI
/** 错误 */
ERROR(RED);
Color textColor;
Status(Color textColor) {
this.textColor = textColor;
}
/**
* 设置该状态的文本颜色
*
* @param textColor 颜色
*/
public void setTextColor(Color textColor) {
this.textColor = textColor;
}
final Color textColor;
}
/** 更新链接 */
@Setter
@Getter
protected String updateURL;
/** 版本标签 */
@@ -187,22 +180,4 @@ public abstract class VersionLabel<T> extends VBox implements TimiFXUI, TimiFXUI
* @return 显示文本
*/
protected abstract String failText(Throwable e);
/**
* 获取更新链接
*
* @return 更新链接
*/
public String getUpdateURL() {
return updateURL;
}
/**
* 设置更新链接
*
* @param updateURL 更新链接
*/
public void setUpdateURL(String updateURL) {
this.updateURL = updateURL;
}
}

View File

@@ -161,9 +161,9 @@ public class XPagination extends HBox implements TimiFXUI {
// ---------- 事件 ----------
new ToggleGroup().getToggles().addAll(pageButtons);
for (int i = 0; i < pageButtons.size(); i++) {
for (PageButton button : pageButtons) {
// 阻止取消选择
pageButtons.get(i).addEventFilter(MouseEvent.MOUSE_PRESSED, EVENT_TOGGLE_BUTTON);
button.addEventFilter(MouseEvent.MOUSE_PRESSED, EVENT_TOGGLE_BUTTON);
}
// 数据变动更新
@@ -176,10 +176,10 @@ public class XPagination extends HBox implements TimiFXUI {
ip.set(0);
}
// 主动选中
for (int i = 0; i < pageButtons.size(); i++) {
for (PageButton pageButton : pageButtons) {
// 分页存在预设页码,只作触发事件用(如前置页的第五第六页),需要主动计算激活的按钮
if (ip.get() == pageButtons.get(i).indexProperty.get() && pageButtons.get(i).isVisible()) {
pageButtons.get(i).setSelected(true);
if (ip.get() == pageButton.indexProperty.get() && pageButton.isVisible()) {
pageButton.setSelected(true);
return;
}
}

View File

@@ -15,6 +15,7 @@ import javafx.scene.control.TabPane;
import javafx.scene.control.skin.TabPaneSkin;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
import lombok.Getter;
import java.util.List;
@@ -24,6 +25,7 @@ import java.util.List;
* @author 夜雨
* @since 2022-07-24 10:54
*/
@Getter
public class XTabPane extends TabPane implements TimiFXUI, TimiFXUI.Colorful {
/** 添加按钮 */
@@ -36,15 +38,6 @@ public class XTabPane extends TabPane implements TimiFXUI, TimiFXUI.Colorful {
add.setPrefWidth(20);
}
/**
* 获取添加按钮
*
* @return 添加按钮
*/
public IconButton getAdd() {
return add;
}
@Override
protected Skin<?> createDefaultSkin() {
Skin<?> skin = super.createDefaultSkin();
@@ -93,8 +86,8 @@ public class XTabPane extends TabPane implements TimiFXUI, TimiFXUI.Colorful {
}
};
ObservableList<Node> tabList = headersRegion.getChildren();
for (int i = 0; i < tabList.size(); i++) {
resizeCloseButton.handler(tabList.get(i));
for (Node node : tabList) {
resizeCloseButton.handler(node);
}
headersRegion.getChildren().addListener((ListChangeListener<Node>) c -> {
if (c.next()) {

View File

@@ -20,6 +20,8 @@ import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.stage.WindowEvent;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
@@ -38,28 +40,40 @@ public abstract class AbstractAlert extends Stage implements TimiFXUI, TimiFXUI.
/** 默认内容边距 */
protected static final Insets PADDING_CONTENT = new Insets(8, 16, 8, 16);
/** 左侧按钮 */
/** 按钮布局面板的左侧面板(如果按钮布局主面板被修改,此面板无效) */
@Getter
protected final HBox leftButtons;
/** 中部按钮 */
/** 按钮布局面板的中间面板(如果按钮布局主面板被修改,此面板无效) */
@Getter
protected final HBox centerButtons;
/** 右侧按钮 */
/** 按钮布局面板的右侧面板(如果按钮布局主面板被修改,此面板无效) */
@Getter
protected final HBox rightButtons;
/** 根面板 */
/** 根布局BorderPane 下部分为按钮面板 */
@Getter
protected final BorderPane root;
/** 按钮面板,{@link #leftButtons}、{@link #centerButtons} 、{@link #rightButtons} 在此面板中 */
@Getter
protected final BorderPane btnPane;
private final ObjectProperty<AlertType> typeProperty;
private final List<CallbackArg<WindowEvent>> shownListeners;
/** 最近用户动作 */
@Getter
private AlertButton.Action action;
/** 弹窗动作事件 */
@Setter
private CallbackArgReturn<AlertButton.Action, Boolean> onActionEvent;
/** 窗体尺寸是否适应场景尺寸,显示前设置有效,默认 true */
/** true 为窗体尺寸适应场景尺寸 */
@Setter
@Getter
protected boolean enableSizeToScene = true;
/** 默认构造 */
@@ -293,11 +307,11 @@ public abstract class AbstractAlert extends Stage implements TimiFXUI, TimiFXUI.
/**
* 设置左侧弹窗按钮
*
* @param btns 按钮
* @param buttons 按钮
*/
public void setLeftButtons(AlertButton... btns) {
public void setLeftButtons(AlertButton... buttons) {
leftButtons.getChildren().clear();
putButtons(leftButtons, btns);
putButtons(leftButtons, buttons);
}
/**
@@ -364,85 +378,4 @@ public abstract class AbstractAlert extends Stage implements TimiFXUI, TimiFXUI.
public void addShownListener(CallbackArg<WindowEvent> callback) {
shownListeners.add(callback);
}
/**
* 设置弹窗动作事件(用户点击带有动作的弹窗按钮)
*
* @param onActionEvent 弹窗动作事件
*/
public void setOnActionEvent(CallbackArgReturn<AlertButton.Action, Boolean> onActionEvent) {
this.onActionEvent = onActionEvent;
}
/**
* 获取最近用户动作(弹窗按钮事件动作)
*
* @return 最近用户动作
*/
public AlertButton.Action getAction() {
return action;
}
/**
* 获取窗体尺寸是否适应场景尺寸
*
* @return true 为窗体尺寸是否适应场景尺寸
*/
public boolean isEnableSizeToScene() {
return enableSizeToScene;
}
/**
* 设置窗体尺寸是否适应场景尺寸,显示前设置有效,默认 true
*
* @param enableSizeToScene true 为窗体尺寸适应场景尺寸
*/
public void setEnableSizeToScene(boolean enableSizeToScene) {
this.enableSizeToScene = enableSizeToScene;
}
/**
* 获取按钮布局的主面板
*
* @return 按钮布局主面板
*/
public BorderPane getBtnPane() {
return btnPane;
}
/**
* 获取按钮布局面板的左侧面板(如果按钮布局主面板被修改,此面板无效)
*
* @return 按钮布局左侧面板
*/
public HBox getLeftButtons() {
return leftButtons;
}
/**
* 获取按钮布局面板的中间面板(如果按钮布局主面板被修改,此面板无效)
*
* @return 按钮布局中间面板
*/
public HBox getCenterButtons() {
return centerButtons;
}
/**
* 获取按钮布局面板的右侧面板(如果按钮布局主面板被修改,此面板无效)
*
* @return 按钮布局右侧面板
*/
public HBox getRightButtons() {
return rightButtons;
}
/**
* 获取根布局BorderPane 下部分为按钮面板)
*
* @return 根布局面板
*/
public BorderPane getRoot() {
return root;
}
}

View File

@@ -21,6 +21,8 @@ import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import lombok.Getter;
import lombok.Setter;
import java.io.File;
import java.util.List;
@@ -47,8 +49,12 @@ public abstract class AbstractAlertFile extends AbstractAlert implements TimiFXU
protected final AlertButton cancel;
/** 文件目录树 */
@Getter
protected final FileTreeView tree;
/** 确认事件,返回 true 自动关闭窗体 */
@Setter
@Getter
private CallbackArgReturn<List<File>, Boolean> onConfirmEvent;
/**
@@ -163,8 +169,8 @@ public abstract class AbstractAlertFile extends AbstractAlert implements TimiFXU
if (items.isEmpty()) {
return true;
}
for (int i = 0; i < items.size(); i++) {
if (roots.contains(items.get(i).getValue())) {
for (TreeItem<File> item : items) {
if (roots.contains(item.getValue())) {
return true;
}
}
@@ -277,31 +283,4 @@ public abstract class AbstractAlertFile extends AbstractAlert implements TimiFXU
public BooleanProperty showHideProperty() {
return toggleHide.selectedProperty();
}
/**
* 获取确认事件
*
* @return 确认事件
*/
public CallbackArgReturn<List<File>, Boolean> getOnConfirmEvent() {
return onConfirmEvent;
}
/**
* 设置确认事件,返回 true 自动关闭窗体
*
* @param onConfirmEvent 确认事件
*/
public void setOnConfirmEvent(CallbackArgReturn<List<File>, Boolean> onConfirmEvent) {
this.onConfirmEvent = onConfirmEvent;
}
/**
* 获取文件目录树
*
* @return 文件目录树
*/
public FileTreeView getTree() {
return tree;
}
}

View File

@@ -6,6 +6,7 @@ import javafx.scene.control.Label;
import javafx.scene.control.TextInputControl;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Region;
import lombok.Getter;
/**
* 抽象输入弹窗
@@ -16,9 +17,11 @@ import javafx.scene.layout.Region;
public abstract class AbstractAlertInput<T extends TextInputControl> extends AbstractAlert {
/** 输入组件 */
@Getter
protected final T input;
/** 提示文本 */
/** 提示标签组件 */
@Getter
protected final Label tips;
/** 内容面板 */
@@ -42,9 +45,9 @@ public abstract class AbstractAlertInput<T extends TextInputControl> extends Abs
* @param title 标题
* @param content 内容
* @param text 预设输入框文本
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AbstractAlertInput(T t, AlertType type, String title, String content, String text, AlertButton... btns) {
public AbstractAlertInput(T t, AlertType type, String title, String content, String text, AlertButton... buttons) {
tips = new Label(content);
tips.setTextFill(GRAY);
tips.setWrapText(true);
@@ -70,7 +73,7 @@ public abstract class AbstractAlertInput<T extends TextInputControl> extends Abs
if (TimiJava.isNotEmpty(title)) {
setTitle(title);
}
putButtons(btns);
putButtons(buttons);
}
/**
@@ -90,22 +93,4 @@ public abstract class AbstractAlertInput<T extends TextInputControl> extends Abs
public void setTips(String tips) {
this.tips.setText(tips);
}
/**
* 获取提示标签组件
*
* @return 提示标签组件
*/
public Label getTips() {
return tips;
}
/**
* 获取输入组件
*
* @return 输入组件
*/
public T getInput() {
return input;
}
}

View File

@@ -3,6 +3,8 @@ package com.imyeyu.fx.ui.components.alert;
import com.imyeyu.fx.ui.TimiFXUI;
import javafx.geometry.HPos;
import javafx.scene.control.Button;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 弹窗按钮
@@ -10,13 +12,15 @@ import javafx.scene.control.Button;
* @author 夜雨
* @since 2022-01-07 09:37
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class AlertButton extends Button {
/**
* 按钮通用动作,用于标记,具体事件由调用决定
*
* @author 夜雨
* @since 2022-01-20 00:55
* @since 2022-01-20 00:55
*/
public enum Action {
@@ -60,7 +64,10 @@ public class AlertButton extends Button {
OTHER
}
/** 按钮所属位置 */
HPos pos;
/** 按钮动作 */
Action action;
/**
@@ -85,60 +92,6 @@ public class AlertButton extends Button {
this.action = action;
}
/**
* 获取按钮所属位置
*
* @return 按钮所属位置
*/
public HPos getPos() {
return pos;
}
/**
* 设置按钮所属位置
*
* @param pos 按钮所属位置
*/
public void setPos(HPos pos) {
this.pos = pos;
}
/**
* 获取按钮动作
*
* @return 按钮动作
*/
public Action getAction() {
return action;
}
/**
* 设置按钮动作
*
* @param action 按钮动作
*/
public void setAction(Action action) {
this.action = action;
}
/**
* 按钮动作是否一致
*
* @param o 比较对象
* @return true 为按钮动作 AlertButton.Action 相同
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AlertButton that = (AlertButton) o;
return action == that.action;
}
/**
* 快速构造应用按钮
*

View File

@@ -41,10 +41,10 @@ public abstract class AlertConfirm extends AlertTips {
*
* @param type 类型
* @param content 提示内容
* @param btns 按钮
* @param buttons 按钮
*/
public AlertConfirm(AlertType type, String content, AlertButton... btns) {
super(type, btns);
public AlertConfirm(AlertType type, String content, AlertButton... buttons) {
super(type, buttons);
setTips(content);
setOnActionEvent(action -> {

View File

@@ -11,6 +11,7 @@ import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TreeItem;
import lombok.Getter;
import java.io.File;
@@ -23,6 +24,7 @@ import java.io.File;
public class AlertFileSelector extends AbstractAlertFile {
/** 格式过滤列表 */
@Getter
protected final ObservableList<String> formatFilters;
private String[] formatFiltersCache;
@@ -75,13 +77,4 @@ public class AlertFileSelector extends AbstractAlertFile {
public void removeFormatFilters(String... formats) {
formatFilters.removeAll(formats);
}
/**
* 获取格式过滤列表
*
* @return 格式过滤列表
*/
public ObservableList<String> getFormatFilters() {
return formatFilters;
}
}

View File

@@ -23,10 +23,10 @@ public class AlertPassword extends AbstractAlertInput<PasswordField> {
* 密码输入弹窗
*
* @param content 内容
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertPassword(String content, AlertButton... btns) {
this(AlertType.INFORMATION, AlertType.INFORMATION.getTitle(), content, "", btns);
public AlertPassword(String content, AlertButton... buttons) {
this(AlertType.INFORMATION, AlertType.INFORMATION.getTitle(), content, "", buttons);
}
/**
@@ -36,9 +36,9 @@ public class AlertPassword extends AbstractAlertInput<PasswordField> {
* @param title 标题
* @param content 内容
* @param text 预设输入框文本
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertPassword(AlertType type, String title, String content, String text, AlertButton... btns) {
super(new PasswordField(), type, title, content, text, btns);
public AlertPassword(AlertType type, String title, String content, String text, AlertButton... buttons) {
super(new PasswordField(), type, title, content, text, buttons);
}
}

View File

@@ -11,6 +11,7 @@ import javafx.geometry.Insets;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Border;
import javafx.stage.Window;
import lombok.Getter;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -23,7 +24,8 @@ import java.io.StringWriter;
*/
public class AlertTextArea extends AbstractAlertInput<TextArea> {
/** 反馈事件 */
/** 反馈错误事件 */
@Getter
private static CallbackArg<String> onFeedback4Error;
/** 默认构造 */
@@ -54,10 +56,10 @@ public class AlertTextArea extends AbstractAlertInput<TextArea> {
* 文本域输入弹窗
*
* @param text 输入内容
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTextArea(String text, AlertButton... btns) {
this(AlertType.INFORMATION, AlertType.INFORMATION.getTitle(), "", text, btns);
public AlertTextArea(String text, AlertButton... buttons) {
this(AlertType.INFORMATION, AlertType.INFORMATION.getTitle(), "", text, buttons);
}
/**
@@ -65,10 +67,10 @@ public class AlertTextArea extends AbstractAlertInput<TextArea> {
*
* @param content 提示
* @param text 输入内容
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTextArea(String content, String text, AlertButton... btns) {
this(AlertType.INFORMATION, AlertType.INFORMATION.getTitle(), content, text, btns);
public AlertTextArea(String content, String text, AlertButton... buttons) {
this(AlertType.INFORMATION, AlertType.INFORMATION.getTitle(), content, text, buttons);
}
/**
@@ -78,10 +80,10 @@ public class AlertTextArea extends AbstractAlertInput<TextArea> {
* @param title 标题
* @param content 内容
* @param text 预设输入框文本
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTextArea(AlertType type, String title, String content, String text, AlertButton... btns) {
super(new TextArea(), type, title, content, text, btns);
public AlertTextArea(AlertType type, String title, String content, String text, AlertButton... buttons) {
super(new TextArea(), type, title, content, text, buttons);
SmoothScroll.textarea(getInput());
setResizable(true);
@@ -195,15 +197,6 @@ public class AlertTextArea extends AbstractAlertInput<TextArea> {
return alert;
}
/**
* 获取反馈错误事件
*
* @return 反馈错误事件
*/
public static CallbackArg<String> getOnFeedback4Error() {
return onFeedback4Error;
}
/**
* 设置反馈错误事件,全局事件,设置一次即可
*

View File

@@ -34,10 +34,10 @@ public class AlertTextField extends AbstractAlertInput<TextField> {
* 输入弹窗
*
* @param content 提示
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTextField(String content, AlertButton... btns) {
this(AlertType.INFORMATION, AlertType.INFORMATION.getTitle(), content, "", btns);
public AlertTextField(String content, AlertButton... buttons) {
this(AlertType.INFORMATION, AlertType.INFORMATION.getTitle(), content, "", buttons);
}
/**
@@ -45,10 +45,10 @@ public class AlertTextField extends AbstractAlertInput<TextField> {
*
* @param type 弹窗类型
* @param content 内容
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTextField(AlertType type, String content, AlertButton... btns) {
super(new TextField(), type, type.getTitle(), content, "", btns);
public AlertTextField(AlertType type, String content, AlertButton... buttons) {
super(new TextField(), type, type.getTitle(), content, "", buttons);
}
/**
@@ -58,10 +58,10 @@ public class AlertTextField extends AbstractAlertInput<TextField> {
* @param title 标题
* @param content 内容
* @param text 预设输入框文本
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTextField(AlertType type, String title, String content, String text, AlertButton... btns) {
super(new TextField(), type, title, content, text, btns);
public AlertTextField(AlertType type, String title, String content, String text, AlertButton... buttons) {
super(new TextField(), type, title, content, text, buttons);
}
/**

View File

@@ -1,7 +1,9 @@
package com.imyeyu.fx.ui.components.alert;
import com.imyeyu.java.TimiJava;
import javafx.scene.control.Label;
import javafx.stage.Window;
import lombok.Getter;
/**
* 弹窗提示
@@ -9,6 +11,7 @@ import javafx.stage.Window;
* @author 夜雨
* @since 2022-01-07 11:29
*/
@Getter
public class AlertTips extends AbstractAlert {
/** 提示标签 */
@@ -27,20 +30,20 @@ public class AlertTips extends AbstractAlert {
* 弹窗提示
*
* @param content 内容
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTips(String content, AlertButton... btns) {
this(AlertType.INFORMATION, null, content, btns);
public AlertTips(String content, AlertButton... buttons) {
this(AlertType.INFORMATION, null, content, buttons);
}
/**
* 弹窗提示
*
* @param type 类型
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTips(AlertType type, AlertButton... btns) {
this(type, null, "", btns);
public AlertTips(AlertType type, AlertButton... buttons) {
this(type, null, "", buttons);
}
/**
@@ -58,10 +61,10 @@ public class AlertTips extends AbstractAlert {
*
* @param type 类型
* @param content 内容
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTips(AlertType type, String content, AlertButton... btns) {
this(type, null, content, btns);
public AlertTips(AlertType type, String content, AlertButton... buttons) {
this(type, null, content, buttons);
}
/**
@@ -70,9 +73,9 @@ public class AlertTips extends AbstractAlert {
* @param type 类型
* @param title 标题
* @param content 内容
* @param btns 可控按钮
* @param buttons 可控按钮
*/
public AlertTips(AlertType type, String title, String content, AlertButton... btns) {
public AlertTips(AlertType type, String title, String content, AlertButton... buttons) {
tips = new Label(content);
tips.setPadding(PADDING_CONTENT);
tips.setWrapText(true);
@@ -82,10 +85,10 @@ public class AlertTips extends AbstractAlert {
setResizable(false);
setType(type);
if (title != null && !title.trim().equals("")) {
if (TimiJava.isNotEmpty(title)) {
setTitle(title);
}
putButtons(btns);
putButtons(buttons);
}
/**
@@ -97,15 +100,6 @@ public class AlertTips extends AbstractAlert {
this.tips.setText(tips);
}
/**
* 获取提示标签
*
* @return 提示标签
*/
public Label getTips() {
return tips;
}
// ---------- 快速构造 ----------
/**

View File

@@ -2,6 +2,8 @@ package com.imyeyu.fx.ui.components.alert;
import com.imyeyu.fx.ui.TimiFXUI;
import javafx.scene.image.Image;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 弹窗类型
@@ -9,6 +11,8 @@ import javafx.scene.image.Image;
* @author 夜雨
* @since 2022-01-07 10:51
*/
@Getter
@AllArgsConstructor
public enum AlertType {
/** 信息 */
@@ -26,29 +30,9 @@ public enum AlertType {
/** 错误 */
ERROR(new Image("timifx/dialog-error16x.png"), TimiFXUI.MULTILINGUAL.text("error", "错误"));
/** 弹窗类型图标 */
final Image icon;
/** 弹窗类型标题 */
final String title;
AlertType(Image icon, String title) {
this.icon = icon;
this.title = title;
}
/**
* 获取弹窗类型的图标
*
* @return 弹窗类型图标
*/
public Image getIcon() {
return icon;
}
/**
* 获取弹窗类型的标题
*
* @return 弹窗类型标题
*/
public String getTitle() {
return title;
}
}

View File

@@ -22,7 +22,7 @@ public class TimiVersionLabel extends VersionLabel<JsonObject> {
private final String appName;
public TimiVersionLabel(String nowVersion, String appName) {
super(TimiFXUI.MULTILINGUAL.textArgs("version.checking", nowVersion));
super(TimiFXUI.MULTILINGUAL.text("version.checking"));
this.nowVersion = nowVersion;
this.appName = appName;
@@ -58,11 +58,11 @@ public class TimiVersionLabel extends VersionLabel<JsonObject> {
@Override
protected String updateText(String newVersion) {
return TimiFXUI.MULTILINGUAL.textArgs("version.new", nowVersion, newVersion);
return TimiFXUI.MULTILINGUAL.text("version.new");
}
@Override
protected String failText(Throwable e) {
return TimiFXUI.MULTILINGUAL.textArgs("version.fail", nowVersion);
return TimiFXUI.MULTILINGUAL.text("version.fail");
}
}

View File

@@ -31,15 +31,13 @@ public class InterpolatorPane extends BorderPane implements TimiFXUI {
private final Region block;
public InterpolatorPane(Interpolates interpolator) {
SplineInterpolator si = interpolator.getValue();
// 二次曲线
Canvas canvas = new Canvas();
canvas.setWidth(64);
canvas.setHeight(64);
// 插值
SelectableLabel label = new SelectableLabel(TimiFXUI.MULTILINGUAL.textArgs("fx.example.interpolator.demo", interpolator, si.getX1(), si.getY1(), si.getX2(), si.getY2()));
SelectableLabel label = new SelectableLabel(TimiFXUI.MULTILINGUAL.text("fx.example.interpolator.demo"));
// 方块
block = new Region();
@@ -76,7 +74,7 @@ public class InterpolatorPane extends BorderPane implements TimiFXUI {
// 绘制图示
{
double[][] list = interpolator.buildBezierPoint(canvas.getWidth(), canvas.getWidth() * .5);
double[][] list = interpolator.buildBezierPoint(canvas.getWidth(), (long) (canvas.getWidth() * .5));
GraphicsContext g = canvas.getGraphicsContext2D();
g.setFill(Colorful.WHITE);
g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());

View File

@@ -64,7 +64,7 @@ public class AnimationRendererDemo extends AbstractDemoPane implements OS.FileSy
SelectableLabel status = new SelectableLabel("-Djavafx.animation.fullspeed=" + isFullSpeed);
// 重启
Button restart = new Button(TimiFXUI.MULTILINGUAL.textArgs("fx.example.animation_renderer.restart", TimiFXUI.MULTILINGUAL.text(isFullSpeed ? "disable" : "enable")));
Button restart = new Button(TimiFXUI.MULTILINGUAL.text("fx.example.animation_renderer.restart"));
// 示例
Label labelDemo = TimiFXUI.title(TimiFXUI.MULTILINGUAL.text("example"));

View File

@@ -45,7 +45,7 @@ public class CheckBoxPickerDemo extends AbstractDemoPane {
}});
for (int i = 0; i < 32; i++) {
picker.getItems().add(TimiFXUI.MULTILINGUAL.textArgs("fx.example.check_box_picker.item", i));
picker.getItems().add(TimiFXUI.MULTILINGUAL.text("fx.example.check_box_picker.item"));
}
}
}