1. /*
  2. * @(#)ColorPaintContext.java 1.18 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt;
  11. import java.awt.image.ColorModel;
  12. import java.awt.image.Raster;
  13. import java.awt.image.WritableRaster;
  14. class ColorPaintContext implements PaintContext {
  15. int color;
  16. ColorModel cm;
  17. WritableRaster savedTile;
  18. Object c;
  19. protected ColorPaintContext(int color, ColorModel cm) {
  20. this.color = color;
  21. this.cm = cm;
  22. c = cm.getDataElements(color, null);
  23. }
  24. public void dispose() {
  25. }
  26. public ColorModel getColorModel() {
  27. return cm;
  28. }
  29. public synchronized Raster getRaster(int x, int y, int w, int h) {
  30. WritableRaster t = savedTile;
  31. if (t == null || w > t.getWidth() || h > t.getHeight()) {
  32. t = cm.createCompatibleWritableRaster(w, h);
  33. for (int i = 0 ; i < h ; i++) {
  34. for (int j = 0 ; j < w ; j++) {
  35. t.setDataElements(j, i, c);
  36. }
  37. }
  38. if (w <= 64 && h <= 64) {
  39. savedTile = t;
  40. }
  41. }
  42. return t;
  43. }
  44. }