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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.element.handler.impl;
\r
14 import java.awt.BasicStroke;
\r
15 import java.awt.Shape;
\r
16 import java.awt.Stroke;
\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
23 public class ConnectionSelectionOutline implements SelectionOutline {
\r
25 private static final long serialVersionUID = 1L;
\r
27 public final static ConnectionSelectionOutline INSTANCE = new ConnectionSelectionOutline();
\r
29 public static final Stroke defaultStroke = new BasicStroke(0.3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
\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
36 return new BasicStroke(1.5f*stroke.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
\r
39 return defaultStroke;
\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