feat: 主界面调整、日志打印

This commit is contained in:
octopus_yan 2024-09-12 01:39:28 +08:00
parent 1f6ba2d8cc
commit ef98a76cd3
5 changed files with 161 additions and 41 deletions

View File

@ -6,6 +6,7 @@ import cn.octopusyan.alistgui.controller.MainController;
import cn.octopusyan.alistgui.controller.RootController;
import cn.octopusyan.alistgui.controller.SetupController;
import cn.octopusyan.alistgui.manager.ConfigManager;
import cn.octopusyan.alistgui.manager.ConsoleLog;
import cn.octopusyan.alistgui.util.FxmlUtil;
import javafx.application.Platform;
import javafx.beans.binding.StringBinding;
@ -112,6 +113,10 @@ public class Context {
Locale.setDefault(locale);
ConfigManager.language(locale);
LANGUAGE_RESOURCE_FACTORY.setResourceBundle(ResourceBundle.getBundle(LANGUAGE_RESOURCE_NAME, locale));
log.info("language changed to {}", locale);
if (ConsoleLog.isInit())
ConsoleLog.info(STR."language changed to \{locale}");
}
/**

View File

@ -1,7 +1,9 @@
package cn.octopusyan.alistgui.controller;
import cn.octopusyan.alistgui.base.BaseController;
import cn.octopusyan.alistgui.manager.ConsoleLog;
import javafx.fxml.FXML;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,6 +18,10 @@ public class MainController extends BaseController<VBox> {
@FXML
public VBox mainView;
@FXML
public VBox logArea;
@FXML
public ScrollPane logAreaSp;
@Override
public VBox getRootPanel() {
@ -24,7 +30,7 @@ public class MainController extends BaseController<VBox> {
@Override
public void initData() {
ConsoleLog.init(logAreaSp, logArea);
}
@Override

View File

@ -0,0 +1,103 @@
package cn.octopusyan.alistgui.manager;
import atlantafx.base.util.BBCodeParser;
import cn.hutool.core.util.StrUtil;
import javafx.application.Platform;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.util.Date;
/**
* 模拟控制台输出
*
* @author octopus_yan
*/
public class ConsoleLog {
public static final String format = "yyyy/MM/dd hh:mm:ss";
private volatile static ConsoleLog log;
private final ScrollPane logAreaSp;
private final VBox textArea;
private ConsoleLog(ScrollPane logAreaSp, VBox textArea) {
this.textArea = textArea;
this.logAreaSp = logAreaSp;
textArea.maxWidthProperty().bind(logAreaSp.prefWidthProperty());
textArea.heightProperty().subscribe(() -> {
logAreaSp.vvalueProperty().setValue(1);
});
}
public static ConsoleLog getInstance() {
if (log == null) {
throw new RuntimeException("are you ready ?");
}
return log;
}
public static void init(ScrollPane logAreaSp, VBox textArea) {
synchronized (ConsoleLog.class) {
log = new ConsoleLog(logAreaSp, textArea);
}
}
public static boolean isInit() {
return log != null;
}
public static void info(String message, Object... param) {
info("", message, param);
}
public static void warning(String message, Object... param) {
warning("", message, param);
}
public static void error(String message, Object... param) {
error("", message, param);
}
public static void info(String tag, String message, Object... param) {
printLog(tag, "INFO", message, param);
}
public static void warning(String tag, String message, Object... param) {
printLog(tag, "[color=-color-chart-2]WARN[/color]", message, param);
}
public static void error(String tag, String message, Object... param) {
printLog(tag, "[color=-color-chart-3]ERROR[/color]", message, param);
}
public static void msg(String message, Object... param) {
Node text = BBCodeParser.createFormattedText(STR."\{StrUtil.format(message, param)}\n\n");
Platform.runLater(() -> log.textArea.getChildren().add(text));
}
public static void printLog(String tag, String level, String message, Object... param) {
String time = DateFormatUtils.format(new Date(), format);
time = STR."[color=-color-accent-emphasis]\{time}[/color]";
String levelStr = StringUtils.substringBetween(level, "]", "[");
if (levelStr == null) levelStr = level;
level = StringUtils.replace(level, levelStr, StringUtils.center(levelStr, 5));
tag = StringUtils.isEmpty(tag) ? "" : STR."\{tag}: ";
String msg = STR."[color=-color-fg-muted]\{StrUtil.format(message, param)}[/color]";
Node text;
if (msg.contains("\n")) {
text = BBCodeParser.createLayout(STR."\{time} \{level} \{tag}\{msg}");
} else {
text = BBCodeParser.createFormattedText(STR."\{time} \{level} \{tag}\{msg}");
}
Platform.runLater(() -> log.textArea.getChildren().add(text));
}
}

View File

@ -8,42 +8,52 @@
#statusLabel {
-fx-padding: 2 5 2 5;
-fx-text-fill: white;
-fx-font-size: 15;
-fx-background-color: -color-success-3;
-fx-background-radius: 10;
-fx-text-alignment: CENTER;
-fx-border-radius: 10;
-color-button-bg: -color-success-3;
-color-button-border: -color-button-bg;
-color-button-border-hover: -color-button-bg;
-color-button-bg-hover: -color-button-bg;
}
.control-menu {
.control-menu, #startButton, #passwordButton, #restartButton, #moreButton {
-fx-font-size: 15;
-fx-background-radius: 15;
-fx-padding: 10 40 10 40;
-fx-border-radius: 15;
-fx-border-width: 2;
-fx-opacity: 1;
&:hover {
-fx-opacity: 0.9;
}
}
#startButton {
-fx-background-color: -color-danger-emphasis;
-fx-border-color: -color-danger-emphasis;
-fx-text-fill: white;
-color-button-bg: -color-danger-4;
-color-button-bg-hover: -color-button-bg;
-color-button-bg-focused: -color-button-bg;
-color-button-bg-pressed: -color-button-bg;
-color-button-border: -color-button-bg;
-color-button-border-hover: -color-button-bg;
-fx-border-color: -color-button-bg;
}
#passwordButton {
-fx-background-color: -color-success-3;
-fx-border-color: -color-success-3;
-color-button-bg: -color-success-3;
-color-button-bg-hover: -color-button-bg;
-color-button-bg-focused: -color-button-bg;
-color-button-bg-pressed: -color-button-bg;
-color-button-border: -color-button-bg;
-color-button-border-hover: -color-button-bg;
-fx-border-color: -color-button-bg;
}
#restartButton {
-fx-background-color: linear-gradient(to bottom right, -color-accent-3, -color-chart-6);
-fx-border-color: linear-gradient(to bottom right, -color-accent-3, -color-chart-6);
-fx-text-fill: white;
-color-button-bg: linear-gradient(to bottom right, -color-accent-3, -color-chart-6);
-color-button-bg-hover: -color-button-bg;
-color-button-bg-focused: -color-button-bg;
-color-button-bg-pressed: -color-button-bg;
-color-button-border: -color-button-bg;
-color-button-border-hover: -color-button-bg;
-fx-border-color: -color-button-bg;
}
#moreButton {
@ -52,17 +62,11 @@
-fx-border-color: -color-chart-6;
}
#logArea {
.logArea {
-fx-font-family: "Lucida Console";
-fx-font-size: 20;
-fx-font-size: 15;
-fx-background-radius: 15;
-fx-border-radius: 15;
-fx-background-insets: 0;
.content {
-fx-padding: 0 15 0 15;
-fx-background-radius: 15;
-fx-border-radius: 15;
}
-fx-padding: 5 15 5 15;
-fx-background-color: -color-neutral-muted;
}

View File

@ -3,19 +3,19 @@
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox fx:id="mainView" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
stylesheets="@../css/main-view.css" prefWidth="720" prefHeight="700"
<VBox fx:id="mainView" prefHeight="700" prefWidth="720" stylesheets="@../css/main-view.css"
xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="cn.octopusyan.alistgui.controller.MainController">
<padding>
<Insets left="10.0" right="10.0" top="10.0"/>
</padding>
<HBox alignment="TOP_CENTER" prefWidth="Infinity">
<Label fx:id="homeLabel" alignment="CENTER" text="AList GUI"/>
<Label fx:id="statusLabel" alignment="TOP_CENTER" text="%main.status.label-running">
<Button fx:id="statusLabel" styleClass="success" alignment="TOP_CENTER" text="%main.status.label-running">
<HBox.margin>
<Insets left="-10.0" top="-5"/>
</HBox.margin>
</Label>
</Button>
</HBox>
<HBox alignment="TOP_CENTER" prefWidth="Infinity" spacing="25.0">
<padding>
@ -24,16 +24,18 @@
<VBox.margin>
<Insets bottom="10.0" top="10.0"/>
</VBox.margin>
<Button fx:id="startButton" styleClass="control-menu" text="%main.control.start"/>
<Button fx:id="passwordButton" styleClass="control-menu" text="%main.control.password"/>
<Button fx:id="restartButton" styleClass="control-menu" text="%main.control.restart"/>
<Button fx:id="startButton" styleClass="control-menu, danger" text="%main.control.start"/>
<Button fx:id="passwordButton" styleClass="control-menu, success" text="%main.control.password"/>
<Button fx:id="restartButton" styleClass="control-menu, success" text="%main.control.restart"/>
<Button fx:id="moreButton" styleClass="control-menu" text="%main.control.more"/>
</HBox>
<TextArea fx:id="logArea" editable="false" prefWidth="Infinity"
text="123d1a32s1d3as21d3a2s1d3a2s1d3a2s1d3a2s1d3a2s1d3a2s1d32aasda3s21da32s1d32a1sd"
wrapText="true" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" top="10.0"/>
</VBox.margin>
</TextArea>
<ScrollPane fx:id="logAreaSp" fitToWidth="true" prefHeight="499.0" prefWidth="Infinity"
styleClass="logArea" VBox.vgrow="ALWAYS">
<VBox fx:id="logArea" spacing="10">
<VBox.margin>
<Insets bottom="10.0" top="10.0"/>
</VBox.margin>
</VBox>
</ScrollPane>
</VBox>