KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > ColorPaintContext


1 /*
2  * @(#)ColorPaintContext.java 1.22 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8
9
10 package java.awt;
11
12 import java.awt.image.ColorModel JavaDoc;
13 import java.awt.image.Raster JavaDoc;
14 import java.awt.image.WritableRaster JavaDoc;
15 import sun.awt.image.IntegerComponentRaster;
16 import java.util.Arrays JavaDoc;
17
18 class ColorPaintContext implements PaintContext JavaDoc {
19     int color;
20     WritableRaster JavaDoc savedTile;
21
22     protected ColorPaintContext(int color, ColorModel JavaDoc cm) {
23         this.color = color;
24     }
25
26     public void dispose() {
27     }
28
29     public ColorModel JavaDoc getColorModel() {
30     return ColorModel.getRGBdefault();
31     }
32
33     public synchronized Raster JavaDoc getRaster(int x, int y, int w, int h) {
34     WritableRaster JavaDoc 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