ThemedExtensionFormCreator

This commit is contained in:
sirjonasxx 2022-02-16 04:13:07 +01:00
parent 1b6e91deb1
commit 77dfd67b3d
7 changed files with 92 additions and 1 deletions

View File

@ -33,7 +33,7 @@ public abstract class ExtensionBase extends IExtension {
volatile PacketInfoManager packetInfoManager = PacketInfoManager.EMPTY; volatile PacketInfoManager packetInfoManager = PacketInfoManager.EMPTY;
protected ObservableObject<HostInfo> observableHostInfo = new ObservableObject<>(null); ObservableObject<HostInfo> observableHostInfo = new ObservableObject<>(null);
void updateHostInfo(HostInfo hostInfo) { void updateHostInfo(HostInfo hostInfo) {
observableHostInfo.setObject(hostInfo); observableHostInfo.setObject(hostInfo);

View File

@ -1,12 +1,17 @@
package gearth.extensions; package gearth.extensions;
import gearth.misc.HostInfo;
import gearth.misc.listenerpattern.Observable;
import gearth.services.packet_info.PacketInfoManager; import gearth.services.packet_info.PacketInfoManager;
import javafx.application.HostServices; import javafx.application.HostServices;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.stage.Stage; import javafx.stage.Stage;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
import java.util.function.Consumer;
/** /**
* Created by Jonas on 22/09/18. * Created by Jonas on 22/09/18.
*/ */
@ -92,4 +97,10 @@ public abstract class ExtensionForm extends ExtensionBase {
public HostServices getHostServices() { public HostServices getHostServices() {
return hostServices; return hostServices;
} }
public HostInfo getHostInfo() {
return extension.observableHostInfo.getObject();
}
Observable<Runnable> fieldsInitialized = new Observable<>(Runnable::run);
} }

View File

@ -60,6 +60,7 @@ public class ExtensionFormLauncher extends Application {
extensionForm.extension = extension; extensionForm.extension = extension;
extensionForm.primaryStage = primaryStage; extensionForm.primaryStage = primaryStage;
extensionForm.fieldsInitialized.fireEvent();
Thread t = new Thread(() -> { Thread t = new Thread(() -> {
extension.run(); extension.run();
//when the extension has ended, close this process //when the extension has ended, close this process

View File

@ -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) {
}
}

View File

@ -974,6 +974,10 @@ VBox > .split-menu-button.last > .arrow-button {
-fx-text-fill: black; -fx-text-fill: black;
} }
.label.softer {
-fx-text-fill: rgba(0, 0, 0, 0.8);
}
.list-view { .list-view {
-fx-border-color: #cccccc; -fx-border-color: #cccccc;
-fx-border-radius: 4; -fx-border-radius: 4;

View File

@ -1036,6 +1036,10 @@ VBox > .split-menu-button.last > .arrow-button {
-fx-text-fill: #f0f0f0 !important; -fx-text-fill: #f0f0f0 !important;
} }
.label.softer {
-fx-text-fill: rgba(240, 240, 240, 0.8);
}
.pckt-info { .pckt-info {
-fx-fill: #ffffffa0; -fx-fill: #ffffffa0;
} }

View File

@ -973,6 +973,10 @@ VBox > .split-menu-button.last > .arrow-button {
-fx-text-fill: black; -fx-text-fill: black;
} }
.label.softer {
-fx-text-fill: rgba(0, 0, 0, 0.8);
}
.list-view { .list-view {
-fx-border-color: #cccccc; -fx-border-color: #cccccc;
-fx-border-radius: 4; -fx-border-radius: 4;