1 11 package org.eclipse.jface.text; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.Assert; 18 19 25 public class DocumentPartitioningChangedEvent { 26 27 28 private final IDocument fDocument; 29 30 private final Map fMap= new HashMap (); 31 32 33 39 public DocumentPartitioningChangedEvent(IDocument document) { 40 fDocument= document; 41 } 42 43 48 public IDocument getDocument() { 49 return fDocument; 50 } 51 52 59 public IRegion getChangedRegion(String partitioning) { 60 return (IRegion) fMap.get(partitioning); 61 } 62 63 68 public String [] getChangedPartitionings() { 69 String [] partitionings= new String [fMap.size()]; 70 fMap.keySet().toArray(partitionings); 71 return partitionings; 72 } 73 74 81 public void setPartitionChange(String partitioning, int offset, int length) { 82 Assert.isNotNull(partitioning); 83 fMap.put(partitioning, new Region(offset, length)); 84 } 85 86 92 public boolean isEmpty() { 93 return fMap.isEmpty(); 94 } 95 96 102 public IRegion getCoverage() { 103 if (fMap.isEmpty()) 104 return new Region(0, 0); 105 106 int offset= -1; 107 int endOffset= -1; 108 Iterator e= fMap.values().iterator(); 109 while (e.hasNext()) { 110 IRegion r= (IRegion) e.next(); 111 112 if (offset < 0 || r.getOffset() < offset) 113 offset= r.getOffset(); 114 115 int end= r.getOffset() + r.getLength(); 116 if (end > endOffset) 117 endOffset= end; 118 } 119 120 return new Region(offset, endOffset - offset); 121 } 122 } 123 | Popular Tags |