KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > AnnotationDesc


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
20 package org.netbeans.editor;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import org.netbeans.editor.Mark;
24 import java.beans.PropertyChangeSupport JavaDoc;
25 import java.awt.Image JavaDoc;
26 import org.netbeans.editor.AnnotationTypes;
27 import javax.swing.Action JavaDoc;
28
29 /** Description of the annotation. The annotations is defined by
30  * AnnotationType, length, offset and description.
31  *
32  * @author David Konecny
33  * @since 07/2001
34  */

35 public abstract class AnnotationDesc extends Object JavaDoc {
36
37     /** Property name of the tip text */
38     public static final String JavaDoc PROP_SHORT_DESCRIPTION = "shortDescription"; // NOI18N
39

40     /** Property name of the annotation type */
41     public static final String JavaDoc PROP_ANNOTATION_TYPE = "annotationType"; // NOI18N
42

43     /** Virtual property for fronting of annotation */
44     public static final String JavaDoc PROP_MOVE_TO_FRONT = "moveToFront"; // NOI18N
45

46     /** Support for property change listeners*/
47     private PropertyChangeSupport JavaDoc support;
48
49     /** This is sequential number which is used for cycling
50      * through the anotations. Each added annotion gets number
51      * and this number if necessary is used for cycling through the
52      * annotations - cycle causes that annotation with higher number
53      * is shown. If no higher number exist the cycling starts from the
54      * begining. */

55     private int order;
56
57     /** Unique counter used for order variable.*/
58     private static int counter = 0;
59
60     /** Length of the annotated text. If -1 than whole line is annotated */
61     private int length;
62
63     /** Private member used by Annotations class. After the annotation is
64      * attached to document, the Mark which is crated (or shared with some
65      * other annotation) is stored here. Only for internal purpose of Annoations
66      * class */

67     private Mark mark;
68
69     /** AnnotationType attached to this annotation. Annotation has a few
70      * pass through methods to AnnotationType for simple access to the
71      * annotation type information. */

72     private AnnotationType type = null;
73
74     public AnnotationDesc(int offset, int length) {
75         counter++;
76         this.order = counter;
77         this.length = length;
78         support = new PropertyChangeSupport JavaDoc(this);
79     }
80
81     /** Gets annotation coloring. This is pass through method to annotation type */
82     public Coloring getColoring() {
83         if (type == null) updateAnnotationType();
84         return (type != null) ? type.getColoring() : new Coloring(null, Coloring.FONT_MODE_DEFAULT, null, null, null, null, null);
85     }
86
87     /** Gets glyph image. This is pass through method to annotation type */
88     public Image JavaDoc getGlyph() {
89         if (type == null) updateAnnotationType();
90         return (type != null) ? type.getGlyphImage() : null;
91     }
92
93     /** Checks whether the annotation type has its own glyph icon */
94     public boolean isDefaultGlyph() {
95         if (type == null) updateAnnotationType();
96         return (type != null) ? type.isDefaultGlyph() : false;
97     }
98
99     /** Is annotation type visible. This is pass through method to annotation type */
100     public boolean isVisible() {
101         if (type == null) updateAnnotationType();
102         return (type != null) ? type.isVisible() : false;
103     }
104
105     /** Internal order of the annotations. Used for correct cycling. */
106     public int getOrderNumber() {
107         return order;
108     }
109
110     /** Returns list of actions associated to this annotation type. */
111     public Action JavaDoc[] getActions() {
112         if (type == null) updateAnnotationType();
113         return (type != null) ? type.getActions() : new Action JavaDoc[0];
114     }
115
116     /** Whether this annotation annotates whole line or just part of the text*/
117     public boolean isWholeLine() {
118         return length == -1;
119     }
120
121     /** Get length of the annotation*/
122     public int getLength() {
123         return length;
124     }
125
126     /** Set Mark which represent this annotation in document */
127     void setMark(Mark mark) {
128         this.mark = mark;
129     }
130
131     /** Get Mark which represent this annotation in document */
132     Mark getMark() {
133         return mark;
134     }
135
136     /** Getter for annotation type object */
137     public AnnotationType getAnnotationTypeInstance() {
138         return type;
139     }
140     
141     /** Getter for annotation type name */
142     public abstract String JavaDoc getAnnotationType();
143
144     /** Getter for localized tooltip text for this annotation */
145     public abstract String JavaDoc getShortDescription();
146
147     /** Getter for offset of this annotation */
148     public abstract int getOffset();
149
150     /** Getter for line number of this annotation */
151     public abstract int getLine();
152
153     
154     /** Method for fetching AnnotationType which
155      * correspond to the name of the annotation type stored
156      * in annotation. */

157     public void updateAnnotationType() {
158         type = AnnotationTypes.getTypes().getType(getAnnotationType());
159     }
160
161     /** Add listeners on changes of annotation properties
162      * @param l change listener*/

163     final public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
164         support.addPropertyChangeListener(l);
165     }
166
167     /** Remove listeners on changes of annotation properties
168      * @param l change listener*/

169     final public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
170         support.removePropertyChangeListener(l);
171     }
172
173     /** Fire property change to registered listeners. */
174     final protected void firePropertyChange(String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
175         support.firePropertyChange(propertyName, oldValue, newValue);
176     }
177
178     public String JavaDoc toString() {
179         return "Annotation: type='" + getAnnotationType() + "', line=" + getLine() + // NOI18N
180
", offset=" + getOffset() + ", length=" + length + // NOI18N
181
", coloring=" + getColoring(); // NOI18N
182
}
183     
184 }
185
Popular Tags