Skip to content

Commit 6e2917e

Browse files
committed
adds Color paint context
1 parent c88ef9d commit 6e2917e

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

sources/net.sf.j2s.java.core/src/java/awt/ColorPaintContext.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@
3131
package java.awt;
3232

3333
import java.awt.image.ColorModel;
34+
import java.awt.image.Raster;
35+
import java.awt.image.WritableRaster;
36+
import java.util.Arrays;
37+
38+
import sun.awt.image.IntegerComponentRaster;
3439

3540
class ColorPaintContext implements PaintContext {
3641
int color;
37-
// WritableRaster savedTile;
42+
WritableRaster savedTile;
3843

3944
protected ColorPaintContext(int color, ColorModel cm) {
4045
this.color = color;
@@ -65,20 +70,21 @@ public ColorModel getColorModel() {
6570
return ColorModel.getRGBdefault();
6671
}
6772

68-
// public synchronized Raster getRaster(int x, int y, int w, int h) {
69-
// WritableRaster t = savedTile;
70-
//
71-
// if (t == null || w > t.getWidth() || h > t.getHeight()) {
72-
// t = getColorModel().createCompatibleWritableRaster(w, h);
73-
// IntegerComponentRaster icr = (IntegerComponentRaster) t;
74-
// Arrays.fill(icr.getDataStorage(), color);
75-
// // Note - markDirty is probably unnecessary since icr is brand new
76-
// icr.markDirty();
77-
// if (w <= 64 && h <= 64) {
78-
// savedTile = t;
79-
// }
80-
// }
81-
//
82-
// return t;
83-
// }
73+
@Override
74+
public synchronized Raster getRaster(int x, int y, int w, int h) {
75+
WritableRaster t = savedTile;
76+
77+
if (t == null || w > t.getWidth() || h > t.getHeight()) {
78+
t = getColorModel().createCompatibleWritableRaster(w, h);
79+
IntegerComponentRaster icr = (IntegerComponentRaster) t;
80+
Arrays.fill(icr.getDataStorage(), color);
81+
// Note - markDirty is probably unnecessary since icr is brand new
82+
icr.markDirty();
83+
if (w <= 64 && h <= 64) {
84+
savedTile = t;
85+
}
86+
}
87+
88+
return t;
89+
}
8490
}

0 commit comments

Comments
 (0)