From a95df6db4e5e7713733e427b2a3b95126e4927c3 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Wed, 12 May 2004 11:15:29 +0000 Subject: [PATCH] Changed internal method synchronization to sync on this Added ArrayList listeners Realized registerAreaListener Added notifyListeners git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197589 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/area/Area.java | 75 ++++++++++++++++++++------ 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/src/java/org/apache/fop/area/Area.java b/src/java/org/apache/fop/area/Area.java index 5942e9991..7b42456cd 100644 --- a/src/java/org/apache/fop/area/Area.java +++ b/src/java/org/apache/fop/area/Area.java @@ -19,6 +19,7 @@ package org.apache.fop.area; import java.awt.geom.Rectangle2D; +import java.util.ArrayList; import org.apache.fop.datastructs.Node; import org.apache.fop.fo.FONode; @@ -83,7 +84,8 @@ public class Area extends AreaNode implements Cloneable { * @param pageSeq through which this area was generated * @param generatedBy the given FONode generated this * @param parent Node of this - * @param sync the object on which this area is synchronized + * @param sync the object on which this area is synchronized for tree + * operations. */ public Area( Rectangle2D area, @@ -100,7 +102,8 @@ public class Area extends AreaNode implements Cloneable { * @param pageSeq through which this area was generated * @param generatedBy the given FONode generated this * @param parent Node of this - * @param sync the object on which this area is synchronized + * @param sync the object on which this area is synchronized for tree + * operations. * @throws IndexOutOfBoundsException */ public Area( @@ -158,10 +161,11 @@ public class Area extends AreaNode implements Cloneable { * of the Rectangle2D representing this area. If no * Rectangle2D exists, a zero-dimensioned default is first * created, then the zero value is returned. + * N.B. The method is synchronized only on this object. * @return the block-progression-dimension in points */ public double getBPDimPts() { - synchronized (sync) { + synchronized (this) { if (area == null) { return 0; } @@ -194,10 +198,11 @@ public class Area extends AreaNode implements Cloneable { * Rectangle2D representing this area. If no * Rectangle2D exists, a zero-dimensioned default is first * created, then the value is applied. + * N.B. The method is synchronized only on this object. * @param pts block-progression-dimension to set, in points */ public void setBPDimPts(double pts) { - synchronized (sync) { + synchronized (this) { if (area == null) { area = new Rectangle2D.Double(); } @@ -214,10 +219,11 @@ public class Area extends AreaNode implements Cloneable { /** * Gets the block-progression-dimension maximum value, * in millipoints + * N.B. The method is synchronized only on this object. * @return the block-progression-dimension maximum value */ public Integer getBPDimMax() { - synchronized (sync) { + synchronized (this) { return bPDimMax; } } @@ -225,11 +231,12 @@ public class Area extends AreaNode implements Cloneable { /** * Sets the block-progression-dimension maximum value, * in millipoints + * N.B. The method is synchronized only on this object. * @param dimMax block-progression-dimension maximum value * to set */ public void setBPDimMax(Integer dimMax) { - synchronized (sync) { + synchronized (this) { bPDimMax = dimMax; } } @@ -237,10 +244,11 @@ public class Area extends AreaNode implements Cloneable { /** * Gets the block-progression-dimension minimum value, * in millipoints + * N.B. The method is synchronized only on this object. * @return the block-progression-dimension minimum value */ public Integer getBPDimMin() { - synchronized (sync) { + synchronized (this) { return bPDimMin; } } @@ -248,11 +256,12 @@ public class Area extends AreaNode implements Cloneable { /** * Sets the block-progression-dimension minimum value, * in millipoints + * N.B. The method is synchronized only on this object. * @param dimMin block-progression-dimension minimum value * to set */ public void setBPDimMin(Integer dimMin) { - synchronized (sync) { + synchronized (this) { bPDimMin = dimMin; } } @@ -263,6 +272,7 @@ public class Area extends AreaNode implements Cloneable { * dimension of the Rectangle2D representing this area. If no * Rectangle2D exists, a zero-dimensioned default is first * created, then the zero value is returned. + * N.B. The method is synchronized only on this object. * @return the inline-progression-dimension in millipoints */ public int getIPDim() { @@ -275,10 +285,11 @@ public class Area extends AreaNode implements Cloneable { * of the Rectangle2D representing this area. If no * Rectangle2D exists, a zero-dimensioned default is first * created, then the zero value is returned. + * N.B. The method is synchronized only on this object. * @return the inline-progression-dimension in points */ public double getIPDimPts() { - synchronized (sync) { + synchronized (this) { if (area == null) { area = new Rectangle2D.Double(); } @@ -309,10 +320,11 @@ public class Area extends AreaNode implements Cloneable { * dimension of the Rectangle2D representing this area. If no * Rectangle2D exists, a zero-dimensioned default is first * created, then the value is applied. + * N.B. The method is synchronized only on this object. * @param pts inline-progression-dimension to set, in points */ public void setIPDimPts(double pts) { - synchronized (sync) { + synchronized (this) { if (area == null) { area = new Rectangle2D.Double(); } @@ -327,10 +339,11 @@ public class Area extends AreaNode implements Cloneable { /** * Gets the inline-progression-dimension maximum value, * in millipoints + * N.B. The method is synchronized only on this object. * @return the inline-progression-dimension maximum value */ public Integer getIPDimMax() { - synchronized(sync) { + synchronized(this) { return iPDimMax; } } @@ -338,11 +351,12 @@ public class Area extends AreaNode implements Cloneable { /** * Sets the inline-progression-dimension maximum value, * in millipoints + * N.B. The method is synchronized only on this object. * @param dimMax inline-progression-dimension maximum value * to set */ public void setIPDimMax(Integer dimMax) { - synchronized (sync) { + synchronized (this) { iPDimMax = dimMax; } } @@ -350,10 +364,11 @@ public class Area extends AreaNode implements Cloneable { /** * Gets the inline-progression-dimension mimimum value, * in millipoints + * N.B. The method is synchronized only on this object. * @return the inline-progression-dimension minimum value */ public Integer getIPDimMin() { - synchronized (sync) { + synchronized (this) { return iPDimMin; } } @@ -361,16 +376,44 @@ public class Area extends AreaNode implements Cloneable { /** * Sets the inline-progression-dimension minimum value, * in millipoints + * N.B. The method is synchronized only on this object. * @param dimMin inline-progression-dimension minimum value * to set */ public void setIPDimMin(Integer dimMin) { - synchronized (sync) { + synchronized (this) { iPDimMin = dimMin; } } - public void registerAreaListener(AreaListener area) { - + /** Initial size of the listeners array */ + private static final int INITIAL_LISTENER_SIZE = 4; + /** Array of registered AreaListeners */ + private ArrayList listeners = null; + /** + * Registers a listener to be notified on any change of dimension in the + * Rectangle2D area + * @param listener to be notified + */ + public void registerAreaListener(AreaListener listener) { + synchronized (this) { + if (listeners == null) { + listeners = new ArrayList(INITIAL_LISTENER_SIZE); + } + listeners.add(listener); + } } + + /** + * Notifies any registered listener of a change of dimensions in the + * Rectangle2D area + */ + protected void notifyListeners() { + for (int i = 0; i < listeners.size(); i++) { + synchronized (this) { + ((AreaListener)(listeners.get(i))).setDimensions(area); + } + } + } + } -- 2.39.5