]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/graphics/LineAttributes.java
43586cb8bc15a2f92135cbf08fa48c4b02a39ca5
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / graphics / LineAttributes.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.graphics;
15
16 import org.eclipse.swt.*;
17
18 /**
19  * <code>LineAttributes</code> defines a set of line attributes that
20  * can be modified in a GC.
21  * <p>
22  * Application code does <em>not</em> need to explicitly release the
23  * resources managed by each instance when those instances are no longer
24  * required, and thus no <code>dispose()</code> method is provided.
25  * </p>
26  *
27  * @see GC#getLineAttributes()
28  * @see GC#setLineAttributes(LineAttributes)
29  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
30  *
31  * @since 3.3
32  */
33 public class LineAttributes {
34
35         /**
36          * The line width.
37          */
38         public float width;
39
40         /**
41          * The line style.
42          *
43          * @see org.eclipse.swt.SWT#LINE_CUSTOM
44          * @see org.eclipse.swt.SWT#LINE_DASH
45          * @see org.eclipse.swt.SWT#LINE_DASHDOT
46          * @see org.eclipse.swt.SWT#LINE_DASHDOTDOT
47          * @see org.eclipse.swt.SWT#LINE_DOT
48          * @see org.eclipse.swt.SWT#LINE_SOLID
49          */
50         public int style;
51
52         /**
53          * The line cap style.
54          *
55          * @see org.eclipse.swt.SWT#CAP_FLAT
56          * @see org.eclipse.swt.SWT#CAP_ROUND
57          * @see org.eclipse.swt.SWT#CAP_SQUARE
58          */
59         public int cap;
60
61         /**
62          * The line join style.
63          *
64          * @see org.eclipse.swt.SWT#JOIN_BEVEL
65          * @see org.eclipse.swt.SWT#JOIN_MITER
66          * @see org.eclipse.swt.SWT#JOIN_ROUND
67          */
68         public int join;
69
70         /**
71          * The line dash style for SWT.LINE_CUSTOM.
72          */
73         public float[] dash;
74
75         /**
76          * The line dash style offset for SWT.LINE_CUSTOM.
77          */
78         public float dashOffset;
79
80         /**
81          * The line miter limit.
82          */
83         public float miterLimit;
84
85 /**
86  * Create a new line attributes with the specified line width.
87  *
88  * @param width the line width
89  */
90 public LineAttributes(float width) {
91         this(width, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_SOLID, null, 0, 10);
92 }
93
94 /**
95  * Create a new line attributes with the specified line cap, join and width.
96  *
97  * @param width the line width
98  * @param cap the line cap style
99  * @param join the line join style
100  */
101 public LineAttributes(float width, int cap, int join) {
102         this(width, cap, join, SWT.LINE_SOLID, null, 0, 10);
103 }
104
105 /**
106  * Create a new line attributes with the specified arguments.
107  *
108  * @param width the line width
109  * @param cap the line cap style
110  * @param join the line join style
111  * @param style the line style
112  * @param dash the line dash style
113  * @param dashOffset the line dash style offset
114  * @param miterLimit the line miter limit
115  */
116 public LineAttributes(float width, int cap, int join, int style, float[] dash, float dashOffset, float miterLimit) {
117         this.width = width;
118         this.cap = cap;
119         this.join = join;
120         this.style = style;
121         this.dash = dash;
122         this.dashOffset = dashOffset;
123         this.miterLimit = miterLimit;
124 }
125
126 /**
127  * Compares the argument to the receiver, and returns true
128  * if they represent the <em>same</em> object using a class
129  * specific comparison.
130  *
131  * @param object the object to compare with this object
132  * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
133  *
134  * @see #hashCode()
135  */
136 @Override
137 public boolean equals (Object object) {
138         if (object == this) return true;
139         if (!(object instanceof LineAttributes)) return false;
140         LineAttributes p = (LineAttributes)object;
141         if (p.width != width) return false;
142         if (p.cap != cap) return false;
143         if (p.join != join) return false;
144         if (p.style != style) return false;
145         if (p.dashOffset != dashOffset) return false;
146         if (p.miterLimit != miterLimit) return false;
147         if (p.dash != null && dash != null) {
148                 if (p.dash.length != dash.length) return false;
149                 for (int i = 0; i < dash.length; i++) {
150                         if (p.dash[i] != dash[i]) return false;
151                 }
152         } else {
153                 if (p.dash != null || dash != null) return false;
154         }
155         return true;
156 }
157
158 /**
159  * Returns an integer hash code for the receiver. Any two
160  * objects that return <code>true</code> when passed to
161  * <code>equals</code> must return the same value for this
162  * method.
163  *
164  * @return the receiver's hash
165  *
166  * @see #equals(Object)
167  */
168 @Override
169 public int hashCode () {
170         int hashCode = Float.floatToIntBits(width);
171         hashCode = 31 * hashCode + cap;
172         hashCode = 31 * hashCode + join;
173         hashCode = 31 * hashCode + style;
174         hashCode = 31 * hashCode + Float.floatToIntBits(dashOffset);
175         hashCode = 31 * hashCode + Float.floatToIntBits(miterLimit);
176         if (dash != null) {
177                 for (int i = 0; i < dash.length; i++) {
178                         hashCode = 31 * hashCode + Float.floatToIntBits(dash[i]);
179                 }
180         }
181         return hashCode;
182 }
183
184 }