001: /*
002: * $RCSfile: GraphicsJAI.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:08 $
010: * $State: Exp $
011: */
012: package javax.media.jai;
013:
014: import java.awt.Color;
015: import java.awt.Component;
016: import java.awt.Composite;
017: import java.awt.Font;
018: import java.awt.FontMetrics;
019: import java.awt.Graphics;
020: import java.awt.Graphics2D;
021: import java.awt.GraphicsConfiguration;
022: import java.awt.Image;
023: import java.awt.Paint;
024: import java.awt.Rectangle;
025: import java.awt.RenderingHints;
026: import java.awt.RenderingHints.Key;
027: import java.awt.Shape;
028: import java.awt.Stroke;
029: import java.awt.font.FontRenderContext;
030: import java.awt.font.GlyphVector;
031: import java.awt.geom.AffineTransform;
032: import java.awt.image.BufferedImage;
033: import java.awt.image.BufferedImageOp;
034: import java.awt.image.ImageObserver;
035: import java.awt.image.RenderedImage;
036: import java.awt.image.renderable.RenderableImage;
037: import java.text.AttributedCharacterIterator;
038: import java.util.Map;
039:
040: /**
041: * A JAI wrapper for a Graphics2D object derived from a Component.
042: * When drawing JAI images to a Component such as a Canvas, a new
043: * GraphicsJAI may be constructed to wrap the Graphics2D object
044: * provided by that Component. This GraphicsJAI object may provide
045: * acceleration for calls to drawRenderedImage(),
046: * drawRenderableImage(), and possibly other methods.
047: *
048: * <p> If it is possible to use a CanvasJAI object instead of a
049: * generic Canvas, or other Canvas subclass, then the Graphics objects
050: * obtained from getGraphics() or received as an argument in paint()
051: * will automatically be instances of GraphicsJAI.
052: *
053: * <p> The portion of the <code>GraphicsJAI</code> interface that
054: * deals with adding and retrieving new hardware-specific implementations
055: * has not been finalized and does not appear in the current API.
056: *
057: * @see CanvasJAI
058: */
059: public class GraphicsJAI extends Graphics2D {
060:
061: Graphics2D g;
062: Component component;
063:
064: /**
065: * Constructs a new instance of <code>GraphicsJAI</code> that
066: * wraps a given instance of <code>Graphics2D</code> for drawing
067: * to a given <code>Component</code>.
068: */
069: protected GraphicsJAI(Graphics2D g, Component component) {
070: this .g = g;
071: this .component = component;
072: }
073:
074: /**
075: * Returns an instance of <code>GraphicsJAI</code> suitable
076: * for rendering to the given <code>Component</code> via the
077: * given <code>Graphics2D</code> instance.
078: *
079: * <p> If one is available, his method will select a hardware-specific
080: * implementation, that is specialized for the display device containing
081: * the component.
082: */
083: public static GraphicsJAI createGraphicsJAI(Graphics2D g,
084: Component component) {
085: return new GraphicsJAI(g, component);
086: }
087:
088: /**
089: * Creates a new <code>GraphicsJAI</code> object that is
090: * a copy of this <code>GraphicsJAI</code> object.
091: *
092: * @see java.awt.Graphics#create()
093: */
094: public Graphics create() {
095: return new GraphicsJAI(g, component);
096: }
097:
098: /**
099: * See comments in java.awt.Graphics.
100: *
101: * @see java.awt.Graphics#getColor()
102: */
103: public Color getColor() {
104: return g.getColor();
105: }
106:
107: /**
108: * See comments in java.awt.Graphics.
109: *
110: * @see java.awt.Graphics#setColor(Color)
111: */
112: public void setColor(Color c) {
113: g.setColor(c);
114: }
115:
116: /**
117: * See comments in java.awt.Graphics.
118: *
119: * @see java.awt.Graphics#setPaintMode()
120: */
121: public void setPaintMode() {
122: g.setPaintMode();
123: }
124:
125: /**
126: * See comments in java.awt.Graphics.
127: *
128: * @see java.awt.Graphics#setXORMode(Color)
129: */
130: public void setXORMode(Color c1) {
131: g.setXORMode(c1);
132: }
133:
134: /**
135: * See comments in java.awt.Graphics.
136: *
137: * @see java.awt.Graphics#getFont
138: */
139: public Font getFont() {
140: return g.getFont();
141: }
142:
143: /**
144: * See comments in java.awt.Graphics.
145: *
146: * @see java.awt.Graphics#setFont(Font)
147: */
148: public void setFont(Font font) {
149: g.setFont(font);
150: }
151:
152: /**
153: * See comments in java.awt.Graphics.
154: *
155: * @see java.awt.Graphics#getFontMetrics(Font)
156: */
157: public FontMetrics getFontMetrics(Font f) {
158: return g.getFontMetrics(f);
159: }
160:
161: /**
162: * See comments in java.awt.Graphics.
163: *
164: * @see java.awt.Graphics#getClipBounds
165: */
166: public Rectangle getClipBounds() {
167: return g.getClipBounds();
168: }
169:
170: /**
171: * See comments in java.awt.Graphics.
172: *
173: * @see java.awt.Graphics#clipRect(int, int, int, int)
174: */
175: public void clipRect(int x, int y, int width, int height) {
176: g.clipRect(x, y, width, height);
177: }
178:
179: /**
180: * See comments in java.awt.Graphics.
181: *
182: * @see java.awt.Graphics#setClip(int, int, int, int)
183: */
184: public void setClip(int x, int y, int width, int height) {
185: g.setClip(x, y, width, height);
186: }
187:
188: /**
189: * See comments in java.awt.Graphics.
190: *
191: * @see java.awt.Graphics#getClip
192: */
193: public Shape getClip() {
194: return g.getClip();
195: }
196:
197: /**
198: * See comments in java.awt.Graphics.
199: *
200: * @see java.awt.Graphics#setClip(Shape)
201: */
202: public void setClip(Shape clip) {
203: g.setClip(clip);
204: }
205:
206: /**
207: * See comments in java.awt.Graphics.
208: *
209: * @see java.awt.Graphics#copyArea(int, int, int, int, int, int)
210: */
211: public void copyArea(int x, int y, int width, int height, int dx,
212: int dy) {
213: g.copyArea(x, y, width, height, dx, dy);
214: }
215:
216: /**
217: * See comments in java.awt.Graphics.
218: *
219: * @see java.awt.Graphics#drawLine(int, int, int, int)
220: */
221: public void drawLine(int x1, int y1, int x2, int y2) {
222: g.drawLine(x1, y1, x2, y2);
223: }
224:
225: /**
226: * See comments in java.awt.Graphics.
227: *
228: * @see java.awt.Graphics#fillRect(int, int, int, int)
229: */
230: public void fillRect(int x, int y, int width, int height) {
231: g.fillRect(x, y, width, height);
232: }
233:
234: /**
235: * See comments in java.awt.Graphics.
236: *
237: * @see java.awt.Graphics#clearRect(int, int, int, int)
238: */
239: public void clearRect(int x, int y, int width, int height) {
240: g.clearRect(x, y, width, height);
241: }
242:
243: /**
244: * See comments in java.awt.Graphics.
245: *
246: * @see java.awt.Graphics#drawRoundRect(int, int, int, int, int, int)
247: */
248: public void drawRoundRect(int x, int y, int width, int height,
249: int arcWidth, int arcHeight) {
250: g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
251: }
252:
253: /**
254: * See comments in java.awt.Graphics.
255: *
256: * @see java.awt.Graphics#fillRoundRect(int, int, int, int, int, int)
257: */
258: public void fillRoundRect(int x, int y, int width, int height,
259: int arcWidth, int arcHeight) {
260: g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
261: }
262:
263: /**
264: * See comments in java.awt.Graphics.
265: *
266: * @see java.awt.Graphics#drawOval(int, int, int, int)
267: */
268: public void drawOval(int x, int y, int width, int height) {
269: g.drawOval(x, y, width, height);
270: }
271:
272: /**
273: * See comments in java.awt.Graphics.
274: *
275: * @see java.awt.Graphics#fillOval(int, int, int, int)
276: */
277: public void fillOval(int x, int y, int width, int height) {
278: g.fillOval(x, y, width, height);
279: }
280:
281: /**
282: * See comments in java.awt.Graphics.
283: *
284: * @see java.awt.Graphics#drawArc(int, int, int, int, int, int)
285: */
286: public void drawArc(int x, int y, int width, int height,
287: int startAngle, int arcAngle) {
288: g.drawArc(x, y, width, height, startAngle, arcAngle);
289: }
290:
291: /**
292: * See comments in java.awt.Graphics.
293: *
294: * @see java.awt.Graphics#fillArc(int, int, int, int, int, int)
295: */
296: public void fillArc(int x, int y, int width, int height,
297: int startAngle, int arcAngle) {
298: g.fillArc(x, y, width, height, startAngle, arcAngle);
299: }
300:
301: /**
302: * See comments in java.awt.Graphics.
303: *
304: * @see java.awt.Graphics#drawPolyline(int[], int[], int)
305: */
306: public void drawPolyline(int xPoints[], int yPoints[], int nPoints) {
307: g.drawPolyline(xPoints, yPoints, nPoints);
308: }
309:
310: /**
311: * See comments in java.awt.Graphics.
312: *
313: * @see java.awt.Graphics#drawPolygon(int[], int[], int)
314: */
315: public void drawPolygon(int xPoints[], int yPoints[], int nPoints) {
316: g.drawPolygon(xPoints, yPoints, nPoints);
317: }
318:
319: /**
320: * See comments in java.awt.Graphics.
321: *
322: * @see java.awt.Graphics#fillPolygon(int[], int[], int)
323: */
324: public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
325: g.fillPolygon(xPoints, yPoints, nPoints);
326: }
327:
328: /**
329: * See comments in java.awt.Graphics.
330: *
331: * @see java.awt.Graphics#drawImage(Image, int, int, ImageObserver)
332: */
333: public boolean drawImage(Image img, int x, int y,
334: ImageObserver observer) {
335: return g.drawImage(img, x, y, observer);
336: }
337:
338: /**
339: * See comments in java.awt.Graphics.
340: *
341: * @see java.awt.Graphics#drawImage(Image, int, int, int, int, ImageObserver)
342: */
343: public boolean drawImage(Image img, int x, int y, int width,
344: int height, ImageObserver observer) {
345: return g.drawImage(img, x, y, width, height, observer);
346: }
347:
348: /**
349: * See comments in java.awt.Graphics.
350: *
351: * @see java.awt.Graphics#drawImage(Image, int, int, Color, ImageObserver)
352: */
353: public boolean drawImage(Image img, int x, int y, Color bgcolor,
354: ImageObserver observer) {
355: return g.drawImage(img, x, y, bgcolor, observer);
356: }
357:
358: /**
359: * See comments in java.awt.Graphics.
360: *
361: * @see java.awt.Graphics#drawImage(Image, int, int, int, int, Color, ImageObserver)
362: */
363: public boolean drawImage(Image img, int x, int y, int width,
364: int height, Color bgcolor, ImageObserver observer) {
365: return g.drawImage(img, x, y, width, height, bgcolor, observer);
366: }
367:
368: /**
369: * See comments in java.awt.Graphics.
370: *
371: * @see java.awt.Graphics#drawImage(Image, int, int, int, int, int, int, int, int, ImageObserver)
372: */
373: public boolean drawImage(Image img, int dx1, int dy1, int dx2,
374: int dy2, int sx1, int sy1, int sx2, int sy2,
375: ImageObserver observer) {
376: return g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
377: observer);
378: }
379:
380: /**
381: * See comments in java.awt.Graphics.
382: *
383: * @see java.awt.Graphics#drawImage(Image, int, int, int, int, int, int, int, int, Color, ImageObserver)
384: */
385: public boolean drawImage(Image img, int dx1, int dy1, int dx2,
386: int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor,
387: ImageObserver observer) {
388: return g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
389: bgcolor, observer);
390: }
391:
392: /**
393: * See comments in java.awt.Graphics.
394: *
395: * @see java.awt.Graphics#dispose
396: */
397: public void dispose() {
398: g.dispose();
399: }
400:
401: /**
402: * See comments in java.awt.Graphics2D.
403: *
404: * @see java.awt.Graphics2D#draw(Shape)
405: */
406: public void draw(Shape s) {
407: g.draw(s);
408: }
409:
410: /**
411: * See comments in java.awt.Graphics2D.
412: *
413: * @see java.awt.Graphics2D#drawImage(Image, AffineTransform, ImageObserver)
414: */
415: public boolean drawImage(Image img, AffineTransform xform,
416: ImageObserver obs) {
417: return g.drawImage(img, xform, obs);
418: }
419:
420: /**
421: * See comments in java.awt.Graphics2D.
422: *
423: * @see java.awt.Graphics2D#drawImage(BufferedImage, BufferedImageOp, int, int)
424: */
425: public void drawImage(BufferedImage img, BufferedImageOp op, int x,
426: int y) {
427: g.drawImage(img, op, x, y);
428: }
429:
430: /**
431: * See comments in java.awt.Graphics2D.
432: *
433: * @see java.awt.Graphics2D#drawRenderedImage(RenderedImage, AffineTransform)
434: */
435: public void drawRenderedImage(RenderedImage img,
436: AffineTransform xform) {
437: g.drawRenderedImage(img, xform);
438: }
439:
440: /**
441: * See comments in java.awt.Graphics2D.
442: *
443: * @see java.awt.Graphics2D#drawRenderableImage(RenderableImage, AffineTransform)
444: */
445: public void drawRenderableImage(RenderableImage img,
446: AffineTransform xform) {
447: g.drawRenderableImage(img, xform);
448: }
449:
450: /**
451: * See comments in java.awt.Graphics2D.
452: *
453: * @see java.awt.Graphics2D#drawString(String, int, int)
454: */
455: public void drawString(String str, int x, int y) {
456: g.drawString(str, x, y);
457: }
458:
459: /**
460: * See comments in java.awt.Graphics2D.
461: *
462: * @see java.awt.Graphics2D#drawString(String, float, float)
463: */
464: public void drawString(String s, float x, float y) {
465: g.drawString(s, x, y);
466: }
467:
468: /**
469: * See comments in java.awt.Graphics2D.
470: *
471: * @see java.awt.Graphics2D#drawString(AttributedCharacterIterator, int, int)
472: */
473: public void drawString(AttributedCharacterIterator iterator, int x,
474: int y) {
475: g.drawString(iterator, x, y);
476: }
477:
478: /**
479: * See comments in java.awt.Graphics2D.
480: *
481: * @see java.awt.Graphics2D#drawString(AttributedCharacterIterator, float, float)
482: */
483: public void drawString(AttributedCharacterIterator iterator,
484: float x, float y) {
485: g.drawString(iterator, x, y);
486: }
487:
488: /**
489: * See comments in java.awt.Graphics2D.
490: *
491: * @see java.awt.Graphics2D#drawGlyphVector(GlyphVector, float, float)
492: */
493: public void drawGlyphVector(GlyphVector g, float x, float y) {
494: (this .g).drawGlyphVector(g, x, y);
495: }
496:
497: /**
498: * See comments in java.awt.Graphics2D.
499: *
500: * @see java.awt.Graphics2D#fill(Shape)
501: */
502: public void fill(Shape s) {
503: g.fill(s);
504: }
505:
506: /**
507: * See comments in java.awt.Graphics2D.
508: *
509: * @see java.awt.Graphics2D#hit(Rectangle, Shape, boolean)
510: */
511: public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
512: return g.hit(rect, s, onStroke);
513: }
514:
515: /**
516: * See comments in java.awt.Graphics2D.
517: *
518: * @see java.awt.Graphics2D#getDeviceConfiguration
519: */
520: public GraphicsConfiguration getDeviceConfiguration() {
521: return g.getDeviceConfiguration();
522: }
523:
524: /**
525: * See comments in java.awt.Graphics2D.
526: *
527: * @see java.awt.Graphics2D#setComposite(Composite)
528: */
529: public void setComposite(Composite comp) {
530: g.setComposite(comp);
531: }
532:
533: /**
534: * See comments in java.awt.Graphics2D.
535: *
536: * @see java.awt.Graphics2D#setPaint(Paint)
537: */
538: public void setPaint(Paint paint) {
539: g.setPaint(paint);
540: }
541:
542: /**
543: * See comments in java.awt.Graphics2D.
544: *
545: * @see java.awt.Graphics2D#setStroke(Stroke)
546: */
547: public void setStroke(Stroke s) {
548: g.setStroke(s);
549: }
550:
551: /**
552: * See comments in java.awt.Graphics2D.
553: *
554: * @see java.awt.Graphics2D#setRenderingHint(RenderingHints.Key, Object)
555: */
556: public void setRenderingHint(Key hintKey, Object hintValue) {
557: g.setRenderingHint(hintKey, hintValue);
558: }
559:
560: /**
561: * See comments in java.awt.Graphics2D.
562: *
563: * @see java.awt.Graphics2D#getRenderingHint(RenderingHints.Key)
564: */
565: public Object getRenderingHint(Key hintKey) {
566: return g.getRenderingHint(hintKey);
567: }
568:
569: /**
570: * See comments in java.awt.Graphics2D.
571: *
572: * @see java.awt.Graphics2D#setRenderingHints(Map)
573: */
574: public void setRenderingHints(Map hints) {
575: g.setRenderingHints(hints);
576: }
577:
578: /**
579: * See comments in java.awt.Graphics2D.
580: *
581: * @see java.awt.Graphics2D#addRenderingHints(Map)
582: */
583: public void addRenderingHints(Map hints) {
584: g.addRenderingHints(hints);
585: }
586:
587: /**
588: * See comments in java.awt.Graphics2D.
589: *
590: * @see java.awt.Graphics2D#getRenderingHints
591: */
592: public RenderingHints getRenderingHints() {
593: return g.getRenderingHints();
594: }
595:
596: /**
597: * See comments in java.awt.Graphics2D.
598: *
599: * @see java.awt.Graphics2D#translate(int, int)
600: */
601: public void translate(int x, int y) {
602: g.translate(x, y);
603: }
604:
605: /**
606: * See comments in java.awt.Graphics2D.
607: *
608: * @see java.awt.Graphics2D#translate(double, double)
609: */
610: public void translate(double tx, double ty) {
611: g.translate(tx, ty);
612: }
613:
614: /**
615: * See comments in java.awt.Graphics2D.
616: *
617: * @see java.awt.Graphics2D#rotate(double)
618: */
619: public void rotate(double theta) {
620: g.rotate(theta);
621: }
622:
623: /**
624: * See comments in java.awt.Graphics2D.
625: *
626: * @see java.awt.Graphics2D#rotate(double, double, double)
627: */
628: public void rotate(double theta, double x, double y) {
629: g.rotate(theta, x, y);
630: }
631:
632: /**
633: * See comments in java.awt.Graphics2D.
634: *
635: * @see java.awt.Graphics2D#scale(double, double)
636: */
637: public void scale(double sx, double sy) {
638: g.scale(sx, sy);
639: }
640:
641: /**
642: * See comments in java.awt.Graphics2D.
643: *
644: * @see java.awt.Graphics2D#shear(double, double)
645: */
646: public void shear(double shx, double shy) {
647: g.shear(shx, shy);
648: }
649:
650: /**
651: * See comments in java.awt.Graphics2D.
652: *
653: * @see java.awt.Graphics2D#transform(AffineTransform)
654: */
655: public void transform(AffineTransform Tx) {
656: g.transform(Tx);
657: }
658:
659: /**
660: * See comments in java.awt.Graphics2D.
661: *
662: * @see java.awt.Graphics2D#setTransform(AffineTransform)
663: */
664: public void setTransform(AffineTransform Tx) {
665: g.setTransform(Tx);
666: }
667:
668: /**
669: * See comments in java.awt.Graphics2D.
670: *
671: * @see java.awt.Graphics2D#getTransform
672: */
673: public AffineTransform getTransform() {
674: return g.getTransform();
675: }
676:
677: /**
678: * See comments in java.awt.Graphics2D.
679: *
680: * @see java.awt.Graphics2D#getPaint
681: */
682: public Paint getPaint() {
683: return g.getPaint();
684: }
685:
686: /**
687: * See comments in java.awt.Graphics2D.
688: *
689: * @see java.awt.Graphics2D#getComposite
690: */
691: public Composite getComposite() {
692: return g.getComposite();
693: }
694:
695: /**
696: * See comments in java.awt.Graphics2D.
697: *
698: * @see java.awt.Graphics2D#setBackground(Color)
699: */
700: public void setBackground(Color color) {
701: g.setBackground(color);
702: }
703:
704: /**
705: * See comments in java.awt.Graphics2D.
706: *
707: * @see java.awt.Graphics2D#getBackground
708: */
709: public Color getBackground() {
710: return g.getBackground();
711: }
712:
713: /**
714: * See comments in java.awt.Graphics2D.
715: *
716: * @see java.awt.Graphics2D#getStroke
717: */
718: public Stroke getStroke() {
719: return g.getStroke();
720: }
721:
722: /**
723: * See comments in java.awt.Graphics2D.
724: *
725: * @see java.awt.Graphics2D#clip(Shape)
726: */
727: public void clip(Shape s) {
728: g.clip(s);
729: }
730:
731: /**
732: * See comments in java.awt.Graphics2D.
733: *
734: * @see java.awt.Graphics2D#getFontRenderContext
735: */
736: public FontRenderContext getFontRenderContext() {
737: return g.getFontRenderContext();
738: }
739: }
|