1 19 package org.netbeans.modules.retouche.editor.semantic; 20 21 import java.lang.ref.Reference ; 22 import java.lang.ref.WeakReference ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.WeakHashMap ; 29 import javax.swing.text.Document ; 30 import org.netbeans.modules.editor.errorstripe.privatespi.Mark; 31 import org.netbeans.modules.editor.errorstripe.privatespi.MarkProvider; 32 import org.netbeans.modules.editor.highlights.spi.Highlight; 33 34 43 public class OccurrencesMarkProvider extends MarkProvider { 44 45 private static Map <Document , Reference <OccurrencesMarkProvider>> providers = new WeakHashMap <Document , Reference <OccurrencesMarkProvider>>(); 46 47 public static synchronized OccurrencesMarkProvider get(Document doc) { 48 Reference <OccurrencesMarkProvider> ref = providers.get(doc); 49 OccurrencesMarkProvider p = ref != null ? ref.get() : null; 50 51 if (p == null) { 52 providers.put(doc, new WeakReference (p = new OccurrencesMarkProvider())); 53 } 54 55 return p; 56 } 57 58 private List <Mark> semantic; 59 private List <Mark> occurrences; 60 private List <Mark> joint; 61 62 63 private OccurrencesMarkProvider() { 64 semantic = Collections.emptyList(); 65 occurrences = Collections.emptyList(); 66 joint = Collections.emptyList(); 67 } 68 69 public synchronized List getMarks() { 70 return joint; 71 } 72 73 public synchronized void setSematic(Collection <Highlight> s) { 74 semantic = new ArrayList <Mark>(); 75 76 for (Highlight h : s) { 77 if (h != null && h instanceof Mark && ((Mark) h).getEnhancedColor() != null) 78 semantic.add((Mark) h); 79 } 80 81 List <Mark> old = joint; 82 83 joint = new ArrayList <Mark>(); 84 85 joint.addAll(semantic); 86 joint.addAll(occurrences); 87 88 firePropertyChange(PROP_MARKS, old, joint); 89 } 90 91 public synchronized void setOccurrences(Collection <Highlight> s) { 92 occurrences = new ArrayList <Mark>(); 93 94 for (Highlight h : s) { 95 if (h != null && h instanceof Mark && ((Mark) h).getEnhancedColor() != null) 96 occurrences.add((Mark) h); 97 } 98 99 List <Mark> old = joint; 100 101 joint = new ArrayList <Mark>(); 102 103 joint.addAll(semantic); 104 joint.addAll(occurrences); 105 106 firePropertyChange(PROP_MARKS, old, joint); 107 } 108 109 } 110 | Popular Tags |