]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/connection/ConnectionVisuals.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / connection / ConnectionVisuals.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.connection;\r
13 \r
14 import java.awt.Color;\r
15 import java.awt.Stroke;\r
16 import java.util.Arrays;\r
17 \r
18 import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;\r
19 \r
20 /**\r
21  * @author Tuukka Lehtonen\r
22  */\r
23 public class ConnectionVisuals {\r
24 \r
25     public final float[] color;\r
26     public final StrokeType strokeType;\r
27     public final Stroke stroke;\r
28 \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
32         this.color = color;\r
33         this.strokeType = strokeType;\r
34         this.stroke = stroke;\r
35     }\r
36 \r
37     public Color toColor() {\r
38         if (color == null)\r
39             return null;\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
43     }\r
44 \r
45     @Override\r
46     public int hashCode() {\r
47         final int prime = 31;\r
48         int result = 1;\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
52         return result;\r
53     }\r
54 \r
55     @Override\r
56     public boolean equals(Object obj) {\r
57         if (this == obj)\r
58             return true;\r
59         if (obj == null)\r
60             return false;\r
61         if (!(obj instanceof ConnectionVisuals))\r
62             return false;\r
63         ConnectionVisuals other = (ConnectionVisuals) obj;\r
64         if (!Arrays.equals(color, other.color))\r
65             return false;\r
66         if (stroke == null) {\r
67             if (other.stroke != null)\r
68                 return false;\r
69         } else if (!stroke.equals(other.stroke))\r
70             return false;\r
71         if (strokeType == null) {\r
72             if (other.strokeType != null)\r
73                 return false;\r
74         } else if (!strokeType.equals(other.strokeType))\r
75             return false;\r
76         return true;\r
77     }\r
78 \r
79 }\r