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 java.awt;
21 
22 import java.awt.image.ImageObserver;
23 
24 public class BDWindowGraphics extends BDGraphics {
25     private BDRootWindow window;
26 
BDWindowGraphics(BDWindowGraphics g)27     BDWindowGraphics(BDWindowGraphics g) {
28         super(g);
29         window = g.window;
30     }
31 
BDWindowGraphics(BDRootWindow window)32     public BDWindowGraphics(BDRootWindow window) {
33         super(window);
34         this.window = window;
35     }
36 
create()37     public Graphics create() {
38         return new BDWindowGraphics(this);
39     }
40 
clearRect(int x, int y, int w, int h)41     public void clearRect(int x, int y, int w, int h) {
42         if (window == null) return;
43         synchronized (window) {
44             super.clearRect(x, y, w, h);
45             window.notifyChanged();
46         }
47     }
48 
fillRect(int x, int y, int w, int h)49     public void fillRect(int x, int y, int w, int h) {
50         if (window == null) return;
51         synchronized (window) {
52             super.fillRect(x, y, w, h);
53             window.notifyChanged();
54         }
55     }
56 
drawRect(int x, int y, int w, int h)57     public void drawRect(int x, int y, int w, int h) {
58         if (window == null) return;
59         synchronized (window) {
60             super.drawRect(x, y, w, h);
61             window.notifyChanged();
62         }
63     }
64 
drawLine(int x1, int y1, int x2, int y2)65     public void drawLine(int x1, int y1, int x2, int y2) {
66         if (window == null) return;
67         synchronized (window) {
68             super.drawLine(x1, y1, x2, y2);
69             window.notifyChanged();
70         }
71     }
72 
copyArea(int x, int y, int w, int h, int dx, int dy)73     public void copyArea(int x, int y, int w, int h, int dx, int dy) {
74         if (window == null) return;
75         synchronized (window) {
76             super.copyArea(x, y, w, h, dx, dy);
77             window.notifyChanged();
78         }
79     }
80 
drawPolyline(int xPoints[], int yPoints[], int nPoints)81     public void drawPolyline(int xPoints[], int yPoints[], int nPoints) {
82         if (window == null) return;
83         synchronized (window) {
84             super.drawPolyline(xPoints, yPoints, nPoints);
85             window.notifyChanged();
86         }
87     }
88 
drawPolygon(int xPoints[], int yPoints[], int nPoints)89     public void drawPolygon(int xPoints[], int yPoints[], int nPoints) {
90         if (window == null) return;
91         synchronized (window) {
92             super.drawPolygon(xPoints, yPoints, nPoints);
93             window.notifyChanged();
94         }
95     }
96 
fillPolygon(int xPoints[], int yPoints[], int nPoints)97     public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
98         if (window == null) return;
99         synchronized (window) {
100             super.fillPolygon(xPoints, yPoints, nPoints);
101             window.notifyChanged();
102         }
103     }
104 
drawOval(int x, int y, int w, int h)105     public void drawOval(int x, int y, int w, int h) {
106         if (window == null) return;
107         synchronized (window) {
108             super.drawOval(x, y, w, h);
109             window.notifyChanged();
110         }
111     }
112 
fillOval(int x, int y, int w, int h)113     public void fillOval(int x, int y, int w, int h) {
114         if (window == null) return;
115         synchronized (window) {
116             super.fillOval(x, y, w, h);
117             window.notifyChanged();
118         }
119     }
120 
drawArc(int x, int y, int w, int h, int startAngle, int endAngle)121     public void drawArc(int x, int y, int w, int h, int startAngle, int endAngle) {
122         if (window == null) return;
123         synchronized (window) {
124             super.drawArc(x, y, w, h, startAngle, endAngle);
125             window.notifyChanged();
126         }
127     }
128 
fillArc(int x, int y, int w, int h, int startAngle, int endAngle)129     public void fillArc(int x, int y, int w, int h, int startAngle, int endAngle) {
130         if (window == null) return;
131         synchronized (window) {
132             super.fillArc(x, y, w, h, startAngle, endAngle);
133             window.notifyChanged();
134         }
135     }
136 
drawRoundRect(int x, int y, int w, int h, int arcWidth, int arcHeight)137     public void drawRoundRect(int x, int y, int w, int h, int arcWidth, int arcHeight) {
138         if (window == null) return;
139         synchronized (window) {
140             super.drawRoundRect(x, y, w, h, arcWidth, arcHeight);
141             window.notifyChanged();
142         }
143     }
144 
fillRoundRect(int x, int y, int w, int h, int arcWidth, int arcHeight)145     public void fillRoundRect(int x, int y, int w, int h, int arcWidth, int arcHeight) {
146         if (window == null) return;
147         synchronized (window) {
148             super.fillRoundRect(x, y, w, h, arcWidth, arcHeight);
149             window.notifyChanged();
150         }
151     }
152 
drawStringN(long ftFace, String string, int x, int y, int rgb)153     protected void drawStringN(long ftFace, String string, int x, int y, int rgb) {
154         if (window == null) return;
155         synchronized (window) {
156             super.drawStringN(ftFace, string, x, y, rgb);
157             window.notifyChanged();
158         }
159     }
160 
dispose()161     public void dispose() {
162         super.dispose();
163         window = null;
164     }
165 
drawImageN(Image img, int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, boolean flipX, boolean flipY, Color bg, ImageObserver observer)166     public boolean drawImageN(Image img,
167         int dx, int dy, int dw, int dh,
168         int sx, int sy, int sw, int sh,
169         boolean flipX, boolean flipY,
170         Color bg, ImageObserver observer) {
171 
172         if (window == null) return true;
173 
174         synchronized (window) {
175             boolean complete = super.drawImageN(
176                 img, dx, dy, dw, dh, sx, sy, sw, sh,
177                 flipX, flipY,
178                 bg, observer);
179             if (complete) {
180                 window.notifyChanged();
181             }
182             return complete;
183         }
184     }
185 }
186