1 19 20 package org.netbeans.spi.editor.highlighting.support; 21 22 import java.util.List ; 23 import org.netbeans.lib.editor.util.ListenerList; 24 import org.netbeans.spi.editor.highlighting.HighlightsChangeEvent; 25 import org.netbeans.spi.editor.highlighting.HighlightsChangeListener; 26 import org.netbeans.spi.editor.highlighting.HighlightsContainer; 27 import org.netbeans.spi.editor.highlighting.HighlightsSequence; 28 29 37 public abstract class AbstractHighlightsContainer implements HighlightsContainer { 38 39 private ListenerList<HighlightsChangeListener> listeners = new ListenerList<HighlightsChangeListener>(); 40 41 42 protected AbstractHighlightsContainer() { 43 } 44 45 public abstract HighlightsSequence getHighlights(int startOffset, int endOffset); 46 47 52 public final void addHighlightsChangeListener(HighlightsChangeListener listener) { 53 synchronized (listeners) { 54 listeners.add(listener); 55 } 56 } 57 58 63 public final void removeHighlightsChangeListener(HighlightsChangeListener listener) { 64 synchronized (listeners) { 65 listeners.remove(listener); 66 } 67 } 68 69 77 protected final void fireHighlightsChange(int changeStartOffset, int changeEndOffset) { 78 List <HighlightsChangeListener> targets; 79 80 synchronized (listeners) { 81 targets = listeners.getListeners(); 82 } 83 84 if (targets.size() > 0) { 85 HighlightsChangeEvent evt = new HighlightsChangeEvent(this, changeStartOffset, changeEndOffset); 86 87 for(HighlightsChangeListener l : targets) { 88 l.highlightChanged(evt); 89 } 90 } 91 } 92 } 93 | Popular Tags |