1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\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;
\r
14 import java.awt.Color;
\r
15 import java.awt.Stroke;
\r
16 import java.util.Arrays;
\r
18 import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;
\r
21 * @author Tuukka Lehtonen
\r
23 public class ConnectionVisuals {
\r
25 public final float[] color;
\r
26 public final StrokeType strokeType;
\r
27 public final Stroke stroke;
\r
29 public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke) {
\r
30 if (color != null && color.length < 3)
\r
31 throw new IllegalArgumentException("colors must have at least 3 components (rgb), got " + color.length);
\r
33 this.strokeType = strokeType;
\r
34 this.stroke = stroke;
\r
37 public Color toColor() {
\r
40 if (color.length == 3)
\r
41 return new Color(color[2], color[1], color[0]);
\r
42 return new Color(color[2], color[1], color[0], color[3]);
\r
46 public int hashCode() {
\r
47 final int prime = 31;
\r
49 result = prime * result + Arrays.hashCode(color);
\r
50 result = prime * result + ((stroke == null) ? 0 : stroke.hashCode());
\r
51 result = prime * result + ((strokeType == null) ? 0 : strokeType.hashCode());
\r
56 public boolean equals(Object obj) {
\r
61 if (!(obj instanceof ConnectionVisuals))
\r
63 ConnectionVisuals other = (ConnectionVisuals) obj;
\r
64 if (!Arrays.equals(color, other.color))
\r
66 if (stroke == null) {
\r
67 if (other.stroke != null)
\r
69 } else if (!stroke.equals(other.stroke))
\r
71 if (strokeType == null) {
\r
72 if (other.strokeType != null)
\r
74 } else if (!strokeType.equals(other.strokeType))
\r