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