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;
29 public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke) {
30 if (color != null && color.length < 3)
31 throw new IllegalArgumentException("colors must have at least 3 components (rgb), got " + color.length);
33 this.strokeType = strokeType;
37 public Color toColor() {
40 if (color.length == 3)
41 return new Color(color[2], color[1], color[0]);
42 return new Color(color[2], color[1], color[0], color[3]);
46 public int hashCode() {
49 result = prime * result + Arrays.hashCode(color);
50 result = prime * result + ((stroke == null) ? 0 : stroke.hashCode());
51 result = prime * result + ((strokeType == null) ? 0 : strokeType.hashCode());
56 public boolean equals(Object obj) {
61 if (!(obj instanceof ConnectionVisuals))
63 ConnectionVisuals other = (ConnectionVisuals) obj;
64 if (!Arrays.equals(color, other.color))
67 if (other.stroke != null)
69 } else if (!stroke.equals(other.stroke))
71 if (strokeType == null) {
72 if (other.strokeType != null)
74 } else if (!strokeType.equals(other.strokeType))