Browse Source

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
tags/Defoe_export
Peter Bernard West 20 years ago
parent
commit
ee2fdb623b
1 changed files with 38 additions and 0 deletions
  1. 38
    0
      src/java/org/apache/fop/area/SpacesRectangle.java

+ 38
- 0
src/java/org/apache/fop/area/SpacesRectangle.java View File

@@ -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);
}
}
}

}

Loading…
Cancel
Save