Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / awt / BasicStroke.java
blobb1772548ac2c14125e85157a5a40b7ae2df3f029
1 /* BasicStroke.java --
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)
9 any later version.
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
19 02111-1307 USA.
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
24 combination.
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. */
39 package java.awt;
41 import java.util.Arrays;
43 /**
44 * STUB CLASS ONLY
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;
63 /**
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
76 * its needs.
78 public BasicStroke(float width, int cap, int join, float miterlimit,
79 float[] dash, float dashPhase)
81 if (width < 0.0f )
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
92 + "]");
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)
97 if (dash.length == 0)
98 throw new IllegalArgumentException("dash.length is 0");
99 else
101 boolean allZero = true;
103 for ( int i = 0; i < dash.length; ++i)
105 if (dash[i] != 0.0f)
107 allZero = false;
108 break;
112 if (allZero)
113 throw new IllegalArgumentException("all dashes are 0.0f");
116 this.width = width;
117 this.cap = cap;
118 this.join = join;
119 limit = miterlimit;
120 this.dash = dash == null ? null : (float[]) dash.clone();
121 phase = dashPhase;
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
134 * its needs.
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
149 * its needs.
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.
172 public BasicStroke()
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()
184 return width;
187 public int getEndCap()
189 return cap;
192 public int getLineJoin()
194 return join;
197 public float getMiterLimit()
199 return limit;
202 public float[] getDashArray()
204 return dash;
207 public float getDashPhase()
209 return phase;
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);
222 hash ^= cap;
223 hash ^= join;
224 hash ^= Float.floatToIntBits(limit);
226 if (dash != null)
227 for (int i = 0; i < dash.length; i++)
228 hash ^= Float.floatToIntBits(dash[i]);
230 hash ^= Float.floatToIntBits(phase);
232 return hash;
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
238 * equal.
240 public boolean equals(Object o)
242 if (! (o instanceof BasicStroke))
243 return false;
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