Files
WebClient/src/main/java/org/openautonomousconnection/webclient/ui/MainFrame.java

82 lines
2.0 KiB
Java
Raw Normal View History

2026-01-18 14:54:52 +01:00
/* Author: Maple
* Dec. 12 2025
* */
package org.openautonomousconnection.webclient.ui;
import lombok.Getter;
import org.openautonomousconnection.webclient.network.website.tab.Tab;
2026-01-19 15:36:21 +01:00
import org.openautonomousconnection.webclient.ui.dom.DOMContainerPanel;
import org.openautonomousconnection.webclient.ui.tab.TabButton;
import org.openautonomousconnection.webclient.ui.tab.TabButtonView;
2026-01-18 14:54:52 +01:00
2026-01-19 15:36:21 +01:00
import javax.swing.*;
import java.awt.*;
2026-01-18 14:54:52 +01:00
import java.net.MalformedURLException;
import java.net.URI;
2026-01-19 15:36:21 +01:00
import java.net.URL;
2026-01-18 14:54:52 +01:00
2026-01-19 15:36:21 +01:00
public final class MainFrame extends BrowserFrame {
2026-01-18 14:54:52 +01:00
@Getter
private Tab openTab;
2026-01-19 15:36:21 +01:00
@Getter
private DOMContainerPanel domContainerPanel;
2026-01-18 14:54:52 +01:00
public MainFrame() {
2026-01-19 15:36:21 +01:00
super(new TabButtonView());
2026-01-18 14:54:52 +01:00
this.setSize(800, 600);
try {
this.openTab = new Tab(
URI.create("web://open-autonomous-connection.org").toURL()
);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
2026-01-19 15:36:21 +01:00
this.add(this.topBar, BorderLayout.NORTH);
this.domContainerPanel = new DOMContainerPanel();
}
private void init() {
this.open(this.openTab);
}
@Override
public TabButtonView getTopBar() {
return (TabButtonView) this.topBar;
}
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 open(URL url) {
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();
2026-01-18 14:54:52 +01:00
}
}