]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionPivotNode.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / SelectionPivotNode.java
diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionPivotNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionPivotNode.java
new file mode 100644 (file)
index 0000000..db44f96
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.scenegraph.g2d.nodes;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.GeneralPath;\r
+import java.awt.geom.Point2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.scenegraph.g2d.G2DNode;\r
+import org.simantics.scenegraph.utils.GeometryUtils;\r
+\r
+public class SelectionPivotNode extends G2DNode {\r
+    /**\r
+        * \r
+        */\r
+       private static final long serialVersionUID = 1382614767907193882L;\r
+\r
+       public transient static final BasicStroke SELECTION_STROKE = new BasicStroke(1.0f,\r
+            BasicStroke.CAP_SQUARE, BasicStroke.CAP_SQUARE, 10.0f);\r
+\r
+    protected Point2D pivot = null;\r
+    \r
+    @SyncField("pivot")\r
+    public void setPivot(Point2D pivot) {\r
+        this.pivot = pivot;\r
+    }\r
+\r
+    @Override\r
+    public void render(Graphics2D g) {\r
+       AffineTransform ot = g.getTransform();\r
+       \r
+        g.setColor(Color.RED);\r
+        g.translate(pivot.getX(), pivot.getY());\r
+\r
+        double scale = GeometryUtils.getScale(g.getTransform());\r
+        double scaleRecip = 1.0 / scale;\r
+\r
+        g.setStroke(GeometryUtils.scaleStroke(SELECTION_STROKE, (float) scaleRecip)); \r
+\r
+        double padding = 5.0 * scaleRecip;\r
+        float d = (float) padding;\r
+\r
+        GeneralPath p = new GeneralPath();\r
+        p.moveTo(-d, 0);\r
+        p.lineTo(d, 0);\r
+        p.moveTo(0, -d);\r
+        p.lineTo(0, d);\r
+\r
+        g.draw(p);\r
+        \r
+        g.setTransform(ot);\r
+    }\r
+\r
+       @Override\r
+       public Rectangle2D getBoundsInLocal() {\r
+               return new Rectangle2D.Double(pivot.getX()-5, pivot.getY()-5, 10, 10);\r
+       }\r
+\r
+}\r