Refractors

This commit is contained in:
Tinglyyy
2026-02-08 14:31:10 +01:00
parent 083d29caa5
commit 9e478afd9d
10 changed files with 163 additions and 284 deletions

View File

@@ -7,6 +7,9 @@ package org.openautonomousconnection.webclient;
import dev.unlegitdqrk.unlegitlibrary.event.EventManager;
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
import org.openautonomousconnection.infonamelib.InfoNames;
import org.openautonomousconnection.oacswing.component.design.Design;
import org.openautonomousconnection.oacswing.component.design.DesignManager;
import org.openautonomousconnection.oacswing.component.design.OACColor;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.ProtocolValues;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
@@ -14,6 +17,7 @@ import org.openautonomousconnection.webclient.network.WebClient;
import org.openautonomousconnection.webclient.network.handlers.ServerPacketHandler;
import org.openautonomousconnection.webclient.packetlistener.listeners.WebPacketListener;
import org.openautonomousconnection.webclient.ui.MainFrame;
import org.openautonomousconnection.webclient.ui.dom.DOMContainerPanel;
import java.beans.EventHandler;
import java.io.File;
@@ -44,6 +48,11 @@ public class Main {
}
registerPacketListeners();
/* Darkmode, wohoo! */
initDesigns();
DesignManager.setGlobalDesign(Design.DARK);
mainFrame = new MainFrame();
mainFrame.setVisible(true);
@@ -82,4 +91,10 @@ public class Main {
private static void registerPacketListeners() {
ServerPacketHandler.registerPacketListener(new WebPacketListener());
}
private static void initDesigns() {
//TODO
DesignManager.getInstance().registerComponent(DOMContainerPanel.class, OACColor.DARK_BACKGROUND);
}
}

View File

@@ -17,7 +17,6 @@ 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.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -38,24 +37,6 @@ public class WebClient extends ProtocolClient {
*/
public static final int TIMEOUT = 30;
/**
* Connect to Webserver with URLs (info name based)
* @param url url containing host and port (port optional)
*/
public void connectToWebServer(URL url) throws Exception {
String host = url.getHost();
int port = url.getPort() != -1 ? url.getPort() : DEFAULT_WEB_PORT_TCP;
// UDP is always preset
this.buildServerConnection(null, true);
try {
this.getClientServerConnection().connect(host, DEFAULT_WEB_PORT_TCP);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Connect to INServer with URLs (ip based)
@@ -115,21 +96,15 @@ public class WebClient extends ProtocolClient {
public void onResponse(INSResponseStatus insResponseStatus, List<INSRecord> list) {
}
// TODO: Just an example (ui would be better than console)
@Override
public boolean trustINS(String caFingerprint) {
getProtocolBridge().getLogger().info("You never connected to this INS before.\n" +
"Fingerprint: " + caFingerprint + "\n" +
"Do you want to connect? (y/N)");
//TODO
return true;
}
@Override
public boolean trustNewINSFingerprint(String oldCAFingerprint, String newCAFingerprint) {
getProtocolBridge().getLogger().warn("INS root Certificate changed.\n" +
"Old fingerprint: " + oldCAFingerprint + "\n" +
"New fingerprint: " + newCAFingerprint + "\n" +
"Do you want to connect? (y/N)");
//TODO
return true;
}

View File

@@ -1,75 +1,14 @@
/* Author: Maple
* Dec. 12 2025
* */
package org.openautonomousconnection.webclient.network.website.tab;
import lombok.Getter;
import lombok.Setter;
import org.openautonomousconnection.webclient.Main;
import org.openautonomousconnection.webclient.network.website.WebSite;
import javax.swing.*;
import java.net.URL;
import java.util.Objects;
@Getter @Setter
public final class Tab {
private URL infoName;
private Icon favicon;
private WebSite webSite;
public interface Tab {
Icon getFavicon();
void setFavicon(Icon favicon);
public Tab(URL infoName, Icon favicon) throws Exception {
Main.client.connectToWebServer(infoName);
URL getInfoName();
void setInfoName(URL infoName);
this.infoName = infoName;
this.favicon = favicon;
this.webSite = new WebSite(infoName);
}
public Tab(URL infoName) throws Exception {
Main.client.connectToWebServer(infoName);
this.infoName = infoName;
this.favicon = WebSite.getFavIcon(infoName);
this.webSite = new WebSite(infoName);
}
public Tab(WebSite webSite) throws Exception {
Main.client.connectToWebServer(webSite.getInfoName());
this.infoName = webSite.getInfoName();
this.favicon = webSite.getFavIcon();
this.webSite = webSite;
}
public void refresh() {
this.webSite.requestNewDom();
this.favicon = this.webSite.getFavIcon();
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (Tab) obj;
return Objects.equals(this.infoName, that.infoName) &&
Objects.equals(this.favicon, that.favicon) &&
Objects.equals(this.webSite, that.webSite);
}
@Override
public int hashCode() {
return Objects.hash(this.infoName, this.favicon, this.webSite);
}
@Override
public String toString() {
return "Tab{" +
"infoName=" + this.infoName +
", favicon=" + this.favicon +
", webSite=" + this.webSite +
'}';
}
void refresh() throws Exception;
}

View File

@@ -0,0 +1,90 @@
/* Author: Maple
* Dec. 12 2025
* */
package org.openautonomousconnection.webclient.network.website.tab;
import lombok.Getter;
import lombok.Setter;
import org.openautonomousconnection.webclient.network.WebClient;
import org.openautonomousconnection.webclient.network.website.WebSite;
import javax.swing.*;
import java.net.URL;
import java.util.Objects;
import static org.openautonomousconnection.webclient.Main.DEFAULT_WEB_PORT_TCP;
public final class WebTab implements Tab {
@Getter @Setter
private URL infoName;
@Getter @Setter
private Icon favicon;
@Getter @Setter
private WebSite webSite;
private WebClient client;
public WebTab(URL infoName, Icon favicon) throws Exception {
refresh();
this.infoName = infoName;
this.favicon = favicon;
this.webSite = new WebSite(infoName);
}
public WebTab(URL infoName) throws Exception {
refresh();
this.infoName = infoName;
this.favicon = WebSite.getFavIcon(infoName);
this.webSite = new WebSite(infoName);
}
public WebTab(WebSite webSite) throws Exception {
refresh();
this.infoName = webSite.getInfoName();
this.favicon = webSite.getFavIcon();
this.webSite = webSite;
}
public void refresh() throws Exception {
if (client.getClientServerConnection().isConnected()) client.getClientServerConnection().disconnect();
int port = infoName.getPort() == -1 ? DEFAULT_WEB_PORT_TCP : infoName.getPort();
client.buildServerConnection(null, true);
try {
client.getClientServerConnection().connect(infoName.getHost(), port);
} catch (Exception e) {
throw new RuntimeException(e);
}
this.webSite.requestNewDom();
this.favicon = this.webSite.getFavIcon();
}
@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
WebTab webTab = (WebTab) o;
return Objects.equals(infoName, webTab.infoName) && Objects.equals(favicon, webTab.favicon) && Objects.equals(webSite, webTab.webSite) && Objects.equals(client, webTab.client);
}
@Override
public int hashCode() {
return Objects.hash(infoName, favicon, webSite, client);
}
@Override
public String toString() {
return "WebTab{" +
"infoName=" + infoName +
", favicon=" + favicon +
", webSite=" + webSite +
", client=" + client +
'}';
}
}

View File

@@ -14,144 +14,9 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
public abstract class BrowserFrame extends JFrame {
private static final int RESIZE_MARGIN = 8;
private Point dragStart;
private Rectangle startBounds;
private int resizeCursor = Cursor.DEFAULT_CURSOR;
@Getter
protected TopBar topBar;
public abstract class BrowserFrame extends OACFrame {
protected BrowserFrame() {
this(new TopBar());
this.topBar.initButtonPanel(BorderLayout.NORTH);
}
protected BrowserFrame(TopBar topBar) {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
this.setUndecorated(true);
this.topBar = topBar;
this.setShape(new RoundRectangle2D.Double(
0, 0,
this.getWidth(),
this.getHeight(),
30, 30
));
this.setLocationRelativeTo(null);
this.init();
}
private void init() {
this.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
setShape(new RoundRectangle2D.Double(
0, 0,
getWidth(),
getHeight(),
30, 30
));
}
});
MouseAdapter adapter = new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
resizeCursor = getResizeCursor(e);
setCursor(Cursor.getPredefinedCursor(resizeCursor));
}
@Override
public void mousePressed(MouseEvent e) {
dragStart = e.getLocationOnScreen();
startBounds = getBounds();
}
@Override
public void mouseDragged(MouseEvent e) {
if (resizeCursor == Cursor.DEFAULT_CURSOR) return;
Point dragNow = e.getLocationOnScreen();
int dx = dragNow.x - dragStart.x;
int dy = dragNow.y - dragStart.y;
Rectangle newBounds = new Rectangle(startBounds);
switch (resizeCursor) {
case Cursor.E_RESIZE_CURSOR -> newBounds.width += dx;
case Cursor.S_RESIZE_CURSOR -> newBounds.height += dy;
case Cursor.SE_RESIZE_CURSOR -> {
newBounds.width += dx;
newBounds.height += dy;
}
case Cursor.W_RESIZE_CURSOR -> {
newBounds.x += dx;
newBounds.width -= dx;
}
case Cursor.N_RESIZE_CURSOR -> {
newBounds.y += dy;
newBounds.height -= dy;
}
case Cursor.NW_RESIZE_CURSOR -> {
newBounds.x += dx;
newBounds.y += dy;
newBounds.width -= dx;
newBounds.height -= dy;
}
case Cursor.NE_RESIZE_CURSOR -> {
newBounds.y += dy;
newBounds.width += dx;
newBounds.height -= dy;
}
case Cursor.SW_RESIZE_CURSOR -> {
newBounds.x += dx;
newBounds.width -= dx;
newBounds.height += dy;
}
}
setBounds(newBounds);
}
};
addMouseListener(adapter);
addMouseMotionListener(adapter);
}
private int getResizeCursor(MouseEvent e) {
int x = e.getX();
int y = e.getY();
int w = e.getComponent().getWidth();
int h = e.getComponent().getHeight();
boolean left = x < RESIZE_MARGIN;
boolean right = x > w - RESIZE_MARGIN;
boolean top = y < RESIZE_MARGIN;
boolean bottom = y > h - RESIZE_MARGIN;
if (left && top) return Cursor.NW_RESIZE_CURSOR;
if (right && top) return Cursor.NE_RESIZE_CURSOR;
if (left && bottom) return Cursor.SW_RESIZE_CURSOR;
if (right && bottom) return Cursor.SE_RESIZE_CURSOR;
if (left) return Cursor.W_RESIZE_CURSOR;
if (right) return Cursor.E_RESIZE_CURSOR;
if (top) return Cursor.N_RESIZE_CURSOR;
if (bottom) return Cursor.S_RESIZE_CURSOR;
return Cursor.DEFAULT_CURSOR;
}
}

View File

@@ -5,26 +5,21 @@
package org.openautonomousconnection.webclient.ui;
import lombok.Getter;
import org.openautonomousconnection.webclient.network.website.tab.Tab;
import org.openautonomousconnection.webclient.network.website.tab.WebTab;
import org.openautonomousconnection.webclient.ui.dom.DOMContainerPanel;
import org.openautonomousconnection.webclient.ui.tab.TabButton;
import org.openautonomousconnection.webclient.ui.tab.TabButtonView;
import javax.swing.*;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
public final class MainFrame extends BrowserFrame {
@Getter
private Tab openTab;
private WebTab openWebTab;
@Getter
private final DOMContainerPanel domContainerPanel;
public MainFrame() {
super(new TabButtonView());
super();
this.setSize(800, 600);
@@ -34,47 +29,42 @@ public final class MainFrame extends BrowserFrame {
throw new RuntimeException(e);
}
this.add(this.topBar, BorderLayout.NORTH);
this.domContainerPanel = new DOMContainerPanel();
this.add(this.domContainerPanel, BorderLayout.CENTER);
}
private void init() {
this.open(this.openTab);
this.open(this.openWebTab);
}
@Override
public TabButtonView getTopBar() {
return (TabButtonView) this.topBar;
public void setOpenWebTab(int index) {
//TODO
}
public void setOpenTab(int index) {
this.openTab = this.getTopBar().getButton(index).getTab();
this.getTopBar().getButton(index).grabFocus();
}
public void setOpenTab(Tab tab) {
for(TabButton button : this.getTopBar().getTabButtons())
if(button.getTab().equals(tab)) {
this.openTab = button.getTab();
button.grabFocus();
}
public void setOpenWebTab(WebTab webTab) {
//TODO
// for(TabButton button : this.getTopBar().getTabButtons())
// if(button.getTab().equals(tab)) {
// this.openTab = button.getTab();
// button.grabFocus();
// }
}
public void open(URL url) throws Exception {
TabButton button = new TabButton(url);
this.getTopBar().addButton(button);
button.grabFocus();
//TODO
// TabButton button = new TabButton(url);
//
// this.getTopBar().addButton(button);
//
// button.grabFocus();
}
public void open(Tab tab) {
TabButton button = new TabButton(tab);
this.getTopBar().addButton(button);
button.grabFocus();
public void open(WebTab webTab) {
//TODO
// TabButton button = new TabButton(tab);
//
// this.getTopBar().addButton(button);
//
// button.grabFocus();
}
}

View File

@@ -10,12 +10,13 @@ import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import lombok.Getter;
import org.openautonomousconnection.oacswing.component.OACPanel;
import org.w3c.dom.Document;
import javax.swing.*;
import java.awt.*;
public class DOMContainerPanel extends JPanel {
public class DOMContainerPanel extends OACPanel {
@Getter
private final JFXPanel dom;
@@ -36,6 +37,7 @@ public class DOMContainerPanel extends JPanel {
public DOMContainerPanel() {
this.setBackground(Color.LIGHT_GRAY);
//TODO: Turn this into designable OAC-JFXpanel
this.dom = new JFXPanel();
Platform.runLater(() -> {

View File

@@ -7,10 +7,10 @@ package org.openautonomousconnection.webclient.ui.tab;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.openautonomousconnection.webclient.network.website.tab.Tab;
import org.openautonomousconnection.oacswing.component.OACButton;
import org.openautonomousconnection.webclient.network.website.tab.WebTab;
import javax.swing.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -18,18 +18,18 @@ import java.net.URL;
* Button that contains Tab data
*/
@Getter @Setter
public class TabButton extends JButton {
private Tab tab;
public class TabButton extends OACButton {
private WebTab webTab;
public TabButton(@NonNull String infoName) throws Exception {
this(URI.create(infoName).toURL());
}
public TabButton(@NonNull URL infoName) throws Exception {
this.tab = new Tab(infoName);
this.webTab = new WebTab(infoName);
}
public TabButton(@NonNull Tab tab) {
this.tab = tab;
public TabButton(@NonNull WebTab webTab) {
this.webTab = webTab;
}
}

View File

@@ -5,7 +5,7 @@
package org.openautonomousconnection.webclient.ui.tab;
import lombok.Getter;
import org.openautonomousconnection.webclient.ui.TopBar;
import org.openautonomousconnection.oacswing.component.OACTitleBar;
import java.awt.*;
import java.util.ArrayList;
@@ -14,8 +14,10 @@ import java.util.List;
/**
* View at the top of the screen that contains the tabs
* @deprecated the OAC-Swing library's solution fits better and works globally
*/
public class TabButtonView extends TopBar {
@Deprecated(forRemoval = true, since = "1.0.0-BETA.1.4")
public class TabButtonView extends OACTitleBar {
@Getter
private final List<TabButton> tabButtons;
@@ -28,7 +30,7 @@ public class TabButtonView extends TopBar {
* @param tabButtons already created buttons
*/
public TabButtonView(Collection<TabButton> tabButtons) {
super();
super(null);
this.tabButtons = (List<TabButton>) tabButtons;
FlowLayout layoutStyle = new FlowLayout(FlowLayout.RIGHT, 0, 0);
@@ -36,10 +38,6 @@ public class TabButtonView extends TopBar {
this.setLayout(layoutStyle);
this.setBackground(Color.gray);
this.add(this.getButtonPanel());
this.getButtonPanel().setBackground(this.getBackground());
}
public void addButton(TabButton tabButton) {