1 /*
2  * This file is part of libbluray
3  * Copyright (C) 2012  libbluray
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see
17  * <http://www.gnu.org/licenses/>.
18  */
19 
20 package org.dvb.ui;
21 
22 import java.awt.AlphaComposite;
23 import java.awt.Color;
24 import java.awt.Composite;
25 import java.awt.Font;
26 import java.awt.FontMetrics;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.GraphicsConfiguration;
30 import java.awt.Image;
31 import java.awt.Paint;
32 import java.awt.Polygon;
33 import java.awt.Rectangle;
34 import java.awt.RenderingHints;
35 import java.awt.Shape;
36 import java.awt.Stroke;
37 import java.awt.font.FontRenderContext;
38 import java.awt.font.GlyphVector;
39 import java.awt.geom.AffineTransform;
40 import java.awt.image.BufferedImage;
41 import java.awt.image.BufferedImageOp;
42 import java.awt.image.ImageObserver;
43 import java.awt.image.RenderedImage;
44 import java.awt.image.renderable.RenderableImage;
45 import java.text.AttributedCharacterIterator;
46 import java.util.Map;
47 
48 public class DVBGraphicsImpl extends DVBGraphics {
49 
50     private Graphics2D gfx;
51 
DVBGraphicsImpl(Graphics2D gfx)52     protected DVBGraphicsImpl(Graphics2D gfx)
53     {
54         this.gfx = gfx;
55     }
56 
57     /*
58      * Graphics methods
59      */
clearRect(int x, int y, int width, int height)60     public void clearRect(int x, int y, int width, int height)
61     {
62         gfx.clearRect(x, y, width, height);
63     }
64 
clipRect(int x, int y, int width, int height)65     public void clipRect(int x, int y, int width, int height)
66     {
67         gfx.clipRect(x, y, width, height);
68     }
69 
copyArea(int x, int y, int width, int height, int dx, int dy)70     public void copyArea(int x, int y, int width, int height, int dx, int dy)
71     {
72         gfx.copyArea(x, y, width, height, dx, dy);
73     }
74 
create()75     public Graphics create()
76     {
77         return gfx.create();
78     }
79 
create(int x, int y, int width, int height)80     public Graphics create(int x, int y, int width, int height)
81     {
82         return gfx.create(x, y, width, height);
83     }
84 
dispose()85     public void dispose()
86     {
87         gfx.dispose();
88     }
89 
draw3DRect(int x, int y, int width, int height, boolean raised)90     public void draw3DRect(int x, int y, int width, int height, boolean raised)
91     {
92         gfx.draw3DRect(x, y, width, height, raised);
93     }
94 
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)95     public void drawArc(int x, int y, int width, int height, int startAngle,
96             int arcAngle)
97     {
98         gfx.drawArc(x, y, width, height, startAngle, arcAngle);
99     }
100 
drawBytes(byte[] data, int offset, int length, int x, int y)101     public void drawBytes(byte[] data, int offset, int length, int x, int y)
102     {
103         gfx.drawBytes(data, offset, length, x, y);
104     }
105 
drawChars(char[] data, int offset, int length, int x, int y)106     public void drawChars(char[] data, int offset, int length, int x, int y)
107     {
108         gfx.drawChars(data, offset, length, x, y);
109     }
110 
drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)111     public boolean drawImage(Image img, int x, int y, Color bgcolor,
112             ImageObserver observer)
113     {
114         return gfx.drawImage(img, x, y, bgcolor, observer);
115     }
116 
drawImage(Image img, int x, int y, ImageObserver observer)117     public boolean drawImage(Image img, int x, int y, ImageObserver observer)
118     {
119         return gfx.drawImage(img, x, y, observer);
120     }
121 
drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)122     public boolean drawImage(Image img, int x, int y, int width, int height,
123             Color bgcolor, ImageObserver observer)
124     {
125         return gfx.drawImage(img, x, y, width, height, bgcolor, observer);
126     }
127 
drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)128     public boolean drawImage(Image img, int x, int y, int width, int height,
129             ImageObserver observer)
130     {
131         return gfx.drawImage(img, x, y, width, height, observer);
132     }
133 
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)134     public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
135             int sx1, int sy1, int sx2, int sy2, Color bgcolor,
136             ImageObserver observer)
137     {
138         return gfx.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
139                              bgcolor, observer);
140     }
141 
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)142     public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
143             int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
144     {
145         return gfx.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
146                              observer);
147     }
148 
drawLine(int x1, int y1, int x2, int y2)149     public void drawLine(int x1, int y1, int x2, int y2)
150     {
151         gfx.drawLine(x1, y1, x2, y2);
152     }
153 
drawOval(int x, int y, int width, int height)154     public void drawOval(int x, int y, int width, int height)
155     {
156         gfx.drawOval(x, y, width, height);
157     }
158 
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)159     public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
160     {
161         gfx.drawPolygon(xPoints, yPoints, nPoints);
162     }
163 
drawPolygon(Polygon p)164     public void drawPolygon(Polygon p)
165     {
166         gfx.drawPolygon(p);
167     }
168 
drawPolyline(int[] xPoints, int[] yPoints, int nPoints)169     public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
170     {
171         gfx.drawPolyline(xPoints, yPoints, nPoints);
172     }
173 
drawRect(int x, int y, int width, int height)174     public void drawRect(int x, int y, int width, int height)
175     {
176         gfx.drawRect(x, y, width, height);
177     }
178 
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)179     public void drawRoundRect(int x, int y, int width, int height,
180             int arcWidth, int arcHeight)
181     {
182         gfx.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
183     }
184 
drawString(AttributedCharacterIterator iterator, int x, int y)185     public void drawString(AttributedCharacterIterator iterator, int x, int y)
186     {
187         gfx.drawString(iterator, x, y);
188     }
189 
drawString(String str, int x, int y)190     public void drawString(String str, int x, int y)
191     {
192         gfx.drawString(str, x, y);
193     }
194 
fill3DRect(int x, int y, int width, int height, boolean raised)195     public void fill3DRect(int x, int y, int width, int height, boolean raised)
196     {
197         gfx.fill3DRect(x, y, width, height, raised);
198     }
199 
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)200     public void fillArc(int x, int y, int width, int height, int startAngle,
201             int arcAngle)
202     {
203         gfx.fillArc(x, y, width, height, startAngle, arcAngle);
204     }
205 
fillOval(int x, int y, int width, int height)206     public void fillOval(int x, int y, int width, int height)
207     {
208         gfx.fillOval(x, y, width, height);
209     }
210 
fillPolygon(int[] xPoints, int[] yPoints, int nPoints)211     public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
212     {
213         gfx.fillPolygon(xPoints, yPoints, nPoints);
214     }
215 
fillPolygon(Polygon p)216     public void fillPolygon(Polygon p)
217     {
218         gfx.fillPolygon(p);
219     }
220 
fillRect(int x, int y, int width, int height)221     public void fillRect(int x, int y, int width, int height)
222     {
223         gfx.fillRect(x, y, width, height);
224     }
225 
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)226     public void fillRoundRect(int x, int y, int width, int height,
227             int arcWidth, int arcHeight)
228     {
229         gfx.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
230     }
231 
232     /*
233     public void finalize()
234     {
235         gfx.finalize();
236     }
237     */
238 
getClip()239     public Shape getClip()
240     {
241         return gfx.getClip();
242     }
243 
getClipBounds()244     public Rectangle getClipBounds()
245     {
246         return gfx.getClipBounds();
247     }
248 
getClipBounds(Rectangle r)249     public Rectangle getClipBounds(Rectangle r)
250     {
251         return gfx.getClipBounds(r);
252     }
253 
getClipRect()254     public Rectangle getClipRect()
255     {
256         return gfx.getClipRect();
257     }
258 
getColor()259     public Color getColor()
260     {
261         return gfx.getColor();
262     }
263 
getFont()264     public Font getFont()
265     {
266         return gfx.getFont();
267     }
268 
getFontMetrics()269     public FontMetrics getFontMetrics()
270     {
271         return gfx.getFontMetrics();
272     }
273 
getFontMetrics(Font f)274     public FontMetrics getFontMetrics(Font f)
275     {
276         return gfx.getFontMetrics(f);
277     }
278 
hitClip(int x, int y, int width, int height)279     public boolean hitClip(int x, int y, int width, int height)
280     {
281         return gfx.hitClip(x, y, width, height);
282     }
283 
setClip(int x, int y, int width, int height)284     public void setClip(int x, int y, int width, int height)
285     {
286         gfx.setClip(x, y, width, height);
287     }
288 
setClip(Shape clip)289     public void setClip(Shape clip)
290     {
291         gfx.setClip(clip);
292     }
293 
setColor(Color c)294     public void setColor(Color c)
295     {
296         gfx.setColor(c);
297     }
298 
setFont(Font font)299     public void setFont(Font font)
300     {
301         gfx.setFont(font);
302     }
303 
setPaintMode()304     public void setPaintMode()
305     {
306         gfx.setPaintMode();
307     }
308 
setXORMode(Color c1)309     public void setXORMode(Color c1)
310     {
311         gfx.setXORMode(c1);
312     }
313 
translate(int x, int y)314     public void translate(int x, int y)
315     {
316         gfx.translate(x, y);
317     }
318 
319     /*
320      * DVBGraphics methods
321      */
322 
getAvailableCompositeRules()323     public int[] getAvailableCompositeRules()
324     {
325         /*
326         int[] rules = { DVBAlphaComposite.CLEAR, DVBAlphaComposite.SRC,
327                         DVBAlphaComposite.SRC_OVER, DVBAlphaComposite.DST_OVER,
328                         DVBAlphaComposite.SRC_IN, DVBAlphaComposite.DST_IN,
329                         DVBAlphaComposite.SRC_OUT, DVBAlphaComposite.DST_OUT };
330         */
331         int[] rules = {
332             DVBAlphaComposite.CLEAR,
333             DVBAlphaComposite.SRC,
334             DVBAlphaComposite.SRC_OVER };
335 
336         return rules;
337     }
338 
getDVBComposite()339     public DVBAlphaComposite getDVBComposite()
340     {
341         Composite comp = gfx.getComposite();
342         if (!(comp instanceof AlphaComposite))
343             return null;
344         return DVBAlphaComposite.getInstance(
345                         ((AlphaComposite)comp).getRule(),
346                         ((AlphaComposite)comp).getAlpha());
347     }
348 
setDVBComposite(DVBAlphaComposite comp)349     public void setDVBComposite(DVBAlphaComposite comp)
350             throws UnsupportedDrawingOperationException
351     {
352         if ((comp.getRule() < DVBAlphaComposite.CLEAR) ||
353             (comp.getRule() > DVBAlphaComposite.SRC_OVER)) {
354             org.videolan.Logger.getLogger("DVBGraphics").error("setDVBComposite() FAILED: unsupported rule " + comp.getRule());
355             throw new UnsupportedDrawingOperationException("Unsupported composition rule: " + comp.getRule());
356         }
357 
358         gfx.setComposite(AlphaComposite.getInstance(comp.getRule(), comp.getAlpha()));
359     }
360 
361     /*
362      * Graphics2D methods
363      */
addRenderingHints(Map hints)364     public void addRenderingHints(Map hints)
365     {
366         gfx.addRenderingHints(hints);
367     }
368 
clip(Shape s)369     public void clip(Shape s)
370     {
371         gfx.clip(s);
372     }
373 
draw(Shape s)374     public void draw(Shape s)
375     {
376         gfx.draw(s);
377     }
378 
drawGlyphVector(GlyphVector g, float x, float y)379     public void drawGlyphVector(GlyphVector g, float x, float y)
380     {
381         gfx.drawGlyphVector(g, x, y);
382     }
383 
drawImage(BufferedImage img, BufferedImageOp op, int x, int y)384     public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
385     {
386         gfx.drawImage(img, op, x, y);
387     }
388 
drawImage(Image img, AffineTransform xform, ImageObserver obs)389     public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
390     {
391         return gfx.drawImage(img, xform, obs);
392     }
393 
drawRenderableImage(RenderableImage img, AffineTransform xform)394     public void drawRenderableImage(RenderableImage img, AffineTransform xform)
395     {
396         gfx.drawRenderableImage(img, xform);
397     }
398 
drawRenderedImage(RenderedImage img, AffineTransform xform)399     public void drawRenderedImage(RenderedImage img, AffineTransform xform)
400     {
401         gfx.drawRenderedImage(img, xform);
402     }
403 
drawString(AttributedCharacterIterator iterator, float x, float y)404     public void drawString(AttributedCharacterIterator iterator, float x,
405             float y)
406     {
407         gfx.drawString(iterator, x, y);
408     }
409 
drawString(String str, float x, float y)410     public void drawString(String str, float x, float y)
411     {
412         gfx.drawString(str, x, y);
413     }
414 
fill(Shape s)415     public void fill(Shape s)
416     {
417         gfx.fill(s);
418     }
419 
getBackground()420     public Color getBackground()
421     {
422         return gfx.getBackground();
423     }
424 
getComposite()425     public Composite getComposite()
426     {
427         return gfx.getComposite();
428     }
429 
getDeviceConfiguration()430     public GraphicsConfiguration getDeviceConfiguration()
431     {
432         return gfx.getDeviceConfiguration();
433     }
434 
getFontRenderContext()435     public FontRenderContext getFontRenderContext()
436     {
437         return gfx.getFontRenderContext();
438     }
439 
getPaint()440     public Paint getPaint()
441     {
442         return gfx.getPaint();
443     }
444 
getRenderingHint(RenderingHints.Key hintKey)445     public Object getRenderingHint(RenderingHints.Key hintKey)
446     {
447         return gfx.getRenderingHint(hintKey);
448     }
449 
getRenderingHints()450     public RenderingHints getRenderingHints()
451     {
452         return gfx.getRenderingHints();
453     }
454 
getStroke()455     public Stroke getStroke()
456     {
457         return gfx.getStroke();
458     }
459 
getTransform()460     public AffineTransform getTransform()
461     {
462         return gfx.getTransform();
463     }
464 
hit(Rectangle rect, Shape s, boolean onStroke)465     public boolean hit(Rectangle rect, Shape s, boolean onStroke)
466     {
467         return gfx.hit(rect, s, onStroke);
468     }
469 
rotate(double theta)470     public void rotate(double theta)
471     {
472         gfx.rotate(theta);
473     }
474 
rotate(double theta, double x, double y)475     public void rotate(double theta, double x, double y)
476     {
477         gfx.rotate(theta, x, y);
478     }
479 
scale(double sx, double sy)480     public void scale(double sx, double sy)
481     {
482         gfx.scale(sx, sy);
483     }
484 
setBackground(Color color)485     public void setBackground(Color color)
486     {
487         gfx.setBackground(color);
488     }
489 
setComposite(Composite comp)490     public void setComposite(Composite comp)
491     {
492         gfx.setComposite(comp);
493     }
494 
setPaint(Paint paint)495     public void setPaint(Paint paint)
496     {
497         gfx.setPaint(paint);
498     }
499 
setRenderingHint(RenderingHints.Key hintKey, Object hintValue)500     public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
501     {
502         gfx.setRenderingHint(hintKey, hintValue);
503     }
504 
setRenderingHints(Map hints)505     public void setRenderingHints(Map hints)
506     {
507         gfx.setRenderingHints(hints);
508     }
509 
setStroke(Stroke s)510     public void setStroke(Stroke s)
511     {
512         gfx.setStroke(s);
513     }
514 
setTransform(AffineTransform Tx)515     public void setTransform(AffineTransform Tx)
516     {
517         gfx.setTransform(Tx);
518     }
519 
shear(double shx, double shy)520     public void shear(double shx, double shy)
521     {
522         gfx.shear(shx, shy);
523     }
524 
transform(AffineTransform Tx)525     public void transform(AffineTransform Tx)
526     {
527         gfx.transform(Tx);
528     }
529 
translate(double tx, double ty)530     public void translate(double tx, double ty)
531     {
532         gfx.translate(tx, ty);
533     }
534 }
535