2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / BasicStroke.java
blob2978c6401d71466f2867e9ad8361ac0793ccab9e
1 /* BasicStroke.java --
2 Copyright (C) 2002, 2003 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;
51 public static final int CAP_BUTT = 0;
52 public static final int CAP_ROUND = 1;
53 public static final int CAP_SQUARE = 2;
55 private final float width;
56 private final int cap;
57 private final int join;
58 private final float limit;
59 private final float[] dash;
60 private final float phase;
62 /**
63 * Creates a basic stroke.
65 * @param width May not be negative .
66 * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
67 * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
68 * @param miterlimit the limit to trim the miter join. The miterlimit must be
69 * greater than or equal to 1.0f.
70 * @param dash The array representing the dashing pattern. There must be at
71 * least one non-zero entry.
72 * @param dash_phase is negative and dash is not null.
74 * @exception IllegalArgumentException If one input parameter doesn't meet
75 * its needs.
77 public BasicStroke(float width, int cap, int join, float miterlimit,
78 float[] dash, float dashPhase)
80 if (width < 0.0f )
81 throw new IllegalArgumentException("width " + width + " < 0");
82 else if (cap < CAP_BUTT || cap > CAP_SQUARE)
83 throw new IllegalArgumentException("cap " + cap + " out of range ["
84 + CAP_BUTT + ".." + CAP_SQUARE + "]");
85 else if (miterlimit < 1.0f && join == JOIN_MITER)
86 throw new IllegalArgumentException("miterlimit " + miterlimit
87 + " < 1.0f while join == JOIN_MITER");
88 else if (join < JOIN_MITER || join > JOIN_BEVEL)
89 throw new IllegalArgumentException("join " + join + " out of range ["
90 + JOIN_MITER + ".." + JOIN_BEVEL
91 + "]");
92 else if (dashPhase < 0.0f && dash != null)
93 throw new IllegalArgumentException("dashPhase " + dashPhase
94 + " < 0.0f while dash != null");
95 else if (dash != null)
96 if (dash.length == 0)
97 throw new IllegalArgumentException("dash.length is 0");
98 else
100 boolean allZero = true;
102 for ( int i = 0; i < dash.length; ++i)
104 if (dash[i] != 0.0f)
106 allZero = false;
107 break;
111 if (allZero)
112 throw new IllegalArgumentException("all dashes are 0.0f");
115 this.width = width;
116 this.cap = cap;
117 this.join = join;
118 limit = miterlimit;
119 this.dash = dash == null ? null : (float[]) dash.clone();
120 phase = dashPhase;
124 * Creates a basic stroke.
126 * @param width The width of the BasicStroke. May not be negative .
127 * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
128 * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
129 * @param miterlimit the limit to trim the miter join. The miterlimit must be
130 * greater than or equal to 1.0f.
132 * @exception IllegalArgumentException If one input parameter doesn't meet
133 * its needs.
135 public BasicStroke(float width, int cap, int join, float miterlimit)
137 this(width, cap, join, miterlimit, null, 0);
141 * Creates a basic stroke.
143 * @param width The width of the BasicStroke. May not be nehative.
144 * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
145 * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
147 * @exception IllegalArgumentException If one input parameter doesn't meet
148 * its needs.
149 * @exception IllegalArgumentException FIXME
151 public BasicStroke(float width, int cap, int join)
153 this(width, cap, join, 10, null, 0);
157 * Creates a basic stroke.
159 * @param width The width of the BasicStroke.
161 * @exception IllegalArgumentException If width is negative.
163 public BasicStroke(float width)
165 this(width, CAP_SQUARE, JOIN_MITER, 10, null, 0);
169 * Creates a basic stroke.
171 public BasicStroke()
173 this(1, CAP_SQUARE, JOIN_MITER, 10, null, 0);
176 public Shape createStrokedShape(Shape s)
178 throw new Error("not implemented");
181 public float getLineWidth()
183 return width;
186 public int getEndCap()
188 return cap;
191 public int getLineJoin()
193 return join;
196 public float getMiterLimit()
198 return limit;
201 public float[] getDashArray()
203 return dash;
206 public float getDashPhase()
208 return phase;
211 public int hashCode()
213 throw new Error("not implemented");
216 public boolean equals(Object o)
218 if (! (o instanceof BasicStroke))
219 return false;
220 BasicStroke s = (BasicStroke) o;
221 return width == s.width && cap == s.cap && join == s.join
222 && limit == s.limit && Arrays.equals(dash, s.dash) && phase == s.phase;
224 } // class BasicStroke