aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui
diff options
context:
space:
mode:
authorJJ2022-12-29 02:07:29 +0000
committerJJ2022-12-29 02:20:51 +0000
commit595853ad76bbebf74a9a737870d5a89fb9f21f55 (patch)
treebb0f0dc491696519c3a5eae9a89087b7b626a004 /src/main/ui
parentddf614b732649875f20b54af3ef622c5c39127ff (diff)
Rework layout generator
Diffstat (limited to 'src/main/ui')
-rw-r--r--src/main/ui/BrowserCanvas.java21
-rw-r--r--src/main/ui/BrowserWindow.java5
2 files changed, 9 insertions, 17 deletions
diff --git a/src/main/ui/BrowserCanvas.java b/src/main/ui/BrowserCanvas.java
index ea20e81..cde894f 100644
--- a/src/main/ui/BrowserCanvas.java
+++ b/src/main/ui/BrowserCanvas.java
@@ -13,33 +13,26 @@ public class BrowserCanvas extends JPanel {
public BrowserCanvas(ArrayList<Node> html) {
super();
this.currentLayout = Layout.constructTree(html);
- printTree(this.currentLayout.children);
- }
-
- private void printTree(ArrayList<Layout> tree) {
- for (Layout node : tree) {
-// System.out.println(System.identityHashCode(node.location));
- printTree((node).children);
- }
+ this.setBackground(Color.BLACK);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Point location = new Point(10, 20); // we need a mutable reference
+ g.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
+ g.setColor(Color.WHITE);
+ g.drawString("X", location.x, location.y);
renderHtml(this.currentLayout.children, g, location);
}
private void renderHtml(ArrayList<Layout> tree, Graphics g, Point location) {
for (Layout layout : tree) {
-// System.out.println(layout.location);
+ g.setColor(new Color((int)(Math.random() * 0x1000000)));
g.drawRect(layout.location.x, layout.location.y, layout.dimension.width, layout.dimension.height);
+ g.setColor(Color.WHITE);
if (layout.associatedNode instanceof TextNode) {
- if (layout.associatedNode.data().length() > 5) {
-// System.out.println(location);
- g.drawString(layout.associatedNode.data(), layout.location.x, layout.location.y);
- g.drawString("X", 10, 20);
- }
+ g.drawString(layout.associatedNode.data(), layout.location.x, layout.location.y + layout.dimension.height - 5);
} else {
renderHtml(layout.children, g, location);
}
diff --git a/src/main/ui/BrowserWindow.java b/src/main/ui/BrowserWindow.java
index abf164f..28d0b13 100644
--- a/src/main/ui/BrowserWindow.java
+++ b/src/main/ui/BrowserWindow.java
@@ -10,8 +10,8 @@ import java.util.*;
// Broad JFrame usage taken from here: https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
public class BrowserWindow extends JFrame {
- public static final int WIDTH = 1200;
- public static final int HEIGHT = 800;
+ public static final int WIDTH = 1500;
+ public static final int HEIGHT = 500;
private BrowserCanvas canvas;
private final BrowserBar browserBar;
@@ -34,7 +34,6 @@ public class BrowserWindow extends JFrame {
public void render(String uri) {
state.currentTab = uri;
remove(canvas);
-// System.out.println(state.currentTab);
try {
String file = Files.readString(Path.of(state.currentTab));
HtmlParser parser = new HtmlParser();