KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > layoutmgr > BreakElement


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: BreakElement.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.layoutmgr;
21
22 import java.util.List JavaDoc;
23
24 import org.apache.fop.fo.Constants;
25
26 /**
27  * This class represents an unresolved break possibility.
28  */

29 public class BreakElement extends UnresolvedListElement {
30
31     private int penaltyWidth;
32     private int penaltyValue;
33     private int breakClass = -1;
34     private List JavaDoc pendingBeforeMarks;
35     private List JavaDoc pendingAfterMarks;
36     
37     /**
38      * Main constructor
39      * @param position the Position instance needed by the addAreas stage of the LMs.
40      * @param penaltyValue the penalty value for the penalty element to be constructed
41      * @param context the layout context which contains the pending conditional elements
42      */

43     public BreakElement(Position position, int penaltyValue, LayoutContext context) {
44         this(position, 0, penaltyValue, -1, context);
45     }
46     
47     /**
48      * Constructor for hard breaks.
49      * @param position the Position instance needed by the addAreas stage of the LMs.
50      * @param penaltyWidth the penalty width
51      * @param penaltyValue the penalty value for the penalty element to be constructed
52      * @param breakClass the break class of this penalty (one of the break-* constants)
53      * @param context the layout context which contains the pending conditional elements
54      */

55     public BreakElement(Position position, int penaltyWidth, int penaltyValue,
56                 int breakClass, LayoutContext context) {
57         super(position);
58         this.penaltyWidth = penaltyWidth;
59         this.penaltyValue = penaltyValue;
60         this.breakClass = breakClass;
61         this.pendingBeforeMarks = context.getPendingBeforeMarks();
62         this.pendingAfterMarks = context.getPendingAfterMarks();
63     }
64     
65     /** @see org.apache.fop.layoutmgr.UnresolvedListElement#isConditional() */
66     public boolean isConditional() {
67         return false; //Does not really apply here
68
}
69
70     /** @see org.apache.fop.layoutmgr.ListElement#isPenalty() */
71     /*
72     public boolean isPenalty() {
73         return true; //not entirely true but a BreakElement will generate a penalty later
74     }*/

75
76     /** @return the penalty width */
77     public int getPenaltyWidth() {
78         return this.penaltyWidth;
79     }
80     
81     /** @return the penalty value */
82     public int getPenaltyValue() {
83         return this.penaltyValue;
84     }
85     
86     /**
87      * Sets the penalty value.
88      * @param p the new penalty value
89      */

90     public void setPenaltyValue(int p) {
91         this.penaltyValue = p;
92     }
93     
94     /** @see org.apache.fop.layoutmgr.ListElement#isForcedBreak() */
95     public boolean isForcedBreak() {
96         return penaltyValue == -KnuthElement.INFINITE;
97     }
98     
99     /** @return the break class of this penalty (one of the break-* constants) */
100     public int getBreakClass() {
101         return breakClass;
102     }
103     
104     /**
105      * Sets the break class.
106      * @param breakClass the new break class
107      */

108     public void setBreakClass(int breakClass) {
109         this.breakClass = breakClass;
110     }
111     
112     /** @return the pending border and padding elements at the before edge */
113     public List JavaDoc getPendingBeforeMarks() {
114         return this.pendingBeforeMarks;
115     }
116     
117     /** @return the pending border and padding elements at the after edge */
118     public List JavaDoc getPendingAfterMarks() {
119         return this.pendingAfterMarks;
120     }
121     
122     /** @see java.lang.Object#toString() */
123     public String JavaDoc toString() {
124         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
125         sb.append("BreakPossibility[p:");
126         sb.append(this.penaltyValue);
127         if (isForcedBreak()) {
128             sb.append(" (forced break");
129             switch (getBreakClass()) {
130             case Constants.EN_PAGE:
131                 sb.append(", page");
132                 break;
133             case Constants.EN_COLUMN:
134                 sb.append(", column");
135                 break;
136             case Constants.EN_EVEN_PAGE:
137                 sb.append(", even page");
138                 break;
139             case Constants.EN_ODD_PAGE:
140                 sb.append(", odd page");
141                 break;
142             default:
143             }
144             sb.append(")");
145         }
146         sb.append("]");
147         return sb.toString();
148     }
149
150 }
151
Popular Tags