]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/src/org/simantics/trend/impl/TrendGraphicalNode.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.trend / src / org / simantics / trend / impl / TrendGraphicalNode.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * 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.trend.impl;\r
13 \r
14 import java.awt.Graphics2D;\r
15 import java.awt.geom.AffineTransform;\r
16 import java.awt.geom.Rectangle2D;\r
17 \r
18 import org.simantics.scenegraph.g2d.G2DNode;\r
19 \r
20 public abstract class TrendGraphicalNode extends G2DNode implements TrendLayout {\r
21 \r
22         private static final long serialVersionUID = 1L;\r
23         \r
24         Rectangle2D bounds = new Rectangle2D.Double();\r
25 \r
26         public double getWidth() { \r
27                 return bounds.getWidth();\r
28         }\r
29         \r
30         public double getHeight() {\r
31                 return bounds.getHeight();\r
32         }\r
33         \r
34         public void setSize(double w, double h) {\r
35                 if (bounds.getWidth()==w && bounds.getHeight()==h) return;\r
36                 bounds.setFrame(0, 0, w, h);\r
37         }\r
38         \r
39         public double getX() {\r
40                 return transform.getTranslateX();\r
41         }\r
42         \r
43         public double getY() {\r
44                 return transform.getTranslateY();\r
45         }\r
46         \r
47         public void setTranslate(double x, double y) {\r
48                 setTransform(AffineTransform.getTranslateInstance(x, y));\r
49         }\r
50         \r
51         @Override\r
52         public Rectangle2D getBoundsInLocal() {\r
53                 return bounds;\r
54         }\r
55 \r
56         @Override\r
57         public void render(Graphics2D g2d) {\r
58                 AffineTransform at = g2d.getTransform();\r
59                 g2d.transform( transform );\r
60                 try {\r
61                         doRender(g2d);\r
62                 } finally {\r
63                         g2d.setTransform(at);\r
64                 }\r
65         }\r
66         \r
67         public TrendNode getTrend() {\r
68                 return (TrendNode) getParent();\r
69         }\r
70         \r
71         protected abstract void doRender(Graphics2D g2d);\r
72 \r
73         \r
74 }\r