1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.element.handler.impl;
14 import java.awt.BasicStroke;
15 import java.awt.Shape;
16 import java.awt.Stroke;
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;
23 public class ConnectionSelectionOutline implements SelectionOutline {
25 private static final long serialVersionUID = 1L;
27 public final static ConnectionSelectionOutline INSTANCE = new ConnectionSelectionOutline();
29 public static final Stroke defaultStroke = new BasicStroke(0.3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
31 public Stroke resolveStroke(IElement e, Stroke defaultValue) {
32 for (EdgeVisuals ev : e.getElementClass().getItemsByClass(EdgeVisuals.class)) {
33 BasicStroke stroke = (BasicStroke) ev.getStroke(e);
36 return new BasicStroke(1.5f*stroke.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
43 public Shape getSelectionShape(IElement e) {
44 Stroke stroke = resolveStroke(e, defaultStroke);
45 Shape es = ElementUtils.getElementShapeOrBounds(e);
46 return stroke.createStrokedShape(es);