KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > gui > splash > OverrideGraphics2D


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.gui.splash;
22
23 import java.awt.*;
24 import java.awt.RenderingHints.Key;
25 import java.awt.font.*;
26 import java.awt.geom.AffineTransform JavaDoc;
27 import java.awt.image.*;
28 import java.awt.image.renderable.RenderableImage JavaDoc;
29 import java.text.AttributedCharacterIterator JavaDoc;
30 import java.util.Map JavaDoc;
31
32 /**
33  * This Graphics2D allows to fix some basic settings (Color, Font, Paint, Stroke,
34  * XORMode) of a delegate Graphics2D, overriding any subsequent attempts to
35  * change those settings.
36  *
37  * @author Eric Lafortune
38  */

39 class OverrideGraphics2D extends Graphics2D
40 {
41     private Graphics2D graphics;
42
43     private Color overrideColor;
44     private Font overrideFont;
45     private Paint overridePaint;
46     private Stroke overrideStroke;
47     private Color overrideXORMode;
48
49     private Color color;
50     private Font font;
51     private Paint paint;
52     private Stroke stroke;
53
54
55     /**
56      * Creates a new OverrideGraphics2D.
57      * @param graphics the delegate Graphics2D.
58      */

59     public OverrideGraphics2D(Graphics2D graphics)
60     {
61         this.graphics = graphics;
62         this.color = graphics.getColor();
63         this.font = graphics.getFont();
64         this.paint = graphics.getPaint();
65         this.stroke = graphics.getStroke();
66     }
67
68
69     /**
70      * Fixes the Color of the Graphics2D.
71      *
72      * @param color the fixed Color, or <code>null</code> to undo the fixing.
73      */

74     public void setOverrideColor(Color color)
75     {
76         this.overrideColor = color;
77         graphics.setColor(color != null ? color : this.color);
78     }
79
80     /**
81      * Fixes the Font of the Graphics2D.
82      *
83      * @param font the fixed Font, or <code>null</code> to undo the fixing.
84      */

85     public void setOverrideFont(Font font)
86     {
87         this.overrideFont = font;
88         graphics.setFont(font != null ? font : this.font);
89     }
90
91     /**
92      * Fixes the Paint of the Graphics2D.
93      *
94      * @param paint the fixed Paint, or <code>null</code> to undo the fixing.
95      */

96     public void setOverridePaint(Paint paint)
97     {
98         this.overridePaint = paint;
99         graphics.setPaint(paint != null ? paint : this.paint);
100     }
101
102     /**
103      * Fixes the Stroke of the Graphics2D.
104      *
105      * @param stroke the fixed Stroke, or <code>null</code> to undo the fixing.
106      */

107     public void setOverrideStroke(Stroke stroke)
108     {
109         this.overrideStroke = stroke;
110         graphics.setStroke(stroke != null ? stroke : this.stroke);
111     }
112
113     /**
114      * Fixes the XORMode of the Graphics2D.
115      *
116      * @param color the fixed XORMode Color, or <code>null</code> to undo the fixing.
117      */

118     public void setOverrideXORMode(Color color)
119     {
120         this.overrideXORMode = color;
121         if (color != null)
122         {
123             graphics.setXORMode(color);
124         }
125         else
126         {
127             graphics.setPaintMode();
128         }
129     }
130
131
132     // Implementations for Graphics2D.
133

134     public void setColor(Color color)
135     {
136         this.color = color;
137         if (overrideColor == null)
138         {
139             graphics.setColor(color);
140         }
141     }
142
143     public void setFont(Font font)
144     {
145         this.font = font;
146         if (overrideFont == null)
147         {
148             graphics.setFont(font);
149         }
150     }
151
152     public void setPaint(Paint paint)
153     {
154         this.paint = paint;
155         if (overridePaint == null)
156         {
157             graphics.setPaint(paint);
158         }
159     }
160
161     public void setStroke(Stroke stroke)
162     {
163         this.stroke = stroke;
164         if (overrideStroke == null)
165         {
166             graphics.setStroke(stroke);
167         }
168     }
169
170     public void setXORMode(Color color)
171     {
172         if (overrideXORMode == null)
173         {
174             graphics.setXORMode(color);
175         }
176     }
177
178     public void setPaintMode()
179     {
180         if (overrideXORMode == null)
181         {
182             graphics.setPaintMode();
183         }
184     }
185
186
187     public Color getColor()
188     {
189         return overrideColor != null ? color : graphics.getColor();
190     }
191
192     public Font getFont()
193     {
194         return overrideFont != null ? font : graphics.getFont();
195     }
196
197     public Paint getPaint()
198     {
199         return overridePaint != null ? paint : graphics.getPaint();
200     }
201
202     public Stroke getStroke()
203     {
204         return overrideStroke != null ? stroke : graphics.getStroke();
205     }
206
207
208     public Graphics create()
209     {
210         OverrideGraphics2D g = new OverrideGraphics2D((Graphics2D)graphics.create());
211         g.setOverrideColor(overrideColor);
212         g.setOverrideFont(overrideFont);
213         g.setOverridePaint(overridePaint);
214         g.setOverrideStroke(overrideStroke);
215
216         return g;
217     }
218
219     public Graphics create(int x, int y, int width, int height)
220     {
221         OverrideGraphics2D g = new OverrideGraphics2D((Graphics2D)graphics.create(x, y, width, height));
222         g.setOverrideColor(overrideColor);
223         g.setOverrideFont(overrideFont);
224         g.setOverridePaint(overridePaint);
225         g.setOverrideStroke(overrideStroke);
226
227         return g;
228     }
229
230
231     // Delegation for Graphics2D
232

233     public void addRenderingHints(Map JavaDoc hints)
234     {
235         graphics.addRenderingHints(hints);
236     }
237
238     public void clearRect(int x, int y, int width, int height)
239     {
240         graphics.clearRect(x, y, width, height);
241     }
242
243     public void clip(Shape s)
244     {
245         graphics.clip(s);
246     }
247
248     public void clipRect(int x, int y, int width, int height)
249     {
250         graphics.clipRect(x, y, width, height);
251     }
252
253     public void copyArea(int x, int y, int width, int height, int dx, int dy)
254     {
255         graphics.copyArea(x, y, width, height, dx, dy);
256     }
257
258     public void dispose()
259     {
260         graphics.dispose();
261     }
262
263     public void draw(Shape s)
264     {
265         graphics.draw(s);
266     }
267
268     public void draw3DRect(int x, int y, int width, int height, boolean raised)
269     {
270         graphics.draw3DRect(x, y, width, height, raised);
271     }
272
273     public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
274     {
275         graphics.drawArc(x, y, width, height, startAngle, arcAngle);
276     }
277
278     public void drawBytes(byte[] data, int offset, int length, int x, int y)
279     {
280         graphics.drawBytes(data, offset, length, x, y);
281     }
282
283     public void drawChars(char[] data, int offset, int length, int x, int y)
284     {
285         graphics.drawChars(data, offset, length, x, y);
286     }
287
288     public void drawGlyphVector(GlyphVector g, float x, float y)
289     {
290         graphics.drawGlyphVector(g, x, y);
291     }
292
293     public boolean drawImage(Image JavaDoc img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
294     {
295         return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
296     }
297
298     public boolean drawImage(Image JavaDoc img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
299     {
300         return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
301     }
302
303     public boolean drawImage(Image JavaDoc img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
304     {
305         return graphics.drawImage(img, x, y, width, height, bgcolor, observer);
306     }
307
308     public boolean drawImage(Image JavaDoc img, int x, int y, int width, int height, ImageObserver observer)
309     {
310         return graphics.drawImage(img, x, y, width, height, observer);
311     }
312
313     public boolean drawImage(Image JavaDoc img, int x, int y, Color bgcolor, ImageObserver observer)
314     {
315         return graphics.drawImage(img, x, y, bgcolor, observer);
316     }
317
318     public boolean drawImage(Image JavaDoc img, int x, int y, ImageObserver observer)
319     {
320         return graphics.drawImage(img, x, y, observer);
321     }
322
323     public boolean drawImage(Image JavaDoc img, AffineTransform JavaDoc xform, ImageObserver obs)
324     {
325         return graphics.drawImage(img, xform, obs);
326     }
327
328     public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
329     {
330         graphics.drawImage(img, op, x, y);
331     }
332
333     public void drawLine(int x1, int y1, int x2, int y2)
334     {
335         graphics.drawLine(x1, y1, x2, y2);
336     }
337
338     public void drawOval(int x, int y, int width, int height)
339     {
340         graphics.drawOval(x, y, width, height);
341     }
342
343     public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
344     {
345         graphics.drawPolygon(xPoints, yPoints, nPoints);
346     }
347
348     public void drawPolygon(Polygon p)
349     {
350         graphics.drawPolygon(p);
351     }
352
353     public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
354     {
355         graphics.drawPolyline(xPoints, yPoints, nPoints);
356     }
357
358     public void drawRect(int x, int y, int width, int height)
359     {
360         graphics.drawRect(x, y, width, height);
361     }
362
363     public void drawRenderableImage(RenderableImage JavaDoc img, AffineTransform JavaDoc xform)
364     {
365         graphics.drawRenderableImage(img, xform);
366     }
367
368     public void drawRenderedImage(RenderedImage img, AffineTransform JavaDoc xform)
369     {
370         graphics.drawRenderedImage(img, xform);
371     }
372
373     public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
374     {
375         graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
376     }
377
378     public void drawString(String JavaDoc s, float x, float y)
379     {
380         graphics.drawString(s, x, y);
381     }
382
383     public void drawString(String JavaDoc str, int x, int y)
384     {
385         graphics.drawString(str, x, y);
386     }
387
388     public void drawString(AttributedCharacterIterator JavaDoc iterator, float x, float y)
389     {
390         graphics.drawString(iterator, x, y);
391     }
392
393     public void drawString(AttributedCharacterIterator JavaDoc iterator, int x, int y)
394     {
395         graphics.drawString(iterator, x, y);
396     }
397
398     public boolean equals(Object JavaDoc obj)
399     {
400         return graphics.equals(obj);
401     }
402
403     public void fill(Shape s)
404     {
405         graphics.fill(s);
406     }
407
408     public void fill3DRect(int x, int y, int width, int height, boolean raised)
409     {
410         graphics.fill3DRect(x, y, width, height, raised);
411     }
412
413     public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
414     {
415         graphics.fillArc(x, y, width, height, startAngle, arcAngle);
416     }
417
418     public void fillOval(int x, int y, int width, int height)
419     {
420         graphics.fillOval(x, y, width, height);
421     }
422
423     public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
424     {
425         graphics.fillPolygon(xPoints, yPoints, nPoints);
426     }
427
428     public void fillPolygon(Polygon p)
429     {
430         graphics.fillPolygon(p);
431     }
432
433     public void fillRect(int x, int y, int width, int height)
434     {
435         graphics.fillRect(x, y, width, height);
436     }
437
438     public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
439     {
440         graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
441     }
442
443     public Color getBackground()
444     {
445         return graphics.getBackground();
446     }
447
448     public Shape getClip()
449     {
450         return graphics.getClip();
451     }
452
453     public Rectangle getClipBounds()
454     {
455         return graphics.getClipBounds();
456     }
457
458     public Rectangle getClipBounds(Rectangle r)
459     {
460         return graphics.getClipBounds(r);
461     }
462
463     public Rectangle getClipRect()
464     {
465         return graphics.getClipRect();
466     }
467
468     public Composite getComposite()
469     {
470         return graphics.getComposite();
471     }
472
473     public GraphicsConfiguration getDeviceConfiguration()
474     {
475         return graphics.getDeviceConfiguration();
476     }
477
478     public FontMetrics getFontMetrics()
479     {
480         return graphics.getFontMetrics();
481     }
482
483     public FontMetrics getFontMetrics(Font f)
484     {
485         return graphics.getFontMetrics(f);
486     }
487
488     public FontRenderContext getFontRenderContext()
489     {
490         return graphics.getFontRenderContext();
491     }
492
493     public Object JavaDoc getRenderingHint(Key hintKey)
494     {
495         return graphics.getRenderingHint(hintKey);
496     }
497
498     public RenderingHints getRenderingHints()
499     {
500         return graphics.getRenderingHints();
501     }
502
503     public AffineTransform JavaDoc getTransform()
504     {
505         return graphics.getTransform();
506     }
507
508     public int hashCode()
509     {
510         return graphics.hashCode();
511     }
512
513     public boolean hit(Rectangle rect, Shape s, boolean onStroke)
514     {
515         return graphics.hit(rect, s, onStroke);
516     }
517
518     public boolean hitClip(int x, int y, int width, int height)
519     {
520         return graphics.hitClip(x, y, width, height);
521     }
522
523     public void rotate(double theta)
524     {
525         graphics.rotate(theta);
526     }
527
528     public void rotate(double theta, double x, double y)
529     {
530         graphics.rotate(theta, x, y);
531     }
532
533     public void scale(double sx, double sy)
534     {
535         graphics.scale(sx, sy);
536     }
537
538     public void setBackground(Color color)
539     {
540         graphics.setBackground(color);
541     }
542
543     public void setClip(int x, int y, int width, int height)
544     {
545         graphics.setClip(x, y, width, height);
546     }
547
548     public void setClip(Shape clip)
549     {
550         graphics.setClip(clip);
551     }
552
553     public void setComposite(Composite comp)
554     {
555         graphics.setComposite(comp);
556     }
557
558     public void setRenderingHint(Key hintKey, Object JavaDoc hintValue)
559     {
560         graphics.setRenderingHint(hintKey, hintValue);
561     }
562
563     public void setRenderingHints(Map JavaDoc hints)
564     {
565         graphics.setRenderingHints(hints);
566     }
567
568     public void setTransform(AffineTransform JavaDoc Tx)
569     {
570         graphics.setTransform(Tx);
571     }
572
573     public void shear(double shx, double shy)
574     {
575         graphics.shear(shx, shy);
576     }
577
578     public String JavaDoc toString()
579     {
580         return graphics.toString();
581     }
582
583     public void transform(AffineTransform JavaDoc Tx)
584     {
585         graphics.transform(Tx);
586     }
587
588     public void translate(double tx, double ty)
589     {
590         graphics.translate(tx, ty);
591     }
592
593     public void translate(int x, int y)
594     {
595         graphics.translate(x, y);
596     }
597 }
598
Popular Tags