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