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