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: LMiter.java 426576 2006-07-28 15:44:37Z jeremias $ */
19:
20: package org.apache.fop.layoutmgr;
21:
22: import java.util.List;
23: import java.util.ListIterator;
24: import java.util.NoSuchElementException;
25:
26: public class LMiter implements ListIterator {
27:
28: protected List listLMs;
29: protected int curPos = 0;
30: /** The LayoutManager to which this LMiter is attached **/
31: private LayoutManager lp;
32:
33: public LMiter(LayoutManager lp) {
34: this .lp = lp;
35: listLMs = lp.getChildLMs();
36: }
37:
38: public boolean hasNext() {
39: return (curPos < listLMs.size()) ? true : lp
40: .createNextChildLMs(curPos);
41: }
42:
43: public boolean hasPrevious() {
44: return (curPos > 0);
45: }
46:
47: public Object previous() throws NoSuchElementException {
48: if (curPos > 0) {
49: return listLMs.get(--curPos);
50: } else {
51: throw new NoSuchElementException();
52: }
53: }
54:
55: public Object next() throws NoSuchElementException {
56: if (curPos < listLMs.size()) {
57: return listLMs.get(curPos++);
58: } else {
59: throw new NoSuchElementException();
60: }
61: }
62:
63: public void remove() throws NoSuchElementException {
64: if (curPos > 0) {
65: listLMs.remove(--curPos);
66: // Note: doesn't actually remove it from the base!
67: } else {
68: throw new NoSuchElementException();
69: }
70: }
71:
72: public void add(Object o) throws UnsupportedOperationException {
73: throw new UnsupportedOperationException(
74: "LMiter doesn't support add");
75: }
76:
77: public void set(Object o) throws UnsupportedOperationException {
78: throw new UnsupportedOperationException(
79: "LMiter doesn't support set");
80: }
81:
82: public int nextIndex() {
83: return curPos;
84: }
85:
86: public int previousIndex() {
87: return curPos - 1;
88: }
89:
90: }
|