KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > pdf > PdfPatternPainter


1 /*
2  * The contents of this file are subject to the Mozilla Public License Version 1.1
3  * (the "License"); you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5  *
6  * Software distributed under the License is distributed on an "AS IS" basis,
7  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8  * for the specific language governing rights and limitations under the License.
9  *
10  * The Original Code is 'iText, a free JAVA-PDF library'.
11  *
12  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
13  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
14  * All Rights Reserved.
15  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
16  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
17  *
18  * Contributor(s): all the names of the contributors are added in the source code
19  * where applicable.
20  *
21  * Alternatively, the contents of this file may be used under the terms of the
22  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
23  * provisions of LGPL are applicable instead of those above. If you wish to
24  * allow use of your version of this file only under the terms of the LGPL
25  * License and not to allow others to use your version of this file under
26  * the MPL, indicate your decision by deleting the provisions above and
27  * replace them with the notice and other provisions required by the LGPL.
28  * If you do not delete the provisions above, a recipient may use your version
29  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
30  *
31  * This library is free software; you can redistribute it and/or modify it
32  * under the terms of the MPL as stated above or under the terms of the GNU
33  * Library General Public License as published by the Free Software Foundation;
34  * either version 2 of the License, or any later version.
35  *
36  * This library is distributed in the hope that it will be useful, but WITHOUT
37  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
38  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
39  * details.
40  *
41  * If you didn't download this code from the following link, you should check if
42  * you aren't using an obsolete version:
43  * http://www.lowagie.com/iText/
44  */

45 package com.lowagie.text.pdf;
46
47 import java.awt.Color JavaDoc;
48
49 import com.lowagie.text.DocumentException;
50 import com.lowagie.text.Image;
51 import com.lowagie.text.Rectangle;
52
53 /**
54  * Implements the pattern.
55  */

56
57 public class PdfPatternPainter extends PdfTemplate {
58     
59     protected float xstep, ystep;
60     protected boolean stencil = false;
61     protected Color JavaDoc defaultColor;
62     
63     /**
64      *Creates a <CODE>PdfPattern</CODE>.
65      */

66     
67     private PdfPatternPainter() {
68         super();
69         type = TYPE_PATTERN;
70     }
71     
72     /**
73      * Creates new PdfPattern
74      *
75      * @param wr the <CODE>PdfWriter</CODE>
76      */

77     
78     PdfPatternPainter(PdfWriter wr) {
79         super(wr);
80         type = TYPE_PATTERN;
81     }
82     
83     PdfPatternPainter(PdfWriter wr, Color JavaDoc defaultColor) {
84         this(wr);
85         stencil = true;
86         if (defaultColor == null)
87             this.defaultColor = Color.gray;
88         else
89             this.defaultColor = defaultColor;
90     }
91     
92     /**
93      * Sets the horizontal interval of this pattern.
94      *
95      * @param xstep the xstep in horizontal painting
96      */

97     
98     public void setXStep(float xstep) {
99         this.xstep = xstep;
100     }
101     
102     /**
103      * Sets the vertical interval of this pattern.
104      *
105      * @param ystep in vertical painting
106      */

107     
108     public void setYStep(float ystep) {
109         this.ystep = ystep;
110     }
111     
112     /**
113      * Returns the horizontal interval when repeating the pattern.
114      * @return a value
115      */

116     public float getXStep() {
117         return this.xstep;
118     }
119     
120     /**
121      * Returns the vertical interval when repeating the pattern.
122      * @return a value
123      */

124     public float getYStep() {
125         return this.ystep;
126     }
127     
128     /**
129      * Tells you if this pattern is colored/uncolored (stencil = uncolored, you need to set a default color).
130      * @return true if the pattern is an uncolored tiling pattern (stencil).
131      */

132     public boolean isStencil() {
133         return stencil;
134     }
135     
136     /**
137      * Sets the transformation matrix for the pattern.
138      * @param a
139      * @param b
140      * @param c
141      * @param d
142      * @param e
143      * @param f
144      */

145     public void setPatternMatrix(float a, float b, float c, float d, float e, float f) {
146         setMatrix(a, b, c, d, e, f);
147     }
148     /**
149      * Gets the stream representing this pattern
150      *
151      * @return the stream representing this pattern
152      */

153     
154     PdfPattern getPattern() {
155         return new PdfPattern(this);
156     }
157     
158     /**
159      * Gets a duplicate of this <CODE>PdfPatternPainter</CODE>. All
160      * the members are copied by reference but the buffer stays different.
161      * @return a copy of this <CODE>PdfPatternPainter</CODE>
162      */

163     
164     public PdfContentByte getDuplicate() {
165         PdfPatternPainter tpl = new PdfPatternPainter();
166         tpl.writer = writer;
167         tpl.pdf = pdf;
168         tpl.thisReference = thisReference;
169         tpl.pageResources = pageResources;
170         tpl.bBox = new Rectangle(bBox);
171         tpl.xstep = xstep;
172         tpl.ystep = ystep;
173         tpl.matrix = matrix;
174         tpl.stencil = stencil;
175         tpl.defaultColor = defaultColor;
176         return tpl;
177     }
178     
179     /**
180      * Returns the default color of the pattern.
181      * @return a Color
182      */

183     public Color JavaDoc getDefaultColor() {
184         return defaultColor;
185     }
186     
187     /**
188      * @see com.lowagie.text.pdf.PdfContentByte#setGrayFill(float)
189      */

190     public void setGrayFill(float gray) {
191         checkNoColor();
192         super.setGrayFill(gray);
193     }
194     
195     /**
196      * @see com.lowagie.text.pdf.PdfContentByte#resetGrayFill()
197      */

198     public void resetGrayFill() {
199         checkNoColor();
200         super.resetGrayFill();
201     }
202     
203     /**
204      * @see com.lowagie.text.pdf.PdfContentByte#setGrayStroke(float)
205      */

206     public void setGrayStroke(float gray) {
207         checkNoColor();
208         super.setGrayStroke(gray);
209     }
210     
211     /**
212      * @see com.lowagie.text.pdf.PdfContentByte#resetGrayStroke()
213      */

214     public void resetGrayStroke() {
215         checkNoColor();
216         super.resetGrayStroke();
217     }
218     
219     /**
220      * @see com.lowagie.text.pdf.PdfContentByte#setRGBColorFillF(float, float, float)
221      */

222     public void setRGBColorFillF(float red, float green, float blue) {
223         checkNoColor();
224         super.setRGBColorFillF(red, green, blue);
225     }
226     
227     /**
228      * @see com.lowagie.text.pdf.PdfContentByte#resetRGBColorFill()
229      */

230     public void resetRGBColorFill() {
231         checkNoColor();
232         super.resetRGBColorFill();
233     }
234     
235     /**
236      * @see com.lowagie.text.pdf.PdfContentByte#setRGBColorStrokeF(float, float, float)
237      */

238     public void setRGBColorStrokeF(float red, float green, float blue) {
239         checkNoColor();
240         super.setRGBColorStrokeF(red, green, blue);
241     }
242     
243     /**
244      * @see com.lowagie.text.pdf.PdfContentByte#resetRGBColorStroke()
245      */

246     public void resetRGBColorStroke() {
247         checkNoColor();
248         super.resetRGBColorStroke();
249     }
250     
251     /**
252      * @see com.lowagie.text.pdf.PdfContentByte#setCMYKColorFillF(float, float, float, float)
253      */

254     public void setCMYKColorFillF(float cyan, float magenta, float yellow, float black) {
255         checkNoColor();
256         super.setCMYKColorFillF(cyan, magenta, yellow, black);
257     }
258     
259     /**
260      * @see com.lowagie.text.pdf.PdfContentByte#resetCMYKColorFill()
261      */

262     public void resetCMYKColorFill() {
263         checkNoColor();
264         super.resetCMYKColorFill();
265     }
266     
267     /**
268      * @see com.lowagie.text.pdf.PdfContentByte#setCMYKColorStrokeF(float, float, float, float)
269      */

270     public void setCMYKColorStrokeF(float cyan, float magenta, float yellow, float black) {
271         checkNoColor();
272         super.setCMYKColorStrokeF(cyan, magenta, yellow, black);
273     }
274     
275     /**
276      * @see com.lowagie.text.pdf.PdfContentByte#resetCMYKColorStroke()
277      */

278     public void resetCMYKColorStroke() {
279         checkNoColor();
280         super.resetCMYKColorStroke();
281     }
282     
283     /**
284      * @see com.lowagie.text.pdf.PdfContentByte#addImage(com.lowagie.text.Image, float, float, float, float, float, float)
285      */

286     public void addImage(Image image, float a, float b, float c, float d, float e, float f) throws DocumentException {
287         if (stencil && !image.isMask())
288             checkNoColor();
289         super.addImage(image, a, b, c, d, e, f);
290     }
291     
292     /**
293      * @see com.lowagie.text.pdf.PdfContentByte#setCMYKColorFill(int, int, int, int)
294      */

295     public void setCMYKColorFill(int cyan, int magenta, int yellow, int black) {
296         checkNoColor();
297         super.setCMYKColorFill(cyan, magenta, yellow, black);
298     }
299     
300     /**
301      * @see com.lowagie.text.pdf.PdfContentByte#setCMYKColorStroke(int, int, int, int)
302      */

303     public void setCMYKColorStroke(int cyan, int magenta, int yellow, int black) {
304         checkNoColor();
305         super.setCMYKColorStroke(cyan, magenta, yellow, black);
306     }
307     
308     /**
309      * @see com.lowagie.text.pdf.PdfContentByte#setRGBColorFill(int, int, int)
310      */

311     public void setRGBColorFill(int red, int green, int blue) {
312         checkNoColor();
313         super.setRGBColorFill(red, green, blue);
314     }
315     
316     /**
317      * @see com.lowagie.text.pdf.PdfContentByte#setRGBColorStroke(int, int, int)
318      */

319     public void setRGBColorStroke(int red, int green, int blue) {
320         checkNoColor();
321         super.setRGBColorStroke(red, green, blue);
322     }
323     
324     /**
325      * @see com.lowagie.text.pdf.PdfContentByte#setColorStroke(java.awt.Color)
326      */

327     public void setColorStroke(Color JavaDoc color) {
328         checkNoColor();
329         super.setColorStroke(color);
330     }
331     
332     /**
333      * @see com.lowagie.text.pdf.PdfContentByte#setColorFill(java.awt.Color)
334      */

335     public void setColorFill(Color JavaDoc color) {
336         checkNoColor();
337         super.setColorFill(color);
338     }
339     
340     /**
341      * @see com.lowagie.text.pdf.PdfContentByte#setColorFill(com.lowagie.text.pdf.PdfSpotColor, float)
342      */

343     public void setColorFill(PdfSpotColor sp, float tint) {
344         checkNoColor();
345         super.setColorFill(sp, tint);
346     }
347     
348     /**
349      * @see com.lowagie.text.pdf.PdfContentByte#setColorStroke(com.lowagie.text.pdf.PdfSpotColor, float)
350      */

351     public void setColorStroke(PdfSpotColor sp, float tint) {
352         checkNoColor();
353         super.setColorStroke(sp, tint);
354     }
355     
356     /**
357      * @see com.lowagie.text.pdf.PdfContentByte#setPatternFill(com.lowagie.text.pdf.PdfPatternPainter)
358      */

359     public void setPatternFill(PdfPatternPainter p) {
360         checkNoColor();
361         super.setPatternFill(p);
362     }
363     
364     /**
365      * @see com.lowagie.text.pdf.PdfContentByte#setPatternFill(com.lowagie.text.pdf.PdfPatternPainter, java.awt.Color, float)
366      */

367     public void setPatternFill(PdfPatternPainter p, Color JavaDoc color, float tint) {
368         checkNoColor();
369         super.setPatternFill(p, color, tint);
370     }
371     
372     /**
373      * @see com.lowagie.text.pdf.PdfContentByte#setPatternStroke(com.lowagie.text.pdf.PdfPatternPainter, java.awt.Color, float)
374      */

375     public void setPatternStroke(PdfPatternPainter p, Color JavaDoc color, float tint) {
376         checkNoColor();
377         super.setPatternStroke(p, color, tint);
378     }
379     
380     /**
381      * @see com.lowagie.text.pdf.PdfContentByte#setPatternStroke(com.lowagie.text.pdf.PdfPatternPainter)
382      */

383     public void setPatternStroke(PdfPatternPainter p) {
384         checkNoColor();
385         super.setPatternStroke(p);
386     }
387     
388     void checkNoColor() {
389         if (stencil)
390             throw new RuntimeException JavaDoc("Colors are not allowed in uncolored tile patterns.");
391     }
392 }
393
Popular Tags