From 375bac9214380c1a43257e860719e725738c2746 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Mon, 11 Dec 2023 17:41:06 +0300 Subject: [PATCH] Init example project with JavaFX --- .gitignore | 2 +- examples/chat/build.gradle | 19 ++++++ .../JGUN/examples/chat/FXMLController.class | Bin 0 -> 1501 bytes .../chronosxyz/JGUN/examples/chat/Main.class | Bin 0 -> 1285 bytes .../chronosxyz/JGUN/examples/chat/scene.fxml | 10 +++ .../JGUN/examples/chat/FXMLController.java | 20 ++++++ .../chronosxyz/JGUN/examples/chat/Main.java | 28 ++++++++ .../chronosxyz/JGUN/examples/chat/scene.fxml | 10 +++ settings.gradle | 2 + .../chronosx88/JGUN/api/PathReference.java | 1 - .../JGUN/api/graph/NodeBuilder.java | 1 - .../chronosx88/JGUN/examples/MainClient.java | 40 ------------ .../JGUN/examples/MainClientServer.java | 43 ------------- .../chronosx88/JGUN/examples/MainServer.java | 60 ------------------ .../JGUN/models/NetworkMessage.java | 6 -- .../JGUN/models/graph/MemoryGraph.java | 2 - .../JGUN/models/graph/NodeMetadata.java | 1 - .../models/graph/NodeValueDeserializer.java | 1 - .../JGUN/storage/StorageManager.java | 1 - 19 files changed, 90 insertions(+), 157 deletions(-) create mode 100644 examples/chat/build.gradle create mode 100644 examples/chat/build/classes/java/main/io/github/chronosxyz/JGUN/examples/chat/FXMLController.class create mode 100644 examples/chat/build/classes/java/main/io/github/chronosxyz/JGUN/examples/chat/Main.class create mode 100644 examples/chat/build/resources/main/io/github/chronosxyz/JGUN/examples/chat/scene.fxml create mode 100644 examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/FXMLController.java create mode 100644 examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/Main.java create mode 100644 examples/chat/src/main/resources/io/github/chronosxyz/JGUN/examples/chat/scene.fxml delete mode 100644 src/main/java/io/github/chronosx88/JGUN/examples/MainClient.java delete mode 100644 src/main/java/io/github/chronosx88/JGUN/examples/MainClientServer.java delete mode 100644 src/main/java/io/github/chronosx88/JGUN/examples/MainServer.java diff --git a/.gitignore b/.gitignore index fe0af9c..51651b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /.gradle/ /.idea/ -/build/ \ No newline at end of file +build \ No newline at end of file diff --git a/examples/chat/build.gradle b/examples/chat/build.gradle new file mode 100644 index 0000000..c5984f6 --- /dev/null +++ b/examples/chat/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'application' + id 'org.openjfx.javafxplugin' version '0.0.9' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation rootProject +} + +javafx { + version = "11" + modules = [ 'javafx.controls', 'javafx.fxml' ] +} + +mainClassName = 'io.github.chronosxyz.JGUN.examples.chat.Main' \ No newline at end of file diff --git a/examples/chat/build/classes/java/main/io/github/chronosxyz/JGUN/examples/chat/FXMLController.class b/examples/chat/build/classes/java/main/io/github/chronosxyz/JGUN/examples/chat/FXMLController.class new file mode 100644 index 0000000000000000000000000000000000000000..2f5e854f0f4f0794ea4a4bec9a3caa6e57a736e5 GIT binary patch literal 1501 zcmbVM+foxj5IvIwHpD0pyrHO30SOB06)*8hECec`1sJXJX%faTFquj1PN)Qb#NV*W zQp*QFz>l)*$p(pK^udRno=f*R-Di6C`;V{R0NlpY6b5iUi3=%Q#CQ@D14v>rLub<| zT*eg-GahC=_zZoDmxW>&D{k{${-3`9*h{XBb^;Xe(=?BtuzN;)&MA zax0Av88Z8!Z<{scFT7qUQb7NGsil3$5TDAG7!n1uDHsNeQj66_tt^5KPB<>uRJbbf zK)Q8jGhw$R0pBS~<5#8KYLxxTR$#OVo2@;6`Ps`=Uo?5Gu0%)&+_p&zQOZgLM4xi( zk}J7K9G9os8TwjS|K(aSAFUczDt}FcrV&)cd_!+4k$0)a8v*HY*(Aa#|}Ivk1o%PFK^3#kH;q9IF{Ismb~nQI za5aro97395Xx*Byls1TbT23JB>TI%P{wU;u5}N zjS72S-WC;0?GYv7w>w~IU;5~VyWH1Xp%pb!sw(V@z|=)xTMUz(>*U)IT%}E!WodR1dO0xq8sk z<#&qg@j@89P}mL8BrT5hV91p`+;{pvW*9$^PwHK>BRcI7rMti@)&wmN^Yn&_#_Tle zbp1Zz?n?!3*xJp1daC+(;v|{nwa@Y zAov9D05pRHISBkYiOUhT|0cHp*5A>(U4g5_N0bn&UWScVL31TEs=NV z>CJfs;p_6z!O6$Gwr5i^0 zYTuk4oo_13V`HgWkd@H(+(5?@qLnF2!(i%Tgl9RzEmDhbyTwRMLik0N*>}z{!8W}^ zzaW=w)um2V;IyjAL^pbL%$b=rQpY6B;J}XEGW_>ztxeaqNOn zEwUCG>$=pqL8ndB(5=#9@4NhgEO0a(MHwzSB2axxrJMR1IXQ%6Bc~qM#gq*hMD5ft z5#Noo!-#QQ8Cu&LIf4w<^{T#F%e!m2oG13A&yhM@G(b)=nuWwl2{P2Ug-rv9CVx7E z#`R=rfeg3oP|bVbJdwP + + + + + + \ No newline at end of file diff --git a/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/FXMLController.java b/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/FXMLController.java new file mode 100644 index 0000000..22b8c4e --- /dev/null +++ b/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/FXMLController.java @@ -0,0 +1,20 @@ +package io.github.chronosxyz.JGUN.examples.chat; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Label; + +import java.net.URL; +import java.util.ResourceBundle; + +public class FXMLController implements Initializable { + @FXML + private Label label; + + @Override + public void initialize(URL url, ResourceBundle rb) { + String javaVersion = System.getProperty("java.version"); + String javafxVersion = System.getProperty("javafx.version"); + label.setText("Hello, JavaFX " + javafxVersion + "\nRunning on Java " + javaVersion + "."); + } +} \ No newline at end of file diff --git a/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/Main.java b/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/Main.java new file mode 100644 index 0000000..5cd8aa6 --- /dev/null +++ b/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/Main.java @@ -0,0 +1,28 @@ +package io.github.chronosxyz.JGUN.examples.chat; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + + +public class Main extends Application { + + @Override + public void start(Stage stage) throws Exception { + Parent root = FXMLLoader.load(getClass().getResource("scene.fxml")); + + Scene scene = new Scene(root); +// scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm()); + + stage.setTitle("JavaFX and Gradle"); + stage.setScene(scene); + stage.show(); + } + + public static void main(String[] args) { + launch(args); + } + +} \ No newline at end of file diff --git a/examples/chat/src/main/resources/io/github/chronosxyz/JGUN/examples/chat/scene.fxml b/examples/chat/src/main/resources/io/github/chronosxyz/JGUN/examples/chat/scene.fxml new file mode 100644 index 0000000..00e0612 --- /dev/null +++ b/examples/chat/src/main/resources/io/github/chronosxyz/JGUN/examples/chat/scene.fxml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index ea95be5..d173b17 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,4 @@ rootProject.name = 'JGUN' +include 'examples:chat' +findProject(':examples:chat')?.name = 'chat' diff --git a/src/main/java/io/github/chronosx88/JGUN/api/PathReference.java b/src/main/java/io/github/chronosx88/JGUN/api/PathReference.java index 791d635..8c66c7b 100644 --- a/src/main/java/io/github/chronosx88/JGUN/api/PathReference.java +++ b/src/main/java/io/github/chronosx88/JGUN/api/PathReference.java @@ -13,7 +13,6 @@ import io.github.chronosx88.JGUN.storage.StorageManager; import java.util.*; import java.util.concurrent.*; -import java.util.stream.Stream; public class PathReference { private final List path = new ArrayList<>(); diff --git a/src/main/java/io/github/chronosx88/JGUN/api/graph/NodeBuilder.java b/src/main/java/io/github/chronosx88/JGUN/api/graph/NodeBuilder.java index b7a2181..96faea3 100644 --- a/src/main/java/io/github/chronosx88/JGUN/api/graph/NodeBuilder.java +++ b/src/main/java/io/github/chronosx88/JGUN/api/graph/NodeBuilder.java @@ -6,7 +6,6 @@ import io.github.chronosx88.JGUN.models.graph.NodeValue; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.List; import java.util.UUID; public class NodeBuilder { diff --git a/src/main/java/io/github/chronosx88/JGUN/examples/MainClient.java b/src/main/java/io/github/chronosx88/JGUN/examples/MainClient.java deleted file mode 100644 index 749f4b6..0000000 --- a/src/main/java/io/github/chronosx88/JGUN/examples/MainClient.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.chronosx88.JGUN.examples; - -import io.github.chronosx88.JGUN.api.Gun; -import io.github.chronosx88.JGUN.api.graph.ArrayBuilder; -import io.github.chronosx88.JGUN.api.graph.NodeBuilder; -import io.github.chronosx88.JGUN.models.Result; -import io.github.chronosx88.JGUN.network.NetworkNode; -import io.github.chronosx88.JGUN.storage.MemoryStorage; -import io.github.chronosx88.JGUN.storage.Storage; - -import java.net.Inet4Address; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.util.concurrent.ExecutionException; - -public class MainClient { - public static void main(String[] args) throws URISyntaxException, UnknownHostException, ExecutionException, InterruptedException { - Storage storage = new MemoryStorage(); - NetworkNode peer = new NetworkNode(Inet4Address.getByAddress(new byte[]{127, 0, 0, 1}), 5054, storage); - Gun gun = new Gun(storage, peer); - - Result result = gun.get("person").put(new NodeBuilder() - .add("firstName", "Test") - .build()).get(); - System.out.println(result); - - result = gun.get("person").get("address").put(new NodeBuilder() - .add("city", "Dallas") - .build()).get(); - System.out.println(result); - - result = gun.get("person").get("homeAddress").put(gun.get("person").get("address")).get(); - System.out.println(result); - - result = gun.get("person").get("homeAddress").put(new NodeBuilder() - .add("city", "New YORK CITY") - .build()).get(); - System.out.println(result); - } -} diff --git a/src/main/java/io/github/chronosx88/JGUN/examples/MainClientServer.java b/src/main/java/io/github/chronosx88/JGUN/examples/MainClientServer.java deleted file mode 100644 index 98309e7..0000000 --- a/src/main/java/io/github/chronosx88/JGUN/examples/MainClientServer.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.chronosx88.JGUN.examples; - -//public class MainClientServer { -// public static void main(String[] args) { -// GunSuperPeer gunSuperNode = new GunSuperPeer(21334, new MemoryStorage()); -// gunSuperNode.start(); -// Runnable task = () -> { -// Gun gun = null; -// try { -// gun = new Gun(Inet4Address.getByAddress(new byte[]{127, 0, 0, 1}), 21334, new MemoryStorage()); -// } catch (UnknownHostException e) { -// e.printStackTrace(); -// } -// gun.get("random").on(data -> { -// if(data != null) { -// System.out.println("New change in \"random\"! " + data.toString(2)); -// } -// }); -// gun.get("random").get("dVFtzE9CL").on(data -> { -// if(data != null) { -// System.out.println("New change in \"random/dVFtzE9CL\"! " + data.toString(2)); -// } else { -// System.out.println("Now random/dVFtzE9CL is null!"); -// } -// -// }); -// gun.get("random").get("dVFtzE9CL").map(((key, value) -> { -// System.out.println("[Map] New change in \"random/dVFtzE9CL\"! " + key + " : " + value.toString()); -// })); -// gun.get("random").map(((key, value) -> { -// System.out.println("[Map] New change in \"random\"! " + key + " : " + value); -// })); -// System.out.println("[FuturePut] Success: " + gun.get("random").get("dVFtzE9CL").put(new JSONObject().put("hello", "world")).await()); -// System.out.println("[FuturePut] Putting an item again: " + gun.get("random").get("dVFtzE9CL").put(new JSONObject().put("hello", "123")).await()); -// System.out.println("Deleting an item random/dVFtzE9CL"); -// gun.get("random").get("dVFtzE9CL").put(null).await(); -// gun.get("random").put(new JSONObject().put("hello", "world")).await(); -// }; -// -// Executor executorService = Executors.newSingleThreadExecutor(); -// executorService.execute(task); -// } -//} diff --git a/src/main/java/io/github/chronosx88/JGUN/examples/MainServer.java b/src/main/java/io/github/chronosx88/JGUN/examples/MainServer.java deleted file mode 100644 index 683911f..0000000 --- a/src/main/java/io/github/chronosx88/JGUN/examples/MainServer.java +++ /dev/null @@ -1,60 +0,0 @@ -package io.github.chronosx88.JGUN.examples; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import io.github.chronosx88.JGUN.api.Gun; -import io.github.chronosx88.JGUN.api.NodeChangeListener; -import io.github.chronosx88.JGUN.api.graph.ArrayBuilder; -import io.github.chronosx88.JGUN.api.graph.NodeBuilder; -import io.github.chronosx88.JGUN.models.Result; -import io.github.chronosx88.JGUN.models.graph.Node; -import io.github.chronosx88.JGUN.network.GatewayNetworkNode; -import io.github.chronosx88.JGUN.network.NetworkNode; -import io.github.chronosx88.JGUN.storage.MemoryStorage; -import io.github.chronosx88.JGUN.storage.Storage; - -import java.net.Inet4Address; -import java.util.concurrent.ExecutionException; - -public class MainServer { - public static void main(String[] args) throws ExecutionException, InterruptedException { - Storage storage = new MemoryStorage(); - GatewayNetworkNode peer = new GatewayNetworkNode(5054, storage); - Gun gun = new Gun(storage, peer); - Result result = gun.get("person").put(new NodeBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", new NodeBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", new ArrayBuilder() - .add(new NodeBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(new NodeBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build()).get(); - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new Jdk8Module()); - gun.get("person").on(node -> { - try { - System.out.println(mapper.writeValueAsString(node)); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - }); - gun.get("person").get("address").on(node -> { - try { - System.out.println(mapper.writeValueAsString(node)); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - }); - System.out.println(result.isOk()); - } -} diff --git a/src/main/java/io/github/chronosx88/JGUN/models/NetworkMessage.java b/src/main/java/io/github/chronosx88/JGUN/models/NetworkMessage.java index 49b302b..82cfc33 100644 --- a/src/main/java/io/github/chronosx88/JGUN/models/NetworkMessage.java +++ b/src/main/java/io/github/chronosx88/JGUN/models/NetworkMessage.java @@ -1,13 +1,7 @@ package io.github.chronosx88.JGUN.models; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import io.github.chronosx88.JGUN.models.acks.Ack; -import io.github.chronosx88.JGUN.models.acks.GetAck; -import io.github.chronosx88.JGUN.models.requests.GetRequest; -import io.github.chronosx88.JGUN.models.requests.PutRequest; import lombok.Data; import lombok.experimental.SuperBuilder; diff --git a/src/main/java/io/github/chronosx88/JGUN/models/graph/MemoryGraph.java b/src/main/java/io/github/chronosx88/JGUN/models/graph/MemoryGraph.java index cef1ec4..705522d 100644 --- a/src/main/java/io/github/chronosx88/JGUN/models/graph/MemoryGraph.java +++ b/src/main/java/io/github/chronosx88/JGUN/models/graph/MemoryGraph.java @@ -3,9 +3,7 @@ package io.github.chronosx88.JGUN.models.graph; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.Builder; import lombok.Data; -import lombok.extern.jackson.Jacksonized; import java.util.LinkedHashMap; import java.util.Map; diff --git a/src/main/java/io/github/chronosx88/JGUN/models/graph/NodeMetadata.java b/src/main/java/io/github/chronosx88/JGUN/models/graph/NodeMetadata.java index 81f004e..7138083 100644 --- a/src/main/java/io/github/chronosx88/JGUN/models/graph/NodeMetadata.java +++ b/src/main/java/io/github/chronosx88/JGUN/models/graph/NodeMetadata.java @@ -5,7 +5,6 @@ import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; diff --git a/src/main/java/io/github/chronosx88/JGUN/models/graph/NodeValueDeserializer.java b/src/main/java/io/github/chronosx88/JGUN/models/graph/NodeValueDeserializer.java index 0d980ef..c2f95b9 100644 --- a/src/main/java/io/github/chronosx88/JGUN/models/graph/NodeValueDeserializer.java +++ b/src/main/java/io/github/chronosx88/JGUN/models/graph/NodeValueDeserializer.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.databind.JsonNode; import io.github.chronosx88.JGUN.models.graph.values.*; import java.io.IOException; -import java.util.ArrayList; public class NodeValueDeserializer extends JsonDeserializer { @Override diff --git a/src/main/java/io/github/chronosx88/JGUN/storage/StorageManager.java b/src/main/java/io/github/chronosx88/JGUN/storage/StorageManager.java index 4212d03..409d7c3 100644 --- a/src/main/java/io/github/chronosx88/JGUN/storage/StorageManager.java +++ b/src/main/java/io/github/chronosx88/JGUN/storage/StorageManager.java @@ -9,7 +9,6 @@ import io.github.chronosx88.JGUN.models.graph.NodeValue; import io.github.chronosx88.JGUN.models.graph.values.NodeLinkValue; import io.github.chronosx88.JGUN.models.requests.GetRequestParams; import io.github.chronosx88.JGUN.network.NetworkManager; -import io.github.chronosx88.JGUN.utils.Pair; import java.util.ArrayList; import java.util.List;