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.scenegraph.g2d.nodes;
14 import java.awt.Color;
15 import java.awt.Graphics2D;
16 import java.awt.Stroke;
17 import java.awt.geom.Line2D;
18 import java.awt.geom.Point2D;
19 import java.awt.geom.Rectangle2D;
21 import org.simantics.scenegraph.g2d.G2DNode;
22 import org.simantics.scenegraph.utils.GeometryUtils;
25 * @author Tuukka Lehtonen
27 public class RelationshipNode2 extends G2DNode {
29 private static final long serialVersionUID = 3517235896431855937L;
31 public static transient double PADDING = 1;
33 protected Stroke boxStroke = null;
34 protected Stroke lineStroke = null;
35 protected Color boxColor = null;
36 protected Color lineColor = null;
37 protected Point2D p1 = null;
38 protected Point2D p2 = null;
40 private transient Rectangle2D boundsInLocal = null;
41 private transient float phase = 0;
42 private transient Line2D line = new Line2D.Double();
44 @SyncField({"linestroke", "linecolor", "p1", "p2"})
45 public void init(Stroke lineStroke, Color lineColor, Point2D p1, Point2D p2) {
46 this.lineStroke = lineStroke;
47 this.lineColor = lineColor;
50 this.boundsInLocal = calculateLocalBounds();
54 public void render(Graphics2D g) {
55 if (p1 == null || p2 == null)
62 float scale = (float) (1.0 / GeometryUtils.getScale(g.getTransform()));
63 float scaledPhase = scale * phase;
65 if (lineStroke != null && lineColor != null) {
66 if (lineStroke != boxStroke)
67 g.setStroke(GeometryUtils.scaleAndOffsetStroke(lineStroke, scale, scaledPhase));
68 if (lineColor != boxColor)
69 g.setColor(lineColor);
76 public Rectangle2D getBoundsInLocal() {
80 private Rectangle2D calculateLocalBounds() {
81 if (p1 == null || p2 == null)
83 Rectangle2D r = new Rectangle2D.Double();
84 r.setFrameFromDiagonal(p1, p2);