01: /*
02: * HiddenLines.java
03: *
04: * Copyright (C) 2002 Peter Graves
05: * $Id: HiddenLines.java,v 1.1.1.1 2002/09/24 16:09:22 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: import java.util.ArrayList;
25:
26: public final class HiddenLines {
27: private final Buffer buffer;
28: private final ArrayList list;
29:
30: public HiddenLines(Editor editor) {
31: buffer = editor.getBuffer();
32: list = new ArrayList();
33: int count = 0;
34: int hidden = -1;
35: for (Line line = buffer.getFirstLine(); line != null; line = line
36: .next()) {
37: if (hidden == line.getHidden()) {
38: ++count;
39: } else {
40: if (count > 0)
41: addEntry(hidden, count);
42: hidden = line.getHidden();
43: count = 1;
44: }
45: }
46: if (count > 0)
47: addEntry(hidden, count);
48: }
49:
50: public void restore() {
51: Line line = buffer.getFirstLine();
52: for (int i = 0; i < list.size(); i++) {
53: HiddenLinesEntry entry = (HiddenLinesEntry) list.get(i);
54: for (int j = 0; j < entry.getCount(); j++) {
55: line.setHidden(entry.getHidden());
56: line = line.next();
57: }
58: }
59: buffer.renumber();
60: }
61:
62: private final void addEntry(int hidden, int count) {
63: list.add(new HiddenLinesEntry(hidden, count));
64: }
65:
66: private static final class HiddenLinesEntry {
67: private final int hidden;
68: private final int count;
69:
70: private HiddenLinesEntry(int hidden, int count) {
71: this .hidden = hidden;
72: this .count = count;
73: }
74:
75: private final int getHidden() {
76: return hidden;
77: }
78:
79: private final int getCount() {
80: return count;
81: }
82: }
83: }
|