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.diagram.content;
\r
14 import java.util.EnumSet;
\r
15 import java.util.StringTokenizer;
\r
17 import org.simantics.g2d.connection.EdgeVisualsConfigurer;
\r
18 import org.simantics.g2d.element.IElement;
\r
19 import org.simantics.g2d.element.handler.EdgeVisuals;
\r
20 import org.simantics.g2d.element.handler.EdgeVisuals.ArrowType;
\r
21 import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd;
\r
24 * @author Tuukka Lehtonen
\r
26 public class ArrowConfigurer implements EdgeVisualsConfigurer {
\r
28 private ArrowType arrow = ArrowType.None;
\r
29 private double arrowSize = 1.0;
\r
31 public ArrowConfigurer() {
\r
34 public ArrowConfigurer(ArrowType arrow, double arrowSize) {
\r
36 this.arrowSize = arrowSize;
\r
39 public ArrowConfigurer(String description) {
\r
40 StringTokenizer tokenizer = new StringTokenizer(description);
\r
41 if (tokenizer.hasMoreTokens()) {
\r
42 String type = tokenizer.nextToken();
\r
43 this.arrow = parseType(type);
\r
45 if (tokenizer.hasMoreTokens()) {
\r
46 String size = tokenizer.nextToken();
\r
47 this.arrowSize = parseSize(size);
\r
51 private double parseSize(String size) {
\r
53 return Double.parseDouble(size);
\r
54 } catch (NumberFormatException e) {
\r
59 private ArrowType parseType(String type) {
\r
60 String lower = type.toLowerCase();
\r
61 if ("none".equals(lower))
\r
62 return ArrowType.None;
\r
63 if ("stroke".equals(lower))
\r
64 return ArrowType.Stroke;
\r
65 if ("fill".equals(lower))
\r
66 return ArrowType.Fill;
\r
67 if ("both".equals(lower))
\r
68 return ArrowType.Both;
\r
69 throw new IllegalArgumentException("unrecognized arrow type: " + type);
\r
73 public void configure(IElement edge, EdgeVisuals visuals, EnumSet<EdgeEnd> ends) {
\r
74 for (EdgeEnd end : ends) {
\r
75 visuals.setArrowType(edge, end, arrow);
\r
76 visuals.setArrowSize(edge, end, arrowSize);
\r
81 public String toString() {
\r
82 return getClass().getSimpleName() + "[" + arrow + " " + arrowSize + "]";
\r