View Javadoc
1   /*
2    * Copyright (c) 2005, The JUNG Authors
3    * All rights reserved.
4    *
5    * This software is open-source under the BSD license; see either "license.txt"
6    * or https://github.com/jrtom/jung/blob/master/LICENSE for a description.
7    *
8    * Created on Jul 11, 2005
9    */
10  
11  package edu.uci.ics.jung.visualization.transform.shape;
12  
13  import java.awt.Color;
14  import java.awt.Composite;
15  import java.awt.Font;
16  import java.awt.FontMetrics;
17  import java.awt.Graphics;
18  import java.awt.Graphics2D;
19  import java.awt.GraphicsConfiguration;
20  import java.awt.Image;
21  import java.awt.Paint;
22  import java.awt.Polygon;
23  import java.awt.Rectangle;
24  import java.awt.RenderingHints;
25  import java.awt.Shape;
26  import java.awt.Stroke;
27  import java.awt.RenderingHints.Key;
28  import java.awt.font.FontRenderContext;
29  import java.awt.font.GlyphVector;
30  import java.awt.geom.AffineTransform;
31  import java.awt.image.BufferedImage;
32  import java.awt.image.BufferedImageOp;
33  import java.awt.image.ImageObserver;
34  import java.awt.image.RenderedImage;
35  import java.awt.image.renderable.RenderableImage;
36  import java.text.AttributedCharacterIterator;
37  import java.util.Map;
38  
39  
40  /**
41   * a complete wrapping of Graphics2D, useful as a base class.
42   * Contains no additional methods, other than direct calls
43   * to the delegate.
44   * 
45   * @see GraphicsDecorator as an example subclass that
46   * adds additional methods.
47   * 
48   * @author Tom Nelson 
49   *
50   *
51   */
52  public class Graphics2DWrapper {
53      
54      protected Graphics2D delegate;
55      
56      public Graphics2DWrapper() {
57          this(null);
58      }
59      public Graphics2DWrapper(Graphics2D delegate) {
60          this.delegate = delegate;
61      }
62      
63      public void setDelegate(Graphics2D delegate) {
64          this.delegate = delegate;
65      }
66      
67      public Graphics2D getDelegate() {
68          return delegate;
69      }
70  
71      /* (non-Javadoc)
72       * @see java.awt.Graphics2D#addRenderingHints(java.util.Map)
73       */
74      public void addRenderingHints(Map<?,?> hints) {
75          delegate.addRenderingHints(hints);
76      }
77  
78      /* (non-Javadoc)
79       * @see java.awt.Graphics#clearRect(int, int, int, int)
80       */
81      public void clearRect(int x, int y, int width, int height) {
82          delegate.clearRect(x, y, width, height);
83      }
84  
85      /* (non-Javadoc)
86       * @see java.awt.Graphics2D#clip(java.awt.Shape)
87       */
88      public void clip(Shape s) {
89          delegate.clip(s);
90      }
91  
92      /* (non-Javadoc)
93       * @see java.awt.Graphics#clipRect(int, int, int, int)
94       */
95      public void clipRect(int x, int y, int width, int height) {
96          delegate.clipRect(x, y, width, height);
97      }
98  
99      /* (non-Javadoc)
100      * @see java.awt.Graphics#copyArea(int, int, int, int, int, int)
101      */
102     public void copyArea(int x, int y, int width, int height, int dx, int dy) {
103         delegate.copyArea(x, y, width, height, dx, dy);
104     }
105 
106     /* (non-Javadoc)
107      * @see java.awt.Graphics#create()
108      */
109     public Graphics create() {
110         return delegate.create();
111     }
112 
113     /* (non-Javadoc)
114      * @see java.awt.Graphics#create(int, int, int, int)
115      */
116     public Graphics create(int x, int y, int width, int height) {
117         return delegate.create(x, y, width, height);
118     }
119 
120     /* (non-Javadoc)
121      * @see java.awt.Graphics#dispose()
122      */
123     public void dispose() {
124         delegate.dispose();
125     }
126 
127     /* (non-Javadoc)
128      * @see java.awt.Graphics2D#draw(java.awt.Shape)
129      */
130     public void draw(Shape s) {
131         delegate.draw(s);
132     }
133 
134     /* (non-Javadoc)
135      * @see java.awt.Graphics2D#draw3DRect(int, int, int, int, boolean)
136      */
137     public void draw3DRect(int x, int y, int width, int height, boolean raised) {
138         delegate.draw3DRect(x, y, width, height, raised);
139     }
140 
141     /* (non-Javadoc)
142      * @see java.awt.Graphics#drawArc(int, int, int, int, int, int)
143      */
144     public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
145         delegate.drawArc(x, y, width, height, startAngle, arcAngle);
146     }
147 
148     /* (non-Javadoc)
149      * @see java.awt.Graphics#drawBytes(byte[], int, int, int, int)
150      */
151     public void drawBytes(byte[] data, int offset, int length, int x, int y) {
152         delegate.drawBytes(data, offset, length, x, y);
153     }
154 
155     /* (non-Javadoc)
156      * @see java.awt.Graphics#drawChars(char[], int, int, int, int)
157      */
158     public void drawChars(char[] data, int offset, int length, int x, int y) {
159         delegate.drawChars(data, offset, length, x, y);
160     }
161 
162     /* (non-Javadoc)
163      * @see java.awt.Graphics2D#drawGlyphVector(java.awt.font.GlyphVector, float, float)
164      */
165     public void drawGlyphVector(GlyphVector g, float x, float y) {
166         delegate.drawGlyphVector(g, x, y);
167     }
168 
169     /* (non-Javadoc)
170      * @see java.awt.Graphics2D#drawImage(java.awt.image.BufferedImage, java.awt.image.BufferedImageOp, int, int)
171      */
172     public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
173         delegate.drawImage(img, op, x, y);
174     }
175 
176     /* (non-Javadoc)
177      * @see java.awt.Graphics2D#drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver)
178      */
179     public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
180         return delegate.drawImage(img, xform, obs);
181     }
182 
183     /* (non-Javadoc)
184      * @see java.awt.Graphics#drawImage(java.awt.Image, int, int, java.awt.Color, java.awt.image.ImageObserver)
185      */
186     public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
187         return delegate.drawImage(img, x, y, bgcolor, observer);
188     }
189 
190     /* (non-Javadoc)
191      * @see java.awt.Graphics#drawImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
192      */
193     public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
194         return delegate.drawImage(img, x, y, observer);
195     }
196 
197     /* (non-Javadoc)
198      * @see java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, java.awt.Color, java.awt.image.ImageObserver)
199      */
200     public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
201         return delegate.drawImage(img, x, y, width, height, bgcolor, observer);
202     }
203 
204     /* (non-Javadoc)
205      * @see java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, java.awt.image.ImageObserver)
206      */
207     public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
208         return delegate.drawImage(img, x, y, width, height, observer);
209     }
210 
211     /* (non-Javadoc)
212      * @see java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.Color, java.awt.image.ImageObserver)
213      */
214     public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) {
215         return delegate.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
216     }
217 
218     /* (non-Javadoc)
219      * @see java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)
220      */
221     public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
222         return delegate.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
223     }
224     
225     /* (non-Javadoc)
226      * @see java.awt.Graphics#drawLine(int, int, int, int)
227      */
228     public void drawLine(int x1, int y1, int x2, int y2) {
229         delegate.drawLine(x1, y1, x2, y2);
230     }
231 
232     /* (non-Javadoc)
233      * @see java.awt.Graphics#drawOval(int, int, int, int)
234      */
235     public void drawOval(int x, int y, int width, int height) {
236         delegate.drawOval(x, y, width, height);
237     }
238 
239     /* (non-Javadoc)
240      * @see java.awt.Graphics#drawPolygon(int[], int[], int)
241      */
242     public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
243         delegate.drawPolygon(xPoints, yPoints, nPoints);
244     }
245 
246     /* (non-Javadoc)
247      * @see java.awt.Graphics#drawPolygon(java.awt.Polygon)
248      */
249     public void drawPolygon(Polygon p) {
250         delegate.drawPolygon(p);
251     }
252 
253     /* (non-Javadoc)
254      * @see java.awt.Graphics#drawPolyline(int[], int[], int)
255      */
256     public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
257         delegate.drawPolyline(xPoints, yPoints, nPoints);
258     }
259 
260     /* (non-Javadoc)
261      * @see java.awt.Graphics#drawRect(int, int, int, int)
262      */
263     public void drawRect(int x, int y, int width, int height) {
264         delegate.drawRect(x, y, width, height);
265     }
266 
267     /* (non-Javadoc)
268      * @see java.awt.Graphics2D#drawRenderableImage(java.awt.image.renderable.RenderableImage, java.awt.geom.AffineTransform)
269      */
270     public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
271         delegate.drawRenderableImage(img, xform);
272     }
273 
274     /* (non-Javadoc)
275      * @see java.awt.Graphics2D#drawRenderedImage(java.awt.image.RenderedImage, java.awt.geom.AffineTransform)
276      */
277     public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
278         delegate.drawRenderedImage(img, xform);
279     }
280 
281     /* (non-Javadoc)
282      * @see java.awt.Graphics#drawRoundRect(int, int, int, int, int, int)
283      */
284     public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
285         delegate.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
286     }
287 
288     /* (non-Javadoc)
289      * @see java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, float, float)
290      */
291     public void drawString(AttributedCharacterIterator iterator, float x, float y) {
292         delegate.drawString(iterator, x, y);
293     }
294 
295     /* (non-Javadoc)
296      * @see java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, int, int)
297      */
298     public void drawString(AttributedCharacterIterator iterator, int x, int y) {
299         delegate.drawString(iterator, x, y);
300     }
301 
302     /* (non-Javadoc)
303      * @see java.awt.Graphics2D#drawString(java.lang.String, float, float)
304      */
305     public void drawString(String s, float x, float y) {
306         delegate.drawString(s, x, y);
307     }
308 
309     /* (non-Javadoc)
310      * @see java.awt.Graphics2D#drawString(java.lang.String, int, int)
311      */
312     public void drawString(String str, int x, int y) {
313         delegate.drawString(str, x, y);
314     }
315 
316     /* (non-Javadoc)
317      * @see java.lang.Object#equals(java.lang.Object)
318      */
319     public boolean equals(Object obj) {
320         return delegate.equals(obj);
321     }
322 
323     /* (non-Javadoc)
324      * @see java.awt.Graphics2D#fill(java.awt.Shape)
325      */
326     public void fill(Shape s) {
327         delegate.fill(s);
328     }
329 
330     /* (non-Javadoc)
331      * @see java.awt.Graphics2D#fill3DRect(int, int, int, int, boolean)
332      */
333     public void fill3DRect(int x, int y, int width, int height, boolean raised) {
334         delegate.fill3DRect(x, y, width, height, raised);
335     }
336 
337     /* (non-Javadoc)
338      * @see java.awt.Graphics#fillArc(int, int, int, int, int, int)
339      */
340     public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
341         delegate.fillArc(x, y, width, height, startAngle, arcAngle);
342     }
343 
344     /* (non-Javadoc)
345      * @see java.awt.Graphics#fillOval(int, int, int, int)
346      */
347     public void fillOval(int x, int y, int width, int height) {
348         delegate.fillOval(x, y, width, height);
349     }
350 
351     /* (non-Javadoc)
352      * @see java.awt.Graphics#fillPolygon(int[], int[], int)
353      */
354     public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
355         delegate.fillPolygon(xPoints, yPoints, nPoints);
356     }
357 
358     /* (non-Javadoc)
359      * @see java.awt.Graphics#fillPolygon(java.awt.Polygon)
360      */
361     public void fillPolygon(Polygon p) {
362         delegate.fillPolygon(p);
363     }
364 
365     /* (non-Javadoc)
366      * @see java.awt.Graphics#fillRect(int, int, int, int)
367      */
368     public void fillRect(int x, int y, int width, int height) {
369         delegate.fillRect(x, y, width, height);
370     }
371 
372     /* (non-Javadoc)
373      * @see java.awt.Graphics#fillRoundRect(int, int, int, int, int, int)
374      */
375     public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
376         delegate.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
377     }
378 
379     /* (non-Javadoc)
380      * @see java.awt.Graphics#finalize()
381      */
382     public void finalize() {
383         delegate.finalize();
384     }
385 
386     /* (non-Javadoc)
387      * @see java.awt.Graphics2D#getBackground()
388      */
389     public Color getBackground() {
390         return delegate.getBackground();
391     }
392 
393     /* (non-Javadoc)
394      * @see java.awt.Graphics#getClip()
395      */
396     public Shape getClip() {
397         return delegate.getClip();
398     }
399 
400     /* (non-Javadoc)
401      * @see java.awt.Graphics#getClipBounds()
402      */
403     public Rectangle getClipBounds() {
404         return delegate.getClipBounds();
405     }
406 
407     /* (non-Javadoc)
408      * @see java.awt.Graphics#getClipBounds(java.awt.Rectangle)
409      */
410     public Rectangle getClipBounds(Rectangle r) {
411         return delegate.getClipBounds(r);
412     }
413 
414     /* (non-Javadoc)
415      * @see java.awt.Graphics#getClipRect()
416      */
417     @SuppressWarnings("deprecation")
418     public Rectangle getClipRect() {
419         return delegate.getClipRect();
420     }
421 
422     /* (non-Javadoc)
423      * @see java.awt.Graphics#getColor()
424      */
425     public Color getColor() {
426         return delegate.getColor();
427     }
428 
429     /* (non-Javadoc)
430      * @see java.awt.Graphics2D#getComposite()
431      */
432     public Composite getComposite() {
433         return delegate.getComposite();
434     }
435 
436     /* (non-Javadoc)
437      * @see java.awt.Graphics2D#getDeviceConfiguration()
438      */
439     public GraphicsConfiguration getDeviceConfiguration() {
440         return delegate.getDeviceConfiguration();
441     }
442 
443     /* (non-Javadoc)
444      * @see java.awt.Graphics#getFont()
445      */
446     public Font getFont() {
447         return delegate.getFont();
448     }
449 
450     /* (non-Javadoc)
451      * @see java.awt.Graphics#getFontMetrics()
452      */
453     public FontMetrics getFontMetrics() {
454         return delegate.getFontMetrics();
455     }
456 
457     /* (non-Javadoc)
458      * @see java.awt.Graphics#getFontMetrics(java.awt.Font)
459      */
460     public FontMetrics getFontMetrics(Font f) {
461         return delegate.getFontMetrics(f);
462     }
463 
464     /* (non-Javadoc)
465      * @see java.awt.Graphics2D#getFontRenderContext()
466      */
467     public FontRenderContext getFontRenderContext() {
468         return delegate.getFontRenderContext();
469     }
470 
471     /* (non-Javadoc)
472      * @see java.awt.Graphics2D#getPaint()
473      */
474     public Paint getPaint() {
475         return delegate.getPaint();
476     }
477 
478     /* (non-Javadoc)
479      * @see java.awt.Graphics2D#getRenderingHint(java.awt.RenderingHints.Key)
480      */
481     public Object getRenderingHint(Key hintKey) {
482         return delegate.getRenderingHint(hintKey);
483     }
484 
485     /* (non-Javadoc)
486      * @see java.awt.Graphics2D#getRenderingHints()
487      */
488     public RenderingHints getRenderingHints() {
489         return delegate.getRenderingHints();
490     }
491 
492     /* (non-Javadoc)
493      * @see java.awt.Graphics2D#getStroke()
494      */
495     public Stroke getStroke() {
496         return delegate.getStroke();
497     }
498 
499     /* (non-Javadoc)
500      * @see java.awt.Graphics2D#getTransform()
501      */
502     public AffineTransform getTransform() {
503         return delegate.getTransform();
504     }
505 
506     /* (non-Javadoc)
507      * @see java.lang.Object#hashCode()
508      */
509     public int hashCode() {
510         return delegate.hashCode();
511     }
512 
513     /* (non-Javadoc)
514      * @see java.awt.Graphics2D#hit(java.awt.Rectangle, java.awt.Shape, boolean)
515      */
516     public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
517         return delegate.hit(rect, s, onStroke);
518     }
519 
520     /* (non-Javadoc)
521      * @see java.awt.Graphics#hitClip(int, int, int, int)
522      */
523     public boolean hitClip(int x, int y, int width, int height) {
524         return delegate.hitClip(x, y, width, height);
525     }
526 
527     /* (non-Javadoc)
528      * @see java.awt.Graphics2D#rotate(double, double, double)
529      */
530     public void rotate(double theta, double x, double y) {
531         delegate.rotate(theta, x, y);
532     }
533 
534     /* (non-Javadoc)
535      * @see java.awt.Graphics2D#rotate(double)
536      */
537     public void rotate(double theta) {
538         delegate.rotate(theta);
539     }
540 
541     /* (non-Javadoc)
542      * @see java.awt.Graphics2D#scale(double, double)
543      */
544     public void scale(double sx, double sy) {
545         delegate.scale(sx, sy);
546     }
547 
548     /* (non-Javadoc)
549      * @see java.awt.Graphics2D#setBackground(java.awt.Color)
550      */
551     public void setBackground(Color color) {
552         delegate.setBackground(color);
553     }
554 
555     /* (non-Javadoc)
556      * @see java.awt.Graphics#setClip(int, int, int, int)
557      */
558     public void setClip(int x, int y, int width, int height) {
559         delegate.setClip(x, y, width, height);
560     }
561 
562     /* (non-Javadoc)
563      * @see java.awt.Graphics#setClip(java.awt.Shape)
564      */
565     public void setClip(Shape clip) {
566         delegate.setClip(clip);
567     }
568 
569     /* (non-Javadoc)
570      * @see java.awt.Graphics#setColor(java.awt.Color)
571      */
572     public void setColor(Color c) {
573         delegate.setColor(c);
574     }
575 
576     /* (non-Javadoc)
577      * @see java.awt.Graphics2D#setComposite(java.awt.Composite)
578      */
579     public void setComposite(Composite comp) {
580         delegate.setComposite(comp);
581     }
582 
583     /* (non-Javadoc)
584      * @see java.awt.Graphics#setFont(java.awt.Font)
585      */
586     public void setFont(Font font) {
587         delegate.setFont(font);
588     }
589 
590     /* (non-Javadoc)
591      * @see java.awt.Graphics2D#setPaint(java.awt.Paint)
592      */
593     public void setPaint(Paint paint) {
594         delegate.setPaint(paint);
595     }
596 
597     /* (non-Javadoc)
598      * @see java.awt.Graphics#setPaintMode()
599      */
600     public void setPaintMode() {
601         delegate.setPaintMode();
602     }
603 
604     /* (non-Javadoc)
605      * @see java.awt.Graphics2D#setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)
606      */
607     public void setRenderingHint(Key hintKey, Object hintValue) {
608         delegate.setRenderingHint(hintKey, hintValue);
609     }
610 
611     /* (non-Javadoc)
612      * @see java.awt.Graphics2D#setRenderingHints(java.util.Map)
613      */
614     public void setRenderingHints(Map<?,?> hints) {
615         delegate.setRenderingHints(hints);
616     }
617 
618     /* (non-Javadoc)
619      * @see java.awt.Graphics2D#setStroke(java.awt.Stroke)
620      */
621     public void setStroke(Stroke s) {
622         delegate.setStroke(s);
623     }
624 
625     /* (non-Javadoc)
626      * @see java.awt.Graphics2D#setTransform(java.awt.geom.AffineTransform)
627      */
628     public void setTransform(AffineTransform Tx) {
629         delegate.setTransform(Tx);
630     }
631 
632     /* (non-Javadoc)
633      * @see java.awt.Graphics#setXORMode(java.awt.Color)
634      */
635     public void setXORMode(Color c1) {
636         delegate.setXORMode(c1);
637     }
638 
639     /* (non-Javadoc)
640      * @see java.awt.Graphics2D#shear(double, double)
641      */
642     public void shear(double shx, double shy) {
643         delegate.shear(shx, shy);
644     }
645 
646     /* (non-Javadoc)
647      * @see java.awt.Graphics#toString()
648      */
649     public String toString() {
650         return delegate.toString();
651     }
652 
653     /* (non-Javadoc)
654      * @see java.awt.Graphics2D#transform(java.awt.geom.AffineTransform)
655      */
656     public void transform(AffineTransform Tx) {
657         delegate.transform(Tx);
658     }
659 
660     /* (non-Javadoc)
661      * @see java.awt.Graphics2D#translate(double, double)
662      */
663     public void translate(double tx, double ty) {
664         delegate.translate(tx, ty);
665     }
666 
667     /* (non-Javadoc)
668      * @see java.awt.Graphics2D#translate(int, int)
669      */
670     public void translate(int x, int y) {
671         delegate.translate(x, y);
672     }
673 
674 }