1 19 20 package org.netbeans.modules.debugger.jpda.projects; 21 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.HashMap ; 25 import java.util.HashSet ; 26 import java.util.Map ; 27 import org.netbeans.modules.editor.highlights.spi.Highlight; 28 import org.netbeans.modules.editor.highlights.spi.Highlighter; 29 import org.netbeans.spi.debugger.jpda.EditorContext; 30 import org.openide.filesystems.FileObject; 31 import org.openide.text.Annotatable; 32 33 import org.openide.text.Annotation; 34 import org.openide.text.Line; 35 import org.openide.util.NbBundle; 36 37 38 43 public class DebuggerAnnotation extends Annotation { 44 45 private Line line; 46 private String type; 47 48 49 DebuggerAnnotation (String type, Line line) { 50 this.type = type; 51 this.line = line; 52 attach (line); 53 } 54 55 DebuggerAnnotation (String type, Line.Part linePart) { 56 this.type = type; 57 this.line = linePart.getLine(); 58 attach (linePart); 59 } 60 61 DebuggerAnnotation (String type, Highlight highlight, FileObject fo) { 62 this.type = type; 63 attach (new HighlightAnnotatable(highlight, fo)); 64 } 65 66 public String getAnnotationType () { 67 return type; 68 } 69 70 Line getLine () { 71 return line; 72 } 73 74 public String getShortDescription () { 75 if (type == EditorContext.BREAKPOINT_ANNOTATION_TYPE) 76 return NbBundle.getBundle (DebuggerAnnotation.class).getString 77 ("TOOLTIP_BREAKPOINT"); else 79 if (type == EditorContext.DISABLED_BREAKPOINT_ANNOTATION_TYPE) 80 return NbBundle.getBundle (DebuggerAnnotation.class).getString 81 ("TOOLTIP_DISABLED_BREAKPOINT"); else 83 if (type == EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE) 84 return NbBundle.getBundle (DebuggerAnnotation.class).getString 85 ("TOOLTIP_CONDITIONAL_BREAKPOINT"); else 87 if (type == EditorContext.DISABLED_CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE) 88 return NbBundle.getBundle (DebuggerAnnotation.class).getString 89 ("TOOLTIP_DISABLED_CONDITIONAL_BREAKPOINT"); else 91 if (type == EditorContext.CURRENT_LINE_ANNOTATION_TYPE) 92 return NbBundle.getMessage 93 (DebuggerAnnotation.class, "TOOLTIP_CURRENT_PC"); else 95 if (type == EditorContext.CALL_STACK_FRAME_ANNOTATION_TYPE) 96 return NbBundle.getBundle (DebuggerAnnotation.class).getString 97 ("TOOLTIP_CALLSITE"); return NbBundle.getBundle (DebuggerAnnotation.class).getString 99 ("TOOLTIP_ANNOTATION"); } 101 102 private static final class HighlightAnnotatable extends Annotatable { 103 104 private static Map highlightsByFiles = new HashMap (); 105 106 private Highlight highlight; 107 private FileObject fo; 108 109 public HighlightAnnotatable(Highlight highlight, FileObject fo) { 110 this.highlight = highlight; 111 this.fo = fo; 112 } 113 114 public String getText() { 115 return null; 116 } 117 118 protected void addAnnotation(Annotation anno) { 119 Collection highlights; 120 synchronized (highlightsByFiles) { 121 highlights = (Collection ) highlightsByFiles.get(fo); 122 if (highlights == null) { 123 highlights = new HashSet (); 124 highlightsByFiles.put(fo, highlights); 125 } 126 highlights.add(highlight); 127 } 128 Highlighter.getDefault().setHighlights(fo, getClass().getName(), highlights); 129 } 130 131 protected void removeAnnotation(Annotation anno) { 132 Collection highlights; 133 synchronized (highlightsByFiles) { 134 highlights = (Collection ) highlightsByFiles.get(fo); 135 if (highlights == null) { 136 highlights = Collections.EMPTY_SET; 137 } else { 138 highlights.remove(highlight); 139 if (highlights.isEmpty()) { 140 highlightsByFiles.remove(fo); 141 } 142 } 143 } 144 Highlighter.getDefault().setHighlights(fo, getClass().getName(), highlights); 145 } 146 147 148 } 149 150 } 151 | Popular Tags |