KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > hints > ParseErrorAnnotation


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.editor.hints;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import javax.swing.text.BadLocationException JavaDoc;
24 import org.netbeans.spi.editor.hints.LazyFixList;
25 import org.netbeans.spi.editor.hints.Severity;
26 import org.openide.text.Annotation;
27 import org.openide.util.WeakListeners;
28
29 /**
30  *
31  * @author Jan Lahoda
32  */

33 public class ParseErrorAnnotation extends Annotation implements PropertyChangeListener JavaDoc {
34
35     private final Severity severity;
36     private final LazyFixList fixes;
37     private final String JavaDoc description;
38     //XXX: should hold Position to handle changes in the document correctly:
39
private final int lineNumber;
40     private final AnnotationHolder holder;
41     
42     /** Creates a new instance of ParseErrorAnnotation */
43     public ParseErrorAnnotation(Severity severity, LazyFixList fixes, String JavaDoc description, int lineNumber, AnnotationHolder holder) {
44         this.severity = severity;
45         this.fixes = fixes;
46         this.description = description;
47         this.lineNumber = lineNumber;
48         this.holder = holder;
49         
50         if (fixes.probablyContainsFixes() && !fixes.isComputed())
51             fixes.addPropertyChangeListener(WeakListeners.propertyChange(this, fixes));
52     }
53
54     public String JavaDoc getAnnotationType() {
55         boolean hasFixes = fixes.isComputed() && !fixes.getFixes().isEmpty();
56         
57         switch (severity) {
58             case ERROR:
59                 if (hasFixes)
60                     return "org-netbeans-spi-editor-hints-parser_annotation_err_fixable";
61                 else
62                     return "org-netbeans-spi-editor-hints-parser_annotation_err";
63                 
64             case WARNING:
65                 if (hasFixes)
66                     return "org-netbeans-spi-editor-hints-parser_annotation_warn_fixable";
67                 else
68                     return "org-netbeans-spi-editor-hints-parser_annotation_warn";
69             case VERIFIER:
70                 if (hasFixes)
71                     return "org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable";
72                 else
73                     return "org-netbeans-spi-editor-hints-parser_annotation_verifier";
74             case HINT:
75                 if (hasFixes)
76                     return "org-netbeans-spi-editor-hints-parser_annotation_hint_fixable";
77                 else
78                     return "org-netbeans-spi-editor-hints-parser_annotation_hint";
79             case TODO:
80                 if (hasFixes)
81                     return "org-netbeans-spi-editor-hints-parser_annotation_todo_fixable";
82                 else
83                     return "org-netbeans-spi-editor-hints-parser_annotation_todo";
84             default:
85                 throw new IllegalArgumentException JavaDoc(String.valueOf(severity));
86         }
87     }
88
89     public String JavaDoc getShortDescription() {
90         return description;
91     }
92
93     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
94         if (fixes.isComputed()) {
95             try {
96                 holder.detachAnnotation(this);
97                 holder.attachAnnotation(lineNumber, this);
98             } catch (BadLocationException JavaDoc ex) {
99                 throw new IllegalStateException JavaDoc(ex);
100             }
101         }
102     }
103     
104     public LazyFixList getFixes() {
105         return fixes;
106     }
107     
108     public String JavaDoc getDescription() {
109         return description;
110     }
111     
112     public int getLineNumber() {
113         return lineNumber;
114     }
115     
116     Severity getSeverity() {
117         return severity;
118     }
119 }
120
Popular Tags