KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > projects > DebuggerAnnotation


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.projects;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Map JavaDoc;
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 /**
39  * Debugger Annotation class.
40  *
41  * @author Jan Jancura
42  */

43 public class DebuggerAnnotation extends Annotation {
44
45     private Line line;
46     private String JavaDoc type;
47
48
49     DebuggerAnnotation (String JavaDoc type, Line line) {
50         this.type = type;
51         this.line = line;
52         attach (line);
53     }
54     
55     DebuggerAnnotation (String JavaDoc type, Line.Part linePart) {
56         this.type = type;
57         this.line = linePart.getLine();
58         attach (linePart);
59     }
60     
61     DebuggerAnnotation (String JavaDoc type, Highlight highlight, FileObject fo) {
62         this.type = type;
63         attach (new HighlightAnnotatable(highlight, fo));
64     }
65     
66     public String JavaDoc getAnnotationType () {
67         return type;
68     }
69     
70     Line getLine () {
71         return line;
72     }
73     
74     public String JavaDoc getShortDescription () {
75         if (type == EditorContext.BREAKPOINT_ANNOTATION_TYPE)
76             return NbBundle.getBundle (DebuggerAnnotation.class).getString
77                 ("TOOLTIP_BREAKPOINT"); // NOI18N
78
else
79         if (type == EditorContext.DISABLED_BREAKPOINT_ANNOTATION_TYPE)
80             return NbBundle.getBundle (DebuggerAnnotation.class).getString
81                 ("TOOLTIP_DISABLED_BREAKPOINT"); // NOI18N
82
else
83         if (type == EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE)
84             return NbBundle.getBundle (DebuggerAnnotation.class).getString
85                 ("TOOLTIP_CONDITIONAL_BREAKPOINT"); // NOI18N
86
else
87         if (type == EditorContext.DISABLED_CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE)
88             return NbBundle.getBundle (DebuggerAnnotation.class).getString
89                 ("TOOLTIP_DISABLED_CONDITIONAL_BREAKPOINT"); // NOI18N
90
else
91         if (type == EditorContext.CURRENT_LINE_ANNOTATION_TYPE)
92             return NbBundle.getMessage
93                 (DebuggerAnnotation.class, "TOOLTIP_CURRENT_PC"); // NOI18N
94
else
95         if (type == EditorContext.CALL_STACK_FRAME_ANNOTATION_TYPE)
96             return NbBundle.getBundle (DebuggerAnnotation.class).getString
97                 ("TOOLTIP_CALLSITE"); // NOI18N
98
return NbBundle.getBundle (DebuggerAnnotation.class).getString
99             ("TOOLTIP_ANNOTATION"); // NOI18N
100
}
101     
102     private static final class HighlightAnnotatable extends Annotatable {
103         
104         private static Map JavaDoc highlightsByFiles = new HashMap JavaDoc();
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 JavaDoc getText() {
115             return null;
116         }
117
118         protected void addAnnotation(Annotation anno) {
119             Collection JavaDoc highlights;
120             synchronized (highlightsByFiles) {
121                 highlights = (Collection JavaDoc) highlightsByFiles.get(fo);
122                 if (highlights == null) {
123                     highlights = new HashSet JavaDoc();
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 JavaDoc highlights;
133             synchronized (highlightsByFiles) {
134                 highlights = (Collection JavaDoc) 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