]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionPivotNode.java
Merge commit 'd186091'
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / SelectionPivotNode.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.scenegraph.g2d.nodes;\r
13 \r
14 import java.awt.BasicStroke;\r
15 import java.awt.Color;\r
16 import java.awt.Graphics2D;\r
17 import java.awt.geom.AffineTransform;\r
18 import java.awt.geom.GeneralPath;\r
19 import java.awt.geom.Point2D;\r
20 import java.awt.geom.Rectangle2D;\r
21 \r
22 import org.simantics.scenegraph.g2d.G2DNode;\r
23 import org.simantics.scenegraph.utils.GeometryUtils;\r
24 \r
25 public class SelectionPivotNode extends G2DNode {\r
26     /**\r
27          * \r
28          */\r
29         private static final long serialVersionUID = 1382614767907193882L;\r
30 \r
31         public transient static final BasicStroke SELECTION_STROKE = new BasicStroke(1.0f,\r
32             BasicStroke.CAP_SQUARE, BasicStroke.CAP_SQUARE, 10.0f);\r
33 \r
34     protected Point2D pivot = null;\r
35     \r
36     @SyncField("pivot")\r
37     public void setPivot(Point2D pivot) {\r
38         this.pivot = pivot;\r
39     }\r
40 \r
41     @Override\r
42     public void render(Graphics2D g) {\r
43         AffineTransform ot = g.getTransform();\r
44         \r
45         g.setColor(Color.RED);\r
46         g.translate(pivot.getX(), pivot.getY());\r
47 \r
48         double scale = GeometryUtils.getScale(g.getTransform());\r
49         double scaleRecip = 1.0 / scale;\r
50 \r
51         g.setStroke(GeometryUtils.scaleStroke(SELECTION_STROKE, (float) scaleRecip)); \r
52 \r
53         double padding = 5.0 * scaleRecip;\r
54         float d = (float) padding;\r
55 \r
56         GeneralPath p = new GeneralPath();\r
57         p.moveTo(-d, 0);\r
58         p.lineTo(d, 0);\r
59         p.moveTo(0, -d);\r
60         p.lineTo(0, d);\r
61 \r
62         g.draw(p);\r
63         \r
64         g.setTransform(ot);\r
65     }\r
66 \r
67         @Override\r
68         public Rectangle2D getBoundsInLocal() {\r
69                 return new Rectangle2D.Double(pivot.getX()-5, pivot.getY()-5, 10, 10);\r
70         }\r
71 \r
72 }\r