001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
011: * Microsystems, Inc. All Rights Reserved.
012: */
013:
014: package org.netbeans.editor;
015:
016: import java.awt.Image;
017: import java.beans.PropertyChangeListener;
018: import java.beans.PropertyChangeSupport;
019:
020: import javax.swing.Action;
021:
022: /**
023: * Description of the annotation. The annotations is defined by AnnotationType,
024: * length, offset and description.
025: *
026: * @author David Konecny
027: * @since 07/2001
028: */
029: public abstract class AnnotationDesc extends Object {
030:
031: /** Property name of the tip text */
032: public static final String PROP_SHORT_DESCRIPTION = "shortDescription";
033:
034: /** Property name of the annotation type */
035: public static final String PROP_ANNOTATION_TYPE = "annotationType";
036:
037: /** Virtual property for fronting of annotation */
038: public static final String PROP_MOVE_TO_FRONT = "moveToFront";
039:
040: /** Support for property change listeners */
041: private PropertyChangeSupport support;
042:
043: /**
044: * This is sequential number which is used for cycling through the
045: * anotations. Each added annotion gets number and this number if necessary
046: * is used for cycling through the annotations - cycle causes that
047: * annotation with higher number is shown. If no higher number exist the
048: * cycling starts from the begining.
049: */
050: private int order;
051:
052: /** Unique counter used for order variable. */
053: private static int counter = 0;
054:
055: /** Length of the annotated text. If -1 than whole line is annotated */
056: private int length;
057:
058: /**
059: * Private member used by Annotations class. After the annotation is
060: * attached to document, the Mark which is crated (or shared with some other
061: * annotation) is stored here. Only for internal purpose of Annoations class
062: */
063: private Mark mark;
064:
065: /**
066: * AnnotationType attached to this annotation. Annotation has a few pass
067: * through methods to AnnotationType for simple access to the annotation
068: * type information.
069: */
070: private AnnotationType type = null;
071:
072: public AnnotationDesc(int offset, int length) {
073: counter++;
074: this .order = counter;
075: this .length = length;
076: support = new PropertyChangeSupport(this );
077: }
078:
079: /** Gets annotation coloring. This is pass through method to annotation type */
080: public Coloring getColoring() {
081: return type.getColoring();
082: }
083:
084: /** Gets glyph image. This is pass through method to annotation type */
085: public Image getGlyph() {
086: return type.getGlyphImage();
087: }
088:
089: /** Checks whether the annotation type has its own glyph icon */
090: public boolean isDefaultGlyph() {
091: return type.isDefaultGlyph();
092: }
093:
094: /**
095: * Is annotation type visible. This is pass through method to annotation
096: * type
097: */
098: public boolean isVisible() {
099: return type.isVisible();
100: }
101:
102: /** Internal order of the annotations. Used for correct cycling. */
103: public int getOrderNumber() {
104: return order;
105: }
106:
107: /** Returns list of actions associated to this annotation type. */
108: public Action[] getActions() {
109: return type.getActions();
110: }
111:
112: /** Whether this annotation annotates whole line or just part of the text */
113: public boolean isWholeLine() {
114: return length == -1;
115: }
116:
117: /** Get length of the annotation */
118: public int getLength() {
119: return length;
120: }
121:
122: /** Set Mark which represent this annotation in document */
123: void setMark(Mark mark) {
124: this .mark = mark;
125: }
126:
127: /** Get Mark which represent this annotation in document */
128: Mark getMark() {
129: return mark;
130: }
131:
132: /** Getter for annotation type object */
133: public AnnotationType getAnnotationTypeInstance() {
134: return type;
135: }
136:
137: /** Getter for annotation type name */
138: public abstract String getAnnotationType();
139:
140: /** Getter for localized tooltip text for this annotation */
141: public abstract String getShortDescription();
142:
143: /** Getter for offset of this annotation */
144: public abstract int getOffset();
145:
146: /** Getter for line number of this annotation */
147: public abstract int getLine();
148:
149: /**
150: * Method for fetching AnnotationType which correspond to the name of the
151: * annotation type stored in annotation.
152: */
153: public void updateAnnotationType() {
154: type = AnnotationTypes.getTypes().getType(getAnnotationType());
155: }
156:
157: /**
158: * Add listeners on changes of annotation properties
159: *
160: * @param l
161: * change listener
162: */
163: final public void addPropertyChangeListener(PropertyChangeListener l) {
164: support.addPropertyChangeListener(l);
165: }
166:
167: /**
168: * Remove listeners on changes of annotation properties
169: *
170: * @param l
171: * change listener
172: */
173: final public void removePropertyChangeListener(
174: PropertyChangeListener l) {
175: support.removePropertyChangeListener(l);
176: }
177:
178: /** Fire property change to registered listeners. */
179: final protected void firePropertyChange(String propertyName,
180: Object oldValue, Object newValue) {
181: support.firePropertyChange(propertyName, oldValue, newValue);
182: }
183:
184: public String toString() {
185: return "Annotation: type='" + getAnnotationType() + "', line="
186: + getLine() + // NOI18N
187: ", offset=" + getOffset() + ", length=" + length + // NOI18N
188: ", coloring=" + getColoring(); // NOI18N
189: }
190:
191: }
|