KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > SimpleMarkerAnnotation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.texteditor;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.jface.text.source.Annotation;
17 import org.eclipse.ui.internal.editors.text.EditorsPlugin;
18
19
20 /**
21  * An annotation representing a marker. This is a model annotation.
22  *
23  * @see IMarker
24  * @since 3.0
25  */

26 public class SimpleMarkerAnnotation extends Annotation {
27
28     private IMarker fMarker;
29
30     /**
31      * Creates a new annotation for the given marker.
32      * @see IMarker
33      *
34      * @param marker the marker
35      */

36     public SimpleMarkerAnnotation(IMarker marker) {
37         this(EditorsPlugin.getDefault().getAnnotationTypeLookup().getAnnotationType(marker), marker);
38     }
39
40     /**
41      * Creates a new annotation of the given type for the given marker.
42      *
43      * @param annotationType the annotation type
44      * @param marker the marker
45      */

46     public SimpleMarkerAnnotation(String JavaDoc annotationType, IMarker marker) {
47         super(annotationType, true, null);
48         Assert.isNotNull(marker);
49         fMarker= marker;
50     }
51
52     /**
53      * Returns this annotation's underlying marker.
54      *
55      * @return the marker
56      */

57     public IMarker getMarker() {
58         return fMarker;
59     }
60
61     /**
62      * The <code>SimpleMarkerAnnotation</code> implementation of this
63      * <code>Object</code> method returns <code>true</code> iff the other
64      * object is of the same class and the marker handles are equal.
65      *
66      * @see Object#equals(java.lang.Object)
67      */

68     public boolean equals(Object JavaDoc o) {
69         if (o != null && o.getClass() == getClass())
70             return fMarker.equals(((SimpleMarkerAnnotation) o).fMarker);
71         return false;
72     }
73
74     /*
75      * @see Object#hashCode()
76      */

77     public int hashCode() {
78         return fMarker.hashCode();
79     }
80
81     /**
82      * Informs this annotation about changes applied to its underlying marker
83      * and adapts to those changes.
84      * <p>
85      * Subclasses may extend this method.
86      * </p>
87      */

88     public void update() {
89         updateType();
90     }
91
92     /**
93      * Updates the type to be synchronized with its underlying marker.
94      *
95      * @since 3.0
96      */

97     private void updateType() {
98         String JavaDoc annotationType= EditorsPlugin.getDefault().getAnnotationTypeLookup().getAnnotationType(fMarker);
99         if (annotationType != null && !annotationType.equals(getType()))
100             setType(annotationType);
101     }
102
103     /*
104      * @see org.eclipse.jface.text.source.Annotation#getText()
105      */

106     public String JavaDoc getText() {
107         return MarkerUtilities.getMessage(fMarker);
108     }
109 }
110
Popular Tags