Implemented the JFX HTML renderer
This commit is contained in:
@@ -26,6 +26,9 @@ public class Main {
|
||||
public static final int DEFAULT_INS_PORT_TCP = 1026;
|
||||
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;
|
||||
|
||||
public static WebClient client;
|
||||
|
||||
@@ -7,23 +7,23 @@ package org.openautonomousconnection.webclient.network;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.Transport;
|
||||
import lombok.Getter;
|
||||
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.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.WebRequestMethod;
|
||||
import org.openautonomousconnection.webclient.Main;
|
||||
import org.openautonomousconnection.webclient.network.type.NTFType;
|
||||
import org.openautonomousconnection.webclient.network.type.text.NetTransmitDocument;
|
||||
import org.openautonomousconnection.webclient.network.type.NetTransmitFile;
|
||||
|
||||
import javax.swing.text.Document;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openautonomousconnection.webclient.Main.*;
|
||||
|
||||
/**
|
||||
* Uses the OAC-Protocol networking client
|
||||
* Suppressing "unchecked" warnings because of generic casts
|
||||
@@ -39,13 +39,26 @@ public class WebClient extends ProtocolWebClient {
|
||||
* Connect to Webserver with URLs (info name based)
|
||||
* @param url url containing host and port (port optional)
|
||||
*/
|
||||
public void connectToServer(URL url) {
|
||||
public void connectToWebServer(URL url) {
|
||||
String host = url.getHost();
|
||||
|
||||
// port 200 is the default port
|
||||
int port = url.getPort() != -1 ? url.getPort() : 200;
|
||||
int port = url.getPort() != -1 ? url.getPort() : DEFAULT_WEB_PORT_TCP;
|
||||
|
||||
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.Setter;
|
||||
import org.openautonomousconnection.webclient.Main;
|
||||
import org.openautonomousconnection.webclient.network.WebClient;
|
||||
import org.openautonomousconnection.webclient.network.website.WebSite;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -21,7 +20,7 @@ public final class Tab {
|
||||
private WebSite webSite;
|
||||
|
||||
public Tab(URL infoName, Icon favicon) {
|
||||
Main.client.connectToServer(infoName);
|
||||
Main.client.connectToWebServer(infoName);
|
||||
|
||||
this.infoName = infoName;
|
||||
this.favicon = favicon;
|
||||
@@ -29,7 +28,7 @@ public final class Tab {
|
||||
}
|
||||
|
||||
public Tab(URL infoName) {
|
||||
Main.client.connectToServer(infoName);
|
||||
Main.client.connectToWebServer(infoName);
|
||||
|
||||
this.infoName = infoName;
|
||||
this.favicon = WebSite.getFavIcon(infoName);
|
||||
@@ -37,7 +36,7 @@ public final class Tab {
|
||||
}
|
||||
|
||||
public Tab(WebSite webSite) {
|
||||
Main.client.connectToServer(webSite.getInfoName());
|
||||
Main.client.connectToWebServer(webSite.getInfoName());
|
||||
|
||||
this.infoName = webSite.getInfoName();
|
||||
this.favicon = webSite.getFavIcon();
|
||||
|
||||
@@ -47,6 +47,8 @@ public abstract class BrowserFrame extends JFrame {
|
||||
30, 30
|
||||
));
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public final class MainFrame extends BrowserFrame {
|
||||
private Tab openTab;
|
||||
|
||||
@Getter
|
||||
private DOMContainerPanel domContainerPanel;
|
||||
private final DOMContainerPanel domContainerPanel;
|
||||
|
||||
public MainFrame() {
|
||||
super(new TabButtonView());
|
||||
@@ -38,6 +38,7 @@ public final class MainFrame extends BrowserFrame {
|
||||
|
||||
this.add(this.topBar, BorderLayout.NORTH);
|
||||
this.domContainerPanel = new DOMContainerPanel();
|
||||
this.add(this.domContainerPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
@@ -4,28 +4,46 @@
|
||||
|
||||
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 org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DOMContainerPanel extends JPanel {
|
||||
@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() {
|
||||
this.setBackground(Color.LIGHT_GRAY);
|
||||
|
||||
this.dom = HTMLRenderer.render(Jsoup.parse("""
|
||||
<html>
|
||||
<body>
|
||||
<p> hello world! </p> \s
|
||||
</body>
|
||||
</html>
|
||||
\s
|
||||
\s
|
||||
\s"""));
|
||||
this.dom = new JFXPanel();
|
||||
|
||||
Platform.runLater(() -> {
|
||||
this.webView = new WebView();
|
||||
this.webEngine = this.webView.getEngine();
|
||||
this.webEngine.setJavaScriptEnabled(false);
|
||||
this.dom.setScene(new Scene(this.webView));
|
||||
});
|
||||
|
||||
this.add(this.dom);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ 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();
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.jsoup.nodes.Attributes;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class HTMLTextRenderer {
|
||||
|
||||
|
||||
@@ -30,11 +31,17 @@ public class HTMLTextRenderer {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Font font = new Font(Font.SERIF, Font.PLAIN, 10);
|
||||
Font font = new Font(Font.SERIF, Font.PLAIN, 15);
|
||||
|
||||
|
||||
// try { TODO: implement css
|
||||
|
||||
Reference in New Issue
Block a user