mirror of
https://github.com/octopusYan/alist-gui.git
synced 2024-11-23 20:46:42 +08:00
feat: 主界面调整、日志打印
This commit is contained in:
parent
1f6ba2d8cc
commit
ef98a76cd3
@ -6,6 +6,7 @@ import cn.octopusyan.alistgui.controller.MainController;
|
|||||||
import cn.octopusyan.alistgui.controller.RootController;
|
import cn.octopusyan.alistgui.controller.RootController;
|
||||||
import cn.octopusyan.alistgui.controller.SetupController;
|
import cn.octopusyan.alistgui.controller.SetupController;
|
||||||
import cn.octopusyan.alistgui.manager.ConfigManager;
|
import cn.octopusyan.alistgui.manager.ConfigManager;
|
||||||
|
import cn.octopusyan.alistgui.manager.ConsoleLog;
|
||||||
import cn.octopusyan.alistgui.util.FxmlUtil;
|
import cn.octopusyan.alistgui.util.FxmlUtil;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.binding.StringBinding;
|
import javafx.beans.binding.StringBinding;
|
||||||
@ -112,6 +113,10 @@ public class Context {
|
|||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
ConfigManager.language(locale);
|
ConfigManager.language(locale);
|
||||||
LANGUAGE_RESOURCE_FACTORY.setResourceBundle(ResourceBundle.getBundle(LANGUAGE_RESOURCE_NAME, 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}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package cn.octopusyan.alistgui.controller;
|
package cn.octopusyan.alistgui.controller;
|
||||||
|
|
||||||
import cn.octopusyan.alistgui.base.BaseController;
|
import cn.octopusyan.alistgui.base.BaseController;
|
||||||
|
import cn.octopusyan.alistgui.manager.ConsoleLog;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -16,6 +18,10 @@ public class MainController extends BaseController<VBox> {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public VBox mainView;
|
public VBox mainView;
|
||||||
|
@FXML
|
||||||
|
public VBox logArea;
|
||||||
|
@FXML
|
||||||
|
public ScrollPane logAreaSp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VBox getRootPanel() {
|
public VBox getRootPanel() {
|
||||||
@ -24,7 +30,7 @@ public class MainController extends BaseController<VBox> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initData() {
|
public void initData() {
|
||||||
|
ConsoleLog.init(logAreaSp, logArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
103
src/main/java/cn/octopusyan/alistgui/manager/ConsoleLog.java
Normal file
103
src/main/java/cn/octopusyan/alistgui/manager/ConsoleLog.java
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
@ -8,42 +8,52 @@
|
|||||||
|
|
||||||
#statusLabel {
|
#statusLabel {
|
||||||
-fx-padding: 2 5 2 5;
|
-fx-padding: 2 5 2 5;
|
||||||
-fx-text-fill: white;
|
|
||||||
-fx-font-size: 15;
|
-fx-font-size: 15;
|
||||||
-fx-background-color: -color-success-3;
|
|
||||||
-fx-background-radius: 10;
|
-fx-background-radius: 10;
|
||||||
-fx-text-alignment: CENTER;
|
-fx-text-alignment: CENTER;
|
||||||
-fx-border-radius: 10;
|
-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-font-size: 15;
|
||||||
-fx-background-radius: 15;
|
-fx-background-radius: 15;
|
||||||
-fx-padding: 10 40 10 40;
|
-fx-padding: 10 40 10 40;
|
||||||
-fx-border-radius: 15;
|
-fx-border-radius: 15;
|
||||||
-fx-border-width: 2;
|
-fx-border-width: 2;
|
||||||
-fx-opacity: 1;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
-fx-opacity: 0.9;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#startButton {
|
#startButton {
|
||||||
-fx-background-color: -color-danger-emphasis;
|
-color-button-bg: -color-danger-4;
|
||||||
-fx-border-color: -color-danger-emphasis;
|
-color-button-bg-hover: -color-button-bg;
|
||||||
-fx-text-fill: white;
|
-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 {
|
#passwordButton {
|
||||||
-fx-background-color: -color-success-3;
|
-color-button-bg: -color-success-3;
|
||||||
-fx-border-color: -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 {
|
#restartButton {
|
||||||
-fx-background-color: linear-gradient(to bottom right, -color-accent-3, -color-chart-6);
|
-color-button-bg: 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);
|
-color-button-bg-hover: -color-button-bg;
|
||||||
-fx-text-fill: white;
|
-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 {
|
#moreButton {
|
||||||
@ -52,17 +62,11 @@
|
|||||||
-fx-border-color: -color-chart-6;
|
-fx-border-color: -color-chart-6;
|
||||||
}
|
}
|
||||||
|
|
||||||
#logArea {
|
.logArea {
|
||||||
-fx-font-family: "Lucida Console";
|
-fx-font-family: "Lucida Console";
|
||||||
-fx-font-size: 20;
|
-fx-font-size: 15;
|
||||||
-fx-background-radius: 15;
|
-fx-background-radius: 15;
|
||||||
-fx-border-radius: 15;
|
-fx-border-radius: 15;
|
||||||
-fx-background-insets: 0;
|
-fx-padding: 5 15 5 15;
|
||||||
|
-fx-background-color: -color-neutral-muted;
|
||||||
.content {
|
|
||||||
-fx-padding: 0 15 0 15;
|
|
||||||
-fx-background-radius: 15;
|
|
||||||
-fx-border-radius: 15;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,19 +3,19 @@
|
|||||||
<?import javafx.geometry.*?>
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<VBox fx:id="mainView" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
|
<VBox fx:id="mainView" prefHeight="700" prefWidth="720" stylesheets="@../css/main-view.css"
|
||||||
stylesheets="@../css/main-view.css" prefWidth="720" prefHeight="700"
|
xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="cn.octopusyan.alistgui.controller.MainController">
|
fx:controller="cn.octopusyan.alistgui.controller.MainController">
|
||||||
<padding>
|
<padding>
|
||||||
<Insets left="10.0" right="10.0" top="10.0"/>
|
<Insets left="10.0" right="10.0" top="10.0"/>
|
||||||
</padding>
|
</padding>
|
||||||
<HBox alignment="TOP_CENTER" prefWidth="Infinity">
|
<HBox alignment="TOP_CENTER" prefWidth="Infinity">
|
||||||
<Label fx:id="homeLabel" alignment="CENTER" text="AList GUI"/>
|
<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>
|
<HBox.margin>
|
||||||
<Insets left="-10.0" top="-5"/>
|
<Insets left="-10.0" top="-5"/>
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
</Label>
|
</Button>
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="TOP_CENTER" prefWidth="Infinity" spacing="25.0">
|
<HBox alignment="TOP_CENTER" prefWidth="Infinity" spacing="25.0">
|
||||||
<padding>
|
<padding>
|
||||||
@ -24,16 +24,18 @@
|
|||||||
<VBox.margin>
|
<VBox.margin>
|
||||||
<Insets bottom="10.0" top="10.0"/>
|
<Insets bottom="10.0" top="10.0"/>
|
||||||
</VBox.margin>
|
</VBox.margin>
|
||||||
<Button fx:id="startButton" styleClass="control-menu" text="%main.control.start"/>
|
<Button fx:id="startButton" styleClass="control-menu, danger" text="%main.control.start"/>
|
||||||
<Button fx:id="passwordButton" styleClass="control-menu" text="%main.control.password"/>
|
<Button fx:id="passwordButton" styleClass="control-menu, success" text="%main.control.password"/>
|
||||||
<Button fx:id="restartButton" styleClass="control-menu" text="%main.control.restart"/>
|
<Button fx:id="restartButton" styleClass="control-menu, success" text="%main.control.restart"/>
|
||||||
<Button fx:id="moreButton" styleClass="control-menu" text="%main.control.more"/>
|
<Button fx:id="moreButton" styleClass="control-menu" text="%main.control.more"/>
|
||||||
</HBox>
|
</HBox>
|
||||||
<TextArea fx:id="logArea" editable="false" prefWidth="Infinity"
|
<ScrollPane fx:id="logAreaSp" fitToWidth="true" prefHeight="499.0" prefWidth="Infinity"
|
||||||
text="123d1a32s1d3as21d3a2s1d3a2s1d3a2s1d3a2s1d3a2s1d3a2s1d32aasda3s21da32s1d32a1sd"
|
styleClass="logArea" VBox.vgrow="ALWAYS">
|
||||||
wrapText="true" VBox.vgrow="ALWAYS">
|
|
||||||
|
<VBox fx:id="logArea" spacing="10">
|
||||||
<VBox.margin>
|
<VBox.margin>
|
||||||
<Insets bottom="10.0" top="10.0"/>
|
<Insets bottom="10.0" top="10.0"/>
|
||||||
</VBox.margin>
|
</VBox.margin>
|
||||||
</TextArea>
|
</VBox>
|
||||||
|
</ScrollPane>
|
||||||
</VBox>
|
</VBox>
|
||||||
|
Loading…
Reference in New Issue
Block a user