diff options
-rw-r--r-- | src/java/org/apache/fop/area/AreaFrame.java | 169 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/BorderRectangle.java | 54 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/ContentRectangle.java | 68 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/PaddingRectangle.java | 54 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/SpacesRectangle.java | 54 |
5 files changed, 399 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/area/AreaFrame.java b/src/java/org/apache/fop/area/AreaFrame.java new file mode 100644 index 000000000..0cb091ca2 --- /dev/null +++ b/src/java/org/apache/fop/area/AreaFrame.java @@ -0,0 +1,169 @@ +/* + * + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Created on 5/06/2004 + * $Id$ + */ +package org.apache.fop.area; + +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +/** + * <code>AreaFrame</code> is the basic type for the geometry of a rectangle + * enclosing another rectangle, e.g., a padding rectangle. + * @author pbw + * @version $Revision$ $Name$ + */ +public class AreaFrame extends Rectangle2D.Double { + + /** + * + */ + private AreaFrame() {} + + /** + * Instantiates a new framing rectangle with the given origin point, the + * given width and height, the given content rectangle, and the given + * offset from the origin of the framing rectangle to the origin of the + * content rectangle. + * @param x x-value of the origin of the framing rectangle in user space + * units + * @param y y-value of the origin of the framing rectangle in user space + * units + * @param w width of the framing rectangle in user space units + * @param h height of the framing rectangle in user space units + * @param contents the framed rectangle + * @param contentOffset the offset to the origin point of the framed + * rectangle from the origin point of <code>this</code> framing rectangle. + */ + public AreaFrame(double x, double y, double w, double h, + Rectangle2D contents, Point2D contentOffset) { + super(x, y, w, h); + this.contents = contents; + this.contentOffset = contentOffset; + } + + /** The framed rectangle */ + private Rectangle2D contents = null; + /** The offset from <code>this</code> origin to the origin of the framed + * rectangle */ + private Point2D contentOffset = null; + + /** + * Instantiates a new framing rectangle from the given rectangle, given + * contents, and given offset from the origin of the framing rectangle to + * the origin of the framed rectangle. The dimensions and location of the + * given rectangle are copied into the dimensions of the new framing + * rectangle. + * @param rect the framing rectangle + * @param contents the framed rectangle + * @param contentOffset offset from origin of the framing rectangle to the + * origin of the framed rectangle + */ + public AreaFrame( + Rectangle2D rect, Rectangle2D contents, Point2D contentOffset) { + this(rect.getX(), rect.getY(), + rect.getWidth(), rect.getHeight(), + contents, contentOffset); + } + + /** + * Sets the contents rectangle. The dimensions of <code>this</code> are + * adjusted to the difference between the current framed contents and + * the new framed contents. The offset is not affected. + * @param contents the new framed contents + */ + public void setContents(Rectangle2D contents) { + setRect(getX(), getY(), + getWidth() + (contents.getWidth() - this.contents.getWidth()), + getHeight() + (contents.getWidth() - this.contents.getWidth())); + contents = this.contents; + } + + /** + * Sets the offset from the origin of <code>this</code> to the origin of + * the framed contents rectangle. The dimensions of the framed contents + * are not affected, but the dimensions of <code>this</code> are changed + * by the difference between the current offset and the new offset in the + * X and Y axes. + * @param offset the new offset to the framed rectangle + */ + public void setContentsOffset(Point2D offset) { + setStart(offset.getX()); + setBefore(offset.getY()); + contentOffset = offset; + } + + /** + * Sets the before edge width of the frame. The <code>contents</code> size + * is unaffected, but the size of the frame (<code>this</code>) will + * change. The height will vary by the difference between the previous and + * new before edge. The <code>contentOffset</code> will also change by the + * same amount. Note that the origin of this frame (<code>getX(), + * getY()</code>) will not change. + * @param before + */ + public void setBefore(double before) { + double diff = before - contentOffset.getY(); + setRect(getX(), getY(), + getWidth(), getHeight() + diff); + contentOffset.setLocation(contentOffset.getX(), before); + } + + /** + * Sets the start edge width of the frame. The <code>contents</code> size + * is unaffected, but the size of the frame (<code>this</code>) will + * change. The width will vary by the difference between the previous and + * new start edge. The <code>contentOffset</code> will also change by the + * same amount. Note that the origin of this frame (<code>getX(), + * getY()</code>) will not change. + * @param start + */ + public void setStart(double start) { + double diff = start - contentOffset.getY(); + setRect(getX(), getY(), + getWidth() + diff, getHeight()); + contentOffset.setLocation(start, contentOffset.getX()); + } + + /** + * Sets the after edge width of the frame. The <code>contents</code> size + * and the <code>contentOffset</code> are unaffected, but the size of the + * frame (<code>this</code>) will change. The height will vary by the + * difference between the previous and new after edge. Note that the + * origin of this frame (<code>getX(), getY()</code>) will not change. + * @param after + */ + public void setAfter(double after) { + double diff = after - (getY() - contentOffset.getY() - contents.getY()); + setRect(getX(), getY(), getWidth(), getHeight() + diff); + } + + /** + * Sets the end edge width of the frame. The <code>contents</code> size + * and the <code>contentOffset</code> are unaffected, but the size of the + * frame (<code>this</code>) will change. The width will vary by the + * difference between the previous and new end edge. Note that the + * origin of this frame (<code>getX(), getY()</code>) will not change. + * @param end + */ + public void setEnd(double end) { + double diff = end - (getX() - contentOffset.getX() - contents.getX()); + setRect(getX(), getY(), getWidth() + diff, getHeight()); + } + +} diff --git a/src/java/org/apache/fop/area/BorderRectangle.java b/src/java/org/apache/fop/area/BorderRectangle.java new file mode 100644 index 000000000..e8fbfaea7 --- /dev/null +++ b/src/java/org/apache/fop/area/BorderRectangle.java @@ -0,0 +1,54 @@ +/* + * + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Created on 7/06/2004 + * $Id$ + */ +package org.apache.fop.area; + +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +/** + * @author pbw + * @version $Revision$ $Name$ + */ +public class BorderRectangle extends AreaFrame { + + /** + * @param x + * @param y + * @param w + * @param h + * @param contents + * @param contentOffset + */ + public BorderRectangle(double x, double y, double w, double h, + Rectangle2D contents, Point2D contentOffset) { + super(x, y, w, h, contents, contentOffset); + } + + /** + * @param rect + * @param contents + * @param contentOffset + */ + public BorderRectangle(Rectangle2D rect, Rectangle2D contents, + Point2D contentOffset) { + super(rect, contents, contentOffset); + } + +} diff --git a/src/java/org/apache/fop/area/ContentRectangle.java b/src/java/org/apache/fop/area/ContentRectangle.java new file mode 100644 index 000000000..c42e06a26 --- /dev/null +++ b/src/java/org/apache/fop/area/ContentRectangle.java @@ -0,0 +1,68 @@ +/* + * + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Created on 6/06/2004 + * $Id$ + */ +package org.apache.fop.area; + +import java.awt.geom.Rectangle2D.Double; + +/** + * Defines the <i>content rectangle</i> of an area. It is the central class + * in the management of the layout geometry of areas. The other generated + * rectangular areas are accessed through and defined in terms of this area. + * @author pbw + * @version $Revision$ $Name$ + */ +public class ContentRectangle extends Double { + + /** + * Creates an empty contents object. + */ + public ContentRectangle() { + super(); + } + + /** + * Creates a contents object from the given origin (<code>x, y</code>) + * width (<code>w</code>) and height (<code>h</code>). + * @param x x-origin + * @param y y-origin + * @param w width + * @param h height + */ + public ContentRectangle(double x, double y, double w, double h) { + super(x, y, w, h); + } + + private PaddingRectangle padding = null; + private BorderRectangle borders = null; + private SpacesRectangle spaces = null; + + public void setPadding(PaddingRectangle padding) { + this.padding = padding; + } + + public void setBorders(BorderRectangle borders) { + this.borders = borders; + } + + public void setSpaces(SpacesRectangle spaces) { + this.spaces = spaces; + } + +} diff --git a/src/java/org/apache/fop/area/PaddingRectangle.java b/src/java/org/apache/fop/area/PaddingRectangle.java new file mode 100644 index 000000000..fd0de4e7b --- /dev/null +++ b/src/java/org/apache/fop/area/PaddingRectangle.java @@ -0,0 +1,54 @@ +/* + * + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Created on 6/06/2004 + * $Id$ + */ +package org.apache.fop.area; + +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +/** + * @author pbw + * @version $Revision$ $Name$ + */ +public class PaddingRectangle extends AreaFrame { + + /** + * @param x + * @param y + * @param w + * @param h + * @param contents + * @param contentOffset + */ + public PaddingRectangle(double x, double y, double w, double h, + Rectangle2D contents, Point2D contentOffset) { + super(x, y, w, h, contents, contentOffset); + } + + /** + * @param rect + * @param contents + * @param contentOffset + */ + public PaddingRectangle(Rectangle2D rect, Rectangle2D contents, + Point2D contentOffset) { + super(rect, contents, contentOffset); + } + +} diff --git a/src/java/org/apache/fop/area/SpacesRectangle.java b/src/java/org/apache/fop/area/SpacesRectangle.java new file mode 100644 index 000000000..0148fbb0e --- /dev/null +++ b/src/java/org/apache/fop/area/SpacesRectangle.java @@ -0,0 +1,54 @@ +/* + * + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Created on 7/06/2004 + * $Id$ + */ +package org.apache.fop.area; + +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +/** + * @author pbw + * @version $Revision$ $Name$ + */ +public class SpacesRectangle extends AreaFrame { + + /** + * @param x + * @param y + * @param w + * @param h + * @param contents + * @param contentOffset + */ + public SpacesRectangle(double x, double y, double w, double h, + Rectangle2D contents, Point2D contentOffset) { + super(x, y, w, h, contents, contentOffset); + } + + /** + * @param rect + * @param contents + * @param contentOffset + */ + public SpacesRectangle(Rectangle2D rect, Rectangle2D contents, + Point2D contentOffset) { + super(rect, contents, contentOffset); + } + +} |