mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
fix bug in extensionForm
This commit is contained in:
parent
4bd2798c71
commit
4d29895f5f
@ -1,11 +1,14 @@
|
||||
package extensions.blockreplacepackets;
|
||||
|
||||
import gearth.extensions.Extension;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.ui.GEarthController;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
@ -15,6 +18,7 @@ import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import gearth.extensions.ExtensionForm;
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
import javafx.stage.WindowEvent;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 22/09/18.
|
||||
@ -32,7 +36,7 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
public TextField txt_replacement;
|
||||
public ComboBox<String> cmb_type;
|
||||
public Button btn_add;
|
||||
public ComboBox<String> cmb_side;
|
||||
public volatile ComboBox<String> cmb_side;
|
||||
public TextField txt_value;
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -44,7 +48,6 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
public void initialize() {
|
||||
cmb_type.getItems().addAll("Block packet", "Replace packet", "Replace integer", "Replace string", "Replace substring");
|
||||
cmb_type.getSelectionModel().selectFirst();
|
||||
cmb_type.requestFocus();
|
||||
|
||||
cmb_side.getItems().addAll("Incoming", "Outgoing");
|
||||
cmb_side.getSelectionModel().selectFirst();
|
||||
@ -55,6 +58,8 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
txt_value.textProperty().addListener(event -> Platform.runLater(this::refreshOptions));
|
||||
|
||||
refreshOptions();
|
||||
cmb_type.requestFocus();
|
||||
|
||||
}
|
||||
|
||||
private void refreshOptions() {
|
||||
@ -118,16 +123,50 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
|
||||
btn_add.setDisable(!isValid);
|
||||
|
||||
String[] spl = type.split(" ");
|
||||
if (repl.equals("") && spl[0].equals("Replace")) {
|
||||
if (spl[1].equals("packet")) {
|
||||
txt_replacement.setPromptText("Enter a packet here");
|
||||
}
|
||||
else if (spl[1].equals("integer")) {
|
||||
txt_replacement.setPromptText("Enter an integer here");
|
||||
}
|
||||
else if (spl[1].endsWith("string")) {
|
||||
txt_replacement.setPromptText("Enter a string here");
|
||||
}
|
||||
}
|
||||
else {
|
||||
txt_replacement.setPromptText("");
|
||||
}
|
||||
|
||||
if (val.equals("")) {
|
||||
if (spl[1].equals("packet")) {
|
||||
txt_value.setPromptText("Enter the headerID");
|
||||
}
|
||||
else if (spl[1].equals("integer")) {
|
||||
txt_value.setPromptText("Enter an integer");
|
||||
}
|
||||
else if (spl[1].endsWith("string")) {
|
||||
txt_value.setPromptText("Enter a string");
|
||||
}
|
||||
}
|
||||
else {
|
||||
txt_value.setPromptText("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initExtension() {
|
||||
|
||||
intercept(HMessage.Side.TOSERVER, new Extension.MessageListener() {
|
||||
@Override
|
||||
public void act(HMessage message) {
|
||||
System.out.println("just testing");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStageData(Stage primaryStage) throws Exception {
|
||||
public ExtensionForm launchForm(Stage primaryStage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(BlockAndReplacePackets.class.getResource("blockreplace.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
@ -135,6 +174,13 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onShow() {
|
||||
Platform.runLater(() -> cmb_type.requestFocus());
|
||||
}
|
||||
|
||||
public void click_btnAddRule(ActionEvent actionEvent) {
|
||||
|
@ -12,8 +12,7 @@ import java.util.Random;
|
||||
*/
|
||||
|
||||
/**
|
||||
* - getTitle(), getDescription(), getVersion() and getAuthor() must be implemented
|
||||
*
|
||||
* This is an example extension and is not included in a G-Earth release
|
||||
*/
|
||||
|
||||
@ExtensionInfo(
|
||||
|
@ -6,6 +6,8 @@ import javafx.stage.Stage;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 22/09/18.
|
||||
*/
|
||||
@ -13,41 +15,36 @@ public abstract class ExtensionForm extends Application {
|
||||
|
||||
private Extension extension = null;
|
||||
protected static String[] args;
|
||||
private volatile Stage primaryStage = null;
|
||||
protected volatile Stage primaryStage;
|
||||
|
||||
private ExtensionForm realForm = null;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
Platform.setImplicitExit(false);
|
||||
setStageData(primaryStage);
|
||||
this.primaryStage = primaryStage;
|
||||
primaryStage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
Platform.runLater(primaryStage::hide);
|
||||
});
|
||||
ExtensionForm thiss = this;
|
||||
|
||||
ExtensionInfo extInfo = getClass().getAnnotation(ExtensionInfo.class);
|
||||
|
||||
Semaphore semaphore = new Semaphore(1);
|
||||
semaphore.acquire();
|
||||
realForm = launchForm(primaryStage);
|
||||
Thread t = new Thread(() -> {
|
||||
extension = new Extension(args) {
|
||||
realForm.extension = new Extension(args) {
|
||||
@Override
|
||||
protected void init() {
|
||||
thiss.initExtension();
|
||||
realForm.initExtension();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
thiss.onClick();
|
||||
realForm.onClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartConnection() {
|
||||
thiss.onStartConnection();
|
||||
realForm.onStartConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEndConnection() {
|
||||
thiss.onEndConnection();
|
||||
realForm.onEndConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,16 +52,29 @@ public abstract class ExtensionForm extends Application {
|
||||
return extInfo;
|
||||
}
|
||||
};
|
||||
extension.run();
|
||||
semaphore.release();
|
||||
realForm.extension.run();
|
||||
// Platform.runLater(primaryStage::close);
|
||||
//when the extension has ended, close this process
|
||||
System.exit(0);
|
||||
});
|
||||
t.start();
|
||||
|
||||
semaphore.acquire();
|
||||
Platform.setImplicitExit(false);
|
||||
realForm = launchForm(primaryStage);
|
||||
realForm.primaryStage = primaryStage;
|
||||
|
||||
primaryStage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
Platform.runLater(() -> {
|
||||
primaryStage.hide();
|
||||
realForm.onHide();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public abstract void setStageData(Stage primaryStage) throws Exception;
|
||||
|
||||
public abstract ExtensionForm launchForm(Stage primaryStage) throws Exception;
|
||||
|
||||
//wrap extension methods
|
||||
protected boolean requestFlags(Extension.FlagsCheckListener flagRequestCallback){
|
||||
@ -86,6 +96,8 @@ public abstract class ExtensionForm extends Application {
|
||||
return extension.sendToClient(packet);
|
||||
}
|
||||
|
||||
protected void onShow(){};
|
||||
protected void onHide(){};
|
||||
|
||||
/**
|
||||
* Gets called when a connection has been established with G-Earth.
|
||||
@ -99,7 +111,9 @@ public abstract class ExtensionForm extends Application {
|
||||
private void onClick(){
|
||||
Platform.runLater(() -> {
|
||||
primaryStage.show();
|
||||
primaryStage.requestFocus();
|
||||
primaryStage.toFront();
|
||||
onShow();
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user