01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
23:
24: /**
25: * Represents a list of block level Knuth elements.
26: */
27: public class BlockKnuthSequence extends KnuthSequence {
28:
29: private boolean isClosed = false;
30:
31: /**
32: * Creates a new and empty list.
33: */
34: public BlockKnuthSequence() {
35: super ();
36: }
37:
38: /**
39: * Creates a new list from an existing list.
40: * @param list The list from which to create the new list.
41: */
42: public BlockKnuthSequence(List list) {
43: super (list);
44: }
45:
46: /* (non-Javadoc)
47: * @see org.apache.fop.layoutmgr.KnuthList#isInlineSequence()
48: */
49: public boolean isInlineSequence() {
50: return false;
51: }
52:
53: /* (non-Javadoc)
54: * @see org.apache.fop.layoutmgr.KnuthList#canAppendSequence(org.apache.fop.layoutmgr.KnuthSequence)
55: */
56: public boolean canAppendSequence(KnuthSequence sequence) {
57: return !sequence.isInlineSequence() && !isClosed;
58: }
59:
60: /* (non-Javadoc)
61: * @see org.apache.fop.layoutmgr.KnuthList#appendSequence(org.apache.fop.layoutmgr.KnuthSequence,)
62: */
63: public boolean appendSequence(KnuthSequence sequence) {
64: // log.debug("Cannot append a sequence without a BreakElement");
65: return false;
66: }
67:
68: /* (non-Javadoc)
69: * @see KnuthList#appendSequence(KnuthSequence, boolean, BreakElement)
70: */
71: public boolean appendSequence(KnuthSequence sequence,
72: boolean keepTogether, BreakElement breakElement) {
73: if (!canAppendSequence(sequence)) {
74: return false;
75: }
76: if (keepTogether) {
77: breakElement.setPenaltyValue(KnuthElement.INFINITE);
78: add(breakElement);
79: } else if (!((ListElement) getLast()).isGlue()) {
80: breakElement.setPenaltyValue(0);
81: add(breakElement);
82: }
83: addAll(sequence);
84: return true;
85: }
86:
87: /* (non-Javadoc)
88: * @see org.apache.fop.layoutmgr.KnuthSequence#endSequence()
89: */
90: public KnuthSequence endSequence() {
91: isClosed = true;
92: return this;
93: }
94:
95: }
|