1 11 package org.eclipse.jface.text.source; 12 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 17 import org.eclipse.jface.text.IDocument; 18 import org.eclipse.jface.text.Position; 19 20 21 22 33 class VisualAnnotationModel extends AnnotationModel implements IAnnotationModelListener { 34 35 36 private IAnnotationModel fModel; 37 38 44 public VisualAnnotationModel(IAnnotationModel modelAnnotationModel) { 45 fModel= modelAnnotationModel; 46 } 47 48 53 public IAnnotationModel getModelAnnotationModel() { 54 return fModel; 55 } 56 57 60 public void addAnnotationModelListener(IAnnotationModelListener listener) { 61 62 if (fModel != null && fAnnotationModelListeners.isEmpty()) 63 fModel.addAnnotationModelListener(this); 64 65 super.addAnnotationModelListener(listener); 66 } 67 68 71 public void connect(IDocument document) { 72 super.connect(document); 73 if (fModel != null) 74 fModel.connect(document); 75 } 76 77 80 public void disconnect(IDocument document) { 81 super.disconnect(document); 82 if (fModel != null) 83 fModel.disconnect(document); 84 } 85 86 89 public Iterator getAnnotationIterator() { 90 91 if (fModel == null) 92 return super.getAnnotationIterator(); 93 94 ArrayList a= new ArrayList (20); 95 96 Iterator e= fModel.getAnnotationIterator(); 97 while (e.hasNext()) 98 a.add(e.next()); 99 100 e= super.getAnnotationIterator(); 101 while (e.hasNext()) 102 a.add(e.next()); 103 104 return a.iterator(); 105 } 106 107 110 public Position getPosition(Annotation annotation) { 111 112 Position p= (Position) getAnnotationMap().get(annotation); 113 if (p != null) 114 return p; 115 116 if (fModel != null) 117 return fModel.getPosition(annotation); 118 119 return null; 120 } 121 122 125 public void modelChanged(IAnnotationModel model) { 126 if (model == fModel) { 127 Iterator iter= new ArrayList (fAnnotationModelListeners).iterator(); 128 while (iter.hasNext()) { 129 IAnnotationModelListener l= (IAnnotationModelListener)iter.next(); 130 l.modelChanged(this); 131 } 132 } 133 } 134 135 138 public void removeAnnotationModelListener(IAnnotationModelListener listener) { 139 super.removeAnnotationModelListener(listener); 140 141 if (fModel != null && fAnnotationModelListeners.isEmpty()) 142 fModel.removeAnnotationModelListener(this); 143 } 144 } 145 | Popular Tags |