alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.editor;

import java.beans.PropertyChangeListener;
import org.netbeans.editor.Mark;
import java.beans.PropertyChangeSupport;
import java.awt.Image;
import org.netbeans.editor.AnnotationTypes;
import javax.swing.Action;

/** Description of the annotation. The annotations is defined by 
 * AnnotationType, length, offset and description.
 *
 * @author David Konecny
 * @since 07/2001
 */
public abstract class AnnotationDesc extends Object {

    /** Property name of the tip text */
    public static final String PROP_SHORT_DESCRIPTION = "shortDescription"; // NOI18N

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

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

    /** Support for property change listeners*/
    private PropertyChangeSupport support;

    /** This is sequential number which is used for cycling 
     * through the anotations. Each added annotion gets number
     * and this number if necessary is used for cycling through the 
     * annotations - cycle causes that annotation with higher number
     * is shown. If no higher number exist the cycling starts from the
     * begining. */
    private int order;

    /** Unique counter used for order variable.*/
    private static int counter = 0;

    /** Length of the annotated text. If -1 than whole line is annotated */
    private int length;

    /** Private member used by Annotations class. After the annotation is
     * attached to document, the Mark which is crated (or shared with some
     * other annotation) is stored here. Only for internal purpose of Annoations 
     * class */
    private Mark mark;

    /** AnnotationType attached to this annotation. Annotation has a few 
     * pass through methods to AnnotationType for simple access to the 
     * annotation type information. */
    private AnnotationType type = null;

    public AnnotationDesc(int offset, int length) {
        counter++;
        this.order = counter;
        this.length = length;
        support = new PropertyChangeSupport(this);
    }

    /** Gets annotation coloring. This is pass through method to annotation type */
    public Coloring getColoring() {
        if (type == null) updateAnnotationType();
        return (type != null) ? type.getColoring() : new Coloring(null, Coloring.FONT_MODE_DEFAULT, null, null, null, null, null);
    }

    /** Gets glyph image. This is pass through method to annotation type */
    public Image getGlyph() {
        if (type == null) updateAnnotationType();
        return (type != null) ? type.getGlyphImage() : null;
    }

    /** Checks whether the annotation type has its own glyph icon */
    public boolean isDefaultGlyph() {
        if (type == null) updateAnnotationType();
        return (type != null) ? type.isDefaultGlyph() : false;
    }

    /** Is annotation type visible. This is pass through method to annotation type */
    public boolean isVisible() {
        if (type == null) updateAnnotationType();
        return (type != null) ? type.isVisible() : false;
    }

    /** Internal order of the annotations. Used for correct cycling. */
    public int getOrderNumber() {
        return order;
    }

    /** Returns list of actions associated to this annotation type. */
    public Action[] getActions() {
        if (type == null) updateAnnotationType();
        return (type != null) ? type.getActions() : new Action[0];
    }

    /** Whether this annotation annotates whole line or just part of the text*/
    public boolean isWholeLine() {
        return length == -1;
    }

    /** Get length of the annotation*/
    public int getLength() {
        return length;
    }

    /** Set Mark which represent this annotation in document */
    void setMark(Mark mark) {
        this.mark = mark;
    }

    /** Get Mark which represent this annotation in document */
    Mark getMark() {
        return mark;
    }

    /** Getter for annotation type object */
    public AnnotationType getAnnotationTypeInstance() {
        return type;
    }
    
    /** Getter for annotation type name */
    public abstract String getAnnotationType();

    /** Getter for localized tooltip text for this annotation */
    public abstract String getShortDescription();

    /** Getter for offset of this annotation */
    public abstract int getOffset();

    /** Getter for line number of this annotation */
    public abstract int getLine();

    
    /** Method for fetching AnnotationType which
     * correspond to the name of the annotation type stored
     * in annotation. */
    public void updateAnnotationType() {
        type = AnnotationTypes.getTypes().getType(getAnnotationType());
    }

    /** Add listeners on changes of annotation properties
     * @param l  change listener*/
    final public void addPropertyChangeListener(PropertyChangeListener l) {
        support.addPropertyChangeListener(l);
    }

    /** Remove listeners on changes of annotation properties
     * @param l  change listener*/
    final public void removePropertyChangeListener(PropertyChangeListener l) {
        support.removePropertyChangeListener(l);
    }

    /** Fire property change to registered listeners. */
    final protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
        support.firePropertyChange(propertyName, oldValue, newValue);
    }

    public String toString() {
        return "Annotation: type='" + getAnnotationType() + "', line=" + getLine() + // NOI18N
            ", offset=" + getOffset() + ", length=" + length + // NOI18N
            ", coloring=" + getColoring(); // NOI18N
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.