mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-26 10:20:51 +01:00
ThemedExtensionFormCreator
This commit is contained in:
parent
1b6e91deb1
commit
77dfd67b3d
@ -33,7 +33,7 @@ public abstract class ExtensionBase extends IExtension {
|
||||
|
||||
|
||||
volatile PacketInfoManager packetInfoManager = PacketInfoManager.EMPTY;
|
||||
protected ObservableObject<HostInfo> observableHostInfo = new ObservableObject<>(null);
|
||||
ObservableObject<HostInfo> observableHostInfo = new ObservableObject<>(null);
|
||||
|
||||
void updateHostInfo(HostInfo hostInfo) {
|
||||
observableHostInfo.setObject(hostInfo);
|
||||
|
@ -1,12 +1,17 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import gearth.misc.HostInfo;
|
||||
import gearth.misc.listenerpattern.Observable;
|
||||
import gearth.services.packet_info.PacketInfoManager;
|
||||
import javafx.application.HostServices;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.stage.Stage;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 22/09/18.
|
||||
*/
|
||||
@ -92,4 +97,10 @@ public abstract class ExtensionForm extends ExtensionBase {
|
||||
public HostServices getHostServices() {
|
||||
return hostServices;
|
||||
}
|
||||
|
||||
public HostInfo getHostInfo() {
|
||||
return extension.observableHostInfo.getObject();
|
||||
}
|
||||
|
||||
Observable<Runnable> fieldsInitialized = new Observable<>(Runnable::run);
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ public class ExtensionFormLauncher extends Application {
|
||||
extensionForm.extension = extension;
|
||||
|
||||
extensionForm.primaryStage = primaryStage;
|
||||
extensionForm.fieldsInitialized.fireEvent();
|
||||
Thread t = new Thread(() -> {
|
||||
extension.run();
|
||||
//when the extension has ended, close this process
|
||||
|
@ -0,0 +1,67 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import gearth.ui.themes.Theme;
|
||||
import gearth.ui.themes.ThemeFactory;
|
||||
import gearth.ui.titlebar.DefaultTitleBarConfig;
|
||||
import gearth.ui.titlebar.TitleBarController;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
public abstract class ThemedExtensionFormCreator extends ExtensionFormCreator {
|
||||
|
||||
@Override
|
||||
protected ExtensionForm createForm(Stage primaryStage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(getFormResource());
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle(getTitle());
|
||||
primaryStage.setScene(new Scene(root));
|
||||
initialize(primaryStage);
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.sizeToScene();
|
||||
|
||||
DefaultTitleBarConfig config = new DefaultTitleBarConfig(primaryStage, ThemeFactory.getDefaultTheme()) {
|
||||
@Override
|
||||
public boolean displayThemePicker() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
TitleBarController.create(primaryStage, config);
|
||||
|
||||
ExtensionForm extensionForm = loader.getController();
|
||||
extensionForm.fieldsInitialized.addListener(() -> extensionForm.extension.observableHostInfo.addListener(hostInfo -> {
|
||||
if (hostInfo.getAttributes().containsKey("theme")) {
|
||||
String themeTitle = hostInfo.getAttributes().get("theme");
|
||||
Theme theme = ThemeFactory.themeForTitle(themeTitle);
|
||||
if (config.getCurrentTheme() != theme) {
|
||||
String styleClassOld = config.getCurrentTheme().title().replace(" ", "-").toLowerCase();
|
||||
String styleClassNew = theme.title().replace(" ", "-").toLowerCase();
|
||||
config.setTheme(theme);
|
||||
Parent currentRoot = primaryStage.getScene().getRoot();
|
||||
Platform.runLater(() -> {
|
||||
currentRoot.getStyleClass().remove(styleClassOld);
|
||||
currentRoot.getStyleClass().add(styleClassNew);
|
||||
});
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
return extensionForm;
|
||||
}
|
||||
|
||||
protected abstract String getTitle();
|
||||
protected abstract URL getFormResource();
|
||||
|
||||
// can be overridden for more settings
|
||||
protected void initialize(Stage primaryStage) {
|
||||
|
||||
}
|
||||
}
|
@ -974,6 +974,10 @@ VBox > .split-menu-button.last > .arrow-button {
|
||||
-fx-text-fill: black;
|
||||
}
|
||||
|
||||
.label.softer {
|
||||
-fx-text-fill: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
|
||||
.list-view {
|
||||
-fx-border-color: #cccccc;
|
||||
-fx-border-radius: 4;
|
||||
|
@ -1036,6 +1036,10 @@ VBox > .split-menu-button.last > .arrow-button {
|
||||
-fx-text-fill: #f0f0f0 !important;
|
||||
}
|
||||
|
||||
.label.softer {
|
||||
-fx-text-fill: rgba(240, 240, 240, 0.8);
|
||||
}
|
||||
|
||||
.pckt-info {
|
||||
-fx-fill: #ffffffa0;
|
||||
}
|
||||
|
@ -973,6 +973,10 @@ VBox > .split-menu-button.last > .arrow-button {
|
||||
-fx-text-fill: black;
|
||||
}
|
||||
|
||||
.label.softer {
|
||||
-fx-text-fill: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
|
||||
.list-view {
|
||||
-fx-border-color: #cccccc;
|
||||
-fx-border-radius: 4;
|
||||
|
Loading…
Reference in New Issue
Block a user