]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/OutlinePick.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / OutlinePick.java
index 6a2222b9f917fed11758549d4565405bfb17328c..4009d27e3fcab1830d07a348f15e4306961c84e3 100644 (file)
@@ -1,84 +1,84 @@
-/*******************************************************************************\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.Shape;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.NoninvertibleTransformException;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.List;\r
-\r
-import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.ElementHandler;\r
-import org.simantics.g2d.element.handler.Outline;\r
-import org.simantics.g2d.element.handler.Pick;\r
-import org.simantics.g2d.element.handler.Transform;\r
-import org.simantics.g2d.utils.GeometryUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class OutlinePick implements Pick {\r
-\r
-    public static final ElementHandler INSTANCE         = new OutlinePick();\r
-\r
-    private static final long          serialVersionUID = 1L;\r
-\r
-    @Override\r
-    public boolean pickTest(IElement e, Shape s, PickPolicy policy) {\r
-        Rectangle2D pickArea = null;\r
-        if (s instanceof Rectangle2D)\r
-            pickArea = (Rectangle2D) s;\r
-        else\r
-            // FIXME: suboptimal, but works.\r
-            pickArea = s.getBounds2D();\r
-\r
-        // Pick with shape handler(s)\r
-        List<Outline> shapeHandlers = e.getElementClass().getItemsByClass(Outline.class);\r
-        if (!shapeHandlers.isEmpty()) {\r
-            // Convert pick shape to element coordinates\r
-            Transform t = e.getElementClass().getSingleItem(Transform.class);\r
-            AffineTransform canvasToElement = t.getTransform(e);\r
-            AffineTransform elementToCanvas;\r
-            try {\r
-                elementToCanvas = canvasToElement.createInverse();\r
-            } catch (NoninvertibleTransformException e1) {\r
-                throw new RuntimeException(e1);\r
-            }\r
-            Shape pickShapeInElementCoords = GeometryUtils.transformShape(pickArea, elementToCanvas);\r
-\r
-            // Intersection with one shape is enough\r
-            switch (policy) {\r
-                case PICK_INTERSECTING_OBJECTS: {\r
-                    for (Outline es : shapeHandlers) {\r
-                        Shape elementShape = es.getElementShape(e);\r
-                        if (elementShape == null)\r
-                            return false;\r
-                        if (GeometryUtils.intersects(pickShapeInElementCoords, elementShape))\r
-                            return true;\r
-                    }\r
-                    return false;\r
-                }\r
-                case PICK_CONTAINED_OBJECTS: {\r
-                    for (Outline es : shapeHandlers) {\r
-                        Shape elementShape = es.getElementShape(e);\r
-                        if (GeometryUtils.contains(pickShapeInElementCoords, elementShape))\r
-                            return true;\r
-                    }\r
-                    return false;\r
-                }\r
-            }\r
-        }\r
-        return false;\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.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.NoninvertibleTransformException;
+import java.awt.geom.Rectangle2D;
+import java.util.List;
+
+import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.ElementHandler;
+import org.simantics.g2d.element.handler.Outline;
+import org.simantics.g2d.element.handler.Pick;
+import org.simantics.g2d.element.handler.Transform;
+import org.simantics.g2d.utils.GeometryUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class OutlinePick implements Pick {
+
+    public static final ElementHandler INSTANCE         = new OutlinePick();
+
+    private static final long          serialVersionUID = 1L;
+
+    @Override
+    public boolean pickTest(IElement e, Shape s, PickPolicy policy) {
+        Rectangle2D pickArea = null;
+        if (s instanceof Rectangle2D)
+            pickArea = (Rectangle2D) s;
+        else
+            // FIXME: suboptimal, but works.
+            pickArea = s.getBounds2D();
+
+        // Pick with shape handler(s)
+        List<Outline> shapeHandlers = e.getElementClass().getItemsByClass(Outline.class);
+        if (!shapeHandlers.isEmpty()) {
+            // Convert pick shape to element coordinates
+            Transform t = e.getElementClass().getSingleItem(Transform.class);
+            AffineTransform canvasToElement = t.getTransform(e);
+            AffineTransform elementToCanvas;
+            try {
+                elementToCanvas = canvasToElement.createInverse();
+            } catch (NoninvertibleTransformException e1) {
+                throw new RuntimeException(e1);
+            }
+            Shape pickShapeInElementCoords = GeometryUtils.transformShape(pickArea, elementToCanvas);
+
+            // Intersection with one shape is enough
+            switch (policy) {
+                case PICK_INTERSECTING_OBJECTS: {
+                    for (Outline es : shapeHandlers) {
+                        Shape elementShape = es.getElementShape(e);
+                        if (elementShape == null)
+                            return false;
+                        if (GeometryUtils.intersects(pickShapeInElementCoords, elementShape))
+                            return true;
+                    }
+                    return false;
+                }
+                case PICK_CONTAINED_OBJECTS: {
+                    for (Outline es : shapeHandlers) {
+                        Shape elementShape = es.getElementShape(e);
+                        if (GeometryUtils.contains(pickShapeInElementCoords, elementShape))
+                            return true;
+                    }
+                    return false;
+                }
+            }
+        }
+        return false;
+    }
+}