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