diff options
author | Peter Bernard West <pbwest@apache.org> | 2004-07-24 17:01:50 +0000 |
---|---|---|
committer | Peter Bernard West <pbwest@apache.org> | 2004-07-24 17:01:50 +0000 |
commit | ee2fdb623b7511761a95bdb200e095571f0b8c97 (patch) | |
tree | c25e7732197b1d58200db0c4abc178a699c52944 | |
parent | 2d0de6d421a82f49d8e465a53588061b9f85087a (diff) | |
download | xmlgraphics-fop-ee2fdb623b7511761a95bdb200e095571f0b8c97.tar.gz xmlgraphics-fop-ee2fdb623b7511761a95bdb200e095571f0b8c97.zip |
Added registerAreaListener() and notifyListeners to allow AllocationRectangle objects to register interest in size modifications to spaces
Override setContents() to call notifyListeners() to update any dependent AllocationRectangles
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197832 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/area/SpacesRectangle.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/area/SpacesRectangle.java b/src/java/org/apache/fop/area/SpacesRectangle.java index 3db7005dc..ca9cdad84 100644 --- a/src/java/org/apache/fop/area/SpacesRectangle.java +++ b/src/java/org/apache/fop/area/SpacesRectangle.java @@ -21,6 +21,9 @@ package org.apache.fop.area; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.util.ArrayList; + +import org.apache.fop.area.Area.AreaGeometry; /** * @author pbw @@ -52,4 +55,39 @@ public class SpacesRectangle extends AreaFrame { super(area, rect, contents, contentOffset); } + public void setContents(AreaGeometry contents) { + super.setContents(contents); + notifyListeners(this); + } + + /** Initial size of the <code>listeners</code> array */ + private static final int INITIAL_SPACES_LISTENER_SIZE = 1; + /** Array of registered <code>AreaListener</code>s */ + private ArrayList listeners = null; + /** + * Registers a listener to be notified on any change of dimension in the + * <code>spaces</code> <code>AreaFrame</code>. + * @param listener to be notified + */ + public void registerAreaListener(AreaListener listener) { + synchronized (this) { + if (listeners == null) { + listeners = new ArrayList(INITIAL_SPACES_LISTENER_SIZE); + } + listeners.add(listener); + } + } + + /** + * Notifies any registered listener of a change of dimensions in the + * <code>Rectangle2D</code> content + */ + protected void notifyListeners(Area.AreaGeometry geometry) { + for (int i = 0; i < listeners.size(); i++) { + synchronized (this) { + ((AreaListener)(listeners.get(i))).setDimensions(geometry); + } + } + } + } |