]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/Scaleable.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / Scaleable.java
index d7c071e0a0f76410093cc0a7e0dc2d4833263983..feb132336a966efa279f99273091353a61d87547 100644 (file)
-/*******************************************************************************\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.g2d.element.handler.impl;\r
-\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Point2D;\r
-import java.util.Collection;\r
-\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.Scale;\r
-import org.simantics.g2d.element.handler.Validator;\r
-\r
-/**\r
- * Handler for an element that can be freely scaled.\r
- * \r
- * @author Toni Kalajainen\r
- */\r
-public class Scaleable implements Scale, Validator {\r
-\r
-    private static final long serialVersionUID = -4033716332747863703L;\r
-\r
-    Double aspectRatio;\r
-\r
-    public Scaleable(Double aspectRatio)\r
-    {\r
-        this.aspectRatio = aspectRatio;\r
-    }\r
-\r
-    @Override\r
-    public Double getFixedAspectRatio(IElement e) {\r
-        return aspectRatio;\r
-    }\r
-\r
-    @Override\r
-    public Point2D getScale(IElement e) {\r
-        AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);\r
-        return _getScale(at);\r
-    }  \r
-\r
-    @Override\r
-    public void setScale(IElement e, Point2D newScale) {\r
-        Point2D oldScale = getScale(e);\r
-        double sx = newScale.getX() / oldScale.getX();\r
-        double sy = newScale.getY() / oldScale.getY();\r
-        AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);\r
-        at = new AffineTransform(at);\r
-        at.scale(sx, sy);\r
-        e.setHint(ElementHints.KEY_TRANSFORM, at);\r
-    }\r
-\r
-    @Override\r
-    public Point2D getMaximumScale(IElement e) {\r
-        return null;\r
-    }\r
-\r
-    @Override\r
-    public Point2D getMinimumScale(IElement e) {\r
-        return null;\r
-    }\r
-\r
-    private static Point2D _getScale(AffineTransform at) {\r
-        double m00 = at.getScaleX();\r
-        double m11 = at.getScaleY();\r
-        double m10 = at.getShearY();\r
-        double m01 = at.getShearX();\r
-        // Project unit vector to canvas\r
-        double sx = Math.sqrt( m00*m00+m10*m10 );\r
-        double sy = Math.sqrt( m01*m01+m11*m11 );\r
-        return new Point2D.Double(sx, sy);\r
-    }\r
-\r
-    @Override\r
-    public void validate(final IElement e, final ICanvasContext ctx, Collection<Issue> lst) {\r
-        /*\r
-               if (aspectRatio!=null)\r
-               {\r
-                       // Validate aspect ratio\r
-                       final Point2D scale = getScale(e);\r
-                       double currentRatio = scale.getX() / scale.getY();\r
-                       if (Math.abs(currentRatio - aspectRatio)>0.000001)\r
-                       {\r
-                               lst.add(new Issue() {\r
-                                       @Override\r
-                                       public String getMessage() {\r
-                                               return "Aspect ratio is wrong";\r
-                                       }\r
-                                       @Override\r
-                                       public void addSuggestions(Collection<Suggestion> suggestionList) {\r
-                                               suggestionList.add(new Suggestion() {\r
-                                                       @Override\r
-                                                       public boolean fix() {\r
-                                                               double newSx = scale.getX();\r
-                                                               double newSy = newSx * aspectRatio;\r
-                                                               Point2D newScale = new Point2D.Double(newSx, newSy);\r
-                                                               setScale(e, newScale);\r
-                                                               ctx.setDirty();\r
-                                                               return true;\r
-                                                       }\r
-                                                       @Override\r
-                                                       public String getMessage() {\r
-                                                               return "Scale height, keep width";\r
-                                                       }});\r
-                                       }});\r
-                       }\r
-                       // TODO min scale validator\r
-                       // TODO max scale validator\r
-               }\r
-         */\r
-    }\r
-\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g2d.element.handler.impl;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.util.Collection;
+
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.Scale;
+import org.simantics.g2d.element.handler.Validator;
+
+/**
+ * Handler for an element that can be freely scaled.
+ * 
+ * @author Toni Kalajainen
+ */
+public class Scaleable implements Scale, Validator {
+
+    private static final long serialVersionUID = -4033716332747863703L;
+
+    Double aspectRatio;
+
+    public Scaleable(Double aspectRatio)
+    {
+        this.aspectRatio = aspectRatio;
+    }
+
+    @Override
+    public Double getFixedAspectRatio(IElement e) {
+        return aspectRatio;
+    }
+
+    @Override
+    public Point2D getScale(IElement e) {
+        AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
+        return _getScale(at);
+    }  
+
+    @Override
+    public void setScale(IElement e, Point2D newScale) {
+        Point2D oldScale = getScale(e);
+        double sx = newScale.getX() / oldScale.getX();
+        double sy = newScale.getY() / oldScale.getY();
+        AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
+        at = new AffineTransform(at);
+        at.scale(sx, sy);
+        e.setHint(ElementHints.KEY_TRANSFORM, at);
+    }
+
+    @Override
+    public Point2D getMaximumScale(IElement e) {
+        return null;
+    }
+
+    @Override
+    public Point2D getMinimumScale(IElement e) {
+        return null;
+    }
+
+    private static Point2D _getScale(AffineTransform at) {
+        double m00 = at.getScaleX();
+        double m11 = at.getScaleY();
+        double m10 = at.getShearY();
+        double m01 = at.getShearX();
+        // Project unit vector to canvas
+        double sx = Math.sqrt( m00*m00+m10*m10 );
+        double sy = Math.sqrt( m01*m01+m11*m11 );
+        return new Point2D.Double(sx, sy);
+    }
+
+    @Override
+    public void validate(final IElement e, final ICanvasContext ctx, Collection<Issue> lst) {
+        /*
+               if (aspectRatio!=null)
+               {
+                       // Validate aspect ratio
+                       final Point2D scale = getScale(e);
+                       double currentRatio = scale.getX() / scale.getY();
+                       if (Math.abs(currentRatio - aspectRatio)>0.000001)
+                       {
+                               lst.add(new Issue() {
+                                       @Override
+                                       public String getMessage() {
+                                               return "Aspect ratio is wrong";
+                                       }
+                                       @Override
+                                       public void addSuggestions(Collection<Suggestion> suggestionList) {
+                                               suggestionList.add(new Suggestion() {
+                                                       @Override
+                                                       public boolean fix() {
+                                                               double newSx = scale.getX();
+                                                               double newSy = newSx * aspectRatio;
+                                                               Point2D newScale = new Point2D.Double(newSx, newSy);
+                                                               setScale(e, newScale);
+                                                               ctx.setDirty();
+                                                               return true;
+                                                       }
+                                                       @Override
+                                                       public String getMessage() {
+                                                               return "Scale height, keep width";
+                                                       }});
+                                       }});
+                       }
+                       // TODO min scale validator
+                       // TODO max scale validator
+               }
+         */
+    }
+
+
+}