From 595853ad76bbebf74a9a737870d5a89fb9f21f55 Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 28 Dec 2022 18:07:29 -0800 Subject: Rework layout generator --- src/main/ui/BrowserCanvas.java | 21 +++++++-------------- src/main/ui/BrowserWindow.java | 5 ++--- 2 files changed, 9 insertions(+), 17 deletions(-) (limited to 'src/main/ui') 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 html) { super(); this.currentLayout = Layout.constructTree(html); - printTree(this.currentLayout.children); - } - - private void printTree(ArrayList 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 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(); -- cgit v1.2.3-70-g09d2