1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
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/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.graphics;
16 import org.eclipse.swt.*;
19 * <code>LineAttributes</code> defines a set of line attributes that
20 * can be modified in a GC.
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.
27 * @see GC#getLineAttributes()
28 * @see GC#setLineAttributes(LineAttributes)
29 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
33 public class LineAttributes {
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
55 * @see org.eclipse.swt.SWT#CAP_FLAT
56 * @see org.eclipse.swt.SWT#CAP_ROUND
57 * @see org.eclipse.swt.SWT#CAP_SQUARE
62 * The line join style.
64 * @see org.eclipse.swt.SWT#JOIN_BEVEL
65 * @see org.eclipse.swt.SWT#JOIN_MITER
66 * @see org.eclipse.swt.SWT#JOIN_ROUND
71 * The line dash style for SWT.LINE_CUSTOM.
76 * The line dash style offset for SWT.LINE_CUSTOM.
78 public float dashOffset;
81 * The line miter limit.
83 public float miterLimit;
86 * Create a new line attributes with the specified line width.
88 * @param width the line width
90 public LineAttributes(float width) {
91 this(width, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_SOLID, null, 0, 10);
95 * Create a new line attributes with the specified line cap, join and width.
97 * @param width the line width
98 * @param cap the line cap style
99 * @param join the line join style
101 public LineAttributes(float width, int cap, int join) {
102 this(width, cap, join, SWT.LINE_SOLID, null, 0, 10);
106 * Create a new line attributes with the specified arguments.
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
116 public LineAttributes(float width, int cap, int join, int style, float[] dash, float dashOffset, float miterLimit) {
122 this.dashOffset = dashOffset;
123 this.miterLimit = miterLimit;
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.
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
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;
153 if (p.dash != null || dash != null) return false;
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
164 * @return the receiver's hash
166 * @see #equals(Object)
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);
177 for (int i = 0; i < dash.length; i++) {
178 hashCode = 31 * hashCode + Float.floatToIntBits(dash[i]);