chore: 整理

This commit is contained in:
2024-11-15 17:02:52 +08:00
parent 943056168f
commit 1dc7a64833
22 changed files with 142 additions and 87 deletions

View File

@ -51,7 +51,8 @@ public abstract class BaseBuilder<T extends BaseBuilder<T, ?>, D extends Dialog<
}
public void close() {
if (dialog.isShowing())
dialog.close();
Platform.runLater(() -> {
if (dialog.isShowing()) dialog.close();
});
}
}

View File

@ -9,7 +9,6 @@ import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -29,7 +28,6 @@ import java.util.ResourceBundle;
*/
public abstract class BaseController<VM extends BaseViewModel> implements Initializable {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@Getter
protected final VM viewModel;
public BaseController() {
@ -97,7 +95,7 @@ public abstract class BaseController<VM extends BaseViewModel> implements Initia
return "";
}
protected Stage getWindow() {
public Stage getWindow() {
try {
return (Stage) getRootPanel().getScene().getWindow();
} catch (Throwable _) {

View File

@ -8,7 +8,7 @@ import lombok.Setter;
* @author octopus_yan
*/
@Setter
public abstract class BaseViewModel<VM extends BaseViewModel<VM, T>, T extends BaseController<VM>> {
public abstract class BaseViewModel<T extends BaseController> {
protected T controller;

View File

@ -60,17 +60,6 @@ public class Context {
Context.application = application;
}
/**
* 有此类所在路径决定相对路径
*
* @param path 资源文件相对路径
* @return 资源文件路径
*/
// 加载资源文件
public static URL load(String path) {
return Context.class.getResource(path);
}
/**
* 初始化场景
*

View File

@ -224,6 +224,11 @@ public class ConfigManager {
getProxyInfo().setPort(port);
}
/**
* 端口检查
*
* @param consumer 检查结果,信息
*/
public static void checkProxy(BiConsumer<Boolean, String> consumer) {
if (ProxySetup.SYSTEM.equals(proxySetup())) {
consumer.accept(true, "");

View File

@ -1,12 +1,20 @@
package cn.octopusyan.dmt.common.util;
import cn.octopusyan.dmt.Application;
import cn.octopusyan.dmt.common.manager.ConfigManager;
import cn.octopusyan.dmt.view.alert.AlertUtil;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* 工具
@ -55,6 +63,35 @@ public class ViewUtil {
});
}
public static void openDecorated(String title, String fxml) {
Stage open = Objects.requireNonNull(open(StageStyle.DECORATED, title, fxml));
open.setResizable(false);
open.showAndWait();
}
public static Stage open(StageStyle style, String title, String fxml) {
FXMLLoader load = FxmlUtil.load(fxml);
try {
return open(style, title, (Pane) load.load());
} catch (IOException e) {
AlertUtil.getInstance().exception(e).show();
}
return null;
}
public static Stage open(StageStyle style, String title, Pane pane) {
Stage stage = new Stage();
stage.initOwner(Application.getPrimaryStage());
stage.initStyle(style);
stage.initModality(Modality.WINDOW_MODAL);
stage.setTitle(title);
Scene scene = new Scene(pane);
scene.setUserAgentStylesheet(ConfigManager.theme().getUserAgentStylesheet());
stage.setScene(scene);
stage.sizeToScene();
return stage;
}
public static Stage getStage() {
return Application.getPrimaryStage();
}