KickJava   Java API By Example, From Geeks To Geeks.

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


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: KnuthGlue.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.layoutmgr;
21
22 /**
23  * An instance of this class represents a piece of content with adjustable
24  * width: for example a space between words of justified text.
25  *
26  * A KnuthGlue is a feasible breaking point only if it immediately follows
27  * a KnuthBox.
28  *
29  * The represented piece of content is suppressed if either the KnuthGlue
30  * is a chosen breaking point or there isn't any KnuthBox between the
31  * previous breaking point and the KnuthGlue itself.
32  *
33  * So, an unsuppressible piece of content with adjustable width, for example
34  * a leader or a word with adjustable letter space, cannot be represented
35  * by a single KnuthGlue; it can be represented using the sequence:
36  * KnuthBox(width = 0)
37  * KnuthPenalty(width = 0, penalty = infinity)
38  * KnuthGlue(...)
39  * KnuthBox(width = 0)
40  * where the infinity penalty avoids choosing the KnuthGlue as a breaking point
41  * and the 0-width KnuthBoxes prevent suppression.
42  *
43  * Besides the inherited methods and attributes, this class has two attributes
44  * used to store the stretchability (difference between max and opt width) and
45  * the shrinkability (difference between opt and min width), and the methods
46  * to get these values.
47  */

48 public class KnuthGlue extends KnuthElement {
49     
50     private int stretchability;
51     private int shrinkability;
52     private int adjustmentClass = -1;
53
54     /**
55      * Create a new KnuthGlue.
56      *
57      * @param w the width of this glue
58      * @param y the stretchability of this glue
59      * @param z the shrinkability of this glue
60      * @param pos the Position stored in this glue
61      * @param bAux is this glue auxiliary?
62      */

63     public KnuthGlue(int w, int y, int z, Position pos, boolean bAux) {
64         super(w, pos, bAux);
65         stretchability = y;
66         shrinkability = z;
67     }
68
69     public KnuthGlue(int w, int y, int z,
70             int iAdjClass, Position pos, boolean bAux) {
71         super(w, pos, bAux);
72         stretchability = y;
73         shrinkability = z;
74         adjustmentClass = iAdjClass;
75     }
76
77     /** @see org.apache.fop.layoutmgr.KnuthElement#isGlue() */
78     public boolean isGlue() {
79         return true;
80     }
81
82     /** @return the stretchability of this glue. */
83     public int getY() {
84         return stretchability;
85     }
86
87     /** @return the shrinkability of this glue. */
88     public int getZ() {
89         return shrinkability;
90     }
91     
92     /** @return the adjustment class (or role) of this glue. */
93     public int getAdjustmentClass() {
94         return adjustmentClass;
95     }
96     
97     /** @see java.lang.Object#toString() */
98     public String JavaDoc toString() {
99         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(64);
100         if (isAuxiliary()) {
101             sb.append("aux. ");
102         }
103         sb.append("glue");
104         sb.append(" w=").append(getW());
105         sb.append(" stretch=").append(getY());
106         sb.append(" shrink=").append(getZ());
107         if (getAdjustmentClass() >= 0) {
108             sb.append(" adj-class=").append(getAdjustmentClass());
109         }
110         return sb.toString();
111     }
112     
113 }
114
Popular Tags