]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/ConnectionSelectionOutline.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / ConnectionSelectionOutline.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.element.handler.impl;
13
14 import java.awt.BasicStroke;
15 import java.awt.Shape;
16 import java.awt.Stroke;
17
18 import org.simantics.g2d.element.ElementUtils;
19 import org.simantics.g2d.element.IElement;
20 import org.simantics.g2d.element.handler.EdgeVisuals;
21 import org.simantics.g2d.element.handler.SelectionOutline;
22
23 public class ConnectionSelectionOutline implements SelectionOutline {
24
25     private static final long                      serialVersionUID = 1L;
26
27     public final static ConnectionSelectionOutline INSTANCE         = new ConnectionSelectionOutline();
28
29     public static final Stroke                    defaultStroke    = new BasicStroke(0.3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
30
31     public Stroke resolveStroke(IElement e, Stroke defaultValue) {
32         for (EdgeVisuals ev : e.getElementClass().getItemsByClass(EdgeVisuals.class)) {
33             BasicStroke stroke = (BasicStroke) ev.getStroke(e);
34             if (stroke != null) {
35 //                return stroke;
36                 return new BasicStroke(1.5f*stroke.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
37             }
38         }
39         return defaultStroke;
40     }
41
42     @Override
43     public Shape getSelectionShape(IElement e) {
44         Stroke stroke = resolveStroke(e, defaultStroke);
45         Shape es = ElementUtils.getElementShapeOrBounds(e);
46         return stroke.createStrokedShape(es);
47     }
48
49 }