001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: BreakElement.java 554689 2007-07-09 15:50:21Z vhennebert $ */
019:
020: package org.apache.fop.layoutmgr;
021:
022: import java.util.List;
023:
024: import org.apache.fop.fo.Constants;
025:
026: /**
027: * This class represents an unresolved break possibility.
028: */
029: public class BreakElement extends UnresolvedListElement {
030:
031: private int penaltyWidth;
032: private int penaltyValue;
033: private int breakClass = -1;
034: private List pendingBeforeMarks;
035: private List pendingAfterMarks;
036:
037: /**
038: * Main constructor
039: * @param position the Position instance needed by the addAreas stage of the LMs.
040: * @param penaltyValue the penalty value for the penalty element to be constructed
041: * @param context the layout context which contains the pending conditional elements
042: */
043: public BreakElement(Position position, int penaltyValue,
044: LayoutContext context) {
045: this (position, 0, penaltyValue, -1, context);
046: }
047:
048: /**
049: * Constructor for hard breaks.
050: * @param position the Position instance needed by the addAreas stage of the LMs.
051: * @param penaltyWidth the penalty width
052: * @param penaltyValue the penalty value for the penalty element to be constructed
053: * @param breakClass the break class of this penalty (one of the break-* constants)
054: * @param context the layout context which contains the pending conditional elements
055: */
056: public BreakElement(Position position, int penaltyWidth,
057: int penaltyValue, int breakClass, LayoutContext context) {
058: super (position);
059: this .penaltyWidth = penaltyWidth;
060: this .penaltyValue = penaltyValue;
061: this .breakClass = breakClass;
062: this .pendingBeforeMarks = context.getPendingBeforeMarks();
063: this .pendingAfterMarks = context.getPendingAfterMarks();
064: }
065:
066: /** @see org.apache.fop.layoutmgr.UnresolvedListElement#isConditional() */
067: public boolean isConditional() {
068: return false; //Does not really apply here
069: }
070:
071: /** @see org.apache.fop.layoutmgr.ListElement#isPenalty() */
072: /*
073: public boolean isPenalty() {
074: return true; //not entirely true but a BreakElement will generate a penalty later
075: }*/
076:
077: /** @return the penalty width */
078: public int getPenaltyWidth() {
079: return this .penaltyWidth;
080: }
081:
082: /** @return the penalty value */
083: public int getPenaltyValue() {
084: return this .penaltyValue;
085: }
086:
087: /**
088: * Sets the penalty value.
089: * @param p the new penalty value
090: */
091: public void setPenaltyValue(int p) {
092: this .penaltyValue = p;
093: }
094:
095: /** @see org.apache.fop.layoutmgr.ListElement#isForcedBreak() */
096: public boolean isForcedBreak() {
097: return penaltyValue == -KnuthElement.INFINITE;
098: }
099:
100: /** @return the break class of this penalty (one of the break-* constants) */
101: public int getBreakClass() {
102: return breakClass;
103: }
104:
105: /**
106: * Sets the break class.
107: * @param breakClass the new break class
108: */
109: public void setBreakClass(int breakClass) {
110: this .breakClass = breakClass;
111: }
112:
113: /** @return the pending border and padding elements at the before edge */
114: public List getPendingBeforeMarks() {
115: return this .pendingBeforeMarks;
116: }
117:
118: /** @return the pending border and padding elements at the after edge */
119: public List getPendingAfterMarks() {
120: return this .pendingAfterMarks;
121: }
122:
123: /** @see java.lang.Object#toString() */
124: public String toString() {
125: StringBuffer sb = new StringBuffer();
126: sb.append("BreakPossibility[p:");
127: sb.append(this .penaltyValue);
128: if (isForcedBreak()) {
129: sb.append(" (forced break");
130: switch (getBreakClass()) {
131: case Constants.EN_PAGE:
132: sb.append(", page");
133: break;
134: case Constants.EN_COLUMN:
135: sb.append(", column");
136: break;
137: case Constants.EN_EVEN_PAGE:
138: sb.append(", even page");
139: break;
140: case Constants.EN_ODD_PAGE:
141: sb.append(", odd page");
142: break;
143: default:
144: }
145: sb.append(")");
146: }
147: sb.append("; w:");
148: sb.append(penaltyWidth);
149: sb.append("]");
150: return sb.toString();
151: }
152:
153: }
|