]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
58d697e31ab304b61b01aaeb39e8f2821bac9532
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.elements;\r
2 \r
3 import java.awt.geom.AffineTransform;\r
4 import java.awt.geom.Point2D;\r
5 \r
6 public abstract class PositionableDrawable extends Drawable implements ITransformable, Cloneable {\r
7         protected double posX;\r
8         protected double posY;\r
9         \r
10         @Override\r
11         public Point2D getPosition() {\r
12                 return new Point2D.Double(posX, posY);\r
13         }\r
14         @Override\r
15         public AffineTransform getTransform() {\r
16                 return new AffineTransform(1.0, 0.0, 0.0, 1.0, posX, posY);\r
17         }\r
18         @Override\r
19         public ITransformable moveTo(double x, double y) {\r
20                 try {\r
21                         PositionableDrawable d = (PositionableDrawable)clone();\r
22                         d.posX = x;\r
23                         d.posY = y;\r
24                         return d;\r
25                 } catch(CloneNotSupportedException e) {                 \r
26                         throw new Error(e);\r
27                 }\r
28         }\r
29         @Override\r
30         public ITransformable setTransform(AffineTransform at) {\r
31                 try {\r
32                         PositionableDrawable d = (PositionableDrawable)clone();\r
33                         d.posX = at.getTranslateX();\r
34                         d.posY = at.getTranslateY();\r
35                         return d;\r
36                 } catch(CloneNotSupportedException e) {                 \r
37                         throw new Error(e);\r
38                 }               \r
39         }\r
40 }\r