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