1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
208 throw new IllegalArgumentException("negative dash phase");
209 }
210 boolean allzero = true;
211 for (int i = 0; i < dash.length; i++) {
212 float d = dash[i];
213 if (d > 0.0) {
214 allzero = false;
215 } else if (d < 0.0) {
216 throw new IllegalArgumentException("negative dash length");
217 }
218 }
219 if (allzero) {
220 throw new IllegalArgumentException("dash lengths all zero");
221 }
222 }
223 this.width = width;
224 this.cap = cap;
225 this.join = join;
226 this.miterlimit = miterlimit;
227 if (dash != null) {
228 this.dash = (float []) dash.clone();
229 }
230 this.dash_phase = dash_phase;
231 }
232
233 /**
234 * Constructs a solid <code>BasicStroke</code> with the specified
235 * attributes.
236 * @param width the width of the <code>BasicStroke</code>
237 * @param cap the decoration of the ends of a <code>BasicStroke</code>
238 * @param join the decoration applied where path segments meet
239 * @param miterlimit the limit to trim the miter join
240 * @throws IllegalArgumentException if <code>width</code> is negative
241 * @throws IllegalArgumentException if <code>cap</code> is not either
242 * CAP_BUTT, CAP_ROUND or CAP_SQUARE
243 * @throws IllegalArgumentException if <code>miterlimit</code> is less
244 * than 1 and <code>join</code> is JOIN_MITER
245 * @throws IllegalArgumentException if <code>join</code> is not
246 * either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER
247 */
248 public BasicStroke(float width, int cap, int join, float miterlimit) {
342 return miterlimit;
343 }
344
345 /**
346 * Returns the array representing the lengths of the dash segments.
347 * Alternate entries in the array represent the user space lengths
348 * of the opaque and transparent segments of the dashes.
349 * As the pen moves along the outline of the <code>Shape</code>
350 * to be stroked, the user space
351 * distance that the pen travels is accumulated. The distance
352 * value is used to index into the dash array.
353 * The pen is opaque when its current cumulative distance maps
354 * to an even element of the dash array and transparent otherwise.
355 * @return the dash array.
356 */
357 public float[] getDashArray() {
358 if (dash == null) {
359 return null;
360 }
361
362 return (float[]) dash.clone();
363 }
364
365 /**
366 * Returns the current dash phase.
367 * The dash phase is a distance specified in user coordinates that
368 * represents an offset into the dashing pattern. In other words, the dash
369 * phase defines the point in the dashing pattern that will correspond to
370 * the beginning of the stroke.
371 * @return the dash phase as a <code>float</code> value.
372 */
373 public float getDashPhase() {
374 return dash_phase;
375 }
376
377 /**
378 * Returns the hashcode for this stroke.
379 * @return a hash code for this stroke.
380 */
381 public int hashCode() {
382 int hash = Float.floatToIntBits(width);
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
208 throw new IllegalArgumentException("negative dash phase");
209 }
210 boolean allzero = true;
211 for (int i = 0; i < dash.length; i++) {
212 float d = dash[i];
213 if (d > 0.0) {
214 allzero = false;
215 } else if (d < 0.0) {
216 throw new IllegalArgumentException("negative dash length");
217 }
218 }
219 if (allzero) {
220 throw new IllegalArgumentException("dash lengths all zero");
221 }
222 }
223 this.width = width;
224 this.cap = cap;
225 this.join = join;
226 this.miterlimit = miterlimit;
227 if (dash != null) {
228 this.dash = dash.clone();
229 }
230 this.dash_phase = dash_phase;
231 }
232
233 /**
234 * Constructs a solid <code>BasicStroke</code> with the specified
235 * attributes.
236 * @param width the width of the <code>BasicStroke</code>
237 * @param cap the decoration of the ends of a <code>BasicStroke</code>
238 * @param join the decoration applied where path segments meet
239 * @param miterlimit the limit to trim the miter join
240 * @throws IllegalArgumentException if <code>width</code> is negative
241 * @throws IllegalArgumentException if <code>cap</code> is not either
242 * CAP_BUTT, CAP_ROUND or CAP_SQUARE
243 * @throws IllegalArgumentException if <code>miterlimit</code> is less
244 * than 1 and <code>join</code> is JOIN_MITER
245 * @throws IllegalArgumentException if <code>join</code> is not
246 * either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER
247 */
248 public BasicStroke(float width, int cap, int join, float miterlimit) {
342 return miterlimit;
343 }
344
345 /**
346 * Returns the array representing the lengths of the dash segments.
347 * Alternate entries in the array represent the user space lengths
348 * of the opaque and transparent segments of the dashes.
349 * As the pen moves along the outline of the <code>Shape</code>
350 * to be stroked, the user space
351 * distance that the pen travels is accumulated. The distance
352 * value is used to index into the dash array.
353 * The pen is opaque when its current cumulative distance maps
354 * to an even element of the dash array and transparent otherwise.
355 * @return the dash array.
356 */
357 public float[] getDashArray() {
358 if (dash == null) {
359 return null;
360 }
361
362 return dash.clone();
363 }
364
365 /**
366 * Returns the current dash phase.
367 * The dash phase is a distance specified in user coordinates that
368 * represents an offset into the dashing pattern. In other words, the dash
369 * phase defines the point in the dashing pattern that will correspond to
370 * the beginning of the stroke.
371 * @return the dash phase as a <code>float</code> value.
372 */
373 public float getDashPhase() {
374 return dash_phase;
375 }
376
377 /**
378 * Returns the hashcode for this stroke.
379 * @return a hash code for this stroke.
380 */
381 public int hashCode() {
382 int hash = Float.floatToIntBits(width);
|