-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.diagram.content;\r
-\r
-import java.util.EnumSet;\r
-import java.util.StringTokenizer;\r
-\r
-import org.simantics.g2d.connection.EdgeVisualsConfigurer;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.EdgeVisuals;\r
-import org.simantics.g2d.element.handler.EdgeVisuals.ArrowType;\r
-import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ArrowConfigurer implements EdgeVisualsConfigurer {\r
-\r
- private ArrowType arrow = ArrowType.None;\r
- private double arrowSize = 1.0;\r
-\r
- public ArrowConfigurer() {\r
- }\r
-\r
- public ArrowConfigurer(ArrowType arrow, double arrowSize) {\r
- this.arrow = arrow;\r
- this.arrowSize = arrowSize;\r
- }\r
-\r
- public ArrowConfigurer(String description) {\r
- StringTokenizer tokenizer = new StringTokenizer(description);\r
- if (tokenizer.hasMoreTokens()) {\r
- String type = tokenizer.nextToken();\r
- this.arrow = parseType(type);\r
- }\r
- if (tokenizer.hasMoreTokens()) {\r
- String size = tokenizer.nextToken();\r
- this.arrowSize = parseSize(size);\r
- }\r
- }\r
-\r
- private double parseSize(String size) {\r
- try {\r
- return Double.parseDouble(size);\r
- } catch (NumberFormatException e) {\r
- return 1.0;\r
- }\r
- }\r
-\r
- private ArrowType parseType(String type) {\r
- String lower = type.toLowerCase();\r
- if ("none".equals(lower))\r
- return ArrowType.None;\r
- if ("stroke".equals(lower))\r
- return ArrowType.Stroke;\r
- if ("fill".equals(lower))\r
- return ArrowType.Fill;\r
- if ("both".equals(lower))\r
- return ArrowType.Both;\r
- throw new IllegalArgumentException("unrecognized arrow type: " + type);\r
- }\r
-\r
- @Override\r
- public void configure(IElement edge, EdgeVisuals visuals, EnumSet<EdgeEnd> ends) {\r
- for (EdgeEnd end : ends) {\r
- visuals.setArrowType(edge, end, arrow);\r
- visuals.setArrowSize(edge, end, arrowSize);\r
- }\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "[" + arrow + " " + arrowSize + "]";\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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<EdgeEnd> ends) {
+ for (EdgeEnd end : ends) {
+ visuals.setArrowType(edge, end, arrow);
+ visuals.setArrowSize(edge, end, arrowSize);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[" + arrow + " " + arrowSize + "]";
+ }
+
+}