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.query;
\r
14 import java.awt.Stroke;
\r
16 import org.simantics.databoard.Bindings;
\r
17 import org.simantics.db.ReadGraph;
\r
18 import org.simantics.db.Resource;
\r
19 import org.simantics.db.common.request.ResourceRead;
\r
20 import org.simantics.db.exception.DatabaseException;
\r
21 import org.simantics.diagram.G2DUtils;
\r
22 import org.simantics.diagram.connection.ConnectionVisuals;
\r
23 import org.simantics.diagram.stubs.G2DResource;
\r
24 import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;
\r
27 * @author Tuukka Lehtonen
\r
29 public class ConnectionVisualsRequest extends ResourceRead<ConnectionVisuals> {
\r
33 public ConnectionVisualsRequest(Resource connectionType) {
\r
34 super(connectionType);
\r
35 assert connectionType != null;
\r
39 public ConnectionVisuals perform(ReadGraph g) throws DatabaseException {
\r
40 g2d = G2DResource.getInstance(g);
\r
41 Resource structuralConnectionType = resource;
\r
43 // Load edge visual aspects
\r
44 Resource c = g.getPossibleObject(structuralConnectionType, g2d.HasColor);
\r
45 float[] color = null;
\r
47 float[] col = g.getPossibleValue(c, Bindings.FLOAT_ARRAY);
\r
48 if (col != null && col.length >= 3) {
\r
53 StrokeType strokeType = toStrokeType(g.getPossibleObject(structuralConnectionType, g2d.HasStrokeType));
\r
54 Stroke stroke = G2DUtils.getStroke(g, g.getPossibleObject(structuralConnectionType, g2d.HasStroke));
\r
56 return new ConnectionVisuals(color, strokeType, stroke);
\r
59 StrokeType toStrokeType(Resource strokeType) {
\r
60 if (strokeType != null) {
\r
61 if (strokeType.equals(g2d.StrokeType_Scaling))
\r
62 return StrokeType.Absolute;
\r
63 if (strokeType.equals(g2d.StrokeType_Nonscaling))
\r
64 return StrokeType.Relative;
\r