]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/ConnectionSelectionOutline.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / ConnectionSelectionOutline.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/ConnectionSelectionOutline.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/ConnectionSelectionOutline.java
new file mode 100644 (file)
index 0000000..2f0f208
--- /dev/null
@@ -0,0 +1,49 @@
+/*******************************************************************************\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.BasicStroke;\r
+import java.awt.Shape;\r
+import java.awt.Stroke;\r
+\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.EdgeVisuals;\r
+import org.simantics.g2d.element.handler.SelectionOutline;\r
+\r
+public class ConnectionSelectionOutline implements SelectionOutline {\r
+\r
+    private static final long                      serialVersionUID = 1L;\r
+\r
+    public final static ConnectionSelectionOutline INSTANCE         = new ConnectionSelectionOutline();\r
+\r
+    public static final Stroke                    defaultStroke    = new BasicStroke(0.3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);\r
+\r
+    public Stroke resolveStroke(IElement e, Stroke defaultValue) {\r
+        for (EdgeVisuals ev : e.getElementClass().getItemsByClass(EdgeVisuals.class)) {\r
+            BasicStroke stroke = (BasicStroke) ev.getStroke(e);\r
+            if (stroke != null) {\r
+//                return stroke;\r
+                return new BasicStroke(1.5f*stroke.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);\r
+            }\r
+        }\r
+        return defaultStroke;\r
+    }\r
+\r
+    @Override\r
+    public Shape getSelectionShape(IElement e) {\r
+        Stroke stroke = resolveStroke(e, defaultStroke);\r
+        Shape es = ElementUtils.getElementShapeOrBounds(e);\r
+        return stroke.createStrokedShape(es);\r
+    }\r
+\r
+}\r