KickJava   Java API By Example, From Geeks To Geeks.

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


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: BlockKnuthSequence.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
25 /**
26  * Represents a list of block level Knuth elements.
27  */

28 public class BlockKnuthSequence extends KnuthSequence {
29     
30     private boolean isClosed = false;
31     
32     /**
33      * Creates a new and empty list.
34      */

35     public BlockKnuthSequence() {
36         super();
37     }
38     
39     /**
40      * Creates a new list from an existing list.
41      * @param list The list from which to create the new list.
42      */

43     public BlockKnuthSequence(List JavaDoc list) {
44         super(list);
45     }
46
47     /* (non-Javadoc)
48      * @see org.apache.fop.layoutmgr.KnuthList#isInlineSequence()
49      */

50     public boolean isInlineSequence() {
51         return false;
52     }
53
54     /* (non-Javadoc)
55      * @see org.apache.fop.layoutmgr.KnuthList#canAppendSequence(org.apache.fop.layoutmgr.KnuthSequence)
56      */

57     public boolean canAppendSequence(KnuthSequence sequence) {
58         return !sequence.isInlineSequence() && !isClosed;
59     }
60
61     /* (non-Javadoc)
62      * @see org.apache.fop.layoutmgr.KnuthList#appendSequence(org.apache.fop.layoutmgr.KnuthSequence,)
63      */

64     public boolean appendSequence(KnuthSequence sequence) {
65         // log.debug("Cannot append a sequence without a BreakElement");
66
return false;
67     }
68     
69     /* (non-Javadoc)
70      * @see KnuthList#appendSequence(KnuthSequence, boolean, BreakElement)
71      */

72     public boolean appendSequence(KnuthSequence sequence, boolean keepTogether,
73                                   BreakElement breakElement) {
74         if (!canAppendSequence(sequence)) {
75             return false;
76         }
77         if (keepTogether) {
78             breakElement.setPenaltyValue(KnuthElement.INFINITE);
79             add(breakElement);
80         } else if (!((ListElement) getLast()).isGlue()) {
81             breakElement.setPenaltyValue(0);
82             add(breakElement);
83         }
84         addAll(sequence);
85         return true;
86     }
87
88     /* (non-Javadoc)
89      * @see org.apache.fop.layoutmgr.KnuthSequence#endSequence()
90      */

91     public KnuthSequence endSequence() {
92         isClosed = true;
93         return this;
94     }
95
96 }
97
Popular Tags