]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/model/Node.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.debug.graphical / src / org / simantics / debug / graphical / model / Node.java
diff --git a/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/model/Node.java b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/model/Node.java
new file mode 100644 (file)
index 0000000..8aa0319
--- /dev/null
@@ -0,0 +1,105 @@
+package org.simantics.debug.graphical.model;\r
+\r
+import java.awt.Color;\r
+import java.awt.Font;\r
+import java.awt.Graphics2D;\r
+import java.awt.font.FontRenderContext;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Point2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+public class Node {\r
+    public static final Font FONT = new Font("Arial", Font.PLAIN, 12);\r
+    public static final FontRenderContext FRC = \r
+            new FontRenderContext(new AffineTransform(), true, true);\r
+    public static final Rectangle2D MAX_BOUNDS = FONT.getMaxCharBounds(FRC);\r
+    public static final double FONT_HEIGHT = MAX_BOUNDS.getHeight();\r
+    \r
+    public static double PADDING = 3.0;\r
+    \r
+    NodeData data;       \r
+    Content content;\r
+    \r
+    double x;\r
+    double y;\r
+    \r
+    double radiusX;\r
+    double radiusY;\r
+    \r
+    // for layouter\r
+    public double forceX, forceY;\r
+    \r
+    public Node(NodeData data) {\r
+        this.data = data;\r
+    }\r
+\r
+    public void setContent(Content content) {\r
+        this.content = content;\r
+        this.radiusX = content.radiusX;\r
+        this.radiusY = content.radiusY;\r
+    }\r
+    \r
+    public NodeData getData() {\r
+        return data;\r
+    }\r
+    \r
+    public void setPos(double x, double y) {\r
+        this.x = x;\r
+        this.y = y;\r
+    }\r
+    \r
+    public void render(Graphics2D g) {\r
+        Rectangle2D rect = new Rectangle2D.Double(x-radiusX, y-radiusY, 2*radiusX, 2*radiusY);\r
+        g.setColor(new Color(200, 200, 255));\r
+        g.fill(rect);\r
+        g.setColor(Color.BLACK);\r
+        \r
+        if(content != null)\r
+            content.render(g, x, y);\r
+        \r
+        g.draw(rect);\r
+    }\r
+    \r
+    public Point2D clipLineFromCenter(double targetX, double targetY) {\r
+        targetX -= x;\r
+        targetY -= y;\r
+        if(radiusX * Math.abs(targetY) < radiusY * Math.abs(targetX)) {\r
+            return new Point2D.Double(\r
+                    x+Math.signum(targetX)*radiusX, \r
+                    y+targetY * radiusX / Math.abs(targetX));\r
+        }\r
+        else {\r
+            return new Point2D.Double(                     \r
+                    x+targetX * radiusY / Math.abs(targetY),\r
+                    y+Math.signum(targetY)*radiusY);\r
+        }\r
+    }\r
+    \r
+    public boolean pick(double px, double py) {\r
+        return Math.abs(px - x) <= radiusX && Math.abs(py - y) <= radiusY; \r
+    }\r
+\r
+    public double getX() {\r
+        return x;\r
+    }\r
+    \r
+    public double getY() {\r
+        return y;\r
+    }\r
+    \r
+    public double getMinX() {\r
+        return x - radiusX;\r
+    }\r
+    \r
+    public double getMinY() {\r
+        return y - radiusY;\r
+    }\r
+    \r
+    public double getMaxX() {\r
+        return x + radiusX;\r
+    }\r
+    \r
+    public double getMaxY() {\r
+        return y + radiusY;\r
+    }\r
+}\r