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