mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2025-02-17 03:32:36 +01:00
stuff
This commit is contained in:
parent
7204b6c2ee
commit
292696172c
@ -4,15 +4,14 @@ import gearth.misc.AdminValidator;
|
|||||||
import gearth.misc.Cacher;
|
import gearth.misc.Cacher;
|
||||||
import gearth.misc.UpdateChecker;
|
import gearth.misc.UpdateChecker;
|
||||||
import gearth.ui.GEarthController;
|
import gearth.ui.GEarthController;
|
||||||
|
import gearth.ui.titlebar.TitleBarConfig;
|
||||||
|
import gearth.ui.titlebar.TitleBarController;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.ToolBar;
|
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.layout.BorderPane;
|
|
||||||
import javafx.scene.layout.Pane;
|
|
||||||
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;
|
||||||
@ -25,6 +24,10 @@ public class GEarth extends Application {
|
|||||||
public static String theme = "G-Earth_Dark";
|
public static String theme = "G-Earth_Dark";
|
||||||
public static String[] themes = new String[] {"G-Earth", "Tanji", "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 {
|
static {
|
||||||
if (Cacher.getCacheContents().has("theme")) {
|
if (Cacher.getCacheContents().has("theme")) {
|
||||||
theme = Cacher.getCacheContents().getString("theme");
|
theme = Cacher.getCacheContents().getString("theme");
|
||||||
@ -34,36 +37,71 @@ public class GEarth extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception{
|
public void start(Stage primaryStage) throws Exception{
|
||||||
main = this;
|
main = this;
|
||||||
|
stage = primaryStage;
|
||||||
|
|
||||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/G-Earth.fxml"));
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/G-Earth.fxml"));
|
||||||
Parent root = loader.load();
|
Parent root = loader.load();
|
||||||
GEarthController companion = loader.getController();
|
controller = loader.getController();
|
||||||
companion.setStage(primaryStage);
|
controller.setStage(primaryStage);
|
||||||
primaryStage.initStyle(StageStyle.TRANSPARENT);
|
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));
|
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.setResizable(false);
|
||||||
primaryStage.sizeToScene();
|
primaryStage.sizeToScene();
|
||||||
|
|
||||||
primaryStage.getScene().setFill(Color.TRANSPARENT);
|
setTheme(theme);
|
||||||
companion.setTheme(theme);
|
|
||||||
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
primaryStage.setOnCloseRequest( event -> {
|
primaryStage.setOnCloseRequest( event -> closeGEarth());
|
||||||
companion.exit();
|
|
||||||
Platform.exit();
|
|
||||||
|
|
||||||
// Platform.exit doesn't seem to be enough on Windows?
|
|
||||||
System.exit(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
AdminValidator.validate();
|
AdminValidator.validate();
|
||||||
UpdateChecker.checkForUpdates();
|
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 String[] args;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -43,9 +43,6 @@ public class GEarthController {
|
|||||||
|
|
||||||
private List<SubForm> tabs = null;
|
private List<SubForm> tabs = null;
|
||||||
|
|
||||||
public Pane titleBar;
|
|
||||||
public Label titleLabel;
|
|
||||||
|
|
||||||
public GEarthController() {
|
public GEarthController() {
|
||||||
SocksConfiguration temporary_socks = new SocksConfiguration() {
|
SocksConfiguration temporary_socks = new SocksConfiguration() {
|
||||||
public boolean useSocks() { return false; }
|
public boolean useSocks() { return false; }
|
||||||
@ -123,54 +120,9 @@ public class GEarthController {
|
|||||||
loggerController.miniLogText(color, text);
|
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() {
|
public void exit() {
|
||||||
tabs.forEach(SubForm::exit);
|
tabs.forEach(SubForm::exit);
|
||||||
hConnection.abort();
|
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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
7
G-Earth/src/main/java/gearth/ui/themes/Theme.java
Normal file
7
G-Earth/src/main/java/gearth/ui/themes/Theme.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package gearth.ui.themes;
|
||||||
|
|
||||||
|
public class Theme {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
10
G-Earth/src/main/java/gearth/ui/titlebar/TitleBarConfig.java
Normal file
10
G-Earth/src/main/java/gearth/ui/titlebar/TitleBarConfig.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package gearth.ui.titlebar;
|
||||||
|
|
||||||
|
public interface TitleBarConfig {
|
||||||
|
|
||||||
|
boolean displayThemePicker();
|
||||||
|
|
||||||
|
void onCloseClicked();
|
||||||
|
void onMinimizeClicked();
|
||||||
|
void onSetTheme(String theme);
|
||||||
|
}
|
@ -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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,33 +8,6 @@
|
|||||||
<!--maxHeight="19.0" minHeight="19.0"-->
|
<!--maxHeight="19.0" minHeight="19.0"-->
|
||||||
|
|
||||||
<VBox id="main-window" prefWidth="650.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.GEarthController">
|
<VBox id="main-window" prefWidth="650.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.GEarthController">
|
||||||
<Pane id="title-bar" fx:id="titleBar" maxHeight="25.0" onMouseDragged="#handleMovementAction" onMousePressed="#handleClickAction" prefHeight="25.0" prefWidth="200.0">
|
|
||||||
<children>
|
|
||||||
<ImageView id="close-button" fitHeight="25.0" fitWidth="50.0" layoutX="601.0" onMouseClicked="#handleCloseAction" onTouchPressed="#handleCloseAction" pickOnBounds="true" preserveRatio="true">
|
|
||||||
<image>
|
|
||||||
<Image url="@titlebar/files/closeButton.png" />
|
|
||||||
</image>
|
|
||||||
</ImageView>
|
|
||||||
<ImageView id="minimize-button" fitHeight="25.0" fitWidth="50.0" layoutX="551.0" onMouseClicked="#handleMinimizeAction" onTouchPressed="#handleMinimizeAction" pickOnBounds="true" preserveRatio="true">
|
|
||||||
<image>
|
|
||||||
<Image url="@titlebar/files/minimizeButton.png" />
|
|
||||||
</image>
|
|
||||||
</ImageView>
|
|
||||||
<ImageView id="icon" fitHeight="16.0" fitWidth="16.0" layoutX="7.0" layoutY="5.0" pickOnBounds="true" preserveRatio="true">
|
|
||||||
<image>
|
|
||||||
<Image url="@../themes/G-Earth/logoSmall.png" />
|
|
||||||
</image>
|
|
||||||
</ImageView>
|
|
||||||
<Label fx:id="titleLabel" layoutX="23.0" layoutY="5.0" text="G-Earth 1.5.1">
|
|
||||||
<padding>
|
|
||||||
<Insets left="2.0" />
|
|
||||||
</padding>
|
|
||||||
</Label>
|
|
||||||
<ImageView id="theme-button" fitHeight="20.0" fitWidth="38.0" layoutX="505.0" layoutY="3.0" onMouseClicked="#toggleTheme" onTouchPressed="#toggleTheme" pickOnBounds="true" preserveRatio="true">
|
|
||||||
<image>
|
|
||||||
<Image url="@../themes/G-Earth/themeButton.png" />
|
|
||||||
</image></ImageView>
|
|
||||||
</children></Pane>
|
|
||||||
<TabPane id="main-tab-pane" fx:id="tabBar" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="295.0" prefWidth="650.0" tabClosingPolicy="UNAVAILABLE">
|
<TabPane id="main-tab-pane" fx:id="tabBar" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="295.0" prefWidth="650.0" tabClosingPolicy="UNAVAILABLE">
|
||||||
<Tab text="Connection">
|
<Tab text="Connection">
|
||||||
<fx:include fx:id="connection" source="connection/Connection.fxml" />
|
<fx:include fx:id="connection" source="connection/Connection.fxml" />
|
||||||
|
35
G-Earth/src/main/resources/gearth/ui/titlebar/Titlebar.fxml
Normal file
35
G-Earth/src/main/resources/gearth/ui/titlebar/Titlebar.fxml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.image.*?>
|
||||||
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<Pane xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="gearth.ui.titlebar.TitleBarController" id="title-bar" fx:id="titleBar" maxHeight="25.0" onMouseDragged="#handleMovementAction" onMousePressed="#handleClickAction" prefHeight="25.0" prefWidth="200.0">
|
||||||
|
<children>
|
||||||
|
<ImageView id="close-button" fitHeight="25.0" fitWidth="50.0" layoutX="601.0" onMouseClicked="#handleCloseAction" onTouchPressed="#handleCloseAction" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@files/closeButton.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
<ImageView id="minimize-button" fitHeight="25.0" fitWidth="50.0" layoutX="551.0" onMouseClicked="#handleMinimizeAction" onTouchPressed="#handleMinimizeAction" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@files/minimizeButton.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
<ImageView id="icon" fitHeight="16.0" fitWidth="16.0" layoutX="7.0" layoutY="5.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../../themes/G-Earth/logoSmall.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
<Label fx:id="titleLabel" layoutX="23.0" layoutY="5.0" text="G-Earth 1.5.1">
|
||||||
|
<padding>
|
||||||
|
<Insets left="2.0" />
|
||||||
|
</padding>
|
||||||
|
</Label>
|
||||||
|
<ImageView id="theme-button" fitHeight="20.0" fitWidth="38.0" layoutX="505.0" layoutY="3.0" onMouseClicked="#toggleTheme" onTouchPressed="#toggleTheme" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../../themes/G-Earth/themeButton.png" />
|
||||||
|
</image></ImageView>
|
||||||
|
</children></Pane>
|
Loading…
x
Reference in New Issue
Block a user