Implemented the JFX HTML renderer
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -12,7 +12,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
41
pom.xml
41
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.openautonomousconnection</groupId>
|
<groupId>org.openautonomousconnection</groupId>
|
||||||
<artifactId>WebClient</artifactId>
|
<artifactId>WebClient</artifactId>
|
||||||
<version>1.0.0-BETA.1.2</version>
|
<version>1.0.0-BETA.1.3</version>
|
||||||
<organization>
|
<organization>
|
||||||
<name>Open Autonomous Connection</name>
|
<name>Open Autonomous Connection</name>
|
||||||
<url>https://open-autonomous-connection.org/</url>
|
<url>https://open-autonomous-connection.org/</url>
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openautonomousconnection</groupId>
|
<groupId>org.openautonomousconnection</groupId>
|
||||||
<artifactId>protocol</artifactId>
|
<artifactId>protocol</artifactId>
|
||||||
<version>1.0.0-BETA.5.4</version>
|
<version>1.0.0-BETA.6.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
@@ -132,5 +132,42 @@
|
|||||||
<artifactId>InfoNameLib</artifactId>
|
<artifactId>InfoNameLib</artifactId>
|
||||||
<version>1.0.0-BETA.1.0</version>
|
<version>1.0.0-BETA.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<artifactId>javafx-base</artifactId>
|
||||||
|
<version>26-ea+22</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<artifactId>javafx-fxml</artifactId>
|
||||||
|
<version>26-ea+22</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<artifactId>javafx-web</artifactId>
|
||||||
|
<version>26-ea+22</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<artifactId>javafx-controls</artifactId>
|
||||||
|
<version>26-ea+22</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<artifactId>javafx</artifactId>
|
||||||
|
<version>26-ea+22</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<artifactId>javafx-swing</artifactId>
|
||||||
|
<version>26-ea+22</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -26,6 +26,9 @@ public class Main {
|
|||||||
public static final int DEFAULT_INS_PORT_TCP = 1026;
|
public static final int DEFAULT_INS_PORT_TCP = 1026;
|
||||||
public static final int DEFAULT_INS_PORT_UDP = 1025;
|
public static final int DEFAULT_INS_PORT_UDP = 1025;
|
||||||
|
|
||||||
|
public static final int DEFAULT_WEB_PORT_TCP = 1028;
|
||||||
|
public static final int DEFAULT_WEB_PORT_UDP = 1027;
|
||||||
|
|
||||||
private static final ProtocolVersion PROTOCOL_VERSION = ProtocolVersion.PV_1_0_0_BETA;
|
private static final ProtocolVersion PROTOCOL_VERSION = ProtocolVersion.PV_1_0_0_BETA;
|
||||||
|
|
||||||
public static WebClient client;
|
public static WebClient client;
|
||||||
|
|||||||
@@ -7,23 +7,23 @@ package org.openautonomousconnection.webclient.network;
|
|||||||
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.Transport;
|
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.Transport;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebRequestPacket;
|
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebRequestPacket;
|
||||||
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
|
|
||||||
import org.openautonomousconnection.protocol.side.client.ProtocolWebClient;
|
import org.openautonomousconnection.protocol.side.client.ProtocolWebClient;
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.WebRequestMethod;
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.WebRequestMethod;
|
||||||
import org.openautonomousconnection.webclient.Main;
|
|
||||||
import org.openautonomousconnection.webclient.network.type.NTFType;
|
import org.openautonomousconnection.webclient.network.type.NTFType;
|
||||||
import org.openautonomousconnection.webclient.network.type.text.NetTransmitDocument;
|
|
||||||
import org.openautonomousconnection.webclient.network.type.NetTransmitFile;
|
import org.openautonomousconnection.webclient.network.type.NetTransmitFile;
|
||||||
|
|
||||||
import javax.swing.text.Document;
|
import javax.swing.text.Document;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.Inet4Address;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.openautonomousconnection.webclient.Main.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the OAC-Protocol networking client
|
* Uses the OAC-Protocol networking client
|
||||||
* Suppressing "unchecked" warnings because of generic casts
|
* Suppressing "unchecked" warnings because of generic casts
|
||||||
@@ -39,13 +39,26 @@ public class WebClient extends ProtocolWebClient {
|
|||||||
* Connect to Webserver with URLs (info name based)
|
* Connect to Webserver with URLs (info name based)
|
||||||
* @param url url containing host and port (port optional)
|
* @param url url containing host and port (port optional)
|
||||||
*/
|
*/
|
||||||
public void connectToServer(URL url) {
|
public void connectToWebServer(URL url) {
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
|
|
||||||
// port 200 is the default port
|
int port = url.getPort() != -1 ? url.getPort() : DEFAULT_WEB_PORT_TCP;
|
||||||
int port = url.getPort() != -1 ? url.getPort() : 200;
|
|
||||||
|
|
||||||
this.connectToServer(host, port);
|
// UDP is always preset
|
||||||
|
this.buildServerConnection(host, port, DEFAULT_WEB_PORT_UDP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to INServer with URLs (ip based)
|
||||||
|
* @param ip ip to server
|
||||||
|
* @param port tcp ins port
|
||||||
|
*/
|
||||||
|
public void connectToINSServer(String ip, int port) {
|
||||||
|
|
||||||
|
port = port != -1 ? port : DEFAULT_INS_PORT_TCP;
|
||||||
|
|
||||||
|
// UDP is always preset
|
||||||
|
this.buildServerConnection(ip, port, DEFAULT_INS_PORT_UDP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.openautonomousconnection.webclient.network.website.tab;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.openautonomousconnection.webclient.Main;
|
import org.openautonomousconnection.webclient.Main;
|
||||||
import org.openautonomousconnection.webclient.network.WebClient;
|
|
||||||
import org.openautonomousconnection.webclient.network.website.WebSite;
|
import org.openautonomousconnection.webclient.network.website.WebSite;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -21,7 +20,7 @@ public final class Tab {
|
|||||||
private WebSite webSite;
|
private WebSite webSite;
|
||||||
|
|
||||||
public Tab(URL infoName, Icon favicon) {
|
public Tab(URL infoName, Icon favicon) {
|
||||||
Main.client.connectToServer(infoName);
|
Main.client.connectToWebServer(infoName);
|
||||||
|
|
||||||
this.infoName = infoName;
|
this.infoName = infoName;
|
||||||
this.favicon = favicon;
|
this.favicon = favicon;
|
||||||
@@ -29,7 +28,7 @@ public final class Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tab(URL infoName) {
|
public Tab(URL infoName) {
|
||||||
Main.client.connectToServer(infoName);
|
Main.client.connectToWebServer(infoName);
|
||||||
|
|
||||||
this.infoName = infoName;
|
this.infoName = infoName;
|
||||||
this.favicon = WebSite.getFavIcon(infoName);
|
this.favicon = WebSite.getFavIcon(infoName);
|
||||||
@@ -37,7 +36,7 @@ public final class Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tab(WebSite webSite) {
|
public Tab(WebSite webSite) {
|
||||||
Main.client.connectToServer(webSite.getInfoName());
|
Main.client.connectToWebServer(webSite.getInfoName());
|
||||||
|
|
||||||
this.infoName = webSite.getInfoName();
|
this.infoName = webSite.getInfoName();
|
||||||
this.favicon = webSite.getFavIcon();
|
this.favicon = webSite.getFavIcon();
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ public abstract class BrowserFrame extends JFrame {
|
|||||||
30, 30
|
30, 30
|
||||||
));
|
));
|
||||||
|
|
||||||
|
this.setLocationRelativeTo(null);
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public final class MainFrame extends BrowserFrame {
|
|||||||
private Tab openTab;
|
private Tab openTab;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private DOMContainerPanel domContainerPanel;
|
private final DOMContainerPanel domContainerPanel;
|
||||||
|
|
||||||
public MainFrame() {
|
public MainFrame() {
|
||||||
super(new TabButtonView());
|
super(new TabButtonView());
|
||||||
@@ -38,6 +38,7 @@ public final class MainFrame extends BrowserFrame {
|
|||||||
|
|
||||||
this.add(this.topBar, BorderLayout.NORTH);
|
this.add(this.topBar, BorderLayout.NORTH);
|
||||||
this.domContainerPanel = new DOMContainerPanel();
|
this.domContainerPanel = new DOMContainerPanel();
|
||||||
|
this.add(this.domContainerPanel, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
|||||||
@@ -4,28 +4,46 @@
|
|||||||
|
|
||||||
package org.openautonomousconnection.webclient.ui.dom;
|
package org.openautonomousconnection.webclient.ui.dom;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.embed.swing.JFXPanel;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.web.WebEngine;
|
||||||
|
import javafx.scene.web.WebView;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DOMContainerPanel extends JPanel {
|
public class DOMContainerPanel extends JPanel {
|
||||||
@Getter
|
@Getter
|
||||||
JPanel dom;
|
private final JFXPanel dom;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private WebView webView;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private WebEngine webEngine;
|
||||||
|
|
||||||
|
public void loadContent(String html) {
|
||||||
|
this.webEngine.loadContent(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadContent(Document html) {
|
||||||
|
this.loadContent(html.html());
|
||||||
|
}
|
||||||
|
|
||||||
public DOMContainerPanel() {
|
public DOMContainerPanel() {
|
||||||
this.setBackground(Color.LIGHT_GRAY);
|
this.setBackground(Color.LIGHT_GRAY);
|
||||||
|
|
||||||
this.dom = HTMLRenderer.render(Jsoup.parse("""
|
this.dom = new JFXPanel();
|
||||||
<html>
|
|
||||||
<body>
|
Platform.runLater(() -> {
|
||||||
<p> hello world! </p> \s
|
this.webView = new WebView();
|
||||||
</body>
|
this.webEngine = this.webView.getEngine();
|
||||||
</html>
|
this.webEngine.setJavaScriptEnabled(false);
|
||||||
\s
|
this.dom.setScene(new Scene(this.webView));
|
||||||
\s
|
});
|
||||||
\s"""));
|
|
||||||
|
|
||||||
this.add(this.dom);
|
this.add(this.dom);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javax.swing.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public class HTMLRenderer {
|
public class HTMLRenderer {
|
||||||
public static JPanel render(Document html) {
|
public static JPanel render(Document html) {
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.jsoup.nodes.Attributes;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public class HTMLTextRenderer {
|
public class HTMLTextRenderer {
|
||||||
|
|
||||||
|
|
||||||
@@ -30,11 +31,17 @@ public class HTMLTextRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static JComponent renderSimple(String text, String decoration, Attributes attributes, String className) {
|
private static JComponent renderSimple(String text, String decoration, Attributes attributes, String className) {
|
||||||
JLabel label = new JLabel(text);
|
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;
|
int d = Font.PLAIN;
|
||||||
|
|
||||||
Font font = new Font(Font.SERIF, Font.PLAIN, 10);
|
Font font = new Font(Font.SERIF, Font.PLAIN, 15);
|
||||||
|
|
||||||
|
|
||||||
// try { TODO: implement css
|
// try { TODO: implement css
|
||||||
|
|||||||
Reference in New Issue
Block a user