]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in 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.g2d.element.handler.impl;\r
13 \r
14 import java.awt.BasicStroke;\r
15 import java.awt.Shape;\r
16 import java.awt.Stroke;\r
17 \r
18 import org.simantics.g2d.element.ElementUtils;\r
19 import org.simantics.g2d.element.IElement;\r
20 import org.simantics.g2d.element.handler.EdgeVisuals;\r
21 import org.simantics.g2d.element.handler.SelectionOutline;\r
22 \r
23 public class ConnectionSelectionOutline implements SelectionOutline {\r
24 \r
25     private static final long                      serialVersionUID = 1L;\r
26 \r
27     public final static ConnectionSelectionOutline INSTANCE         = new ConnectionSelectionOutline();\r
28 \r
29     public static final Stroke                    defaultStroke    = new BasicStroke(0.3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);\r
30 \r
31     public Stroke resolveStroke(IElement e, Stroke defaultValue) {\r
32         for (EdgeVisuals ev : e.getElementClass().getItemsByClass(EdgeVisuals.class)) {\r
33             BasicStroke stroke = (BasicStroke) ev.getStroke(e);\r
34             if (stroke != null) {\r
35 //                return stroke;\r
36                 return new BasicStroke(1.5f*stroke.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);\r
37             }\r
38         }\r
39         return defaultStroke;\r
40     }\r
41 \r
42     @Override\r
43     public Shape getSelectionShape(IElement e) {\r
44         Stroke stroke = resolveStroke(e, defaultStroke);\r
45         Shape es = ElementUtils.getElementShapeOrBounds(e);\r
46         return stroke.createStrokedShape(es);\r
47     }\r
48 \r
49 }\r