diff options
Diffstat (limited to 'src/main/model/layout')
-rw-r--r-- | src/main/model/layout/BlockLayout.java | 10 | ||||
-rw-r--r-- | src/main/model/layout/DocumentLayout.java | 5 | ||||
-rw-r--r-- | src/main/model/layout/InlineLayout.java | 22 | ||||
-rw-r--r-- | src/main/model/layout/Layout.java | 6 |
4 files changed, 15 insertions, 28 deletions
diff --git a/src/main/model/layout/BlockLayout.java b/src/main/model/layout/BlockLayout.java index f011847..9204b61 100644 --- a/src/main/model/layout/BlockLayout.java +++ b/src/main/model/layout/BlockLayout.java @@ -4,17 +4,13 @@ import model.html.Node; import java.awt.*; -// A block style layout. public class BlockLayout extends Layout { - // MODIFIES: this - // EFFECTS: constructs a new BlockLayout public BlockLayout(Node node, Layout parent) { super(node, parent); } - // MODIFIES: this - // EFFECTS: recursively constructs the layout tree + // recursively construct the layout tree public void layout() { this.setLocation(this.getParent().getLocation()); this.getPreviousSibling().ifPresent( @@ -28,8 +24,8 @@ public class BlockLayout extends Layout { child.layout(); this.setHeight(this.getHeight() + child.getHeight()); } - System.out.println(this.getAssociatedNode().getData() + this.getLocation()); - System.out.println(System.identityHashCode(this.getLocation())); +// System.out.println(this.getAssociatedNode().getData() + this.getLocation()); +// System.out.println(System.identityHashCode(this.getLocation())); // System.out.println(this.getAssociatedNode().getData() + this.getDimension()); } } diff --git a/src/main/model/layout/DocumentLayout.java b/src/main/model/layout/DocumentLayout.java index 92c0b00..2e9d778 100644 --- a/src/main/model/layout/DocumentLayout.java +++ b/src/main/model/layout/DocumentLayout.java @@ -1,9 +1,7 @@ package model.layout; import java.awt.*; -import java.util.ArrayList; -// root document layout style public class DocumentLayout extends Layout { /* @@ -15,8 +13,7 @@ public class DocumentLayout extends Layout { super(null, null); } - // MODIFIES: this - // EFFECTS: recursively constructs the layout tree + // recursively construct the layout tree public void layout() { this.setLocation(new Point(10, 20)); this.setDimension(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); diff --git a/src/main/model/layout/InlineLayout.java b/src/main/model/layout/InlineLayout.java index 8e375d5..c4c51b5 100644 --- a/src/main/model/layout/InlineLayout.java +++ b/src/main/model/layout/InlineLayout.java @@ -6,19 +6,16 @@ import model.html.TextNode; import java.awt.*; -// Inline layout style public class InlineLayout extends Layout { private Point cursor; - // Constructs a new InlineLayout public InlineLayout(Node node, Layout parent) { super(node, parent); cursor = new Point(); } - // MODIFIES: this - // EFFECTS: recursively constructs the layout tree + // recursively construct the layout tree public void layout() { this.setLocation(this.getParent().getLocation()); this.getPreviousSibling().ifPresent( @@ -28,14 +25,17 @@ public class InlineLayout extends Layout { this.setCursor(this.getX(), this.getY()); Node node = this.getAssociatedNode(); - if (node instanceof TextNode) { - if (node.getData().length() > 5) { - this.setHeight(20); -// this.setWidth(this.getWidth() + node.getData().length()); + switch (node) { + case ElementNode e -> { + if (e.getTag().equals("a")) { + this.setX(this.getX() + this.getParent().getWidth()); + } } - } else if (node instanceof ElementNode) { - if (((ElementNode) node).getTag().equals("a")) { - this.setX(this.getX() + this.getParent().getWidth()); + default -> { + if (node.getData().length() > 5) { + this.setHeight(20); +// this.setWidth(this.getWidth() + node.getData().length()); + } } } diff --git a/src/main/model/layout/Layout.java b/src/main/model/layout/Layout.java index 4d9f48f..5a19302 100644 --- a/src/main/model/layout/Layout.java +++ b/src/main/model/layout/Layout.java @@ -31,8 +31,6 @@ public abstract class Layout { // the big function public abstract void layout(); - // MODIFIES: this - // EFFECTS: recursively constructs the layout tree public Layout(Node node, Layout parent) { this.associatedNode = node; @@ -47,8 +45,6 @@ public abstract class Layout { // eh, probably the best place to put this // parent MAY BE nil: a handy call to Optional.ofNullable allows this - // MODIFIES: this - // EFFECTS: recursively constructs the layout tree public static ArrayList<Layout> constructTree(ArrayList<Node> html, Layout parent) { ArrayDeque<Layout> result = new ArrayDeque<>(); for (Node node : html) { @@ -74,8 +70,6 @@ public abstract class Layout { return new ArrayList<>(result); // haha } - // MODIFIES: this - // EFFECTS: recursively constructs the layout tree public static DocumentLayout constructTree(ArrayList<Node> html) { DocumentLayout result = new DocumentLayout(); result.setChildren(constructTree(html, result)); |