2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import java
.util
.Arrays
;
46 public class BasicStroke
implements Stroke
48 public static final int JOIN_MITER
= 0;
49 public static final int JOIN_ROUND
= 1;
50 public static final int JOIN_BEVEL
= 2;
52 public static final int CAP_BUTT
= 0;
53 public static final int CAP_ROUND
= 1;
54 public static final int CAP_SQUARE
= 2;
56 private final float width
;
57 private final int cap
;
58 private final int join
;
59 private final float limit
;
60 private final float[] dash
;
61 private final float phase
;
64 * Creates a basic stroke.
66 * @param width May not be negative .
67 * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
68 * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
69 * @param miterlimit the limit to trim the miter join. The miterlimit must be
70 * greater than or equal to 1.0f.
71 * @param dash The array representing the dashing pattern. There must be at
72 * least one non-zero entry.
73 * @param dashPhase is negative and dash is not null.
75 * @exception IllegalArgumentException If one input parameter doesn't meet
78 public BasicStroke(float width
, int cap
, int join
, float miterlimit
,
79 float[] dash
, float dashPhase
)
82 throw new IllegalArgumentException("width " + width
+ " < 0");
83 else if (cap
< CAP_BUTT
|| cap
> CAP_SQUARE
)
84 throw new IllegalArgumentException("cap " + cap
+ " out of range ["
85 + CAP_BUTT
+ ".." + CAP_SQUARE
+ "]");
86 else if (miterlimit
< 1.0f
&& join
== JOIN_MITER
)
87 throw new IllegalArgumentException("miterlimit " + miterlimit
88 + " < 1.0f while join == JOIN_MITER");
89 else if (join
< JOIN_MITER
|| join
> JOIN_BEVEL
)
90 throw new IllegalArgumentException("join " + join
+ " out of range ["
91 + JOIN_MITER
+ ".." + JOIN_BEVEL
93 else if (dashPhase
< 0.0f
&& dash
!= null)
94 throw new IllegalArgumentException("dashPhase " + dashPhase
95 + " < 0.0f while dash != null");
96 else if (dash
!= null)
98 throw new IllegalArgumentException("dash.length is 0");
101 boolean allZero
= true;
103 for ( int i
= 0; i
< dash
.length
; ++i
)
113 throw new IllegalArgumentException("all dashes are 0.0f");
120 this.dash
= dash
== null ?
null : (float[]) dash
.clone();
125 * Creates a basic stroke.
127 * @param width The width of the BasicStroke. May not be negative .
128 * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
129 * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
130 * @param miterlimit the limit to trim the miter join. The miterlimit must be
131 * greater than or equal to 1.0f.
133 * @exception IllegalArgumentException If one input parameter doesn't meet
136 public BasicStroke(float width
, int cap
, int join
, float miterlimit
)
138 this(width
, cap
, join
, miterlimit
, null, 0);
142 * Creates a basic stroke.
144 * @param width The width of the BasicStroke. May not be nehative.
145 * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
146 * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
148 * @exception IllegalArgumentException If one input parameter doesn't meet
150 * @exception IllegalArgumentException FIXME
152 public BasicStroke(float width
, int cap
, int join
)
154 this(width
, cap
, join
, 10, null, 0);
158 * Creates a basic stroke.
160 * @param width The width of the BasicStroke.
162 * @exception IllegalArgumentException If width is negative.
164 public BasicStroke(float width
)
166 this(width
, CAP_SQUARE
, JOIN_MITER
, 10, null, 0);
170 * Creates a basic stroke.
174 this(1, CAP_SQUARE
, JOIN_MITER
, 10, null, 0);
177 public Shape
createStrokedShape(Shape s
)
179 throw new Error("not implemented");
182 public float getLineWidth()
187 public int getEndCap()
192 public int getLineJoin()
197 public float getMiterLimit()
202 public float[] getDashArray()
207 public float getDashPhase()
213 * Returns the hash code for this object. The hash is calculated by
214 * xoring the hash, cap, join, limit, dash array and phase values
215 * (converted to <code>int</code> first with
216 * <code>Float.floatToIntBits()</code> if the value is a
217 * <code>float</code>).
219 public int hashCode()
221 int hash
= Float
.floatToIntBits(width
);
224 hash ^
= Float
.floatToIntBits(limit
);
227 for (int i
= 0; i
< dash
.length
; i
++)
228 hash ^
= Float
.floatToIntBits(dash
[i
]);
230 hash ^
= Float
.floatToIntBits(phase
);
236 * Returns true if the given Object is an instance of BasicStroke
237 * and the width, cap, join, limit, dash array and phase are all
240 public boolean equals(Object o
)
242 if (! (o
instanceof BasicStroke
))
244 BasicStroke s
= (BasicStroke
) o
;
245 return width
== s
.width
&& cap
== s
.cap
&& join
== s
.join
246 && limit
== s
.limit
&& Arrays
.equals(dash
, s
.dash
) && phase
== s
.phase
;
248 } // class BasicStroke