001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * BoxAlignContext.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.layout.process.valign;
030:
031: import org.jfree.report.layout.model.RenderBox;
032: import org.jfree.report.layout.model.context.BoxDefinition;
033: import org.jfree.report.layout.model.context.StaticBoxLayoutProperties;
034: import org.jfree.report.layout.text.ExtendedBaselineInfo;
035:
036: /**
037: * Creation-Date: 13.10.2006, 22:22:10
038: *
039: * @author Thomas Morgner
040: */
041: public class BoxAlignContext extends AlignContext {
042: private long insetsTop;
043: private long insetsBottom;
044: private long[] baselines;
045: private AlignContext firstChild;
046: private AlignContext lastChild;
047:
048: public BoxAlignContext(final RenderBox box) {
049: super (box);
050:
051: ExtendedBaselineInfo baselineInfo = box.getBaselineInfo();
052: if (baselineInfo == null) {
053: baselineInfo = box.getStaticBoxLayoutProperties()
054: .getNominalBaselineInfo();
055: }
056: if (baselineInfo == null) {
057: throw new IllegalStateException(
058: "A box that has no baseline info.");
059: }
060: final int dominantBaselineValue = box
061: .getStaticBoxLayoutProperties().getDominantBaseline();
062: if (dominantBaselineValue == -1) {
063: setDominantBaseline(baselineInfo.getDominantBaseline());
064: } else {
065: setDominantBaseline(dominantBaselineValue);
066: }
067:
068: final StaticBoxLayoutProperties blp = box
069: .getStaticBoxLayoutProperties();
070: final BoxDefinition bdef = box.getBoxDefinition();
071: insetsTop = blp.getBorderTop() + bdef.getPaddingTop();
072: insetsBottom = blp.getBorderBottom() + bdef.getPaddingBottom();
073:
074: baselines = (long[]) baselineInfo.getBaselines().clone();
075: final int length = baselines.length;
076: for (int i = 1; i < length; i++) {
077: baselines[i] += insetsTop;
078: }
079: baselines[ExtendedBaselineInfo.AFTER_EDGE] = baselines[ExtendedBaselineInfo.TEXT_AFTER_EDGE]
080: + insetsBottom;
081: }
082:
083: public void addChild(final AlignContext context) {
084: if (lastChild == null) {
085: firstChild = context;
086: lastChild = context;
087: return;
088: }
089: lastChild.setNext(context);
090: lastChild = context;
091: }
092:
093: public AlignContext getFirstChild() {
094: return firstChild;
095: }
096:
097: public long getInsetsTop() {
098: return insetsTop;
099: }
100:
101: public long getInsetsBottom() {
102: return insetsBottom;
103: }
104:
105: public long getBaselineDistance(final int baseline) {
106: return baselines[baseline] - baselines[getDominantBaseline()];
107: }
108:
109: public void shift(final long delta) {
110: final int length = baselines.length;
111: for (int i = 0; i < length; i++) {
112: baselines[i] += delta;
113: }
114:
115: AlignContext child = getFirstChild();
116: while (child != null) {
117: child.shift(delta);
118: child = child.getNext();
119: }
120: }
121:
122: public long getAfterEdge() {
123: return this .baselines[ExtendedBaselineInfo.AFTER_EDGE];
124: }
125:
126: public long getBeforeEdge() {
127: return this .baselines[ExtendedBaselineInfo.BEFORE_EDGE];
128: }
129:
130: public void setBeforeEdge(final long offset) {
131: this .baselines[ExtendedBaselineInfo.BEFORE_EDGE] = offset;
132: }
133:
134: public void setAfterEdge(final long offset) {
135: this.baselines[ExtendedBaselineInfo.AFTER_EDGE] = offset;
136: }
137: }
|