Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: scooby/visualexprbuilder
base: 7b20840679
...
head fork: scooby/visualexprbuilder
compare: ed7d006dfd
  • 2 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
View
7 src/net/samuel/ben/BasicExpressionUI.java
@@ -19,13 +19,12 @@
**/
package net.samuel.ben;
-import java.awt.Font;
-import java.awt.Stroke;
import java.awt.BasicStroke;
-import java.awt.Paint;
import java.awt.Color;
-import java.awt.FontMetrics;
+import java.awt.Font;
import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Stroke;
import java.awt.geom.Rectangle2D;
public class BasicExpressionUI extends ExpressionUI {
View
4 src/quicktests/OnePiece.java
@@ -7,7 +7,9 @@
import net.samuel.ben.*;
public class OnePiece extends JPanel {
- public OnePiece() {
+ private static final long serialVersionUID = -2574375926597058507L;
+
+ public OnePiece() {
super();
inset = new Rectangle2D.Double();
strk = new BasicStroke(1.0f);
View
19 src/quicktests/OnePiece2.java
@@ -1,12 +1,23 @@
package quicktests;
-import java.awt.*;
-import java.awt.event.*;
-import java.awt.geom.*;
-import javax.swing.*;
+import java.awt.BasicStroke;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
public class OnePiece2 extends JPanel {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6304004113864637817L;
+
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
View
5 src/veb/Content.java
@@ -0,0 +1,5 @@
+package veb;
+
+public interface Content extends Drawable {
+ Drawable getDecoration(int s, int t);
+}
View
33 src/veb/Direction.java
@@ -0,0 +1,33 @@
+package veb;
+
+public enum Direction {
+ north(0, 1),
+ east(1, 0),
+ south(0, -1),
+ west(-1, 0);
+ private final int x;
+ private final int y;
+ private final Vector v;
+ private static final int yflip = 1;
+ private static Direction[] members = new Direction[] { north, east, south, west };
+ private Direction(int x, int y) {
+ this.x = x;
+ this.y = y * yflip;
+ v = new Vector(x, y);
+ }
+ public int getX() {
+ return x;
+ }
+ public int getY() {
+ return y;
+ }
+ public Vector getV() {
+ return v;
+ }
+ public Direction cw() {
+ return members[(ordinal() + 1) % 4];
+ }
+ public Direction ccw() {
+ return members[(ordinal() + 3) % 4];
+ }
+}
View
8 src/veb/Drawable.java
@@ -0,0 +1,8 @@
+package veb;
+
+public interface Drawable {
+ Vector getSize();
+ void draw(Surface surf, Vector origin, Vector size);
+ Drawable merge(Drawable o);
+ boolean isEmpty();
+}
View
14 src/veb/GenericTree.java
@@ -0,0 +1,14 @@
+package veb;
+
+/**
+ * All the tree needs to do is say:
+ * Here are the nodes
+ * Given any particular node, here are the children or parent nodes.
+ * @author ben
+ *
+ */
+public interface GenericTree {
+ Content getRoot();
+ Iterable<Content> getChildrenOf(Content node);
+ Content getParentOf(Content node);
+}
View
84 src/veb/Layout.java
@@ -0,0 +1,84 @@
+package veb;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Layout {
+ final private Direction overall_dir;
+ final private Vector origin;
+ final private GenericTree tree;
+ final private Surface surface;
+
+ public Layout(Direction d, Vector o, GenericTree gt, Surface s) {
+ overall_dir = d;
+ origin = o;
+ tree = gt;
+ surface = s;
+ }
+ /**
+ * The algorithm is as such:
+ * Organize the nodes into a grid to determine relative offsets
+ * Expand along each axis into margin/decoration/content/decoration/margin
+ * Collapse dmd to d where possible.
+ */
+ public void layout() {
+ Map <Offset, Content> grid = new HashMap<Offset, Content>();
+ grid(grid, tree.getRoot(), 0, 0);
+ Map <Offset, Drawable> dgrid = new HashMap<Offset, Drawable>();
+ for(Offset o : grid.keySet()) {
+ Content n = grid.get(o);
+ for(int s = -2; s < 3; s++) {
+ for(int t = -2; t < 3; t++) {
+ Drawable d = n.getDecoration(s, t);
+ dgrid.put(o.slot(s, t), d);
+ }
+ }
+ }
+ }
+ private int grid(Map<Offset, Content> g, Content n, int x, int y) {
+ int sx = x, cx = x;
+ for(Content d : tree.getChildrenOf(n)) {
+ cx = grid(g, d, cx, y + 1);
+ }
+ if(cx == sx)
+ cx += 1;
+ for(x = sx; x < cx; x++) {
+ g.put(new Offset(x, y), n);
+ }
+ return cx;
+ }
+ private final class Offset {
+ public final int x;
+ public final int y;
+ public final int s;
+ public final int t;
+
+ public Offset(int x, int y) { this.x = x; this.y = y; this.s = 0; this.t = 0;}
+ public Offset(int x, int y, int s, int t) { this.x = x; this.y = y; this.s = s; this.t = t;}
+ public Offset slot(int _s, int _t) {
+ return s == _s && t == _t ? this : new Offset(x, y, _s, _t);
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 101;
+ return prime * (prime * (prime + x) + y) + s;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null || !(obj instanceof Offset))
+ return false;
+ Offset other = (Offset) obj;
+ return x == other.x && y == other.y && s == other.s;
+ }
+ }
+}
View
28 src/veb/Scalar.java
@@ -0,0 +1,28 @@
+/**
+ *
+ */
+package veb;
+
+/**
+ * @author ben
+ *
+ */
+public abstract class Scalar {
+ public abstract double getDouble();
+ public long getLong() { return (long) getDouble(); }
+ public int getInt() { return (int) getDouble(); }
+ public abstract Scalar scale(int s);
+ public static Scalar inst(double x) { return new ScalarDouble(x); }
+ public static Scalar inst(long x) { return new ScalarLong(x); }
+ public static Scalar inst(int x) { return new ScalarInt(x); }
+ public abstract Scalar add(Scalar other);
+ public abstract boolean isIntegral();
+ @Override
+ public abstract boolean equals(Object o);
+ @Override
+ public abstract int hashCode();
+ @Override
+ public String toString() {
+ return String.format("Scalar[%s]", isIntegral() ? getLong() : getDouble());
+ }
+}
View
58 src/veb/ScalarDouble.java
@@ -0,0 +1,58 @@
+/**
+ *
+ */
+package veb;
+
+/**
+ * @author ben
+ *
+ */
+public final class ScalarDouble extends Scalar {
+ final double val;
+ public ScalarDouble(double x) { val = x; }
+ @Override
+ public double getDouble() {
+ return val;
+ }
+ @Override
+ public Scalar scale(int s) {
+ return new ScalarDouble(val * s);
+ }
+ @Override
+ public boolean isIntegral() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ @Override
+ public Scalar add(Scalar other) {
+ return new ScalarDouble(val + other.getDouble());
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ long temp;
+ temp = Double.doubleToLongBits(val);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ return result;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ScalarDouble))
+ return false;
+ ScalarDouble other = (ScalarDouble) obj;
+ if (Double.doubleToLongBits(val) != Double.doubleToLongBits(other.val))
+ return false;
+ return true;
+ }
+}
View
62 src/veb/ScalarInt.java
@@ -0,0 +1,62 @@
+package veb;
+
+public final class ScalarInt extends Scalar {
+ private final int val;
+ public ScalarInt(int x) {
+ val = x;
+ }
+ @Override
+ public double getDouble() {
+ return (double) val;
+ }
+ @Override
+ public long getLong() {
+ return val;
+ }
+ @Override
+ public int getInt() {
+ return val;
+ }
+ @Override
+ public Scalar scale(int s) {
+ return new ScalarInt(val * s);
+ }
+ @Override
+ public Scalar add(Scalar other) {
+ if(other == null)
+ return this;
+ if(other instanceof ScalarInt)
+ return new ScalarInt(val + ((ScalarInt) other).val);
+ return other.add(this);
+ }
+ @Override
+ public boolean isIntegral() {
+ return true;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + val;
+ return result;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ScalarInt))
+ return false;
+ ScalarInt other = (ScalarInt) obj;
+ if (val != other.val)
+ return false;
+ return true;
+ }
+}
View
67 src/veb/ScalarLong.java
@@ -0,0 +1,67 @@
+/**
+ *
+ */
+package veb;
+
+/**
+ * @author ben
+ *
+ */
+public final class ScalarLong extends Scalar {
+ private final long val;
+ public ScalarLong(long x) {
+ val = x;
+ }
+ @Override
+ public double getDouble() {
+ // TODO Auto-generated method stub
+ return (double) val;
+ }
+ @Override
+ public long getLong() {
+ return val;
+ }
+ @Override
+ public Scalar scale(int s) {
+ return new ScalarLong(val * s);
+ }
+ @Override
+ public boolean isIntegral() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+ @Override
+ public Scalar add(Scalar other) {
+ if(other == null)
+ return this;
+ if(!other.isIntegral())
+ return other.add(this);
+ return new ScalarLong(val + other.getLong());
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (val ^ (val >>> 32));
+ return result;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ScalarLong))
+ return false;
+ ScalarLong other = (ScalarLong) obj;
+ if (val != other.val)
+ return false;
+ return true;
+ }
+}
View
12 src/veb/Surface.java
@@ -0,0 +1,12 @@
+/**
+ *
+ */
+package veb;
+
+/**
+ * @author ben
+ *
+ */
+public interface Surface {
+ void draw(Vector o, Vector s, Drawable dec);
+}
View
76 src/veb/Vector.java
@@ -0,0 +1,76 @@
+package veb;
+
+public final class Vector {
+ public final Scalar x;
+ public final Scalar y;
+ public Vector(Scalar x, Scalar y) {
+ this.x = x;
+ this.y = y;
+ }
+ public Vector(double x, double y) {
+ this.x = Scalar.inst(x);
+ this.y = Scalar.inst(y);
+ }
+ public Vector(long x, long y) {
+ this.x = Scalar.inst(x);
+ this.y = Scalar.inst(y);
+ }
+ public Vector(int x, int y) {
+ this.x = Scalar.inst(x);
+ this.y = Scalar.inst(y);
+ }
+ public Vector scale(int s) {
+ return new Vector(x.scale(s), y.scale(s));
+ }
+ public Vector rotatecw() {
+ return new Vector(y.scale(-1), x);
+ }
+ public Vector rotateccw() {
+ return new Vector(y, x.scale(-1));
+ }
+ public Scalar getAxis(int a) {
+ if(a == 0)
+ return x;
+ else if(a == 1)
+ return y;
+ else
+ throw new AssertionError(a);
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((x == null) ? 0 : x.hashCode());
+ result = prime * result + ((y == null) ? 0 : y.hashCode());
+ return result;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof Vector))
+ return false;
+ Vector other = (Vector) obj;
+ if (x == null) {
+ if (other.x != null)
+ return false;
+ } else if (!x.equals(other.x))
+ return false;
+ if (y == null) {
+ if (other.y != null)
+ return false;
+ } else if (!y.equals(other.y))
+ return false;
+ return true;
+ }
+}
+
+

No commit comments for this range

Something went wrong with that request. Please try again.