01: /*
02: * JRefactoryAnnotation.java
03: *
04: * Created on 04 May 2004, 13:15
05: */
06:
07: package org.acm.seguin.ide.netbeans;
08:
09: import java.beans.PropertyChangeEvent;
10: import java.beans.PropertyChangeListener;
11: import java.util.ArrayList;
12: import java.util.Iterator;
13: import java.util.List;
14: import org.openide.text.Annotation;
15: import org.openide.text.Annotatable;
16: import org.openide.text.Line;
17:
18: /**
19: *
20: * @author mikea
21: */
22: public class CPDAnnotation extends Annotation implements
23: PropertyChangeListener {
24:
25: /** The error message shown on mouseover on the pmd icon */
26: private String errormessage = null;
27: private static List annotations = new ArrayList();
28:
29: private CPDAnnotation() {
30: }
31:
32: public static final CPDAnnotation getNewInstance() {
33: CPDAnnotation jra = new CPDAnnotation();
34: annotations.add(jra);
35: return jra;
36: }
37:
38: public static final void clearAll() {
39: Iterator iterator = annotations.iterator();
40: while (iterator.hasNext()) {
41: ((Annotation) iterator.next()).detach();
42: }
43: annotations.clear();
44: }
45:
46: /**
47: * The annotation type.
48: *
49: * @return pmd-annotation
50: */
51: public String getAnnotationType() {
52: return "jrefactory-cpd-annotation";
53: }
54:
55: /**
56: * Sets the current errormessage
57: *
58: * @param message the errormessage
59: */
60: public void setErrorMessage(String message) {
61: errormessage = message;
62: }
63:
64: /**
65: * A short description of this annotation
66: *
67: * @return the short description
68: */
69: public String getShortDescription() {
70: return errormessage;
71: }
72:
73: /**
74: * Invoked when the user change the content on the line where the annotation is
75: * attached
76: *
77: * @param propertyChangeEvent the event fired
78: */
79: public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
80: String type = propertyChangeEvent.getPropertyName();
81: if (type == null || type == Annotatable.PROP_TEXT) {
82: Line line = (Line) propertyChangeEvent.getSource();
83: line.removePropertyChangeListener(this);
84: detach();
85: }
86: }
87: }
|