From 072bf1d2731763cb366c1ef5746bcabae3f43506 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Thu, 27 Sep 2018 15:05:38 +0200 Subject: [PATCH] changes in extensions --- src/main/extensions/Extension.java | 23 +++++++++- src/main/extensions/ExtensionForm.java | 1 + .../adminonconnect/AdminOnConnect.java | 2 +- .../speechcolorizer/SpeechColorizer.java | 2 +- .../ui/extensions/ExtensionItemContainer.java | 12 +++-- src/main/ui/extensions/GEarthExtension.java | 44 ++++++++++--------- 6 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/main/extensions/Extension.java b/src/main/extensions/Extension.java index 8b842ee..3acf65c 100644 --- a/src/main/extensions/Extension.java +++ b/src/main/extensions/Extension.java @@ -23,7 +23,11 @@ public abstract class Extension { void act(String[] args); } + protected static final boolean CANLEAVE = true; // can you disconnect the ext + protected static final boolean CANDELETE = true; // can you delete the ext (will be false for some built-in extensions) + private String[] args; + private boolean isCorrupted = false; private static final String[] PORT_FLAG = {"--port", "-p"}; private static final String[] FILE_FLAG = {"--filename", "-f"}; @@ -49,6 +53,8 @@ public abstract class Extension { */ public Extension(String[] args) { //obtain port + this.args = args; + if (getInfoAnnotations() == null) { System.err.println("Extension info not found\n\n" + @@ -59,6 +65,17 @@ public abstract class Extension { " Version = \"...\",\n" + " Author = \"...\"" + "\n)"); + isCorrupted = true; + } + + if (getArgument(args, PORT_FLAG) == null) { + System.err.println("Don't forget to include G-Earth's port as program parameters (-p {port})"); + isCorrupted = true; + } + } + + public void run() { + if (isCorrupted) { return; } @@ -67,7 +84,7 @@ public abstract class Extension { Socket gEarthExtensionServer = null; try { - gEarthExtensionServer = new Socket("127.0.0.2", port); + gEarthExtensionServer = new Socket("127.0.0.1", port); InputStream in = gEarthExtensionServer.getInputStream(); DataInputStream dIn = new DataInputStream(in); out = gEarthExtensionServer.getOutputStream(); @@ -105,7 +122,9 @@ public abstract class Extension { .appendString(info.Description()) .appendBoolean(isOnClickMethodUsed()) .appendBoolean(file == null) - .appendString(file == null ? "": file); + .appendString(file == null ? "": file) + .appendBoolean(CANLEAVE) + .appendBoolean(CANDELETE); writeToStream(response.toBytes()); } else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.CONNECTIONSTART) { diff --git a/src/main/extensions/ExtensionForm.java b/src/main/extensions/ExtensionForm.java index 3c33741..fe50b9a 100644 --- a/src/main/extensions/ExtensionForm.java +++ b/src/main/extensions/ExtensionForm.java @@ -55,6 +55,7 @@ public abstract class ExtensionForm extends Application { return extInfo; } }; + extension.run(); // Platform.runLater(primaryStage::close); //when the extension has ended, close this process Platform.exit(); diff --git a/src/main/extensions/examples/adminonconnect/AdminOnConnect.java b/src/main/extensions/examples/adminonconnect/AdminOnConnect.java index 76987b2..499f3e1 100644 --- a/src/main/extensions/examples/adminonconnect/AdminOnConnect.java +++ b/src/main/extensions/examples/adminonconnect/AdminOnConnect.java @@ -20,7 +20,7 @@ import main.protocol.HPacket; public class AdminOnConnect extends Extension { public static void main(String[] args) { - new AdminOnConnect(args); + new AdminOnConnect(args).run(); } public AdminOnConnect(String[] args) { super(args); diff --git a/src/main/extensions/examples/speechcolorizer/SpeechColorizer.java b/src/main/extensions/examples/speechcolorizer/SpeechColorizer.java index b70bee8..919c76c 100644 --- a/src/main/extensions/examples/speechcolorizer/SpeechColorizer.java +++ b/src/main/extensions/examples/speechcolorizer/SpeechColorizer.java @@ -25,7 +25,7 @@ import java.util.Random; public class SpeechColorizer extends Extension { public static void main(String[] args) { - new SpeechColorizer(args); + new SpeechColorizer(args).run(); } private SpeechColorizer(String[] args) { super(args); diff --git a/src/main/ui/extensions/ExtensionItemContainer.java b/src/main/ui/extensions/ExtensionItemContainer.java index 0e15a53..519344c 100644 --- a/src/main/ui/extensions/ExtensionItemContainer.java +++ b/src/main/ui/extensions/ExtensionItemContainer.java @@ -70,16 +70,14 @@ public class ExtensionItemContainer extends GridPane { exitButton.show(); exitButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.isRemoveClickTrigger()); SimpleClickButton clickButton = new SimpleClickButton(); + clickButton.show(); clickButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.isClickTrigger()); HBox buttonsBox = new HBox(clickButton, exitButton); - if (item.isFireButtonUsed()) { - clickButton.show(); - } - else { - HBox.setMargin(exitButton, new Insets(0,0,0,24)); - } - buttonsBox.setSpacing(item.isFireButtonUsed() ? 8 : 0); + + clickButton.setVisible(item.isFireButtonUsed()); + exitButton.setVisible(item.isLeaveButtonVisible()); + buttonsBox.setSpacing(8); buttonsBox.setAlignment(Pos.CENTER); GridPane.setMargin(buttonsBox, new Insets(0, 5, 0, 5)); add(buttonsBox, 4, 0); diff --git a/src/main/ui/extensions/GEarthExtension.java b/src/main/ui/extensions/GEarthExtension.java index 8d02fb8..459e668 100644 --- a/src/main/ui/extensions/GEarthExtension.java +++ b/src/main/ui/extensions/GEarthExtension.java @@ -19,7 +19,10 @@ public class GEarthExtension { private String author; private String version; private String description; + private boolean fireEventButtonVisible; + private boolean leaveButtonVisible; + private boolean deleteButtonVisible; private boolean isInstalledExtension; // <- extension is in the extensions directory private String fileName; @@ -53,13 +56,7 @@ public class GEarthExtension { if (packet.headerId() == Extensions.INCOMING_MESSAGES_IDS.EXTENSIONINFO) { GEarthExtension gEarthExtension = new GEarthExtension( - packet.readString(), - packet.readString(), - packet.readString(), - packet.readString(), - packet.readBoolean(), - packet.readBoolean(), - packet.readString(), + packet, connection, onDisconnectedCallback ); @@ -73,15 +70,21 @@ public class GEarthExtension { } - private GEarthExtension(String title, String author, String version, String description, boolean fireEventButtonVisible, boolean isInstalledExtension, String fileName, Socket connection, OnDisconnectedCallback onDisconnectedCallback) { - this.title = title; - this.author = author; - this.version = version; - this.description = description; - this.fireEventButtonVisible = fireEventButtonVisible; + private GEarthExtension(HPacket extensionInfo, Socket connection, OnDisconnectedCallback onDisconnectedCallback) { - this.isInstalledExtension = isInstalledExtension; - this.fileName = fileName; + + + this.title = extensionInfo.readString(); + this.author = extensionInfo.readString(); + this.version = extensionInfo.readString(); + this.description = extensionInfo.readString(); + this.fireEventButtonVisible = extensionInfo.readBoolean(); + + this.isInstalledExtension = extensionInfo.readBoolean(); + this.fileName = extensionInfo.readString(); + + this.leaveButtonVisible = extensionInfo.readBoolean(); + this.deleteButtonVisible = extensionInfo.readBoolean(); this.connection = connection; @@ -134,26 +137,27 @@ public class GEarthExtension { public String getAuthor() { return author; } - public String getDescription() { return description; } - public String getTitle() { return title; } - public String getVersion() { return version; } - public boolean isFireButtonUsed() { return fireEventButtonVisible; } - public String getFileName() { return fileName; } + public boolean isDeleteButtonVisible() { + return deleteButtonVisible; + } + public boolean isLeaveButtonVisible() { + return leaveButtonVisible; + } public boolean isInstalledExtension() { return isInstalledExtension;