Init example project with JavaFX

This commit is contained in:
ChronosX88 2023-12-11 17:41:06 +03:00
parent 08912a6f67
commit 375bac9214
19 changed files with 90 additions and 157 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
/.gradle/
/.idea/
/build/
build

View File

@ -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'

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="io.github.chronosxyz.JGUN.examples.chat.FXMLController">
<Label fx:id="label" text="Label"/>
</StackPane>

View File

@ -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 + ".");
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="io.github.chronosxyz.JGUN.examples.chat.FXMLController">
<Label fx:id="label" text="Label"/>
</StackPane>

View File

@ -1,2 +1,4 @@
rootProject.name = 'JGUN'
include 'examples:chat'
findProject(':examples:chat')?.name = 'chat'

View File

@ -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<String> path = new ArrayList<>();

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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);
// }
//}

View File

@ -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());
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<NodeValue> {
@Override

View File

@ -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;