X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fcontent%2FArrowConfigurer.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fcontent%2FArrowConfigurer.java;h=abe51ce9606b1950dc11e1039a1abd639a258cb6;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/content/ArrowConfigurer.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/ArrowConfigurer.java new file mode 100644 index 000000000..abe51ce96 --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/ArrowConfigurer.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.content; + +import java.util.EnumSet; +import java.util.StringTokenizer; + +import org.simantics.g2d.connection.EdgeVisualsConfigurer; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.EdgeVisuals; +import org.simantics.g2d.element.handler.EdgeVisuals.ArrowType; +import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd; + +/** + * @author Tuukka Lehtonen + */ +public class ArrowConfigurer implements EdgeVisualsConfigurer { + + private ArrowType arrow = ArrowType.None; + private double arrowSize = 1.0; + + public ArrowConfigurer() { + } + + public ArrowConfigurer(ArrowType arrow, double arrowSize) { + this.arrow = arrow; + this.arrowSize = arrowSize; + } + + public ArrowConfigurer(String description) { + StringTokenizer tokenizer = new StringTokenizer(description); + if (tokenizer.hasMoreTokens()) { + String type = tokenizer.nextToken(); + this.arrow = parseType(type); + } + if (tokenizer.hasMoreTokens()) { + String size = tokenizer.nextToken(); + this.arrowSize = parseSize(size); + } + } + + private double parseSize(String size) { + try { + return Double.parseDouble(size); + } catch (NumberFormatException e) { + return 1.0; + } + } + + private ArrowType parseType(String type) { + String lower = type.toLowerCase(); + if ("none".equals(lower)) + return ArrowType.None; + if ("stroke".equals(lower)) + return ArrowType.Stroke; + if ("fill".equals(lower)) + return ArrowType.Fill; + if ("both".equals(lower)) + return ArrowType.Both; + throw new IllegalArgumentException("unrecognized arrow type: " + type); + } + + @Override + public void configure(IElement edge, EdgeVisuals visuals, EnumSet ends) { + for (EdgeEnd end : ends) { + visuals.setArrowType(edge, end, arrow); + visuals.setArrowSize(edge, end, arrowSize); + } + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[" + arrow + " " + arrowSize + "]"; + } + +}