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.Polygon;
32 import java.awt.Rectangle;
33 import java.awt.Shape;
34 import java.awt.Stroke;
35 import java.awt.image.ImageObserver;
36 import java.text.AttributedCharacterIterator;
37 
38 public class DVBGraphicsImpl extends DVBGraphics {
39 
40     private Graphics2D gfx;
41 
DVBGraphicsImpl(Graphics2D gfx)42     protected DVBGraphicsImpl(Graphics2D gfx)
43     {
44         this.gfx = gfx;
45     }
46 
47     /*
48      * Graphics methods
49      */
clearRect(int x, int y, int width, int height)50     public void clearRect(int x, int y, int width, int height)
51     {
52         gfx.clearRect(x, y, width, height);
53     }
54 
clipRect(int x, int y, int width, int height)55     public void clipRect(int x, int y, int width, int height)
56     {
57         gfx.clipRect(x, y, width, height);
58     }
59 
copyArea(int x, int y, int width, int height, int dx, int dy)60     public void copyArea(int x, int y, int width, int height, int dx, int dy)
61     {
62         gfx.copyArea(x, y, width, height, dx, dy);
63     }
64 
create()65     public Graphics create()
66     {
67         return gfx.create();
68     }
69 
create(int x, int y, int width, int height)70     public Graphics create(int x, int y, int width, int height)
71     {
72         return gfx.create(x, y, width, height);
73     }
74 
dispose()75     public void dispose()
76     {
77         gfx.dispose();
78     }
79 
draw3DRect(int x, int y, int width, int height, boolean raised)80     public void draw3DRect(int x, int y, int width, int height, boolean raised)
81     {
82         gfx.draw3DRect(x, y, width, height, raised);
83     }
84 
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)85     public void drawArc(int x, int y, int width, int height, int startAngle,
86             int arcAngle)
87     {
88         gfx.drawArc(x, y, width, height, startAngle, arcAngle);
89     }
90 
drawBytes(byte[] data, int offset, int length, int x, int y)91     public void drawBytes(byte[] data, int offset, int length, int x, int y)
92     {
93         gfx.drawBytes(data, offset, length, x, y);
94     }
95 
drawChars(char[] data, int offset, int length, int x, int y)96     public void drawChars(char[] data, int offset, int length, int x, int y)
97     {
98         gfx.drawChars(data, offset, length, x, y);
99     }
100 
drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)101     public boolean drawImage(Image img, int x, int y, Color bgcolor,
102             ImageObserver observer)
103     {
104         return gfx.drawImage(img, x, y, bgcolor, observer);
105     }
106 
drawImage(Image img, int x, int y, ImageObserver observer)107     public boolean drawImage(Image img, int x, int y, ImageObserver observer)
108     {
109         return gfx.drawImage(img, x, y, observer);
110     }
111 
drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)112     public boolean drawImage(Image img, int x, int y, int width, int height,
113             Color bgcolor, ImageObserver observer)
114     {
115         return gfx.drawImage(img, x, y, width, height, bgcolor, observer);
116     }
117 
drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)118     public boolean drawImage(Image img, int x, int y, int width, int height,
119             ImageObserver observer)
120     {
121         return gfx.drawImage(img, x, y, width, height, observer);
122     }
123 
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)124     public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
125             int sx1, int sy1, int sx2, int sy2, Color bgcolor,
126             ImageObserver observer)
127     {
128         return gfx.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
129                              bgcolor, observer);
130     }
131 
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)132     public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
133             int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
134     {
135         return gfx.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
136                              observer);
137     }
138 
drawLine(int x1, int y1, int x2, int y2)139     public void drawLine(int x1, int y1, int x2, int y2)
140     {
141         gfx.drawLine(x1, y1, x2, y2);
142     }
143 
drawOval(int x, int y, int width, int height)144     public void drawOval(int x, int y, int width, int height)
145     {
146         gfx.drawOval(x, y, width, height);
147     }
148 
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)149     public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
150     {
151         gfx.drawPolygon(xPoints, yPoints, nPoints);
152     }
153 
drawPolygon(Polygon p)154     public void drawPolygon(Polygon p)
155     {
156         gfx.drawPolygon(p);
157     }
158 
drawPolyline(int[] xPoints, int[] yPoints, int nPoints)159     public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
160     {
161         gfx.drawPolyline(xPoints, yPoints, nPoints);
162     }
163 
drawRect(int x, int y, int width, int height)164     public void drawRect(int x, int y, int width, int height)
165     {
166         gfx.drawRect(x, y, width, height);
167     }
168 
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)169     public void drawRoundRect(int x, int y, int width, int height,
170             int arcWidth, int arcHeight)
171     {
172         gfx.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
173     }
174 
drawString(AttributedCharacterIterator iterator, int x, int y)175     public void drawString(AttributedCharacterIterator iterator, int x, int y)
176     {
177         gfx.drawString(iterator, x, y);
178     }
179 
drawString(String str, int x, int y)180     public void drawString(String str, int x, int y)
181     {
182         gfx.drawString(str, x, y);
183     }
184 
fill3DRect(int x, int y, int width, int height, boolean raised)185     public void fill3DRect(int x, int y, int width, int height, boolean raised)
186     {
187         gfx.fill3DRect(x, y, width, height, raised);
188     }
189 
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)190     public void fillArc(int x, int y, int width, int height, int startAngle,
191             int arcAngle)
192     {
193         gfx.fillArc(x, y, width, height, startAngle, arcAngle);
194     }
195 
fillOval(int x, int y, int width, int height)196     public void fillOval(int x, int y, int width, int height)
197     {
198         gfx.fillOval(x, y, width, height);
199     }
200 
fillPolygon(int[] xPoints, int[] yPoints, int nPoints)201     public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
202     {
203         gfx.fillPolygon(xPoints, yPoints, nPoints);
204     }
205 
fillPolygon(Polygon p)206     public void fillPolygon(Polygon p)
207     {
208         gfx.fillPolygon(p);
209     }
210 
fillRect(int x, int y, int width, int height)211     public void fillRect(int x, int y, int width, int height)
212     {
213         gfx.fillRect(x, y, width, height);
214     }
215 
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)216     public void fillRoundRect(int x, int y, int width, int height,
217             int arcWidth, int arcHeight)
218     {
219         gfx.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
220     }
221 
finalize()222     public void finalize()
223     {
224         gfx.finalize();
225     }
226 
getClip()227     public Shape getClip()
228     {
229         return gfx.getClip();
230     }
231 
getClipBounds()232     public Rectangle getClipBounds()
233     {
234         return gfx.getClipBounds();
235     }
236 
getClipBounds(Rectangle r)237     public Rectangle getClipBounds(Rectangle r)
238     {
239         return gfx.getClipBounds(r);
240     }
241 
getColor()242     public Color getColor()
243     {
244         return gfx.getColor();
245     }
246 
getFont()247     public Font getFont()
248     {
249         return gfx.getFont();
250     }
251 
getFontMetrics()252     public FontMetrics getFontMetrics()
253     {
254         return gfx.getFontMetrics();
255     }
256 
getFontMetrics(Font f)257     public FontMetrics getFontMetrics(Font f)
258     {
259         return gfx.getFontMetrics(f);
260     }
261 
hitClip(int x, int y, int width, int height)262     public boolean hitClip(int x, int y, int width, int height)
263     {
264         return gfx.hitClip(x, y, width, height);
265     }
266 
setClip(int x, int y, int width, int height)267     public void setClip(int x, int y, int width, int height)
268     {
269         gfx.setClip(x, y, width, height);
270     }
271 
setClip(Shape clip)272     public void setClip(Shape clip)
273     {
274         gfx.setClip(clip);
275     }
276 
setColor(Color c)277     public void setColor(Color c)
278     {
279         gfx.setColor(c);
280     }
281 
setFont(Font font)282     public void setFont(Font font)
283     {
284         gfx.setFont(font);
285     }
286 
setPaintMode()287     public void setPaintMode()
288     {
289         gfx.setPaintMode();
290     }
291 
setXORMode(Color c1)292     public void setXORMode(Color c1)
293     {
294         gfx.setXORMode(c1);
295     }
296 
translate(int x, int y)297     public void translate(int x, int y)
298     {
299         gfx.translate(x, y);
300     }
301 
302     /*
303      * DVBGraphics methods
304      */
getAvailableCompositeRules()305     public int[] getAvailableCompositeRules()
306     {
307         int[] rules = {
308             DVBAlphaComposite.CLEAR,
309             DVBAlphaComposite.SRC,
310             DVBAlphaComposite.SRC_OVER };
311 
312         return rules;
313     }
314 
getDVBComposite()315     public DVBAlphaComposite getDVBComposite()
316     {
317         Composite comp = gfx.getComposite();
318         if (!(comp instanceof AlphaComposite))
319             return null;
320         return DVBAlphaComposite.getInstance(
321                         ((AlphaComposite)comp).getRule(),
322                         ((AlphaComposite)comp).getAlpha());
323     }
324 
setDVBComposite(DVBAlphaComposite comp)325     public void setDVBComposite(DVBAlphaComposite comp)
326             throws UnsupportedDrawingOperationException
327     {
328         if ((comp.getRule() < DVBAlphaComposite.CLEAR) ||
329             (comp.getRule() > DVBAlphaComposite.SRC_OVER))
330             throw new UnsupportedDrawingOperationException("Unsupported composition rule");
331 
332         gfx.setComposite(AlphaComposite.getInstance(comp.getRule(), comp.getAlpha()));
333     }
334 
335     /*
336      * Graphics2D methods
337      */
getComposite()338     public Composite getComposite()
339     {
340         return gfx.getComposite();
341     }
342 
getStroke()343     public Stroke getStroke()
344     {
345         return gfx.getStroke();
346     }
347 
getDeviceConfiguration()348     public GraphicsConfiguration getDeviceConfiguration()
349     {
350         return gfx.getDeviceConfiguration();
351     }
352 
setComposite(Composite comp)353     public void setComposite(Composite comp)
354     {
355         gfx.setComposite(comp);
356     }
357 
setStroke(Stroke s)358     public void setStroke(Stroke s)
359     {
360         gfx.setStroke(s);
361     }
362 }
363