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.connection;
14 import java.awt.Color;
15 import java.awt.Stroke;
16 import java.util.Arrays;
18 import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;
21 * @author Tuukka Lehtonen
23 public class ConnectionVisuals {
25 public final float[] color;
26 public final StrokeType strokeType;
27 public final Stroke stroke;
28 public final Double branchPointRadius;
29 public final Double rounding;
31 public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke, Double rounding) {
32 this(color, strokeType, stroke, null, rounding);
35 public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke, Double branchPointRadius, Double rounding) {
36 if (color != null && color.length < 3)
37 throw new IllegalArgumentException("colors must have at least 3 components (rgb), got " + color.length);
39 this.strokeType = strokeType;
41 this.branchPointRadius = branchPointRadius;
42 this.rounding = rounding;
45 public Color toColor() {
48 if (color.length == 3)
49 return new Color(color[2], color[1], color[0]);
50 return new Color(color[2], color[1], color[0], color[3]);
54 public int hashCode() {
57 result = prime * result + ((branchPointRadius == null) ? 0 : branchPointRadius.hashCode());
58 result = prime * result + Arrays.hashCode(color);
59 result = prime * result + ((rounding == null) ? 0 : rounding.hashCode());
60 result = prime * result + ((stroke == null) ? 0 : stroke.hashCode());
61 result = prime * result + ((strokeType == null) ? 0 : strokeType.hashCode());
66 public boolean equals(Object obj) {
71 if (getClass() != obj.getClass())
73 ConnectionVisuals other = (ConnectionVisuals) obj;
74 if (branchPointRadius == null) {
75 if (other.branchPointRadius != null)
77 } else if (!branchPointRadius.equals(other.branchPointRadius))
79 if (!Arrays.equals(color, other.color))
81 if (rounding == null) {
82 if (other.rounding != null)
84 } else if (!rounding.equals(other.rounding))
87 if (other.stroke != null)
89 } else if (!stroke.equals(other.stroke))
91 if (strokeType != other.strokeType)