mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-26 18:30:52 +01:00
cleanup extensionForm
This commit is contained in:
parent
d1bbb3cb52
commit
4ef6789bf0
@ -1,14 +1,10 @@
|
||||
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;
|
||||
@ -18,7 +14,6 @@ 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.
|
||||
@ -40,8 +35,7 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
public TextField txt_value;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ExtensionForm.args = args;
|
||||
launch(args);
|
||||
runExtensionForm(args, BlockAndReplacePackets.class);
|
||||
}
|
||||
|
||||
//initialize javaFX elements
|
||||
|
@ -0,0 +1,7 @@
|
||||
package extensions.blockreplacepackets;
|
||||
|
||||
/**
|
||||
* Created by Jeunez on 6/11/2018.
|
||||
*/
|
||||
public class RuleContainer {
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<GridPane prefHeight="324.0" prefWidth="588.0" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx/8.0.131" xmlns:fx="http://javafx.com/fxml/1" fx:controller="extensions.blockreplacepackets.BlockAndReplacePackets">
|
||||
<GridPane prefHeight="324.0" prefWidth="588.0" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="extensions.blockreplacepackets.BlockAndReplacePackets">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
@ -107,16 +107,16 @@
|
||||
</GridPane>
|
||||
<ScrollPane fx:id="scrollpane" hbarPolicy="NEVER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-border-color: #888888; -fx-background: #FFFFFF; -fx-border-radius: 4px;" vbarPolicy="ALWAYS">
|
||||
<content>
|
||||
<VBox fx:id="schedulecontainer" maxHeight="1.7976931348623157E308" prefWidth="559.0">
|
||||
<VBox fx:id="schedulecontainer" maxHeight="1.7976931348623157E308" prefWidth="574.0">
|
||||
<children>
|
||||
<GridPane fx:id="header" gridLinesVisible="true">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="163.0" minWidth="10.0" percentWidth="12.0" prefWidth="57.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="190.0" minWidth="10.0" percentWidth="14.0" prefWidth="189.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="190.0" minWidth="10.0" percentWidth="12.0" prefWidth="189.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="118.0" minWidth="10.0" percentWidth="18.0" prefWidth="66.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="33.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="15.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="6.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="8.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
@ -142,6 +142,6 @@
|
||||
</ScrollPane>
|
||||
</children>
|
||||
<padding>
|
||||
<Insets left="17.0" right="17.0" top="17.0" />
|
||||
<Insets left="10.0" right="10.0" top="8.0" />
|
||||
</padding>
|
||||
</GridPane>
|
||||
|
@ -11,65 +11,17 @@ import java.util.concurrent.Semaphore;
|
||||
/**
|
||||
* Created by Jonas on 22/09/18.
|
||||
*/
|
||||
public abstract class ExtensionForm extends Application {
|
||||
public abstract class ExtensionForm {
|
||||
|
||||
private volatile Extension extension;
|
||||
protected static String[] args;
|
||||
protected volatile Stage primaryStage;
|
||||
volatile Extension extension;
|
||||
volatile Stage primaryStage;
|
||||
|
||||
private volatile ExtensionForm realForm = null;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
ExtensionInfo extInfo = getClass().getAnnotation(ExtensionInfo.class);
|
||||
|
||||
realForm = launchForm(primaryStage);
|
||||
realForm.extension = new Extension(args) {
|
||||
@Override
|
||||
protected void init() {
|
||||
realForm.initExtension();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
realForm.onClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartConnection() {
|
||||
realForm.onStartConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEndConnection() {
|
||||
realForm.onEndConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
ExtensionInfo getInfoAnnotations() {
|
||||
return extInfo;
|
||||
}
|
||||
};
|
||||
realForm.primaryStage = primaryStage;
|
||||
Thread t = new Thread(() -> {
|
||||
realForm.extension.run();
|
||||
// Platform.runLater(primaryStage::close);
|
||||
//when the extension has ended, close this process
|
||||
System.exit(0);
|
||||
});
|
||||
t.start();
|
||||
|
||||
Platform.setImplicitExit(false);
|
||||
|
||||
primaryStage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
Platform.runLater(() -> {
|
||||
primaryStage.hide();
|
||||
realForm.onHide();
|
||||
});
|
||||
});
|
||||
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
|
||||
@ -104,7 +56,7 @@ public abstract class ExtensionForm extends Application {
|
||||
/**
|
||||
* The application got doubleclicked from the G-Earth interface. Doing something here is optional
|
||||
*/
|
||||
private void onClick(){
|
||||
protected void onClick(){
|
||||
Platform.runLater(() -> {
|
||||
primaryStage.show();
|
||||
primaryStage.requestFocus();
|
||||
|
@ -0,0 +1,73 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* Created by Jeunez on 6/11/2018.
|
||||
*/
|
||||
public class ExtensionFormLauncher extends Application{
|
||||
|
||||
private static Class<? extends ExtensionForm> extension;
|
||||
private static String[] args;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
ExtensionInfo extInfo = extension.getAnnotation(ExtensionInfo.class);
|
||||
|
||||
ExtensionForm creator = extension.newInstance();
|
||||
ExtensionForm extensionForm = creator.launchForm(primaryStage);
|
||||
|
||||
extensionForm.extension = new Extension(args) {
|
||||
@Override
|
||||
protected void init() {
|
||||
extensionForm.initExtension();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
extensionForm.onClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartConnection() {
|
||||
extensionForm.onStartConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEndConnection() {
|
||||
extensionForm.onEndConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
ExtensionInfo getInfoAnnotations() {
|
||||
return extInfo;
|
||||
}
|
||||
};
|
||||
extensionForm.primaryStage = primaryStage;
|
||||
Thread t = new Thread(() -> {
|
||||
extensionForm.extension.run();
|
||||
//when the extension has ended, close this process
|
||||
System.exit(0);
|
||||
});
|
||||
t.start();
|
||||
|
||||
Platform.setImplicitExit(false);
|
||||
|
||||
primaryStage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
Platform.runLater(() -> {
|
||||
primaryStage.hide();
|
||||
extensionForm.onHide();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static void trigger( Class<? extends ExtensionForm> extension, String[] args) {
|
||||
ExtensionFormLauncher.extension = extension;
|
||||
ExtensionFormLauncher.args = args;
|
||||
launch(args);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user