🎉 init project
This commit is contained in:
parent
5c847f2237
commit
8adf737156
7
src/main/java/com/cecilia/AppStart.java
Normal file
7
src/main/java/com/cecilia/AppStart.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package com.cecilia;
|
||||||
|
|
||||||
|
public class AppStart {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AppUI.main(args);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,9 @@
|
|||||||
package com.cecilia;
|
package com.cecilia;
|
||||||
|
|
||||||
|
import com.cecilia.event.BrowseEvent;
|
||||||
|
import com.cecilia.event.DefaultEventBus;
|
||||||
|
import com.cecilia.event.HotkeyEvent;
|
||||||
|
import com.cecilia.event.Listener;
|
||||||
import com.goxr3plus.fxborderlessscene.borderless.BorderlessPane;
|
import com.goxr3plus.fxborderlessscene.borderless.BorderlessPane;
|
||||||
import com.goxr3plus.fxborderlessscene.borderless.BorderlessScene;
|
import com.goxr3plus.fxborderlessscene.borderless.BorderlessScene;
|
||||||
import com.cecilia.theme.ThemeManager;
|
import com.cecilia.theme.ThemeManager;
|
||||||
@ -11,10 +15,17 @@ import fr.brouillard.oss.cssfx.CSSFX;
|
|||||||
import fr.brouillard.oss.cssfx.api.URIToPathConverter;
|
import fr.brouillard.oss.cssfx.api.URIToPathConverter;
|
||||||
import fr.brouillard.oss.cssfx.impl.log.CSSFXLogger;
|
import fr.brouillard.oss.cssfx.impl.log.CSSFXLogger;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.application.ConditionalFeature;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.css.PseudoClass;
|
import javafx.css.PseudoClass;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.SceneAntialiasing;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.input.KeyCodeCombination;
|
||||||
|
import javafx.scene.input.KeyCombination;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.StageStyle;
|
import javafx.stage.StageStyle;
|
||||||
@ -23,6 +34,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
@ -36,66 +48,80 @@ public class AppUI extends Application {
|
|||||||
Resources.getPropertyOrEnv("app.profiles.active", "app.profiles.active")
|
Resources.getPropertyOrEnv("app.profiles.active", "app.profiles.active")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static final List<KeyCodeCombination> SUPPORTED_HOTKEYS = List.of(
|
||||||
|
new KeyCodeCombination(KeyCode.SLASH),
|
||||||
|
new KeyCodeCombination(KeyCode.T, KeyCombination.CONTROL_DOWN),
|
||||||
|
new KeyCodeCombination(KeyCode.W, KeyCombination.CONTROL_DOWN)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
Thread.currentThread().setUncaughtExceptionHandler(new DefaultExceptionHandler(primaryStage));
|
Thread.currentThread().setUncaughtExceptionHandler(new DefaultExceptionHandler(stage));
|
||||||
|
|
||||||
if ("DEV".equalsIgnoreCase(System.getProperty("app.profiles.active"))) {
|
|
||||||
System.out.println("-------[WARNING] Application is running in development mode.");
|
|
||||||
}
|
|
||||||
loadApplicationProperties();
|
loadApplicationProperties();
|
||||||
|
|
||||||
// Application.setUserAgentStylesheet(new NordDark().getUserAgentStylesheet());
|
if (IS_DEV_MODE) {
|
||||||
|
System.out.println("[WARNING] Application is running in development mode.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var antialiasing = Platform.isSupported(ConditionalFeature.SCENE3D)
|
||||||
|
? SceneAntialiasing.BALANCED
|
||||||
|
: SceneAntialiasing.DISABLED;
|
||||||
|
|
||||||
ViewTuple<WindowView, WindowViewModel> viewTuple = FluentViewLoader.fxmlView(WindowView.class).load();
|
ViewTuple<WindowView, WindowViewModel> viewTuple = FluentViewLoader.fxmlView(WindowView.class).load();
|
||||||
Parent mainView = viewTuple.getView();
|
Parent mainView = viewTuple.getView();
|
||||||
|
BorderlessScene scene = new BorderlessScene(stage, StageStyle.TRANSPARENT, mainView, 950, 650);
|
||||||
|
|
||||||
BorderlessScene scene = new BorderlessScene(primaryStage, StageStyle.TRANSPARENT, mainView, 250, 250);
|
|
||||||
BorderlessPane rootPane = (BorderlessPane) scene.getRoot();
|
BorderlessPane rootPane = (BorderlessPane) scene.getRoot();
|
||||||
rootPane.setPadding(new Insets(15, 15, 15, 15));
|
rootPane.setPadding(new Insets(15, 15, 15, 15));
|
||||||
|
|
||||||
|
scene.setOnKeyPressed(this::dispatchHotkeys);
|
||||||
|
scene.removeDefaultCSS();
|
||||||
|
scene.setMoveControl(mainView);
|
||||||
|
scene.setFill(Color.TRANSPARENT);
|
||||||
|
|
||||||
var tm = ThemeManager.getInstance();
|
var tm = ThemeManager.getInstance();
|
||||||
tm.setScene(scene);
|
tm.setScene(scene);
|
||||||
tm.setTheme(tm.getDefaultTheme());
|
tm.setTheme(tm.getDefaultTheme());
|
||||||
if ("DEV".equalsIgnoreCase(System.getProperty("app.profiles.active"))) {
|
if (IS_DEV_MODE) {
|
||||||
startCssFX(scene);
|
startCssFX(scene);
|
||||||
}
|
}
|
||||||
scene.removeDefaultCSS();
|
|
||||||
scene.setMoveControl(mainView);
|
|
||||||
scene.setFill(Color.TRANSPARENT);
|
|
||||||
// viewTuple.getViewModel().setTitle(System.getProperty("app.name"));
|
|
||||||
primaryStage.setTitle(System.getProperty("app.name"));
|
|
||||||
scene.getStylesheets().addAll(AppUI.class.getResource("/styles/index.css").toExternalForm());
|
|
||||||
|
|
||||||
scene.maximizedProperty().addListener((observableValue, oldVal, newVal) -> {
|
scene.maximizedProperty().addListener((observableValue, oldVal, newVal) -> {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
rootPane.setPadding(new Insets(0, 0, 0, 0));
|
rootPane.setPadding(new Insets(0, 0, 0, 0));
|
||||||
} else {
|
} else {
|
||||||
rootPane.setPadding(new Insets(15, 15, 15, 15));
|
rootPane.setPadding(new Insets(15, 15, 15, 15));
|
||||||
}
|
}
|
||||||
// viewTuple.getViewModel().setMaximized(newVal);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scene.getStylesheets().addAll(Resources.resolve("assets/styles/index.css"));
|
||||||
|
|
||||||
PseudoClass CUSTOM_THEME = PseudoClass.getPseudoClass("custom-theme");
|
PseudoClass CUSTOM_THEME = PseudoClass.getPseudoClass("custom-theme");
|
||||||
scene.getRoot().pseudoClassStateChanged(CUSTOM_THEME, true);
|
scene.getRoot().pseudoClassStateChanged(CUSTOM_THEME, true);
|
||||||
//Show
|
//Show
|
||||||
primaryStage.setScene(scene);
|
stage.setScene(scene);
|
||||||
primaryStage.setWidth(900);
|
stage.setTitle(System.getProperty("app.name"));
|
||||||
primaryStage.setHeight(600);
|
loadIcons(stage);
|
||||||
|
stage.setResizable(true);
|
||||||
|
stage.setOnCloseRequest(t -> Platform.exit());
|
||||||
|
|
||||||
// primaryStage.titleProperty().bind(viewTuple.getViewModel().titleProperty());
|
// register event listeners
|
||||||
primaryStage.show();
|
DefaultEventBus.getInstance().subscribe(BrowseEvent.class, this::onBrowseEvent);
|
||||||
|
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
stage.show();
|
||||||
|
stage.requestFocus();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadApplicationProperties() {
|
private void loadApplicationProperties() {
|
||||||
try {
|
Properties properties = new Properties();
|
||||||
var properties = new Properties();
|
try (InputStreamReader in = new InputStreamReader(Resources.getResourceAsStream("/application.properties"),
|
||||||
properties.load(new InputStreamReader(Resources.getResourceAsStream("application.properties"), UTF_8));
|
UTF_8)) {
|
||||||
|
properties.load(in);
|
||||||
properties.forEach((key, value) -> System.setProperty(
|
properties.forEach((key, value) -> System.setProperty(
|
||||||
String.valueOf(key),
|
String.valueOf(key),
|
||||||
String.valueOf(value)
|
String.valueOf(value)
|
||||||
@ -118,16 +144,39 @@ public class AppUI extends Application {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CSSFX.addConverter(fileUrlConverter).start();
|
CSSFX.addConverter(fileUrlConverter).start();
|
||||||
CSSFXLogger.setLoggerFactory(loggerName -> (level, message, args) ->
|
CSSFXLogger.setLoggerFactory(loggerName -> (level, message, args) -> {
|
||||||
System.out.println("[CSSFX] " + String.format(message, args))
|
if (level.ordinal() <= CSSFXLogger.LogLevel.INFO.ordinal()) {
|
||||||
);
|
System.out.println("[" + level + "] CSSFX: " + String.format(message, args));
|
||||||
|
}
|
||||||
|
});
|
||||||
CSSFX.start(scene);
|
CSSFX.start(scene);
|
||||||
}
|
}
|
||||||
|
private void dispatchHotkeys(KeyEvent event) {
|
||||||
|
for (KeyCodeCombination k : SUPPORTED_HOTKEYS) {
|
||||||
|
if (k.match(event)) {
|
||||||
|
DefaultEventBus.getInstance().publish(new HotkeyEvent(k));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void loadIcons(Stage stage) {
|
||||||
|
int iconSize = 16;
|
||||||
|
while (iconSize <= 1024) {
|
||||||
|
iconSize *= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void init() throws Exception {
|
||||||
|
super.init();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void stop() throws Exception {
|
||||||
|
super.stop();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
}
|
||||||
|
@Listener
|
||||||
|
private void onBrowseEvent(BrowseEvent event) {
|
||||||
launch(args);
|
getHostServices().showDocument(event.getUri().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user