]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/connection/ConnectionVisuals.java
802881e1610efa52d787e0670edddb4c291e45de
[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     public final Double branchPointRadius;
29     public final Double rounding;
30
31     public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke, Double rounding) {
32         this(color, strokeType, stroke, null, rounding);
33     }
34
35     public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke, Double branchPointRadius, Double rounding) {
36         if (color != null && color.length < 3)
37             throw new IllegalArgumentException("colors must have at least 3 components (rgb), got " + color.length);
38         this.color = color;
39         this.strokeType = strokeType;
40         this.stroke = stroke;
41         this.branchPointRadius = branchPointRadius;
42         this.rounding = rounding;
43     }
44
45     public Color toColor() {
46         if (color == null)
47             return null;
48         if (color.length == 3)
49             return new Color(color[2], color[1], color[0]);
50         return new Color(color[2], color[1], color[0], color[3]);
51     }
52
53     @Override
54     public int hashCode() {
55         final int prime = 31;
56         int result = 1;
57         result = prime * result + ((branchPointRadius == null) ? 0 : branchPointRadius.hashCode());
58         result = prime * result + Arrays.hashCode(color);
59         result = prime * result + ((rounding == null) ? 0 : rounding.hashCode());
60         result = prime * result + ((stroke == null) ? 0 : stroke.hashCode());
61         result = prime * result + ((strokeType == null) ? 0 : strokeType.hashCode());
62         return result;
63     }
64
65     @Override
66     public boolean equals(Object obj) {
67         if (this == obj)
68             return true;
69         if (obj == null)
70             return false;
71         if (getClass() != obj.getClass())
72             return false;
73         ConnectionVisuals other = (ConnectionVisuals) obj;
74         if (branchPointRadius == null) {
75             if (other.branchPointRadius != null)
76                 return false;
77         } else if (!branchPointRadius.equals(other.branchPointRadius))
78             return false;
79         if (!Arrays.equals(color, other.color))
80             return false;
81         if (rounding == null) {
82             if (other.rounding != null)
83                 return false;
84         } else if (!rounding.equals(other.rounding))
85             return false;
86         if (stroke == null) {
87             if (other.stroke != null)
88                 return false;
89         } else if (!stroke.equals(other.stroke))
90             return false;
91         if (strokeType != other.strokeType)
92             return false;
93         return true;
94     }
95 }