--- /dev/null
+/*******************************************************************************\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.query;\r
+\r
+import java.awt.Stroke;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ResourceRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.G2DUtils;\r
+import org.simantics.diagram.connection.ConnectionVisuals;\r
+import org.simantics.diagram.stubs.G2DResource;\r
+import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ConnectionVisualsRequest extends ResourceRead<ConnectionVisuals> {\r
+\r
+ G2DResource g2d;\r
+\r
+ public ConnectionVisualsRequest(Resource connectionType) {\r
+ super(connectionType);\r
+ assert connectionType != null;\r
+ }\r
+\r
+ @Override\r
+ public ConnectionVisuals perform(ReadGraph g) throws DatabaseException {\r
+ g2d = G2DResource.getInstance(g);\r
+ Resource structuralConnectionType = resource;\r
+\r
+ // Load edge visual aspects\r
+ Resource c = g.getPossibleObject(structuralConnectionType, g2d.HasColor);\r
+ float[] color = null;\r
+ if (c != null) {\r
+ float[] col = g.getPossibleValue(c, Bindings.FLOAT_ARRAY);\r
+ if (col != null && col.length >= 3) {\r
+ color = col;\r
+ }\r
+ }\r
+\r
+ StrokeType strokeType = toStrokeType(g.getPossibleObject(structuralConnectionType, g2d.HasStrokeType));\r
+ Stroke stroke = G2DUtils.getStroke(g, g.getPossibleObject(structuralConnectionType, g2d.HasStroke));\r
+\r
+ return new ConnectionVisuals(color, strokeType, stroke);\r
+ }\r
+\r
+ StrokeType toStrokeType(Resource strokeType) {\r
+ if (strokeType != null) {\r
+ if (strokeType.equals(g2d.StrokeType_Scaling))\r
+ return StrokeType.Absolute;\r
+ if (strokeType.equals(g2d.StrokeType_Nonscaling))\r
+ return StrokeType.Relative;\r
+ }\r
+ return null;\r
+ }\r
+\r
+}\r