1. /*
  2. * @(#)WritableRenderedImage.java 1.18 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. *** 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. * @param to the specified <code>TileObserver</code>
  53. */
  54. public void addTileObserver(TileObserver to);
  55. /**
  56. * Removes an observer. If the observer was not registered,
  57. * nothing happens. If the observer was registered for multiple
  58. * notifications, it will now be registered for one fewer.
  59. * @param to the specified <code>TileObserver</code>
  60. */
  61. public void removeTileObserver(TileObserver to);
  62. /**
  63. * Checks out a tile for writing.
  64. *
  65. * The WritableRenderedImage is responsible for notifying all
  66. * of its TileObservers when a tile goes from having
  67. * no writers to having one writer.
  68. *
  69. * @param tileX the X index of the tile.
  70. * @param tileY the Y index of the tile.
  71. * @return a writable tile.
  72. */
  73. public WritableRaster getWritableTile(int tileX, int tileY);
  74. /**
  75. * Relinquishes the right to write to a tile. If the caller
  76. * continues to write to the tile, the results are undefined.
  77. * Calls to this method should only appear in matching pairs
  78. * with calls to getWritableTile; any other use will lead
  79. * to undefined results.
  80. *
  81. * The WritableRenderedImage is responsible for notifying all of
  82. * its TileObservers when a tile goes from having one writer
  83. * to having no writers.
  84. *
  85. * @param tileX the X index of the tile.
  86. * @param tileY the Y index of the tile.
  87. */
  88. public void releaseWritableTile(int tileX, int tileY);
  89. /**
  90. * Returns whether a tile is currently checked out for writing.
  91. *
  92. * @param tileX the X index of the tile.
  93. * @param tileY the Y index of the tile.
  94. * @return <code>true</code> if specified tile is checked out
  95. * for writing; <code>false</code> otherwise.
  96. */
  97. public boolean isTileWritable(int tileX, int tileY);
  98. /**
  99. * Returns an array of Point objects indicating which tiles
  100. * are checked out for writing. Returns null if none are
  101. * checked out.
  102. * @return an array containing the locations of tiles that are
  103. * checked out for writing.
  104. */
  105. public Point[] getWritableTileIndices();
  106. /**
  107. * Returns whether any tile is checked out for writing.
  108. * Semantically equivalent to (getWritableTileIndices() != null).
  109. * @return <code>true</code> if any tiles are checked out for
  110. * writing; <code>false</code> otherwise.
  111. */
  112. public boolean hasTileWriters();
  113. /**
  114. * Sets a rect of the image to the contents of the Raster r, which is
  115. * assumed to be in the same coordinate space as the WritableRenderedImage.
  116. * The operation is clipped to the bounds of the WritableRenderedImage.
  117. * @param r the specified <code>Raster</code>
  118. */
  119. public void setData(Raster r);
  120. }