1 19 package org.openide.text; 20 21 import java.beans.PropertyChangeSupport ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 35 public abstract class Annotatable extends Object { 36 37 public static final String PROP_ANNOTATION_COUNT = "annotationCount"; 39 40 public static final String PROP_DELETED = "deleted"; 42 45 public static final String PROP_TEXT = "text"; 47 48 private PropertyChangeSupport propertyChangeSupport; 49 50 51 private int annotationCount; 52 53 54 private List <Annotation> attachedAnnotations; 55 56 58 private boolean deleted; 59 60 public Annotatable() { 61 deleted = false; 62 annotationCount = 0; 63 propertyChangeSupport = new PropertyChangeSupport (this); 64 attachedAnnotations = new LinkedList <Annotation>(); 65 } 66 67 69 protected void addAnnotation(Annotation anno) { 70 annotationCount++; 71 attachedAnnotations.add(anno); 72 propertyChangeSupport.firePropertyChange(PROP_ANNOTATION_COUNT, annotationCount - 1, annotationCount); 73 } 74 75 77 protected void removeAnnotation(Annotation anno) { 78 annotationCount--; 79 attachedAnnotations.remove(anno); 80 propertyChangeSupport.firePropertyChange(PROP_ANNOTATION_COUNT, annotationCount + 1, annotationCount); 81 } 82 83 85 List <? extends Annotation> getAnnotations() { 86 return attachedAnnotations; 87 } 88 89 91 final public void addPropertyChangeListener(java.beans.PropertyChangeListener l) { 92 propertyChangeSupport.addPropertyChangeListener(l); 93 } 94 95 97 final public void removePropertyChangeListener(java.beans.PropertyChangeListener l) { 98 propertyChangeSupport.removePropertyChangeListener(l); 99 } 100 101 102 final protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { 103 propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); 104 } 105 106 109 final public boolean isDeleted() { 110 return deleted; 111 } 112 113 120 abstract public String getText(); 121 122 125 void setDeleted(boolean deleted) { 126 if (this.deleted != deleted) { 127 this.deleted = deleted; 128 propertyChangeSupport.firePropertyChange(PROP_DELETED, !deleted, deleted); 129 } 130 } 131 132 137 final public int getAnnotationCount() { 138 return annotationCount; 139 } 140 } 141 | Popular Tags |