1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.query;
14 import java.awt.Stroke;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.request.ResourceRead;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.diagram.G2DUtils;
22 import org.simantics.diagram.connection.ConnectionVisuals;
23 import org.simantics.diagram.stubs.G2DResource;
24 import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;
27 * @author Tuukka Lehtonen
29 public class ConnectionVisualsRequest extends ResourceRead<ConnectionVisuals> {
33 public ConnectionVisualsRequest(Resource connectionType) {
34 super(connectionType);
35 assert connectionType != null;
39 public ConnectionVisuals perform(ReadGraph g) throws DatabaseException {
40 g2d = G2DResource.getInstance(g);
41 Resource structuralConnectionType = resource;
43 // Load edge visual aspects
44 Resource c = g.getPossibleObject(structuralConnectionType, g2d.HasColor);
47 float[] col = g.getPossibleValue(c, Bindings.FLOAT_ARRAY);
48 if (col != null && col.length >= 3) {
53 StrokeType strokeType = toStrokeType(g.getPossibleObject(structuralConnectionType, g2d.HasStrokeType));
54 Stroke stroke = G2DUtils.getStroke(g, g.getPossibleObject(structuralConnectionType, g2d.HasStroke));
56 return new ConnectionVisuals(color, strokeType, stroke);
59 StrokeType toStrokeType(Resource strokeType) {
60 if (strokeType != null) {
61 if (strokeType.equals(g2d.StrokeType_Scaling))
62 return StrokeType.Absolute;
63 if (strokeType.equals(g2d.StrokeType_Nonscaling))
64 return StrokeType.Relative;