style stuff

This commit is contained in:
sirjonasxx 2022-02-15 04:13:10 +01:00
parent 08f157d2c4
commit e95fd7b9e2
12 changed files with 195 additions and 87 deletions

View File

@ -3,7 +3,9 @@ package gearth;
import gearth.misc.AdminValidator;
import gearth.misc.Cacher;
import gearth.misc.UpdateChecker;
import gearth.misc.listenerpattern.Observable;
import gearth.ui.GEarthController;
import gearth.ui.subforms.logger.loggerdisplays.PacketLogger;
import gearth.ui.themes.Theme;
import gearth.ui.themes.ThemeFactory;
import gearth.ui.titlebar.TitleBarConfig;
@ -17,12 +19,15 @@ import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import java.util.function.Consumer;
public class GEarth extends Application {
public static GEarth main;
public static String version = "1.5.1";
public static String gitApi = "https://api.github.com/repos/sirjonasxx/G-Earth/releases/latest";
public static Theme theme;
public static Observable<Consumer<Theme>> themeObservable = new Observable<>();
private Stage stage;
private GEarthController controller;
@ -54,6 +59,16 @@ public class GEarth extends Application {
return true;
}
@Override
public boolean displayMinimizeButton() {
return true;
}
// @Override
// public boolean allowResizing() {
// return false;
// }
@Override
public void onCloseClicked() {
closeGEarth();
@ -94,9 +109,11 @@ public class GEarth extends Application {
}
private void setGearthTheme(Theme theme) {
themeObservable.fireEvent(t -> t.accept(theme));
GEarth.theme = theme;
Theme defaultTheme = ThemeFactory.getDefaultTheme();
// Platform.runLater(() -> {
stage.getScene().getStylesheets().clear();
stage.getScene().getStylesheets().add(GEarth.class.getResource(String.format("/gearth/ui/themes/%s/styling.css", theme.internalName())).toExternalForm());
@ -111,6 +128,8 @@ public class GEarth extends Application {
)
)));
controller.infoController.version.setText(stage.getTitle());
// });
}
public static String[] args;
@ -139,4 +158,8 @@ public class GEarth extends Application {
}
return null;
}
public static Observable<Consumer<Theme>> getThemeObservable() {
return themeObservable;
}
}

View File

@ -1,16 +1,11 @@
package gearth.misc;
import gearth.GEarth;
import gearth.ui.titlebar.DefaultTitleBarConfig;
import gearth.ui.titlebar.TitleBarController;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import java.io.IOException;
import java.io.PrintStream;
@ -51,35 +46,13 @@ public class AdminValidator {
new Thread(() -> {
if (!AdminValidator.isAdmin()) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.WARNING, "G-Earth needs admin privileges in order to work on Flash, please restart G-Earth with admin permissions unless you're using Unity", ButtonType.OK);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(GEarth.class.getResourceAsStream("/gearth/ui/themes/G-Earth/logoSmall.png")));
stage.getScene().getStylesheets().add(GEarth.class.getResource(String.format("/gearth/ui/themes/%s/styling.css", GEarth.theme.internalName())).toExternalForm());
// try {
// TitleBarController.create(stage, new DefaultTitleBarConfig(stage));
// } catch (IOException e) {
// e.printStackTrace();
// }
// alert.getDialogPane().setMaxHeight(-1);
// alert.getDialogPane().setMinHeight(200);
// alert.getDialogPane()
//
//
// boolean[] once = new boolean[]{false};
// stage.heightProperty().addListener(observable -> {
// if (!once[0]) {
// once[0] = true;
// stage.setMinHeight(alert.getDialogPane().getHeight() + 25);
// stage.setHeight(alert.getDialogPane().getHeight() + 25);
// stage.setMaxHeight(alert.getDialogPane().getHeight() + 25);
// }
//
// });
// stage.setHeight(stage.getHeight() + 25);
// stage.setResizable(false);
// stage.sizeToScene();x
stage.show();
Alert alert = new Alert(Alert.AlertType.WARNING, "", ButtonType.OK);
alert.getDialogPane().setContent(new Label("G-Earth needs admin privileges in order to work on Flash,\nplease restart G-Earth with admin permissions unless\nyou're using Unity"));
try {
TitleBarController.create(alert).showAlert();
} catch (IOException e) {
e.printStackTrace();
}
});
}

View File

@ -2,6 +2,8 @@ package gearth.services.internal_extensions.uilogger;
import gearth.GEarth;
import gearth.extensions.InternalExtensionFormLauncher;
import gearth.ui.titlebar.DefaultTitleBarConfig;
import gearth.ui.titlebar.TitleBarController;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
@ -30,6 +32,13 @@ public class UiLoggerLauncher extends InternalExtensionFormLauncher<UiLogger> {
controller.setStage(stage);
stage.setScene(scene);
// TitleBarController.create(stage, new DefaultTitleBarConfig(stage) {
// @Override
// public void onCloseClicked() {
// stage.hide();
//// uiLogger.onHide();
// }
// });
return uiLogger;
}
}

View File

@ -4,6 +4,7 @@ import gearth.protocol.connection.proxy.ProxyProviderFactory;
import gearth.protocol.connection.proxy.SocksConfiguration;
import gearth.ui.subforms.logger.loggerdisplays.PacketLoggerFactory;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import gearth.protocol.HConnection;
import gearth.ui.subforms.connection.ConnectionController;

View File

@ -2,6 +2,7 @@ package gearth.ui.subforms.extensions.logger;
import gearth.GEarth;
import gearth.ui.titlebar.DefaultTitleBarConfig;
import gearth.ui.titlebar.GEarthThemedTitleBarConfig;
import gearth.ui.titlebar.TitleBarController;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
@ -49,7 +50,7 @@ public class ExtensionLogger {
controller.setStage(stage);
stage.setScene(scene);
TitleBarController.create(stage, new DefaultTitleBarConfig(stage) {
TitleBarController.create(stage, new GEarthThemedTitleBarConfig(stage) {
@Override
public void onCloseClicked() {
stage.hide();

View File

@ -1,13 +1,17 @@
package gearth.ui.subforms.info;
import gearth.GEarth;
import gearth.ui.titlebar.TitleBarController;
import javafx.event.ActionEvent;
import javafx.scene.control.*;
import gearth.ui.SubForm;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import java.io.IOException;
/**
* Created by Jonas on 06/04/18.
*/
@ -53,15 +57,20 @@ public class InfoController extends SubForm {
Alert alert = new Alert(Alert.AlertType.INFORMATION, "Donate Bitcoins", ButtonType.OK);
alert.setHeaderText("Donate Bitcoins");
WebView webView = new WebView();
webView.getEngine().loadContent("<html>Bitcoin public address:<br><br>" +
"<textarea>" + pubkey +"</textarea>" +
"</html>");
webView.setPrefSize(200, 100);
VBox test = new VBox();
test.getChildren().add(new Label("Bitcoin public address:"));
TextArea pubText = new TextArea(pubkey);
pubText.setPrefHeight(28);
pubText.setMaxWidth(250);
test.getChildren().add(pubText);
alert.setResizable(false);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.getDialogPane().setContent(webView);
alert.show();
alert.getDialogPane().setContent(test);
try {
TitleBarController.create(alert).showAlert();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -3,6 +3,7 @@ package gearth.ui.titlebar;
import gearth.GEarth;
import gearth.ui.themes.Theme;
import gearth.ui.themes.ThemeFactory;
import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.stage.Stage;
@ -15,16 +16,30 @@ public class DefaultTitleBarConfig implements TitleBarConfig {
public DefaultTitleBarConfig(Stage stage) {
this(stage, ThemeFactory.getDefaultTheme());
}
public DefaultTitleBarConfig(Stage stage, Theme theme) {
this.stage = stage;
currentTheme = ThemeFactory.getDefaultTheme();
setTheme(currentTheme);
currentTheme = theme;
setTheme(theme);
}
@Override
public boolean displayThemePicker() {
return false;
return true;
}
@Override
public boolean displayMinimizeButton() {
return true;
}
// @Override
// public boolean allowResizing() {
// return false;
// }
@Override
public void onCloseClicked() {
stage.close();
@ -38,6 +53,7 @@ public class DefaultTitleBarConfig implements TitleBarConfig {
@Override
public void setTheme(Theme theme) {
currentTheme = theme;
Platform.runLater(() -> {
Theme defaultTheme = ThemeFactory.getDefaultTheme();
if (currentStylesheet != null) {
stage.getScene().getStylesheets().remove(currentStylesheet);
@ -47,6 +63,8 @@ public class DefaultTitleBarConfig implements TitleBarConfig {
stage.getIcons().clear();
stage.getIcons().add(new Image(GEarth.class.getResourceAsStream(String.format("/gearth/ui/themes/%s/logoSmall.png", theme.overridesLogo() ? theme.internalName() : defaultTheme.internalName()))));
});
}
@Override

View File

@ -0,0 +1,21 @@
package gearth.ui.titlebar;
import gearth.GEarth;
import gearth.ui.themes.Theme;
import javafx.stage.Stage;
import java.util.function.Consumer;
public class GEarthThemedTitleBarConfig extends DefaultTitleBarConfig {
public GEarthThemedTitleBarConfig(Stage stage) {
super(stage, GEarth.theme);
GEarth.themeObservable.addListener(this::setTheme);
}
@Override
public boolean displayThemePicker() {
return false;
}
}

View File

@ -5,6 +5,8 @@ import gearth.ui.themes.Theme;
public interface TitleBarConfig {
boolean displayThemePicker();
boolean displayMinimizeButton();
// boolean allowResizing();
void onCloseClicked();
void onMinimizeClicked();

View File

@ -1,16 +1,20 @@
package gearth.ui.titlebar;
import gearth.GEarth;
import gearth.ui.themes.Theme;
import gearth.ui.themes.ThemeFactory;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.fxml.FXMLLoader;
import javafx.scene.Cursor;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
@ -24,24 +28,54 @@ public class TitleBarController {
public Label titleLabel;
public Pane titleBar;
public ImageView titleIcon;
public ImageView themeBtn;
public ImageView minimizeBtn;
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();
Parent titleBar = loader.load();
TitleBarController controller = initNewController(loader, stage, config);
VBox newParent = new VBox(titleBar, stage.getScene().getRoot());
newParent.setId("titlebar-main-container");
stage.getScene().setRoot(newParent);
return controller;
}
public static TitleBarController create(Alert alert) throws IOException {
FXMLLoader loader = new FXMLLoader(TitleBarController.class.getResource("Titlebar.fxml"));
Parent titleBar = loader.load();
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
TitleBarConfig config = new GEarthThemedTitleBarConfig(stage) {
@Override
public boolean displayMinimizeButton() {
return false;
}
};
TitleBarController controller = initNewController(loader, stage, config);
Parent parent = alert.getDialogPane().getScene().getRoot();
VBox newParent = new VBox(titleBar, parent);
newParent.setId("titlebar-main-container");
stage.setScene(new Scene(newParent));
stage.getScene().setFill(Color.TRANSPARENT);
return controller;
}
private static TitleBarController initNewController(FXMLLoader loader, Stage stage, TitleBarConfig config) throws IOException {
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);
newParent.setId("titlebar-main-container");
stage.getScene().setRoot(newParent);
parent.getScene().setFill(Color.TRANSPARENT);
stage.getScene().setFill(Color.TRANSPARENT);
stage.titleProperty().addListener((i) -> controller.setTitle(stage.getTitle()));
controller.setTitle(stage.getTitle());
@ -49,17 +83,23 @@ public class TitleBarController {
stage.getIcons().addListener((InvalidationListener) observable -> controller.updateIcon());
controller.updateIcon();
Platform.runLater(() -> {
controller.themeBtn.setVisible(config.displayThemePicker());
if (!config.displayMinimizeButton()) {
((GridPane) controller.minimizeBtn.getParent()).getChildren().remove(controller.minimizeBtn);
}
});
return controller;
}
public void updateIcon() {
titleIcon.setImage(stage.getIcons().size() > 0 ? stage.getIcons().get(0) :
Platform.runLater(() -> titleIcon.setImage(stage.getIcons().size() > 0 ? stage.getIcons().get(0) :
new Image(GEarth.class.getResourceAsStream(
String.format("/gearth/ui/themes/%s/logoSmall.png", ThemeFactory.getDefaultTheme().internalName()))));
String.format("/gearth/ui/themes/%s/logoSmall.png", ThemeFactory.getDefaultTheme().internalName())))));
}
public void setTitle(String title) {
titleLabel.setText(title);
Platform.runLater(() -> titleLabel.setText(title));
}
@ -72,20 +112,33 @@ public class TitleBarController {
}
private double xOffset, yOffset;
private boolean isMoving = false;
public void handleClickAction(MouseEvent event) {
xOffset = event.getSceneX();
yOffset = event.getSceneY();
isMoving = true;
}
public void handleMovementAction(MouseEvent event) {
if (isMoving) {
stage.setX(event.getScreenX() - xOffset);
stage.setY(event.getScreenY() - yOffset);
}
}
public void handleClickReleaseAction(MouseEvent mouseEvent) {
isMoving = false;
}
public void toggleTheme(MouseEvent event) {
int themeIndex = ThemeFactory.allThemes().indexOf(config.getCurrentTheme());
config.setTheme(ThemeFactory.allThemes().get((themeIndex + 1) % ThemeFactory.allThemes().size()));
}
public void showAlert() {
stage.show();
Platform.runLater(() -> stage.sizeToScene());
}
}

View File

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<!--maxHeight="19.0" minHeight="19.0"-->
<VBox prefWidth="650.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.GEarthController">
<VBox prefWidth="650.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.GEarthController">
<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">
<fx:include fx:id="connection" source="subforms/connection/Connection.fxml" />

View File

@ -15,7 +15,7 @@
<RowConstraints maxHeight="25.0" minHeight="25.0" prefHeight="25.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<ImageView id="minimize-button" fitHeight="25.0" fitWidth="50.0" onMouseClicked="#handleMinimizeAction" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1">
<ImageView fx:id="minimizeBtn" id="minimize-button" fitHeight="25.0" fitWidth="50.0" onMouseClicked="#handleMinimizeAction" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1">
<image>
<Image url="@files/minimizeButton.png" />
</image>
@ -25,7 +25,7 @@
<Image url="@files/closeButton.png" />
</image>
</ImageView>
<GridPane maxHeight="25.0" maxWidth="1.7976931348623157E308" minHeight="25.0" minWidth="-Infinity" onMouseDragged="#handleMovementAction" onMousePressed="#handleClickAction" prefHeight="25.0">
<GridPane maxHeight="25.0" maxWidth="1.7976931348623157E308" minHeight="25.0" minWidth="-Infinity" onMouseDragged="#handleMovementAction" onMousePressed="#handleClickAction" onMouseReleased="#handleClickReleaseAction" prefHeight="25.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="7.0" minWidth="7.0" prefWidth="7.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" />
@ -47,7 +47,7 @@
<Insets left="2.0" />
</padding>
</Label>
<ImageView id="theme-button" fitHeight="20.0" fitWidth="38.0" onMouseClicked="#toggleTheme" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="3">
<ImageView fx:id="themeBtn" id="theme-button" fitHeight="20.0" fitWidth="38.0" onMouseClicked="#toggleTheme" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="3">
<image>
<Image url="@../themes/G-Earth/themeButton.png" />
</image>