1 7 8 9 10 package java.awt; 11 12 import java.awt.image.ColorModel ; 13 import java.awt.image.Raster ; 14 import java.awt.image.WritableRaster ; 15 import sun.awt.image.IntegerComponentRaster; 16 import java.util.Arrays ; 17 18 class ColorPaintContext implements PaintContext { 19 int color; 20 WritableRaster savedTile; 21 22 protected ColorPaintContext(int color, ColorModel cm) { 23 this.color = color; 24 } 25 26 public void dispose() { 27 } 28 29 public ColorModel getColorModel() { 30 return ColorModel.getRGBdefault(); 31 } 32 33 public synchronized Raster getRaster(int x, int y, int w, int h) { 34 WritableRaster t = savedTile; 35 36 if (t == null || w > t.getWidth() || h > t.getHeight()) { 37 t = getColorModel().createCompatibleWritableRaster(w, h); 38 IntegerComponentRaster icr = (IntegerComponentRaster) t; 39 int[] array = icr.getDataStorage(); 40 Arrays.fill(icr.getDataStorage(), color); 41 if (w <= 64 && h <= 64) { 42 savedTile = t; 43 } 44 } 45 46 return t; 47 } 48 } 49 | Popular Tags |