From 292696172cae3268e45c1d62aeab1a6178298dde Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sun, 13 Feb 2022 01:44:39 +0100 Subject: [PATCH] stuff --- G-Earth/src/main/java/gearth/GEarth.java | 74 ++++++++++++++----- .../main/java/gearth/ui/GEarthController.java | 48 ------------ .../src/main/java/gearth/ui/themes/Theme.java | 7 ++ .../gearth/ui/titlebar/TitleBarConfig.java | 10 +++ .../ui/titlebar/TitleBarController.java | 73 ++++++++++++++++++ .../src/main/resources/gearth/ui/G-Earth.fxml | 27 ------- .../gearth/ui/titlebar/Titlebar.fxml | 35 +++++++++ 7 files changed, 181 insertions(+), 93 deletions(-) create mode 100644 G-Earth/src/main/java/gearth/ui/themes/Theme.java create mode 100644 G-Earth/src/main/java/gearth/ui/titlebar/TitleBarConfig.java create mode 100644 G-Earth/src/main/java/gearth/ui/titlebar/TitleBarController.java create mode 100644 G-Earth/src/main/resources/gearth/ui/titlebar/Titlebar.fxml diff --git a/G-Earth/src/main/java/gearth/GEarth.java b/G-Earth/src/main/java/gearth/GEarth.java index 6cb6041..9c98f6b 100644 --- a/G-Earth/src/main/java/gearth/GEarth.java +++ b/G-Earth/src/main/java/gearth/GEarth.java @@ -4,15 +4,14 @@ import gearth.misc.AdminValidator; import gearth.misc.Cacher; import gearth.misc.UpdateChecker; import gearth.ui.GEarthController; +import gearth.ui.titlebar.TitleBarConfig; +import gearth.ui.titlebar.TitleBarController; import javafx.application.Application; import javafx.application.Platform; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.ToolBar; import javafx.scene.image.Image; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.stage.StageStyle; @@ -25,6 +24,10 @@ public class GEarth extends Application { public static String theme = "G-Earth_Dark"; public static String[] themes = new String[] {"G-Earth", "Tanji", "G-Earth_Dark"}; + private Stage stage; + private TitleBarController titleBar; + private GEarthController controller; + static { if (Cacher.getCacheContents().has("theme")) { theme = Cacher.getCacheContents().getString("theme"); @@ -34,36 +37,71 @@ public class GEarth extends Application { @Override public void start(Stage primaryStage) throws Exception{ main = this; + stage = primaryStage; FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/G-Earth.fxml")); Parent root = loader.load(); - GEarthController companion = loader.getController(); - companion.setStage(primaryStage); - primaryStage.initStyle(StageStyle.TRANSPARENT); + controller = loader.getController(); + controller.setStage(primaryStage); + stage.initStyle(StageStyle.TRANSPARENT); - // https://stackoverflow.com/questions/20732100/javafx-why-does-stage-setresizablefalse-cause-additional-margins -// primaryStage.setScene(new Scene(root, 650, 295)); primaryStage.setScene(new Scene(root)); + titleBar = TitleBarController.create(primaryStage, new TitleBarConfig() { + @Override + public boolean displayThemePicker() { + return true; + } + + @Override + public void onCloseClicked() { + closeGEarth(); + } + + @Override + public void onMinimizeClicked() { + stage.setIconified(true); + } + + @Override + public void onSetTheme(String theme) { + setTheme(theme); + } + }); primaryStage.setResizable(false); primaryStage.sizeToScene(); - - primaryStage.getScene().setFill(Color.TRANSPARENT); - companion.setTheme(theme); + + setTheme(theme); primaryStage.show(); - primaryStage.setOnCloseRequest( event -> { - companion.exit(); - Platform.exit(); - - // Platform.exit doesn't seem to be enough on Windows? - System.exit(0); - }); + primaryStage.setOnCloseRequest( event -> closeGEarth()); AdminValidator.validate(); UpdateChecker.checkForUpdates(); } + private void closeGEarth() { + controller.exit(); + Platform.exit(); + System.exit(0); + } + + private void setTheme(String theme) { + GEarth.theme = theme; + + stage.getScene().getStylesheets().clear(); + stage.getScene().getStylesheets().add(GEarth.class.getResource(String.format("/gearth/themes/%s/styling.css", theme)).toExternalForm()); + + stage.getIcons().clear(); + stage.getIcons().add(new Image(GEarth.class.getResourceAsStream(String.format("/gearth/themes/%s/logoSmall.png", theme)))); + + stage.setTitle(theme.split("_")[0] + " " + GEarth.version); + titleBar.setTitle(stage.getTitle()); + + controller.infoController.img_logo.setImage(new Image(GEarth.class.getResourceAsStream(String.format("/gearth/themes/%s/logo.png", theme)))); + controller.infoController.version.setText(stage.getTitle()); + } + public static String[] args; public static void main(String[] args) { diff --git a/G-Earth/src/main/java/gearth/ui/GEarthController.java b/G-Earth/src/main/java/gearth/ui/GEarthController.java index 4627294..2106a99 100644 --- a/G-Earth/src/main/java/gearth/ui/GEarthController.java +++ b/G-Earth/src/main/java/gearth/ui/GEarthController.java @@ -43,9 +43,6 @@ public class GEarthController { private List tabs = null; - public Pane titleBar; - public Label titleLabel; - public GEarthController() { SocksConfiguration temporary_socks = new SocksConfiguration() { public boolean useSocks() { return false; } @@ -123,54 +120,9 @@ public class GEarthController { loggerController.miniLogText(color, text); } - public void setTheme(String theme) { - GEarth.theme = theme; - - getStage().getScene().getStylesheets().clear(); - getStage().getScene().getStylesheets().add(GEarth.class.getResource(String.format("/gearth/themes/%s/styling.css", theme)).toExternalForm()); - - getStage().getIcons().clear(); - getStage().getIcons().add(new Image(GEarth.class.getResourceAsStream(String.format("/gearth/themes/%s/logoSmall.png", theme)))); - - getStage().setTitle(theme.split("_")[0] + " " + GEarth.version); - titleLabel.setText(getStage().getTitle()); - - infoController.img_logo.setImage(new Image(GEarth.class.getResourceAsStream(String.format("/gearth/themes/%s/logo.png", theme)))); - infoController.version.setText(getStage().getTitle()); - } - - public void exit() { tabs.forEach(SubForm::exit); hConnection.abort(); } - public void handleCloseAction(MouseEvent event) { - this.exit(); - Platform.exit(); - - // Platform.exit doesn't seem to be enough on Windows? - System.exit(0); - } - - public void handleMinimizeAction(MouseEvent event) { - getStage().setIconified(true); - } - - private double xOffset, yOffset; - - public void handleClickAction(MouseEvent event) { - xOffset = event.getSceneX(); - yOffset = event.getSceneY(); - } - - public void handleMovementAction(MouseEvent event) { - getStage().setX(event.getScreenX() - xOffset); - getStage().setY(event.getScreenY() - yOffset); - } - - public void toggleTheme(MouseEvent event) { - int themeIndex = Arrays.asList(GEarth.themes).indexOf(GEarth.theme); - setTheme(GEarth.themes[(themeIndex + 1) % GEarth.themes.length]); - } } diff --git a/G-Earth/src/main/java/gearth/ui/themes/Theme.java b/G-Earth/src/main/java/gearth/ui/themes/Theme.java new file mode 100644 index 0000000..a2bae69 --- /dev/null +++ b/G-Earth/src/main/java/gearth/ui/themes/Theme.java @@ -0,0 +1,7 @@ +package gearth.ui.themes; + +public class Theme { + + + +} diff --git a/G-Earth/src/main/java/gearth/ui/titlebar/TitleBarConfig.java b/G-Earth/src/main/java/gearth/ui/titlebar/TitleBarConfig.java new file mode 100644 index 0000000..57537d0 --- /dev/null +++ b/G-Earth/src/main/java/gearth/ui/titlebar/TitleBarConfig.java @@ -0,0 +1,10 @@ +package gearth.ui.titlebar; + +public interface TitleBarConfig { + + boolean displayThemePicker(); + + void onCloseClicked(); + void onMinimizeClicked(); + void onSetTheme(String theme); +} diff --git a/G-Earth/src/main/java/gearth/ui/titlebar/TitleBarController.java b/G-Earth/src/main/java/gearth/ui/titlebar/TitleBarController.java new file mode 100644 index 0000000..c2709c0 --- /dev/null +++ b/G-Earth/src/main/java/gearth/ui/titlebar/TitleBarController.java @@ -0,0 +1,73 @@ +package gearth.ui.titlebar; + +import gearth.GEarth; +import javafx.application.Platform; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.control.Label; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.stage.Stage; +import javafx.stage.StageStyle; + +import java.io.IOException; +import java.util.Arrays; + +public class TitleBarController { + + public Label titleLabel; + public Pane titleBar; + + private Stage stage; + private TitleBarConfig config; + + public static TitleBarController create(Stage stage, TitleBarConfig config) throws IOException { + FXMLLoader loader = new FXMLLoader(TitleBarController.class.getResource("Titlebar.fxml")); + Parent root = loader.load(); + TitleBarController controller = loader.getController(); + controller.stage = stage; + controller.config = config; + stage.initStyle(StageStyle.TRANSPARENT); + + Parent parent = stage.getScene().getRoot(); + + VBox newParent = new VBox(root, parent); + stage.getScene().setRoot(newParent); + parent.getScene().setFill(Color.TRANSPARENT); + + return controller; + } + + public void setTitle(String title) { + titleLabel.setText(title); + } + + + public void handleCloseAction(MouseEvent event) { + config.onCloseClicked(); + } + + public void handleMinimizeAction(MouseEvent event) { + stage.setIconified(true); + } + + private double xOffset, yOffset; + + public void handleClickAction(MouseEvent event) { + xOffset = event.getSceneX(); + yOffset = event.getSceneY(); + } + + public void handleMovementAction(MouseEvent event) { + stage.setX(event.getScreenX() - xOffset); + stage.setY(event.getScreenY() - yOffset); + } + + public void toggleTheme(MouseEvent event) { + int themeIndex = Arrays.asList(GEarth.themes).indexOf(GEarth.theme); + config.onSetTheme(GEarth.themes[(themeIndex + 1) % GEarth.themes.length]); + } + +} diff --git a/G-Earth/src/main/resources/gearth/ui/G-Earth.fxml b/G-Earth/src/main/resources/gearth/ui/G-Earth.fxml index 6dc6ac7..9f9f0d3 100644 --- a/G-Earth/src/main/resources/gearth/ui/G-Earth.fxml +++ b/G-Earth/src/main/resources/gearth/ui/G-Earth.fxml @@ -8,33 +8,6 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/G-Earth/src/main/resources/gearth/ui/titlebar/Titlebar.fxml b/G-Earth/src/main/resources/gearth/ui/titlebar/Titlebar.fxml new file mode 100644 index 0000000..24acbca --- /dev/null +++ b/G-Earth/src/main/resources/gearth/ui/titlebar/Titlebar.fxml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file