1 /*******************************************************************************
\r
2 * Copyright (c) 2011 Association for Decentralized Information Management in
\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.connection.rendering;
\r
14 import java.awt.Color;
\r
15 import java.awt.Graphics2D;
\r
16 import java.awt.Stroke;
\r
17 import java.awt.geom.Ellipse2D;
\r
18 import java.awt.geom.Line2D;
\r
19 import java.awt.geom.Path2D;
\r
20 import java.io.Serializable;
\r
23 * @author Tuukka Lehtonen
\r
25 public class BasicConnectionStyle implements ConnectionStyle, Serializable {
\r
27 private static final long serialVersionUID = -5799681720482456895L;
\r
29 // line thickness in millimeters.
\r
30 final Color lineColor;
\r
31 final Color branchPointColor;
\r
32 final double branchPointRadius;
\r
33 final Stroke lineStroke;
\r
34 final Stroke routeLineStroke;
\r
35 final double degenerateLineLength;
\r
37 transient Line2D line = new Line2D.Double();
\r
38 transient Ellipse2D ellipse = new Ellipse2D.Double();
\r
40 public BasicConnectionStyle(Color lineColor, Color branchPointColor, double branchPointRadius, Stroke lineStroke, Stroke routeLineStroke, double degenerateLineLength) {
\r
41 this.lineColor = lineColor;
\r
42 this.branchPointColor = branchPointColor;
\r
43 this.branchPointRadius = branchPointRadius;
\r
44 this.lineStroke = lineStroke;
\r
45 this.routeLineStroke = routeLineStroke;
\r
46 this.degenerateLineLength = degenerateLineLength;
\r
49 public Color getLineColor() {
\r
53 public Color getBranchPointColor() {
\r
54 return branchPointColor;
\r
57 public double getBranchPointRadius() {
\r
58 return branchPointRadius;
\r
61 public Stroke getLineStroke() {
\r
65 public Stroke getRouteLineStroke() {
\r
66 return routeLineStroke;
\r
70 public void drawLine(Graphics2D g, double x1, double y1, double x2,
\r
71 double y2, boolean isTransient) {
\r
72 if (lineColor != null)
\r
73 g.setColor(lineColor);
\r
75 g.setStroke(lineStroke);
\r
76 line.setLine(x1, y1, x2, y2);
\r
79 g.setStroke(routeLineStroke);
\r
80 line.setLine(x1, y1, x2, y2);
\r
86 public void drawPath(Graphics2D g, Path2D path, boolean isTransient) {
\r
87 if (lineColor != null)
\r
88 g.setColor(lineColor);
\r
89 if (lineStroke != null)
\r
90 g.setStroke(lineStroke);
\r
95 public void drawBranchPoint(Graphics2D g, double x, double y) {
\r
96 g.setColor(branchPointColor);
\r
97 double r = branchPointRadius;
\r
99 ellipse.setFrame(x-r, y-r, d, d);
\r
104 public void drawDegeneratedLine(Graphics2D g, double x, double y,
\r
105 boolean isHorizontal, boolean isTransient) {
\r
106 double d = getDegeneratedLineLength()*0.5;
\r
108 line.setLine(x-d, y, x+d, y);
\r
111 line.setLine(x, y-d, x, y+d);
\r
117 public double getDegeneratedLineLength() {
\r
118 return degenerateLineLength;
\r
122 public int hashCode() {
\r
123 final int prime = 31;
\r
125 result = prime * result + ((branchPointColor == null) ? 0 : branchPointColor.hashCode());
\r
127 temp = Double.doubleToLongBits(branchPointRadius);
\r
128 result = prime * result + (int) (temp ^ (temp >>> 32));
\r
129 temp = Double.doubleToLongBits(degenerateLineLength);
\r
130 result = prime * result + (int) (temp ^ (temp >>> 32));
\r
131 result = prime * result + ((lineColor == null) ? 0 : lineColor.hashCode());
\r
132 result = prime * result + ((lineStroke == null) ? 0 : lineStroke.hashCode());
\r
133 result = prime * result + ((routeLineStroke == null) ? 0 : routeLineStroke.hashCode());
\r
138 public boolean equals(Object obj) {
\r
143 if (getClass() != obj.getClass())
\r
145 BasicConnectionStyle other = (BasicConnectionStyle) obj;
\r
146 if (branchPointColor == null) {
\r
147 if (other.branchPointColor != null)
\r
149 } else if (!branchPointColor.equals(other.branchPointColor))
\r
151 if (Double.doubleToLongBits(branchPointRadius) != Double.doubleToLongBits(other.branchPointRadius))
\r
153 if (Double.doubleToLongBits(degenerateLineLength) != Double.doubleToLongBits(other.degenerateLineLength))
\r
155 if (lineColor == null) {
\r
156 if (other.lineColor != null)
\r
158 } else if (!lineColor.equals(other.lineColor))
\r
160 if (lineStroke == null) {
\r
161 if (other.lineStroke != null)
\r
163 } else if (!lineStroke.equals(other.lineStroke))
\r
165 if (routeLineStroke == null) {
\r
166 if (other.routeLineStroke != null)
\r
168 } else if (!routeLineStroke.equals(other.routeLineStroke))
\r