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