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 1610839 2014-07-15 20:25:58Z vhennebert $ */
19 
20 package org.apache.fop.layoutmgr;
21 
22 import java.util.List;
23 
24 
25 /**
26  * Represents a list of block level Knuth elements.
27  */
28 public class BlockKnuthSequence extends KnuthSequence {
29 
30     private static final long serialVersionUID = 1648962416582509095L;
31 
32     private boolean isClosed;
33 
34     /**
35      * Creates a new and empty list.
36      */
BlockKnuthSequence()37     public BlockKnuthSequence() {
38         super();
39     }
40 
41     /**
42      * Creates a new list from an existing list.
43      * @param list The list from which to create the new list.
44      */
BlockKnuthSequence(List list)45     public BlockKnuthSequence(List list) {
46         super(list);
47     }
48 
49     /** {@inheritDoc} */
isInlineSequence()50     public boolean isInlineSequence() {
51         return false;
52     }
53 
54     /** {@inheritDoc} */
canAppendSequence(KnuthSequence sequence)55     public boolean canAppendSequence(KnuthSequence sequence) {
56         return !sequence.isInlineSequence() && !isClosed;
57     }
58 
59     /** {@inheritDoc} */
appendSequence(KnuthSequence sequence)60     public boolean appendSequence(KnuthSequence sequence) {
61         // log.debug("Cannot append a sequence without a BreakElement");
62         return false;
63     }
64 
65     /** {@inheritDoc} */
appendSequence(KnuthSequence sequence, boolean keepTogether, BreakElement breakElement)66     public boolean appendSequence(KnuthSequence sequence, boolean keepTogether,
67                                   BreakElement breakElement) {
68         if (!canAppendSequence(sequence)) {
69             return false;
70         }
71         if (keepTogether) {
72             breakElement.setPenaltyValue(KnuthElement.INFINITE);
73             add(breakElement);
74         } else if (!getLast().isGlue()) {
75             breakElement.setPenaltyValue(0);
76             add(breakElement);
77         }
78         addAll(sequence);
79         return true;
80     }
81 
82     /** {@inheritDoc} */
endSequence()83     public KnuthSequence endSequence() {
84         isClosed = true;
85         return this;
86     }
87 
88 }
89