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 rounding;
30 public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke, Double rounding) {
31 if (color != null && color.length < 3)
32 throw new IllegalArgumentException("colors must have at least 3 components (rgb), got " + color.length);
34 this.strokeType = strokeType;
36 this.rounding = rounding;
39 public Color toColor() {
42 if (color.length == 3)
43 return new Color(color[2], color[1], color[0]);
44 return new Color(color[2], color[1], color[0], color[3]);
48 public int hashCode() {
51 result = prime * result + Arrays.hashCode(color);
52 result = prime * result + ((rounding == null) ? 0 : rounding.hashCode());
53 result = prime * result + ((stroke == null) ? 0 : stroke.hashCode());
54 result = prime * result + ((strokeType == null) ? 0 : strokeType.hashCode());
59 public boolean equals(Object obj) {
64 if (getClass() != obj.getClass())
66 ConnectionVisuals other = (ConnectionVisuals) obj;
67 if (!Arrays.equals(color, other.color))
69 if (rounding == null) {
70 if (other.rounding != null)
72 } else if (!rounding.equals(other.rounding))
75 if (other.stroke != null)
77 } else if (!stroke.equals(other.stroke))
79 if (strokeType != other.strokeType)