1 21 22 package org.armedbear.j; 23 24 import java.util.ArrayList ; 25 26 public final class HiddenLines 27 { 28 private final Buffer buffer; 29 private final ArrayList list; 30 31 public HiddenLines(Editor editor) 32 { 33 buffer = editor.getBuffer(); 34 list = new ArrayList (); 35 int count = 0; 36 int hidden = -1; 37 for (Line line = buffer.getFirstLine(); line != null; line = line.next()) { 38 if (hidden == line.getHidden()) { 39 ++count; 40 } else { 41 if (count > 0) 42 addEntry(hidden, count); 43 hidden = line.getHidden(); 44 count = 1; 45 } 46 } 47 if (count > 0) 48 addEntry(hidden, count); 49 } 50 51 public void restore() 52 { 53 Line line = buffer.getFirstLine(); 54 for (int i = 0; i < list.size(); i++) { 55 HiddenLinesEntry entry = (HiddenLinesEntry) list.get(i); 56 for (int j = 0; j < entry.getCount(); j++) { 57 line.setHidden(entry.getHidden()); 58 line = line.next(); 59 } 60 } 61 buffer.renumber(); 62 } 63 64 private final void addEntry(int hidden, int count) 65 { 66 list.add(new HiddenLinesEntry(hidden, count)); 67 } 68 69 private static final class HiddenLinesEntry 70 { 71 private final int hidden; 72 private final int count; 73 74 private HiddenLinesEntry(int hidden, int count) 75 { 76 this.hidden = hidden; 77 this.count = count; 78 } 79 80 private final int getHidden() 81 { 82 return hidden; 83 } 84 85 private final int getCount() 86 { 87 return count; 88 } 89 } 90 } 91 | Popular Tags |