001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: DefaultGraphics2D.java 447155 2006-09-17 21:50:03Z jeremias $ */
019:
020: package org.apache.xmlgraphics.java2d;
021:
022: import java.awt.Color;
023: import java.awt.Font;
024: import java.awt.FontMetrics;
025: import java.awt.Graphics;
026: import java.awt.Graphics2D;
027: import java.awt.GraphicsConfiguration;
028: import java.awt.Image;
029: import java.awt.Shape;
030: import java.awt.geom.AffineTransform;
031: import java.awt.image.BufferedImage;
032: import java.awt.image.ImageObserver;
033: import java.awt.image.RenderedImage;
034: import java.awt.image.renderable.RenderableImage;
035: import java.text.AttributedCharacterIterator;
036:
037: /**
038: * This concrete implementation of <tt>AbstractGraphics2D</tt> is a
039: * simple help to programmers to get started with their own
040: * implementation of <tt>Graphics2D</tt>.
041: * <tt>DefaultGraphics2D</tt> implements all the abstract methods
042: * is <tt>AbstractGraphics2D</tt> and makes it easy to start
043: * implementing a <tt>Graphic2D</tt> piece-meal.
044: *
045: * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
046: * @version $Id: DefaultGraphics2D.java 447155 2006-09-17 21:50:03Z jeremias $
047: * @see org.apache.xmlgraphics.java2d.AbstractGraphics2D
048: */
049: public class DefaultGraphics2D extends AbstractGraphics2D {
050: /**
051: * Default constructor
052: */
053: public DefaultGraphics2D(boolean textAsShapes) {
054: super (textAsShapes);
055: }
056:
057: /**
058: * This constructor supports the create method
059: */
060: public DefaultGraphics2D(DefaultGraphics2D g) {
061: super (g);
062: }
063:
064: /**
065: * Creates a new <code>Graphics</code> object that is
066: * a copy of this <code>Graphics</code> object.
067: * @return a new graphics context that is a copy of
068: * this graphics context.
069: */
070: public Graphics create() {
071: return new DefaultGraphics2D(this );
072: }
073:
074: /**
075: * Draws as much of the specified image as is currently available.
076: * The image is drawn with its top-left corner at
077: * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
078: * space. Transparent pixels in the image do not affect whatever
079: * pixels are already there.
080: * <p>
081: * This method returns immediately in all cases, even if the
082: * complete image has not yet been loaded, and it has not been dithered
083: * and converted for the current output device.
084: * <p>
085: * If the image has not yet been completely loaded, then
086: * <code>drawImage</code> returns <code>false</code>. As more of
087: * the image becomes available, the process that draws the image notifies
088: * the specified image observer.
089: * @param img the specified image to be drawn.
090: * @param x the <i>x</i> coordinate.
091: * @param y the <i>y</i> coordinate.
092: * @param observer object to be notified as more of
093: * the image is converted.
094: * @see java.awt.Image
095: * @see java.awt.image.ImageObserver
096: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
097: */
098: public boolean drawImage(Image img, int x, int y,
099: ImageObserver observer) {
100: System.err.println("drawImage");
101: return true;
102: }
103:
104: /**
105: * Draws as much of the specified image as has already been scaled
106: * to fit inside the specified rectangle.
107: * <p>
108: * The image is drawn inside the specified rectangle of this
109: * graphics context's coordinate space, and is scaled if
110: * necessary. Transparent pixels do not affect whatever pixels
111: * are already there.
112: * <p>
113: * This method returns immediately in all cases, even if the
114: * entire image has not yet been scaled, dithered, and converted
115: * for the current output device.
116: * If the current output representation is not yet complete, then
117: * <code>drawImage</code> returns <code>false</code>. As more of
118: * the image becomes available, the process that draws the image notifies
119: * the image observer by calling its <code>imageUpdate</code> method.
120: * <p>
121: * A scaled version of an image will not necessarily be
122: * available immediately just because an unscaled version of the
123: * image has been constructed for this output device. Each size of
124: * the image may be cached separately and generated from the original
125: * data in a separate image production sequence.
126: * @param img the specified image to be drawn.
127: * @param x the <i>x</i> coordinate.
128: * @param y the <i>y</i> coordinate.
129: * @param width the width of the rectangle.
130: * @param height the height of the rectangle.
131: * @param observer object to be notified as more of
132: * the image is converted.
133: * @see java.awt.Image
134: * @see java.awt.image.ImageObserver
135: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
136: */
137: public boolean drawImage(Image img, int x, int y, int width,
138: int height, ImageObserver observer) {
139: System.out.println("drawImage");
140: return true;
141: }
142:
143: /**
144: * Disposes of this graphics context and releases
145: * any system resources that it is using.
146: * A <code>Graphics</code> object cannot be used after
147: * <code>dispose</code>has been called.
148: * <p>
149: * When a Java program runs, a large number of <code>Graphics</code>
150: * objects can be created within a short time frame.
151: * Although the finalization process of the garbage collector
152: * also disposes of the same system resources, it is preferable
153: * to manually free the associated resources by calling this
154: * method rather than to rely on a finalization process which
155: * may not run to completion for a long period of time.
156: * <p>
157: * Graphics objects which are provided as arguments to the
158: * <code>paint</code> and <code>update</code> methods
159: * of components are automatically released by the system when
160: * those methods return. For efficiency, programmers should
161: * call <code>dispose</code> when finished using
162: * a <code>Graphics</code> object only if it was created
163: * directly from a component or another <code>Graphics</code> object.
164: * @see java.awt.Graphics#finalize
165: * @see java.awt.Component#paint
166: * @see java.awt.Component#update
167: * @see java.awt.Component#getGraphics
168: * @see java.awt.Graphics#create()
169: */
170: public void dispose() {
171: System.out.println("dispose");
172: }
173:
174: /**
175: * Strokes the outline of a <code>Shape</code> using the settings of the
176: * current <code>Graphics2D</code> context. The rendering attributes
177: * applied include the <code>Clip</code>, <code>Transform</code>,
178: * <code>Paint</code>, <code>Composite</code> and
179: * <code>Stroke</code> attributes.
180: * @param s the <code>Shape</code> to be rendered
181: * @see #setStroke(java.awt.Stroke)
182: * @see #setPaint(java.awt.Paint)
183: * @see java.awt.Graphics#setColor
184: * @see #setTransform(AffineTransform)
185: * @see #setClip(Shape)
186: * @see #setComposite(java.awt.Composite)
187: */
188: public void draw(Shape s) {
189: System.out.println("draw(Shape)");
190: }
191:
192: /**
193: * Renders a {@link RenderedImage},
194: * applying a transform from image
195: * space into user space before drawing.
196: * The transformation from user space into device space is done with
197: * the current <code>Transform</code> in the <code>Graphics2D</code>.
198: * The specified transformation is applied to the image before the
199: * transform attribute in the <code>Graphics2D</code> context is applied.
200: * The rendering attributes applied include the <code>Clip</code>,
201: * <code>Transform</code>, and <code>Composite</code> attributes. Note
202: * that no rendering is done if the specified transform is
203: * noninvertible.
204: * @param img the image to be rendered
205: * @param xform the transformation from image space into user space
206: * @see #setTransform(AffineTransform)
207: * @see #setComposite(java.awt.Composite)
208: * @see #setClip(Shape)
209: */
210: public void drawRenderedImage(RenderedImage img,
211: AffineTransform xform) {
212: System.out.println("drawRenderedImage");
213: }
214:
215: /**
216: * Renders a
217: * {@link RenderableImage},
218: * applying a transform from image space into user space before drawing.
219: * The transformation from user space into device space is done with
220: * the current <code>Transform</code> in the <code>Graphics2D</code>.
221: * The specified transformation is applied to the image before the
222: * transform attribute in the <code>Graphics2D</code> context is applied.
223: * The rendering attributes applied include the <code>Clip</code>,
224: * <code>Transform</code>, and <code>Composite</code> attributes. Note
225: * that no rendering is done if the specified transform is
226: * noninvertible.
227: *<p>
228: * Rendering hints set on the <code>Graphics2D</code> object might
229: * be used in rendering the <code>RenderableImage</code>.
230: * If explicit control is required over specific hints recognized by a
231: * specific <code>RenderableImage</code>, or if knowledge of which hints
232: * are used is required, then a <code>RenderedImage</code> should be
233: * obtained directly from the <code>RenderableImage</code>
234: * and rendered using
235: *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
236: * @param img the image to be rendered
237: * @param xform the transformation from image space into user space
238: * @see #setTransform(AffineTransform)
239: * @see #setComposite(java.awt.Composite)
240: * @see #setClip(Shape)
241: * @see #drawRenderedImage
242: */
243: public void drawRenderableImage(RenderableImage img,
244: AffineTransform xform) {
245: System.out.println("drawRenderableImage");
246: }
247:
248: /**
249: * Renders the text specified by the specified <code>String</code>,
250: * using the current <code>Font</code> and <code>Paint</code> attributes
251: * in the <code>Graphics2D</code> context.
252: * The baseline of the first character is at position
253: * (<i>x</i>, <i>y</i>) in the User Space.
254: * The rendering attributes applied include the <code>Clip</code>,
255: * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
256: * <code>Composite</code> attributes. For characters in script systems
257: * such as Hebrew and Arabic, the glyphs can be rendered from right to
258: * left, in which case the coordinate supplied is the location of the
259: * leftmost character on the baseline.
260: * @param s the <code>String</code> to be rendered
261: * @param x the x coordinate where the <code>String</code> should be
262: * rendered
263: * @param y the y coordinate where the <code>String</code> should be
264: * rendered
265: * @see #setPaint(java.awt.Paint)
266: * @see java.awt.Graphics#setColor
267: * @see java.awt.Graphics#setFont
268: * @see #setTransform(AffineTransform)
269: * @see #setComposite(java.awt.Composite)
270: * @see #setClip(Shape)
271: */
272: public void drawString(String s, float x, float y) {
273: System.out.println("drawString(String)");
274: }
275:
276: /**
277: * Renders the text of the specified iterator, using the
278: * <code>Graphics2D</code> context's current <code>Paint</code>. The
279: * iterator must specify a font
280: * for each character. The baseline of the
281: * first character is at position (<i>x</i>, <i>y</i>) in the
282: * User Space.
283: * The rendering attributes applied include the <code>Clip</code>,
284: * <code>Transform</code>, <code>Paint</code>, and
285: * <code>Composite</code> attributes.
286: * For characters in script systems such as Hebrew and Arabic,
287: * the glyphs can be rendered from right to left, in which case the
288: * coordinate supplied is the location of the leftmost character
289: * on the baseline.
290: * @param iterator the iterator whose text is to be rendered
291: * @param x the x coordinate where the iterator's text is to be rendered
292: * @param y the y coordinate where the iterator's text is to be rendered
293: * @see #setPaint(java.awt.Paint)
294: * @see java.awt.Graphics#setColor
295: * @see #setTransform(AffineTransform)
296: * @see #setComposite(java.awt.Composite)
297: * @see #setClip(Shape)
298: */
299: public void drawString(AttributedCharacterIterator iterator,
300: float x, float y) {
301: System.err.println("drawString(AttributedCharacterIterator)");
302: }
303:
304: /**
305: * Fills the interior of a <code>Shape</code> using the settings of the
306: * <code>Graphics2D</code> context. The rendering attributes applied
307: * include the <code>Clip</code>, <code>Transform</code>,
308: * <code>Paint</code>, and <code>Composite</code>.
309: * @param s the <code>Shape</code> to be filled
310: * @see #setPaint(java.awt.Paint)
311: * @see java.awt.Graphics#setColor
312: * @see #setTransform(AffineTransform)
313: * @see #setComposite(java.awt.Composite)
314: * @see #setClip(Shape)
315: */
316: public void fill(Shape s) {
317: System.err.println("fill");
318: }
319:
320: /**
321: * Returns the device configuration associated with this
322: * <code>Graphics2D</code>.
323: */
324: public GraphicsConfiguration getDeviceConfiguration() {
325: System.out.println("getDeviceConviguration");
326: return null;
327: }
328:
329: /**
330: * Used to create proper font metrics
331: */
332: private Graphics2D fmg;
333:
334: {
335: BufferedImage bi = new BufferedImage(1, 1,
336: BufferedImage.TYPE_INT_ARGB);
337:
338: fmg = bi.createGraphics();
339: }
340:
341: /**
342: * Gets the font metrics for the specified font.
343: * @return the font metrics for the specified font.
344: * @param f the specified font
345: * @see java.awt.Graphics#getFont
346: * @see java.awt.FontMetrics
347: * @see java.awt.Graphics#getFontMetrics()
348: */
349: public FontMetrics getFontMetrics(Font f) {
350: return fmg.getFontMetrics(f);
351: }
352:
353: /**
354: * Sets the paint mode of this graphics context to alternate between
355: * this graphics context's current color and the new specified color.
356: * This specifies that logical pixel operations are performed in the
357: * XOR mode, which alternates pixels between the current color and
358: * a specified XOR color.
359: * <p>
360: * When drawing operations are performed, pixels which are the
361: * current color are changed to the specified color, and vice versa.
362: * <p>
363: * Pixels that are of colors other than those two colors are changed
364: * in an unpredictable but reversible manner; if the same figure is
365: * drawn twice, then all pixels are restored to their original values.
366: * @param c1 the XOR alternation color
367: */
368: public void setXORMode(Color c1) {
369: System.out.println("setXORMode");
370: }
371:
372: /**
373: * Copies an area of the component by a distance specified by
374: * <code>dx</code> and <code>dy</code>. From the point specified
375: * by <code>x</code> and <code>y</code>, this method
376: * copies downwards and to the right. To copy an area of the
377: * component to the left or upwards, specify a negative value for
378: * <code>dx</code> or <code>dy</code>.
379: * If a portion of the source rectangle lies outside the bounds
380: * of the component, or is obscured by another window or component,
381: * <code>copyArea</code> will be unable to copy the associated
382: * pixels. The area that is omitted can be refreshed by calling
383: * the component's <code>paint</code> method.
384: * @param x the <i>x</i> coordinate of the source rectangle.
385: * @param y the <i>y</i> coordinate of the source rectangle.
386: * @param width the width of the source rectangle.
387: * @param height the height of the source rectangle.
388: * @param dx the horizontal distance to copy the pixels.
389: * @param dy the vertical distance to copy the pixels.
390: */
391: public void copyArea(int x, int y, int width, int height, int dx,
392: int dy) {
393: System.out.println("copyArea");
394: }
395:
396: }
|