1. /*
  2. * @(#)WritableRenderedImage.java 1.13 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /* ****************************************************************
  8. ******************************************************************
  9. ******************************************************************
  10. *** COPYRIGHT (c) Eastman Kodak Company, 1997
  11. *** As an unpublished work pursuant to Title 17 of the United
  12. *** States Code. All rights reserved.
  13. ******************************************************************
  14. ******************************************************************
  15. ******************************************************************/
  16. package java.awt.image;
  17. import java.awt.Point;
  18. /**
  19. * WriteableRenderedImage is a common interface for objects which
  20. * contain or can produce image data in the form of Rasters and
  21. * which can be modified and/or written over. The image
  22. * data may be stored/produced as a single tile or a regular array
  23. * of tiles.
  24. * <p>
  25. * WritableRenderedImage provides notification to other interested
  26. * objects when a tile is checked out for writing (via the
  27. * getWritableTile method) and when the last writer of a particular
  28. * tile relinquishes its access (via a call to releaseWritableTile).
  29. * Additionally, it allows any caller to determine whether any tiles
  30. * are currently checked out (via hasTileWriters), and to obtain a
  31. * list of such tiles (via getWritableTileIndices, in the form of a Vector
  32. * of Point objects).
  33. * <p>
  34. * Objects wishing to be notified of changes in tile writability must
  35. * implement the TileObserver interface, and are added by a
  36. * call to addTileObserver. Multiple calls to
  37. * addTileObserver for the same object will result in multiple
  38. * notifications. An existing observer may reduce its notifications
  39. * by calling removeTileObserver; if the observer had no
  40. * notifications the operation is a no-op.
  41. * <p>
  42. * It is necessary for a WritableRenderedImage to ensure that
  43. * notifications occur only when the first writer acquires a tile and
  44. * the last writer releases it.
  45. *
  46. */
  47. public interface WritableRenderedImage extends RenderedImage
  48. {
  49. /**
  50. * Adds an observer. If the observer is already present,
  51. * it will receive multiple notifications.
  52. */
  53. public void addTileObserver(TileObserver to);
  54. /**
  55. * Removes an observer. If the observer was not registered,
  56. * nothing happens. If the observer was registered for multiple
  57. * notifications, it will now be registered for one fewer.
  58. */
  59. public void removeTileObserver(TileObserver to);
  60. /**
  61. * Checks out a tile for writing.
  62. *
  63. * The WritableRenderedImage is responsible for notifying all
  64. * of its TileObservers when a tile goes from having
  65. * no writers to having one writer.
  66. *
  67. * @param tileX the X index of the tile.
  68. * @param tileY the Y index of the tile.
  69. */
  70. public WritableRaster getWritableTile(int tileX, int tileY);
  71. /**
  72. * Relinquishes the right to write to a tile. If the caller
  73. * continues to write to the tile, the results are undefined.
  74. * Calls to this method should only appear in matching pairs
  75. * with calls to getWritableTile; any other use will lead
  76. * to undefined results.
  77. *
  78. * The WritableRenderedImage is responsible for notifying all of
  79. * its TileObservers when a tile goes from having one writer
  80. * to having no writers.
  81. *
  82. * @param tileX the X index of the tile.
  83. * @param tileY the Y index of the tile.
  84. */
  85. public void releaseWritableTile(int tileX, int tileY);
  86. /**
  87. * Returns whether a tile is currently checked out for writing.
  88. *
  89. * @param tileX the X index of the tile.
  90. * @param tileY the Y index of the tile.
  91. */
  92. public boolean isTileWritable(int tileX, int tileY);
  93. /**
  94. * Returns an array of Point objects indicating which tiles
  95. * are checked out for writing. Returns null if none are
  96. * checked out.
  97. */
  98. public Point[] getWritableTileIndices();
  99. /**
  100. * Returns whether any tile is checked out for writing.
  101. * Semantically equivalent to (getWritableTileIndices() != null).
  102. */
  103. public boolean hasTileWriters();
  104. /**
  105. * Sets a rect of the image to the contents of the Raster r, which is
  106. * assumed to be in the same coordinate space as the WritableRenderedImage.
  107. * The operation is clipped to the bounds of the WritableRenderedImage.
  108. */
  109. public void setData(Raster r);
  110. }