mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 00:40:51 +01:00
ExtensionForm split launchForm() to different class
This commit is contained in:
parent
6621a468f1
commit
c968a24e8d
@ -50,10 +50,9 @@ public abstract class ExtensionBase extends IExtension {
|
||||
if (!listeners.containsKey(headerId)) {
|
||||
listeners.put(headerId, new ArrayList<>());
|
||||
}
|
||||
|
||||
listeners.get(headerId).add(messageListener);
|
||||
}
|
||||
|
||||
|
||||
listeners.get(headerId).add(messageListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,10 +71,9 @@ public abstract class ExtensionBase extends IExtension {
|
||||
if (!listeners.containsKey(hashOrName)) {
|
||||
listeners.put(hashOrName, new ArrayList<>());
|
||||
}
|
||||
|
||||
listeners.get(hashOrName).add(messageListener);
|
||||
}
|
||||
|
||||
|
||||
listeners.get(hashOrName).add(messageListener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,14 +16,6 @@ public abstract class ExtensionForm extends ExtensionBase {
|
||||
protected volatile Stage primaryStage;
|
||||
volatile HostServices hostServices;
|
||||
|
||||
protected static void runExtensionForm(String[] args, Class<? extends ExtensionForm> extension) {
|
||||
ExtensionFormLauncher launcher = new ExtensionFormLauncher();
|
||||
launcher.trigger(extension, args);
|
||||
}
|
||||
|
||||
|
||||
public abstract ExtensionForm launchForm(Stage primaryStage) throws Exception;
|
||||
|
||||
//wrap extension methods
|
||||
public boolean requestFlags(Extension.FlagsCheckListener flagRequestCallback){
|
||||
return extension.requestFlags(flagRequestCallback);
|
||||
@ -37,6 +29,9 @@ public abstract class ExtensionForm extends ExtensionBase {
|
||||
public void intercept(HMessage.Direction direction, Extension.MessageListener messageListener) {
|
||||
extension.intercept(direction, messageListener);
|
||||
}
|
||||
public void intercept(HMessage.Direction direction, String hashOrName, Extension.MessageListener messageListener){
|
||||
extension.intercept(direction, hashOrName, messageListener);
|
||||
}
|
||||
public void intercept(HMessage.Direction direction, int headerId, Extension.MessageListener messageListener){
|
||||
extension.intercept(direction, headerId, messageListener);
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public abstract class ExtensionFormCreator {
|
||||
|
||||
// creates an ExtensionForm object and initializes the JavaFX application
|
||||
protected abstract ExtensionForm createForm(Stage primaryStage) throws Exception;
|
||||
|
||||
public static void runExtensionForm(String[] args, Class<? extends ExtensionFormCreator> creator) {
|
||||
ExtensionFormLauncher.trigger(creator, args);
|
||||
}
|
||||
|
||||
}
|
@ -9,15 +9,16 @@ import javafx.stage.Stage;
|
||||
*/
|
||||
public class ExtensionFormLauncher extends Application {
|
||||
|
||||
private static Class<? extends ExtensionForm> extension;
|
||||
private static Class<? extends ExtensionFormCreator> extensionFormCreator;
|
||||
private static String[] args;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
ExtensionInfo extInfo = extension.getAnnotation(ExtensionInfo.class);
|
||||
// ExtensionInfo extInfo = extensionFormCreator.getAnnotation(ExtensionInfo.class);
|
||||
|
||||
ExtensionForm creator = extension.newInstance();
|
||||
ExtensionForm extensionForm = creator.launchForm(primaryStage);
|
||||
ExtensionFormCreator creator = extensionFormCreator.newInstance();
|
||||
ExtensionForm extensionForm = creator.createForm(primaryStage);
|
||||
ExtensionInfo extInfo = extensionForm.getClass().getAnnotation(ExtensionInfo.class);
|
||||
|
||||
Extension extension = new Extension(args) {
|
||||
@Override
|
||||
@ -77,8 +78,8 @@ public class ExtensionFormLauncher extends Application {
|
||||
});
|
||||
}
|
||||
|
||||
public static void trigger( Class<? extends ExtensionForm> extension, String[] args) {
|
||||
ExtensionFormLauncher.extension = extension;
|
||||
public static void trigger(Class<? extends ExtensionFormCreator> creator, String[] args) {
|
||||
ExtensionFormLauncher.extensionFormCreator = creator;
|
||||
ExtensionFormLauncher.args = args;
|
||||
launch(args);
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.extensions.ExtensionBase;
|
||||
import gearth.extensions.IExtension;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
|
||||
|
@ -6,15 +6,14 @@ import gearth.services.extension_handler.extensions.extensionproducers.Extension
|
||||
import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class InternalExtensionFormBuilder<T extends ExtensionForm> {
|
||||
public class InternalExtensionFormBuilder<L extends InternalExtensionFormLauncher<T>, T extends ExtensionForm> {
|
||||
|
||||
public T launch(Class<T> extensionClass, ExtensionProducerObserver observer) {
|
||||
public T launch(L launcher, ExtensionProducerObserver observer) {
|
||||
try {
|
||||
ExtensionInfo extInfo = extensionClass.getAnnotation(ExtensionInfo.class);
|
||||
T creator = extensionClass.newInstance();
|
||||
|
||||
Stage stage = new Stage();
|
||||
T extensionForm = (T)(creator.launchForm(stage));
|
||||
T extensionForm = launcher.createForm(stage);
|
||||
|
||||
ExtensionInfo extInfo = extensionForm.getClass().getAnnotation(ExtensionInfo.class);
|
||||
|
||||
InternalExtension internalExtension = new InternalExtension() {
|
||||
@Override
|
||||
|
@ -0,0 +1,10 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public abstract class InternalExtensionFormLauncher<T extends ExtensionForm> {
|
||||
|
||||
// creates an ExtensionForm object and initializes the JavaFX application
|
||||
public abstract T createForm(Stage primaryStage) throws Exception;
|
||||
|
||||
}
|
@ -4,7 +4,9 @@ import gearth.extensions.InternalExtensionFormBuilder;
|
||||
import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducer;
|
||||
import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducerObserver;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.BlockAndReplacePackets;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.BlockAndReplacePacketsLauncher;
|
||||
import gearth.services.internal_extensions.packetinfoexplorer.PacketInfoExplorer;
|
||||
import gearth.services.internal_extensions.packetinfoexplorer.PacketInfoExplorerLauncher;
|
||||
|
||||
public class SimpleExtensionProducer implements ExtensionProducer {
|
||||
|
||||
@ -14,10 +16,10 @@ public class SimpleExtensionProducer implements ExtensionProducer {
|
||||
// uncomment the next line if you want to see an embedded example extension in G-Earth
|
||||
// observer.onExtensionProduced(new ExampleExtension());
|
||||
|
||||
new InternalExtensionFormBuilder<BlockAndReplacePackets>()
|
||||
.launch(BlockAndReplacePackets.class, observer);
|
||||
new InternalExtensionFormBuilder<BlockAndReplacePacketsLauncher, BlockAndReplacePackets>()
|
||||
.launch(new BlockAndReplacePacketsLauncher(), observer);
|
||||
|
||||
new InternalExtensionFormBuilder<PacketInfoExplorer>()
|
||||
.launch(PacketInfoExplorer.class, observer);
|
||||
new InternalExtensionFormBuilder<PacketInfoExplorerLauncher, PacketInfoExplorer>()
|
||||
.launch(new PacketInfoExplorerLauncher(), observer);
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,20 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.extensions.ExtensionForm;
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
import gearth.services.packet_info.PacketInfo;
|
||||
import gearth.services.packet_info.PacketInfoManager;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.rules.BlockReplaceRule;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.rules.RuleFactory;
|
||||
import gearth.ui.GEarthController;
|
||||
import gearth.services.packet_info.PacketInfo;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -210,20 +202,6 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
refreshOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionForm launchForm(Stage primaryStage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(BlockAndReplacePackets.class.getResource("blockreplace.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle("Packet blocker &/ replacer");
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("G-EarthLogoSmaller.png")));
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onShow() {
|
||||
Platform.runLater(() -> cmb_type.requestFocus());
|
||||
|
@ -0,0 +1,27 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.extensions.InternalExtensionFormLauncher;
|
||||
import gearth.ui.GEarthController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class BlockAndReplacePacketsLauncher extends InternalExtensionFormLauncher<BlockAndReplacePackets> {
|
||||
|
||||
@Override
|
||||
public BlockAndReplacePackets createForm(Stage primaryStage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(BlockAndReplacePackets.class.getResource("blockreplace.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle("Packet blocker &/ replacer");
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("G-EarthLogoSmaller.png")));
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
}
|
@ -45,21 +45,6 @@ public class PacketInfoExplorer extends ExtensionForm {
|
||||
private TableView<PacketInfo> tableView;
|
||||
public GridPane grid;
|
||||
|
||||
@Override
|
||||
public ExtensionForm launchForm(Stage primaryStage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(PacketInfoExplorer.class.getResource("PacketInfoExplorer.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle("Packet info explorer");
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setMinWidth(430);
|
||||
primaryStage.setMinHeight(260);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("G-EarthLogoSmaller.png")));
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
Platform.runLater( () -> grid.requestFocus() );
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package gearth.services.internal_extensions.packetinfoexplorer;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.extensions.InternalExtensionFormLauncher;
|
||||
import gearth.ui.GEarthController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class PacketInfoExplorerLauncher extends InternalExtensionFormLauncher<PacketInfoExplorer> {
|
||||
|
||||
@Override
|
||||
public PacketInfoExplorer createForm(Stage primaryStage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(PacketInfoExplorer.class.getResource("PacketInfoExplorer.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle("Packet info explorer");
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setMinWidth(430);
|
||||
primaryStage.setMinHeight(260);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("G-EarthLogoSmaller.png")));
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
}
|
@ -57,25 +57,6 @@ public class UiLogger extends ExtensionForm implements PacketLogger {
|
||||
controller.onDisconnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionForm launchForm(Stage stage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(UiLogger.class.getResource("UiLogger.fxml"));
|
||||
|
||||
Parent root = loader.load();
|
||||
stage.setTitle("G-Earth | Packet Logger");
|
||||
stage.initModality(Modality.NONE);
|
||||
stage.getIcons().add(new Image(getClass().getResourceAsStream("/gearth/G-EarthLogoSmaller.png")));
|
||||
|
||||
Scene scene = new Scene(root);
|
||||
scene.getStylesheets().add("/gearth/ui/bootstrap3.css");
|
||||
scene.getStylesheets().add("/gearth/services/internal_extensions/uilogger/logger.css");
|
||||
controller = loader.getController();
|
||||
controller.setStage(stage);
|
||||
|
||||
stage.setScene(scene);
|
||||
return this;
|
||||
}
|
||||
|
||||
private class Elem {
|
||||
HPacket packet;
|
||||
int types;
|
||||
@ -104,4 +85,8 @@ public class UiLogger extends ExtensionForm implements PacketLogger {
|
||||
protected boolean canDelete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setController(UiLoggerController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package gearth.services.internal_extensions.uilogger;
|
||||
|
||||
import gearth.extensions.InternalExtensionFormLauncher;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class UiLoggerLauncher extends InternalExtensionFormLauncher<UiLogger> {
|
||||
@Override
|
||||
public UiLogger createForm(Stage stage) throws Exception {
|
||||
UiLogger uiLogger = new UiLogger();
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(UiLogger.class.getResource("UiLogger.fxml"));
|
||||
|
||||
Parent root = loader.load();
|
||||
stage.setTitle("G-Earth | Packet Logger");
|
||||
stage.initModality(Modality.NONE);
|
||||
stage.getIcons().add(new Image(getClass().getResourceAsStream("/gearth/G-EarthLogoSmaller.png")));
|
||||
|
||||
Scene scene = new Scene(root);
|
||||
scene.getStylesheets().add("/gearth/ui/bootstrap3.css");
|
||||
scene.getStylesheets().add("/gearth/services/internal_extensions/uilogger/logger.css");
|
||||
|
||||
UiLoggerController controller = loader.getController();
|
||||
uiLogger.setController(controller);
|
||||
controller.setStage(stage);
|
||||
|
||||
stage.setScene(scene);
|
||||
return uiLogger;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import gearth.services.extension_handler.ExtensionHandler;
|
||||
import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducer;
|
||||
import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducerObserver;
|
||||
import gearth.services.internal_extensions.uilogger.UiLogger;
|
||||
import gearth.services.internal_extensions.uilogger.UiLoggerLauncher;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 04/04/18.
|
||||
@ -39,8 +40,8 @@ public class PacketLoggerFactory implements ExtensionProducer {
|
||||
@Override
|
||||
public void startProducing(ExtensionProducerObserver observer) {
|
||||
if (usesUIlogger()) {
|
||||
uiLogger = new InternalExtensionFormBuilder<UiLogger>()
|
||||
.launch(UiLogger.class, observer);
|
||||
uiLogger = new InternalExtensionFormBuilder<UiLoggerLauncher, UiLogger>()
|
||||
.launch(new UiLoggerLauncher(), observer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user