KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > inline > InlineArea


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: InlineArea.java 462812 2006-10-11 14:19:28Z spepping $ */
19
20 package org.apache.fop.area.inline;
21
22 import org.apache.fop.area.Area;
23 import org.apache.fop.area.LineArea;
24 import org.apache.fop.area.Trait;
25
26 /**
27  * Inline Area
28  * This area is for all inline areas that can be placed
29  * in a line area.
30  */

31 public class InlineArea extends Area {
32     
33     /**
34      * this class stores information about potential adjustments
35      * that can be used in order to re-compute adjustments when a
36      * page-number or a page-number-citation is resolved
37      */

38     protected class InlineAdjustingInfo {
39         /** stretch of the inline area */
40         protected int availableStretch;
41         /** shrink of the inline area */
42         protected int availableShrink;
43         /** total adjustment (= ipd - width of fixed elements) */
44         protected int adjustment;
45         
46         /**
47          * Constructor
48          *
49          * @param stretch the available space for stretching
50          * @param shrink the available space for shrinking
51          * @param adj space adjustment type
52          */

53         protected InlineAdjustingInfo(int stretch, int shrink, int adj) {
54             availableStretch = stretch;
55             availableShrink = shrink;
56             adjustment = adj;
57         }
58         
59         /**
60          * Apply the variation factor
61          *
62          * @param variationFactor the factor by which the adjustment is to be changed
63          * @return the IPD increase
64          */

65         protected int applyVariationFactor(double variationFactor) {
66             int oldAdjustment = adjustment;
67             adjustment *= variationFactor;
68             return adjustment - oldAdjustment;
69         }
70     }
71     
72     /**
73      * offset position from before edge of parent area
74      */

75     protected int offset = 0;
76     
77     /**
78      * parent area
79      * it is needed in order to recompute adjust ratio and indents
80      * when a page-number or a page-number-citation is resolved
81      */

82     private Area parentArea = null;
83     
84     /**
85      * ipd variation of child areas: if this area has not already
86      * been added and cannot notify its parent area, store the variation
87      * and wait for the parent area to be set
88      */

89     private int storedIPDVariation = 0;
90
91     /**
92      * The adjustment information object
93      */

94     protected InlineAdjustingInfo adjustingInfo = null;
95     
96     /**
97      * @return the adjustment information object
98      */

99     public InlineAdjustingInfo getAdjustingInfo() {
100         return adjustingInfo;
101     }
102
103     /**
104      * Create a new adjustment information object
105      * @param stretch the available space for stretching
106      * @param shrink the available space for shrinking
107      * @param adj space adjustment type
108      */

109     public void setAdjustingInfo(int stretch, int shrink, int adjustment) {
110         adjustingInfo = new InlineAdjustingInfo(stretch, shrink, adjustment);
111     }
112     
113     /**
114      * Modify the adjustment value in the adjustment information object
115      * @param adjustment the new adjustment value
116      */

117     public void setAdjustment(int adjustment) {
118         if (adjustingInfo != null) {
119             adjustingInfo.adjustment = adjustment;
120         }
121     }
122     
123     /**
124      * Increase the inline progression dimensions of this area.
125      * This is used for inline parent areas that contain mulitple child areas.
126      *
127      * @param ipd the inline progression to increase by
128      */

129     public void increaseIPD(int ipd) {
130         this.ipd += ipd;
131     }
132
133     /**
134      * Set the offset of this inline area.
135      * This is used to set the offset of the inline area
136      * which is relative to the before edge of the parent area.
137      *
138      * @param offset the offset
139      */

140     public void setOffset(int offset) {
141         this.offset = offset;
142     }
143
144     /**
145      * Get the offset of this inline area.
146      * This returns the offset of the inline area
147      * which is relative to the before edge of the parent area.
148      *
149      * @return the offset
150      */

151     public int getOffset() {
152         return offset;
153     }
154
155     /**
156      * @param parentArea The parentArea to set.
157      */

158     public void setParentArea(Area parentArea) {
159         this.parentArea = parentArea;
160     }
161
162     /**
163      * @return Returns the parentArea.
164      */

165     public Area getParentArea() {
166         return parentArea;
167     }
168     
169     /**
170      * Set the parent for the child area.
171      *
172      * @see org.apache.fop.area.Area#addChildArea(Area)
173      */

174     public void addChildArea(Area childArea) {
175         super.addChildArea(childArea);
176         if (childArea instanceof InlineArea) {
177             ((InlineArea) childArea).setParentArea(this);
178         }
179     }
180     
181     /**
182      *@return true if the inline area is underlined.
183      */

184     public boolean hasUnderline() {
185         return getBooleanTrait(Trait.UNDERLINE);
186     }
187
188     /** @return true if the inline area is overlined. */
189     public boolean hasOverline() {
190         return getBooleanTrait(Trait.OVERLINE);
191     }
192     
193     /** @return true if the inline area has a line through. */
194     public boolean hasLineThrough() {
195         return getBooleanTrait(Trait.LINETHROUGH);
196     }
197     
198     /** @return true if the inline area is blinking. */
199     public boolean isBlinking() {
200         return getBooleanTrait(Trait.BLINK);
201     }
202     
203     /**
204      * recursively apply the variation factor to all descendant areas
205      * @param variationFactor the variation factor that must be applied to adjustments
206      * @param lineStretch the total stretch of the line
207      * @param lineShrink the total shrink of the line
208      * @return true if there is an UnresolvedArea descendant
209      */

210     public boolean applyVariationFactor(double variationFactor,
211                                         int lineStretch, int lineShrink) {
212         // default behaviour: update the IPD and return false
213
if (adjustingInfo != null) {
214             setIPD(getIPD() + adjustingInfo.applyVariationFactor(variationFactor));
215         }
216         return false;
217     }
218     
219     public void handleIPDVariation(int ipdVariation) {
220         increaseIPD(ipdVariation);
221         notifyIPDVariation(ipdVariation);
222     }
223     
224         /**
225      * notify the parent area about the ipd variation of this area
226      * or of a descendant area
227      * @param ipdVariation the difference between new and old ipd
228      */

229     protected void notifyIPDVariation(int ipdVariation) {
230         if (getParentArea() instanceof InlineArea) {
231             ((InlineArea) getParentArea()).handleIPDVariation(ipdVariation);
232         } else if (getParentArea() instanceof LineArea) {
233             ((LineArea) getParentArea()).handleIPDVariation(ipdVariation);
234         } else if (getParentArea() == null) {
235             // parent area not yet set: store the variations
236
storedIPDVariation += ipdVariation;
237         }
238     }
239 }
240
241
Popular Tags