KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > g2d > DefaultGraphics2D


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.g2d;
19
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Font JavaDoc;
23 import java.awt.FontMetrics JavaDoc;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.Graphics2D JavaDoc;
26 import java.awt.GraphicsConfiguration JavaDoc;
27 import java.awt.Image JavaDoc;
28 import java.awt.Shape JavaDoc;
29 import java.awt.geom.AffineTransform JavaDoc;
30 import java.awt.image.BufferedImage JavaDoc;
31 import java.awt.image.ImageObserver JavaDoc;
32 import java.awt.image.RenderedImage JavaDoc;
33 import java.awt.image.renderable.RenderableImage JavaDoc;
34 import java.text.AttributedCharacterIterator JavaDoc;
35
36 /**
37  * This concrete implementation of <tt>AbstractGraphics2D</tt> is a
38  * simple help to programmers to get started with their own
39  * implementation of <tt>Graphics2D</tt>.
40  * <tt>DefaultGraphics2D</tt> implements all the abstract methods
41  * is <tt>AbstractGraphics2D</tt> and makes it easy to start
42  * implementing a <tt>Graphic2D</tt> piece-meal.
43  *
44  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
45  * @version $Id: DefaultGraphics2D.java,v 1.5 2005/03/27 08:58:32 cam Exp $
46  * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
47  */

48 public class DefaultGraphics2D extends AbstractGraphics2D {
49     /**
50      * Default constructor
51      */

52     public DefaultGraphics2D(boolean textAsShapes){
53         super(textAsShapes);
54     }
55
56     /**
57      * This constructor supports the create method
58      */

59     public DefaultGraphics2D(DefaultGraphics2D g){
60         super(g);
61     }
62
63     /**
64      * Creates a new <code>Graphics</code> object that is
65      * a copy of this <code>Graphics</code> object.
66      * @return a new graphics context that is a copy of
67      * this graphics context.
68      */

69     public Graphics JavaDoc create(){
70         return new DefaultGraphics2D(this);
71     }
72
73     /**
74      * Draws as much of the specified image as is currently available.
75      * The image is drawn with its top-left corner at
76      * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
77      * space. Transparent pixels in the image do not affect whatever
78      * pixels are already there.
79      * <p>
80      * This method returns immediately in all cases, even if the
81      * complete image has not yet been loaded, and it has not been dithered
82      * and converted for the current output device.
83      * <p>
84      * If the image has not yet been completely loaded, then
85      * <code>drawImage</code> returns <code>false</code>. As more of
86      * the image becomes available, the process that draws the image notifies
87      * the specified image observer.
88      * @param img the specified image to be drawn.
89      * @param x the <i>x</i> coordinate.
90      * @param y the <i>y</i> coordinate.
91      * @param observer object to be notified as more of
92      * the image is converted.
93      * @see java.awt.Image
94      * @see java.awt.image.ImageObserver
95      * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
96      */

97     public boolean drawImage(Image JavaDoc img, int x, int y, ImageObserver JavaDoc observer){
98         System.err.println("drawImage");
99         return true;
100     }
101
102     /**
103      * Draws as much of the specified image as has already been scaled
104      * to fit inside the specified rectangle.
105      * <p>
106      * The image is drawn inside the specified rectangle of this
107      * graphics context's coordinate space, and is scaled if
108      * necessary. Transparent pixels do not affect whatever pixels
109      * are already there.
110      * <p>
111      * This method returns immediately in all cases, even if the
112      * entire image has not yet been scaled, dithered, and converted
113      * for the current output device.
114      * If the current output representation is not yet complete, then
115      * <code>drawImage</code> returns <code>false</code>. As more of
116      * the image becomes available, the process that draws the image notifies
117      * the image observer by calling its <code>imageUpdate</code> method.
118      * <p>
119      * A scaled version of an image will not necessarily be
120      * available immediately just because an unscaled version of the
121      * image has been constructed for this output device. Each size of
122      * the image may be cached separately and generated from the original
123      * data in a separate image production sequence.
124      * @param img the specified image to be drawn.
125      * @param x the <i>x</i> coordinate.
126      * @param y the <i>y</i> coordinate.
127      * @param width the width of the rectangle.
128      * @param height the height of the rectangle.
129      * @param observer object to be notified as more of
130      * the image is converted.
131      * @see java.awt.Image
132      * @see java.awt.image.ImageObserver
133      * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
134      */

135     public boolean drawImage(Image JavaDoc img, int x, int y,
136                              int width, int height,
137                              ImageObserver JavaDoc observer) {
138         System.out.println("drawImage");
139         return true;
140     }
141
142     /**
143      * Disposes of this graphics context and releases
144      * any system resources that it is using.
145      * A <code>Graphics</code> object cannot be used after
146      * <code>dispose</code>has been called.
147      * <p>
148      * When a Java program runs, a large number of <code>Graphics</code>
149      * objects can be created within a short time frame.
150      * Although the finalization process of the garbage collector
151      * also disposes of the same system resources, it is preferable
152      * to manually free the associated resources by calling this
153      * method rather than to rely on a finalization process which
154      * may not run to completion for a long period of time.
155      * <p>
156      * Graphics objects which are provided as arguments to the
157      * <code>paint</code> and <code>update</code> methods
158      * of components are automatically released by the system when
159      * those methods return. For efficiency, programmers should
160      * call <code>dispose</code> when finished using
161      * a <code>Graphics</code> object only if it was created
162      * directly from a component or another <code>Graphics</code> object.
163      * @see java.awt.Graphics#finalize
164      * @see java.awt.Component#paint
165      * @see java.awt.Component#update
166      * @see java.awt.Component#getGraphics
167      * @see java.awt.Graphics#create
168      */

169     public void dispose(){
170         System.out.println("dispose");
171     }
172
173     /**
174      * Strokes the outline of a <code>Shape</code> using the settings of the
175      * current <code>Graphics2D</code> context. The rendering attributes
176      * applied include the <code>Clip</code>, <code>Transform</code>,
177      * <code>Paint</code>, <code>Composite</code> and
178      * <code>Stroke</code> attributes.
179      * @param s the <code>Shape</code> to be rendered
180      * @see #setStroke
181      * @see #setPaint
182      * @see java.awt.Graphics#setColor
183      * @see #transform
184      * @see #setTransform
185      * @see #clip
186      * @see #setClip
187      * @see #setComposite
188      */

189     public void draw(Shape JavaDoc s){
190         System.out.println("draw(Shape)");
191     }
192
193     /**
194      * Renders a {@link RenderedImage},
195      * applying a transform from image
196      * space into user space before drawing.
197      * The transformation from user space into device space is done with
198      * the current <code>Transform</code> in the <code>Graphics2D</code>.
199      * The specified transformation is applied to the image before the
200      * transform attribute in the <code>Graphics2D</code> context is applied.
201      * The rendering attributes applied include the <code>Clip</code>,
202      * <code>Transform</code>, and <code>Composite</code> attributes. Note
203      * that no rendering is done if the specified transform is
204      * noninvertible.
205      * @param img the image to be rendered
206      * @param xform the transformation from image space into user space
207      * @see #transform
208      * @see #setTransform
209      * @see #setComposite
210      * @see #clip
211      * @see #setClip
212      */

213     public void drawRenderedImage(RenderedImage JavaDoc img,
214                                   AffineTransform JavaDoc xform) {
215         System.out.println("drawRenderedImage");
216     }
217
218
219     /**
220      * Renders a
221      * {@link RenderableImage},
222      * applying a transform from image space into user space before drawing.
223      * The transformation from user space into device space is done with
224      * the current <code>Transform</code> in the <code>Graphics2D</code>.
225      * The specified transformation is applied to the image before the
226      * transform attribute in the <code>Graphics2D</code> context is applied.
227      * The rendering attributes applied include the <code>Clip</code>,
228      * <code>Transform</code>, and <code>Composite</code> attributes. Note
229      * that no rendering is done if the specified transform is
230      * noninvertible.
231      *<p>
232      * Rendering hints set on the <code>Graphics2D</code> object might
233      * be used in rendering the <code>RenderableImage</code>.
234      * If explicit control is required over specific hints recognized by a
235      * specific <code>RenderableImage</code>, or if knowledge of which hints
236      * are used is required, then a <code>RenderedImage</code> should be
237      * obtained directly from the <code>RenderableImage</code>
238      * and rendered using
239      *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
240      * @param img the image to be rendered
241      * @param xform the transformation from image space into user space
242      * @see #transform
243      * @see #setTransform
244      * @see #setComposite
245      * @see #clip
246      * @see #setClip
247      * @see #drawRenderedImage
248      */

249      public void drawRenderableImage(RenderableImage JavaDoc img,
250                                      AffineTransform JavaDoc xform){
251          System.out.println("drawRenderableImage");
252      }
253
254     /**
255      * Renders the text specified by the specified <code>String</code>,
256      * using the current <code>Font</code> and <code>Paint</code> attributes
257      * in the <code>Graphics2D</code> context.
258      * The baseline of the first character is at position
259      * (<i>x</i>,&nbsp;<i>y</i>) in the User Space.
260      * The rendering attributes applied include the <code>Clip</code>,
261      * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
262      * <code>Composite</code> attributes. For characters in script systems
263      * such as Hebrew and Arabic, the glyphs can be rendered from right to
264      * left, in which case the coordinate supplied is the location of the
265      * leftmost character on the baseline.
266      * @param s the <code>String</code> to be rendered
267      * @param x the x coordinate where the <code>String</code> should be
268      * rendered
269      * @param y the y coordinate where the <code>String</code> should be
270      * rendered
271      * @see #setPaint
272      * @see java.awt.Graphics#setColor
273      * @see java.awt.Graphics#setFont
274      * @see #setTransform
275      * @see #setComposite
276      * @see #setClip
277      */

278     public void drawString(String JavaDoc s, float x, float y){
279         System.out.println("drawString(String)");
280     }
281
282     /**
283      * Renders the text of the specified iterator, using the
284      * <code>Graphics2D</code> context's current <code>Paint</code>. The
285      * iterator must specify a font
286      * for each character. The baseline of the
287      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in the
288      * User Space.
289      * The rendering attributes applied include the <code>Clip</code>,
290      * <code>Transform</code>, <code>Paint</code>, and
291      * <code>Composite</code> attributes.
292      * For characters in script systems such as Hebrew and Arabic,
293      * the glyphs can be rendered from right to left, in which case the
294      * coordinate supplied is the location of the leftmost character
295      * on the baseline.
296      * @param iterator the iterator whose text is to be rendered
297      * @param x the x coordinate where the iterator's text is to be rendered
298      * @param y the y coordinate where the iterator's text is to be rendered
299      * @see #setPaint
300      * @see java.awt.Graphics#setColor
301      * @see #setTransform
302      * @see #setComposite
303      * @see #setClip
304      */

305      public void drawString(AttributedCharacterIterator JavaDoc iterator,
306                             float x, float y) {
307          System.err.println("drawString(AttributedCharacterIterator)");
308      }
309
310
311
312     /**
313      * Fills the interior of a <code>Shape</code> using the settings of the
314      * <code>Graphics2D</code> context. The rendering attributes applied
315      * include the <code>Clip</code>, <code>Transform</code>,
316      * <code>Paint</code>, and <code>Composite</code>.
317      * @param s the <code>Shape</code> to be filled
318      * @see #setPaint
319      * @see java.awt.Graphics#setColor
320      * @see #transform
321      * @see #setTransform
322      * @see #setComposite
323      * @see #clip
324      * @see #setClip
325      */

326     public void fill(Shape JavaDoc s){
327         System.err.println("fill");
328     }
329     
330     /**
331      * Returns the device configuration associated with this
332      * <code>Graphics2D</code>.
333      */

334     public GraphicsConfiguration JavaDoc getDeviceConfiguration(){
335         System.out.println("getDeviceConviguration");
336         return null;
337     }
338
339     /**
340      * Used to create proper font metrics
341      */

342     private Graphics2D JavaDoc fmg;
343
344     {
345         BufferedImage JavaDoc bi
346             = new BufferedImage JavaDoc(1, 1, BufferedImage.TYPE_INT_ARGB);
347
348         fmg = bi.createGraphics();
349     }
350
351     /**
352      * Gets the font metrics for the specified font.
353      * @return the font metrics for the specified font.
354      * @param f the specified font
355      * @see java.awt.Graphics#getFont
356      * @see java.awt.FontMetrics
357      * @see java.awt.Graphics#getFontMetrics()
358      */

359     public FontMetrics JavaDoc getFontMetrics(Font JavaDoc f){
360         return fmg.getFontMetrics(f);
361     }
362
363     /**
364      * Sets the paint mode of this graphics context to alternate between
365      * this graphics context's current color and the new specified color.
366      * This specifies that logical pixel operations are performed in the
367      * XOR mode, which alternates pixels between the current color and
368      * a specified XOR color.
369      * <p>
370      * When drawing operations are performed, pixels which are the
371      * current color are changed to the specified color, and vice versa.
372      * <p>
373      * Pixels that are of colors other than those two colors are changed
374      * in an unpredictable but reversible manner; if the same figure is
375      * drawn twice, then all pixels are restored to their original values.
376      * @param c1 the XOR alternation color
377      */

378     public void setXORMode(Color JavaDoc c1){
379         System.out.println("setXORMode");
380     }
381
382
383     /**
384      * Copies an area of the component by a distance specified by
385      * <code>dx</code> and <code>dy</code>. From the point specified
386      * by <code>x</code> and <code>y</code>, this method
387      * copies downwards and to the right. To copy an area of the
388      * component to the left or upwards, specify a negative value for
389      * <code>dx</code> or <code>dy</code>.
390      * If a portion of the source rectangle lies outside the bounds
391      * of the component, or is obscured by another window or component,
392      * <code>copyArea</code> will be unable to copy the associated
393      * pixels. The area that is omitted can be refreshed by calling
394      * the component's <code>paint</code> method.
395      * @param x the <i>x</i> coordinate of the source rectangle.
396      * @param y the <i>y</i> coordinate of the source rectangle.
397      * @param width the width of the source rectangle.
398      * @param height the height of the source rectangle.
399      * @param dx the horizontal distance to copy the pixels.
400      * @param dy the vertical distance to copy the pixels.
401      */

402     public void copyArea(int x, int y, int width, int height,
403                          int dx, int dy){
404         System.out.println("copyArea");
405     }
406
407 }
408
Popular Tags