network work

This commit is contained in:
Tinglyyy
2026-01-19 21:31:57 +01:00
parent 2bb9d522f3
commit c4c5f42922
5 changed files with 17 additions and 190 deletions

View File

@@ -108,7 +108,7 @@
<dependency>
<groupId>org.openautonomousconnection</groupId>
<artifactId>protocol</artifactId>
<version>1.0.0-BETA.6.0</version>
<version>1.0.0-BETA.6.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>

View File

@@ -16,6 +16,7 @@ import org.openautonomousconnection.webclient.network.type.NetTransmitFile;
import javax.swing.text.Document;
import java.io.IOException;
import java.net.ConnectException;
import java.net.Inet4Address;
import java.net.URL;
import java.util.HashMap;
@@ -46,6 +47,12 @@ public class WebClient extends ProtocolWebClient {
// UDP is always preset
this.buildServerConnection(host, port, DEFAULT_WEB_PORT_UDP);
try {
this.getClientServerConnection().connect();
} catch (ConnectException e) {
throw new RuntimeException(e);
}
}
/**
@@ -59,6 +66,12 @@ public class WebClient extends ProtocolWebClient {
// UDP is always preset
this.buildServerConnection(ip, port, DEFAULT_INS_PORT_UDP);
try {
this.getClientINSConnection().connect();
} catch (ConnectException e) {
throw new RuntimeException(e);
}
}
/**
@@ -156,6 +169,8 @@ public class WebClient extends ProtocolWebClient {
System.out.println(promise(NTFType.DOCUMENT).getClass().getSimpleName());
return null;//(Promise<NetTransmitFile<Document>>) promise(NTFType.DOCUMENT);
}

View File

@@ -30,7 +30,7 @@ public final class MainFrame extends BrowserFrame {
try {
this.openTab = new Tab(
URI.create("web://open-autonomous-connection.org").toURL()
URI.create("web://127.0.0.1").toURL()
);
} catch (MalformedURLException e) {
throw new RuntimeException(e);

View File

@@ -1,90 +0,0 @@
package org.openautonomousconnection.webclient.ui.dom;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.openautonomousconnection.webclient.ui.dom.renderers.HTMLTextRenderer;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
@Deprecated(forRemoval = true)
public class HTMLRenderer {
public static JPanel render(Document html) {
JPanel panel = new JPanel();
for(JComponent component : renderHead(html.head()))
panel.add(component);
for(JComponent component : renderBody(html.body()))
panel.add(component);
return panel;
}
private static List<JComponent> renderHead(Element head) {
List<JComponent> result = new ArrayList<>();
return result;
}
private static List<JComponent> renderBody(Element body) {
return renderAndChildren(body);
}
private static List<JComponent> renderAndChildren(Element element) {
List<JComponent> result = new ArrayList<>();
element.children().forEach(e -> {
if(!e.children().isEmpty())
result.addAll(renderAndChildren(e));
result.add(renderElement(e));
});
return result;
}
private static JComponent renderElement(Element element) {
String tagName = element.tagName().toLowerCase();
String text = element.text();
Attributes attributes = element.attributes();
String className = element.className();
switch (tagName) {
case "p":
case "u":
case "var":
case "span":
case "h1":
case "h2":
case "h3":
case "em":
case "del":
case "ins":
case "q":
case "sub":
case "sup":
case "cite":
case "code":
case "b":
case "i":
case "strong":
case "blockquote":
return HTMLTextRenderer.render(
HTMLTextRenderer.TEXTTYPE.of(tagName),
text,
attributes,
className
);
default:
return new JPanel();
}
}
}

View File

@@ -1,98 +0,0 @@
package org.openautonomousconnection.webclient.ui.dom.renderers;
import lombok.Getter;
import org.jsoup.nodes.Attributes;
import javax.swing.*;
import java.awt.*;
@Deprecated(forRemoval = true)
public class HTMLTextRenderer {
public static JComponent render(TEXTTYPE texttype, String text, Attributes attributes, String className) {
// TODO: Implementation
return switch (texttype) {
case P, VAR, SPAN, H1, H2, H3 -> renderSimple(text, "", attributes, className);
case U -> renderSimple(text, "underlined", attributes, className);
case INS -> null;
case Q -> null;
case SUB -> null;
case SUP -> null;
case CITE -> null;
case CODE -> null;
// remember: b = bold text, Strong = bold & emphasized, like with TTS
case B, STRONG -> renderSimple(text, "bold", attributes, className);
case I -> renderSimple(text, "italic", attributes, className);
case EM -> renderSimple(text, "bold italic", attributes, className);
case DEL -> renderSimple(text, "strikethrough", attributes, className);
case BLOCKQUOTE -> null;
};
}
private static JComponent renderSimple(String text, String decoration, Attributes attributes, String className) {
JTextArea label = new JTextArea(text);
label.setEditable(false);
label.setLineWrap(true);
label.setWrapStyleWord(true);
label.setBorder(null);
label.setOpaque(false);
label.setCaretColor(new Color(0, 0, 0, 0));
int d = Font.PLAIN;
Font font = new Font(Font.SERIF, Font.PLAIN, 15);
// try { TODO: implement css
// font = new Font(
// attributes.get("font"),
// Font.PLAIN,
// 0);
// } catch (Exception ignored) {
// font = new Font(Font.SERIF, Font.PLAIN, 0);
//
// }
label.setFont(font);
return label;
}
public enum TEXTTYPE {
P("p"),
U("u"),
VAR("var"),
SPAN("span"),
H1("h1"),
H2("h2"),
H3("h3"),
EM("em"),
DEL("del"),
INS("ins"),
Q("q"),
SUB("sub"),
SUP("sup"),
CITE("cite"),
CODE("code"),
B("b"),
I("i"),
STRONG("strong"),
BLOCKQUOTE("blockquote");
public static TEXTTYPE of(String name) {
for(TEXTTYPE texttype : values())
if(texttype.name.equals(name))
return texttype;
return null;
}
@Getter
private final String name;
TEXTTYPE(String name) {
this.name = name;
}
}
}