KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.osgi.framework.Bundle;
17
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IConfigurationElement;
20 import org.eclipse.core.runtime.Platform;
21
22 import org.eclipse.swt.graphics.RGB;
23
24 import org.eclipse.jface.resource.ImageDescriptor;
25
26 import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
27
28
29 /**
30  * An annotation preference provides all the information required for handing
31  * the preferences for the presentation of annotations of a specified type. The
32  * type can be changed and retrieved using the <code>getAnnotationType</code>
33  * and <code>setAnnotationType</code> methods. For each preference, getter and
34  * setter methods are provided.
35  * <p>
36  * Preferences that may be changed by the user also have a corresponding key
37  * that can be used to obtain the currently set value from an
38  * <code>IPreferenceStore</code>.
39  * </p>
40  * <h3>The following annotation preferences are covered:</h4>
41  * <h4>Display Preferences controlling how and where annotations are shown</h4>
42  * <ul>
43  * <li>as text background highlighting (and respective preference key),</li>
44  * <li>as text decorations (and respective preference key),</li>
45  * <li>on the overview ruler (and respective preference key),</li>
46  * <li>on the overview ruler header,</li>
47  * <li>on the vertical ruler (and respective preference key),</li>
48  * </li>
49  * </ul>
50  * <h4>Additional Display Preferences</h4>
51  * <ul>
52  * <li>the base color for annotations of this type (and respective preference key),
53  * <li>the style of text decorations that are drawn (and respective preference
54  * key),</li>
55  * <li>the annotation image provider,</li>
56  * <li>the quick fix image descriptor,</li>
57  * <li>the image descriptor,</li>
58  * <li>the symbolic image name,</li>
59  * <li>the presentation layer.</li>
60  * </ul>
61  * <h4>Navigation Preferences</h4>
62  * <ul>
63  * <li>whether included in the "Go to Next Annotation" navigation action (and
64  * respective preference key),</li>
65  * <li>whether included in the "Go to Previous Annotation" navigation action
66  * (and respective preference key),</li>
67  * <li>whether to be shown in the "Go to Next/Previous Annotation" navigation
68  * toolbar drop down (and respective preference key).</li>
69  * </ul>
70  * <h4>Preference Page Preferences</h4>
71  * <ul>
72  * <li>whether the annotation type should be included on the generic annotation
73  * preference page,</li>
74  * <li>preference label.</li>
75  * </ul>
76  *
77  * @since 2.1
78  */

79 public class AnnotationPreference {
80
81     /* String constants for style enumeration */
82
83     /**
84      * Constant defining no decoration for the show in text style preference.
85      * @since 3.0
86      */

87     public static final String JavaDoc STYLE_NONE= "NONE"; //$NON-NLS-1$
88
/**
89      * Constant defining squiggly decoration for the show in text style preference.
90      * @since 3.0
91      */

92     public static final String JavaDoc STYLE_SQUIGGLES= "SQUIGGLES"; //$NON-NLS-1$
93
/**
94      * Constant defining box decoration for the show in text style preference.
95      * @since 3.0
96      */

97     public static final String JavaDoc STYLE_BOX= "BOX"; //$NON-NLS-1$
98

99     /**
100      * Constant defining dashed box decoration for the show in text style preference.
101      * @since 3.3
102      */

103     public static final String JavaDoc STYLE_DASHED_BOX= "DASHED_BOX"; //$NON-NLS-1$
104

105     /**
106      * Constant defining underline decoration for the show in text style preference.
107      * @since 3.0
108      */

109     public static final String JavaDoc STYLE_UNDERLINE= "UNDERLINE"; //$NON-NLS-1$
110
/**
111      * Constant defining i-beam decoration for the show in text style preference.
112      * @since 3.0
113      */

114     public static final String JavaDoc STYLE_IBEAM= "IBEAM"; //$NON-NLS-1$
115

116     /* IDs for presentation preference attributes */
117
118     /**
119      * The image to be used for drawing in the vertical ruler.
120      * @since 3.0
121      */

122     protected final static Object JavaDoc IMAGE_DESCRIPTOR= new Object JavaDoc();
123     /**
124      * The Quick Fix image to be used for drawing in the vertical ruler.
125      * @since 3.2
126      */

127     protected final static Object JavaDoc QUICK_FIX_IMAGE_DESCRIPTOR= new Object JavaDoc();
128     /**
129      * The preference label.
130      * @since 3.0
131      */

132     protected final static Object JavaDoc PREFERENCE_LABEL= new Object JavaDoc();
133     /**
134      * The presentation layer.
135      * @since 3.0
136      */

137     protected final static Object JavaDoc PRESENTATION_LAYER= new Object JavaDoc();
138     /**
139      * The symbolic name of the image to be drawn in the vertical ruler.
140      * @since 3.0
141      */

142     protected final static Object JavaDoc SYMBOLIC_IMAGE_NAME= new Object JavaDoc();
143     /**
144      * Indicates whether the annotation type contributed to the overview ruler's header.
145      * @since 3.0
146      */

147     protected final static Object JavaDoc HEADER_VALUE= new Object JavaDoc();
148     /**
149      * The annotation image provider.
150      * @since 3.0
151      */

152     protected final static Object JavaDoc IMAGE_PROVIDER= new Object JavaDoc();
153     /**
154      * The value for the includeOnPreferencePage property.
155      * @since 3.0
156      */

157     protected final static Object JavaDoc INCLUDE_ON_PREFERENCE_PAGE= new Object JavaDoc();
158
159     /* IDs for preference store access and initialization */
160
161     /**
162      * The preference key for the visibility inside text.
163      * @since 3.0
164      */

165     protected final static Object JavaDoc TEXT_PREFERENCE_KEY= new Object JavaDoc();
166     /**
167      * The visibility inside text.
168      * @since 3.0
169      */

170     protected final static Object JavaDoc TEXT_PREFERENCE_VALUE= new Object JavaDoc();
171     /**
172      * The preference key for the presentation color.
173      * @since 3.0
174      */

175     protected final static Object JavaDoc COLOR_PREFERENCE_KEY= new Object JavaDoc();
176     /** The presentation color.
177      * @since 3.0
178      */

179     protected final static Object JavaDoc COLOR_PREFERENCE_VALUE= new Object JavaDoc();
180     /**
181      * The preference key for highlighting inside text.
182      * @since 3.0
183      */

184     protected final static Object JavaDoc HIGHLIGHT_PREFERENCE_KEY= new Object JavaDoc();
185     /**
186      * The value for highlighting inside text.
187      * @since 3.0
188      */

189     protected final static Object JavaDoc HIGHLIGHT_PREFERENCE_VALUE= new Object JavaDoc();
190     /**
191      * The preference key for go to next navigation enablement.
192      * @since 3.0
193      */

194     protected final static Object JavaDoc IS_GO_TO_NEXT_TARGET_KEY= new Object JavaDoc();
195     /**
196      * The value for go to next navigation enablement.
197      * @since 3.0
198      */

199     protected final static Object JavaDoc IS_GO_TO_NEXT_TARGET_VALUE= new Object JavaDoc();
200     /**
201      * The preference key for go to previous navigation enablement.
202      * @since 3.0
203      */

204     protected final static Object JavaDoc IS_GO_TO_PREVIOUS_TARGET_KEY= new Object JavaDoc();
205     /**
206      * The value for go to previous navigation enablement.
207      * @since 3.0
208      */

209     protected final static Object JavaDoc IS_GO_TO_PREVIOUS_TARGET_VALUE= new Object JavaDoc();
210     /**
211      * The preference key for the visibility in the vertical ruler.
212      * @since 3.0
213      */

214     protected final static Object JavaDoc VERTICAL_RULER_PREFERENCE_KEY= new Object JavaDoc();
215     /**
216      * The visibility in the vertical ruler.
217      * @since 3.0
218      */

219     protected final static Object JavaDoc VERTICAL_RULER_PREFERENCE_VALUE= new Object JavaDoc();
220     /**
221      * The preference key for the visibility in the overview ruler.
222      * @since 3.0
223      */

224     protected final static Object JavaDoc OVERVIEW_RULER_PREFERENCE_KEY= new Object JavaDoc();
225     /**
226      * The visibility in the overview ruler.
227      * @since 3.0
228      */

229     protected final static Object JavaDoc OVERVIEW_RULER_PREFERENCE_VALUE= new Object JavaDoc();
230     /**
231      * The preference key for the visibility in the next/previous drop down toolbar action.
232      * @since 3.0
233      */

234     protected final static Object JavaDoc SHOW_IN_NAVIGATION_DROPDOWN_KEY= new Object JavaDoc();
235     /**
236      * The value for the visibility in the next/previous drop down toolbar action.
237      * @since 3.0
238      */

239     protected final static Object JavaDoc SHOW_IN_NAVIGATION_DROPDOWN_VALUE= new Object JavaDoc();
240     /**
241      * The preference key for the decoration style.
242      * @since 3.0
243      */

244     protected final static Object JavaDoc TEXT_STYLE_PREFERENCE_KEY= new Object JavaDoc();
245     /**
246      * The value for the text decoration style.
247      * @since 3.0
248      */

249     protected final static Object JavaDoc TEXT_STYLE_PREFERENCE_VALUE= new Object JavaDoc();
250
251     /**
252      * Array of all supported attributes.
253      * @since 3.0
254      */

255     protected final static Object JavaDoc[] ATTRIBUTES= new Object JavaDoc[] {
256             IMAGE_DESCRIPTOR,
257             QUICK_FIX_IMAGE_DESCRIPTOR,
258             PREFERENCE_LABEL,
259             PRESENTATION_LAYER,
260             SYMBOLIC_IMAGE_NAME,
261             HEADER_VALUE,
262             IMAGE_PROVIDER,
263             TEXT_PREFERENCE_KEY,
264             TEXT_PREFERENCE_VALUE,
265             COLOR_PREFERENCE_KEY,
266             COLOR_PREFERENCE_VALUE,
267             HIGHLIGHT_PREFERENCE_KEY,
268             HIGHLIGHT_PREFERENCE_VALUE,
269             IS_GO_TO_NEXT_TARGET_KEY,
270             IS_GO_TO_NEXT_TARGET_VALUE,
271             IS_GO_TO_PREVIOUS_TARGET_KEY,
272             IS_GO_TO_PREVIOUS_TARGET_VALUE,
273             VERTICAL_RULER_PREFERENCE_KEY,
274             VERTICAL_RULER_PREFERENCE_VALUE,
275             OVERVIEW_RULER_PREFERENCE_KEY,
276             OVERVIEW_RULER_PREFERENCE_VALUE,
277             SHOW_IN_NAVIGATION_DROPDOWN_KEY,
278             SHOW_IN_NAVIGATION_DROPDOWN_VALUE,
279             TEXT_STYLE_PREFERENCE_KEY,
280             TEXT_STYLE_PREFERENCE_VALUE,
281             INCLUDE_ON_PREFERENCE_PAGE
282     };
283
284     /** The annotation type */
285     private Object JavaDoc fAnnotationType;
286     /** The marker type */
287     private String JavaDoc fMarkerType;
288     /** The marker severity */
289     private int fSeverity;
290     /**
291      * The annotation image provider.
292      * @since 3.0
293      */

294     public IAnnotationImageProvider fAnnotationImageProvider;
295     /**
296      * The configuration element from which to create the annotation image provider.
297      * @since 3.0
298      */

299     public IConfigurationElement fConfigurationElement;
300     /**
301      * The name of the attribute used to load the annotation image provider
302      * from the configuration element.
303      * @since 3.0
304      */

305     public String JavaDoc fAnnotationImageProviderAttribute;
306     /**
307      * The map of attributes.
308      * @since 3.0
309      */

310     private Map JavaDoc fAttributes= new HashMap JavaDoc();
311
312
313
314     /**
315      * Creates a new un-initialized annotation preference. Note that instances
316      * with a <code>null</code> annotation type are invalid and should not be
317      * used.
318      */

319     public AnnotationPreference() {
320     }
321
322     /**
323      * Creates a new annotation preference for the given annotation type.
324      *
325      * @param annotationType the annotation type
326      * @param colorKey the preference key for the presentation color
327      * @param textKey the preference key for the visibility inside text
328      * @param overviewRulerKey the preference key for the visibility in the
329      * overview ruler
330      * @param presentationLayer the presentation layer
331      */

332     public AnnotationPreference(Object JavaDoc annotationType, String JavaDoc colorKey, String JavaDoc textKey, String JavaDoc overviewRulerKey, int presentationLayer) {
333         fAnnotationType= annotationType;
334         setValue(COLOR_PREFERENCE_KEY, colorKey);
335         setValue(TEXT_PREFERENCE_KEY, textKey);
336         setValue(OVERVIEW_RULER_PREFERENCE_KEY, overviewRulerKey);
337         setValue(PRESENTATION_LAYER, presentationLayer);
338     }
339
340     /**
341      * Sets the given value for the given attribute.
342      *
343      * @param attribute the attribute
344      * @param value the attribute value
345      * @since 3.0
346      */

347     protected void setValue(Object JavaDoc attribute, Object JavaDoc value) {
348         fAttributes.put(attribute, value);
349     }
350
351     /**
352      * Sets the given value for the given attribute.
353      *
354      * @param attribute the attribute
355      * @param value the attribute value
356      * @since 3.0
357      */

358     protected void setValue(Object JavaDoc attribute, int value) {
359         fAttributes.put(attribute, new Integer JavaDoc(value));
360     }
361
362     /**
363      * Sets the given value for the given attribute.
364      *
365      * @param attribute the attribute
366      * @param value the attribute value
367      * @since 3.0
368      */

369     protected void setValue(Object JavaDoc attribute, boolean value) {
370         fAttributes.put(attribute, value ? Boolean.TRUE : Boolean.FALSE);
371     }
372
373     /**
374      * Returns the value of the given attribute as string.
375      *
376      * @param attribute the attribute
377      * @return the attribute value
378      * @since 3.0
379      */

380     protected String JavaDoc getStringValue(Object JavaDoc attribute) {
381         Object JavaDoc value= fAttributes.get(attribute);
382         if (value instanceof String JavaDoc)
383             return (String JavaDoc) value;
384         return null;
385     }
386
387     /**
388      * Returns the value of the given attribute as boolean.
389      *
390      * @param attribute the attribute
391      * @return the attribute value
392      * @since 3.0
393      */

394     protected boolean getBooleanValue(Object JavaDoc attribute) {
395         Object JavaDoc value= fAttributes.get(attribute);
396         if (value instanceof Boolean JavaDoc)
397             return ((Boolean JavaDoc) value).booleanValue();
398         return false;
399     }
400
401     /**
402      * Returns the value of the given attribute as integer.
403      *
404      * @param attribute the attribute
405      * @return the attribute value
406      * @since 3.0
407      */

408     protected int getIntegerValue(Object JavaDoc attribute) {
409         Object JavaDoc value= fAttributes.get(attribute);
410         if (value instanceof Integer JavaDoc)
411             return ((Integer JavaDoc) value).intValue();
412         return 0;
413     }
414
415     /**
416      * Returns the value of the given attribute.
417      *
418      * @param attribute the attribute
419      * @return the attribute value
420      * @since 3.0
421      */

422     public Object JavaDoc getValue(Object JavaDoc attribute) {
423         return fAttributes.get(attribute);
424     }
425
426     /**
427      * Returns whether the given attribute is defined.
428      *
429      * @param attribute the attribute
430      * @return <code>true</code> if the attribute has a value <code>false</code> otherwise
431      * @since 3.0
432      */

433     public boolean hasValue(Object JavaDoc attribute) {
434         return fAttributes.get(attribute) != null;
435     }
436
437     /**
438      * Returns whether the given string is a preference key.
439      *
440      * @param key the string to test
441      * @return <code>true</code> if the string is a preference key
442      */

443     public boolean isPreferenceKey(String JavaDoc key) {
444         if (key == null)
445             return false;
446
447         return key.equals(getStringValue(COLOR_PREFERENCE_KEY)) ||
448                 key.equals(getStringValue(OVERVIEW_RULER_PREFERENCE_KEY)) ||
449                 key.equals(getStringValue(TEXT_PREFERENCE_KEY)) ||
450                 key.equals(getStringValue(HIGHLIGHT_PREFERENCE_KEY)) ||
451                 key.equals(getStringValue(TEXT_STYLE_PREFERENCE_KEY)) ||
452                 key.equals(getStringValue(VERTICAL_RULER_PREFERENCE_KEY));
453     }
454
455     /**
456      * Returns the annotation type. Should not be null in a completely set up
457      * instance.
458      *
459      * @return the annotation type, <code>null</code> if the receiver has not
460      * been initialized yet
461      */

462     public Object JavaDoc getAnnotationType() {
463         return fAnnotationType;
464     }
465
466     /**
467      * Returns the marker type.
468      *
469      * @return the marker type, or <code>null</code> if none is set
470      * @deprecated since 3.0
471      */

472     public String JavaDoc getMarkerType() {
473         return fMarkerType;
474     }
475
476     /**
477      * Returns the marker severity.
478      *
479      * @return the marker severity
480      * @deprecated since 3.0
481      */

482     public int getSeverity() {
483         return fSeverity;
484     }
485
486     /**
487      * Sets the annotation type. Note that instances with a <code>null</code>
488      * annotation type are considered invalid and should not be used with the
489      * framework.
490      *
491      * @param annotationType the annotation type
492      */

493     public void setAnnotationType(Object JavaDoc annotationType) {
494         fAnnotationType= annotationType;
495     }
496
497     /**
498      * Sets the marker type.
499      *
500      * @param markerType the marker type
501      */

502     public void setMarkerType(String JavaDoc markerType) {
503         fMarkerType= markerType;
504     }
505
506     /**
507      * Sets the marker severity.
508      *
509      * @param severity the marker severity
510      */

511     public void setSeverity(int severity) {
512         fSeverity= severity;
513     }
514
515     /**
516      * Returns the preference key for the presentation color.
517      *
518      * @return the preference key for the presentation color or <code>null</code>
519      * if none is set
520      */

521     public String JavaDoc getColorPreferenceKey() {
522         return getStringValue(COLOR_PREFERENCE_KEY);
523     }
524
525     /**
526      * Returns the default presentation color.
527      *
528      * @return the default presentation color or <code>null</code> if none is
529      * set
530      */

531     public RGB getColorPreferenceValue() {
532         return (RGB) getValue(COLOR_PREFERENCE_VALUE);
533     }
534
535     /**
536      * Returns the presentation string for this annotation type.
537      *
538      * @return the presentation string for this annotation type or <code>null</code>
539      * if none is set
540      */

541     public String JavaDoc getPreferenceLabel() {
542         return getStringValue(PREFERENCE_LABEL);
543     }
544
545     /**
546      * Returns the preference key for the visibility in the overview ruler.
547      *
548      * @return the preference key for the visibility in the overview ruler or
549      * <code>null</code> if none is set
550      */

551     public String JavaDoc getOverviewRulerPreferenceKey() {
552         return getStringValue(OVERVIEW_RULER_PREFERENCE_KEY);
553     }
554
555     /**
556      * Returns the default visibility in the overview ruler.
557      *
558      * @return the default visibility in the overview ruler
559      */

560     public boolean getOverviewRulerPreferenceValue() {
561         return getBooleanValue(OVERVIEW_RULER_PREFERENCE_VALUE);
562     }
563
564     /**
565      * Returns the preference key for the visibility in the vertical ruler.
566      *
567      * @return the preference key for the visibility in the vertical ruler or
568      * <code>null</code> if none is set
569      * @since 3.0
570      */

571     public String JavaDoc getVerticalRulerPreferenceKey() {
572         return getStringValue(VERTICAL_RULER_PREFERENCE_KEY);
573     }
574
575     /**
576      * Returns the default visibility in the vertical ruler.
577      *
578      * @return the default visibility in the vertical ruler
579      * @since 3.0
580      */

581     public boolean getVerticalRulerPreferenceValue() {
582         return getBooleanValue(VERTICAL_RULER_PREFERENCE_VALUE);
583     }
584
585     /**
586      * Returns the presentation layer.
587      *
588      * @return the presentation layer
589      */

590     public int getPresentationLayer() {
591         return getIntegerValue(PRESENTATION_LAYER);
592     }
593
594     /**
595      * Returns the preference key for the visibility inside text.
596      *
597      * @return the preference key for the visibility inside text or <code>null</code>
598      * if none is set
599      */

600     public String JavaDoc getTextPreferenceKey() {
601         return getStringValue(TEXT_PREFERENCE_KEY);
602     }
603
604     /**
605      * Returns the default visibility inside text.
606      *
607      * @return the default visibility inside text
608      */

609     public boolean getTextPreferenceValue() {
610         return getBooleanValue(TEXT_PREFERENCE_VALUE);
611     }
612
613     /**
614      * Returns the preference key for highlighting inside text.
615      *
616      * @return the preference key for highlighting inside text or <code>null</code>
617      * if none is set
618      * @since 3.0
619      */

620     public String JavaDoc getHighlightPreferenceKey() {
621         return getStringValue(HIGHLIGHT_PREFERENCE_KEY);
622     }
623
624     /**
625      * Returns the default value for highlighting inside text.
626      *
627      * @return the default value for highlighting inside text
628      * @since 3.0
629      */

630     public boolean getHighlightPreferenceValue() {
631         return getBooleanValue(HIGHLIGHT_PREFERENCE_VALUE);
632     }
633
634     /**
635      * Returns whether the annotation type contributes to the header of the overview ruler.
636      *
637      * @return <code>true</code> if the annotation type contributes to the header of the overview ruler
638      */

639     public boolean contributesToHeader() {
640         return getBooleanValue(HEADER_VALUE);
641     }
642
643     /**
644      * Sets the preference key for the presentation color.
645      *
646      * @param colorKey the preference key
647      */

648     public void setColorPreferenceKey(String JavaDoc colorKey) {
649         setValue(COLOR_PREFERENCE_KEY, colorKey);
650     }
651
652     /**
653      * Sets the default presentation color.
654      *
655      * @param colorValue the default color
656      */

657     public void setColorPreferenceValue(RGB colorValue) {
658         setValue(COLOR_PREFERENCE_VALUE, colorValue);
659     }
660
661     /**
662      * Sets the presentation label of this annotation type.
663      *
664      * @param label the presentation label
665      */

666     public void setPreferenceLabel(String JavaDoc label) {
667         setValue(PREFERENCE_LABEL, label);
668     }
669
670     /**
671      * Sets the preference key for the visibility in the overview ruler.
672      *
673      * @param overviewRulerKey the preference key
674      */

675     public void setOverviewRulerPreferenceKey(String JavaDoc overviewRulerKey) {
676         setValue(OVERVIEW_RULER_PREFERENCE_KEY, overviewRulerKey);
677     }
678
679     /**
680      * Sets the default visibility in the overview ruler.
681      *
682      * @param overviewRulerValue <code>true</code> if visible by default, <code>false</code> otherwise
683      */

684     public void setOverviewRulerPreferenceValue(boolean overviewRulerValue) {
685         setValue(OVERVIEW_RULER_PREFERENCE_VALUE, overviewRulerValue);
686     }
687
688     /**
689      * Sets the preference key for the visibility in the vertical ruler.
690      *
691      * @param verticalRulerKey the preference key
692      * @since 3.0
693      */

694     public void setVerticalRulerPreferenceKey(String JavaDoc verticalRulerKey) {
695         setValue(VERTICAL_RULER_PREFERENCE_KEY, verticalRulerKey);
696     }
697
698     /**
699      * Sets the default visibility in the vertical ruler.
700      *
701      * @param verticalRulerValue <code>true</code> if visible by default, <code>false</code> otherwise
702      * @since 3.0
703      */

704     public void setVerticalRulerPreferenceValue(boolean verticalRulerValue) {
705         setValue(VERTICAL_RULER_PREFERENCE_VALUE, verticalRulerValue);
706     }
707
708     /**
709      * Sets the presentation layer.
710      *
711      * @param presentationLayer the presentation layer
712      */

713     public void setPresentationLayer(int presentationLayer) {
714         setValue(PRESENTATION_LAYER, presentationLayer);
715     }
716
717     /**
718      * Sets the preference key for the visibility of squiggles inside text.
719      *
720      * @param textKey the preference key
721      */

722     public void setTextPreferenceKey(String JavaDoc textKey) {
723         setValue(TEXT_PREFERENCE_KEY, textKey);
724     }
725
726     /**
727      * Sets the default visibility inside text.
728      *
729      * @param textValue <code>true</code> if visible by default, <code>false</code> otherwise
730      */

731     public void setTextPreferenceValue(boolean textValue) {
732         setValue(TEXT_PREFERENCE_VALUE, textValue);
733     }
734
735     /**
736      * Sets the preference key for highlighting inside text.
737      *
738      * @param highlightKey the preference key
739      * @since 3.0
740      */

741     public void setHighlightPreferenceKey(String JavaDoc highlightKey) {
742         setValue(HIGHLIGHT_PREFERENCE_KEY, highlightKey);
743     }
744
745     /**
746      * Sets the default value for highlighting inside text.
747      *
748      * @param highlightValue <code>true</code> if highlighted in text by default, <code>false</code> otherwise
749      * @since 3.0
750      */

751     public void setHighlightPreferenceValue(boolean highlightValue) {
752         setValue(HIGHLIGHT_PREFERENCE_VALUE, highlightValue);
753     }
754
755     /**
756      * Sets whether the annotation type contributes to the overview ruler's header.
757      *
758      * @param contributesToHeader <code>true</code> if in header, <code>false</code> otherwise
759      */

760     public void setContributesToHeader(boolean contributesToHeader) {
761         setValue(HEADER_VALUE, contributesToHeader);
762     }
763
764     /**
765      * Returns the default value for go to next navigation enablement.
766      *
767      * @return <code>true</code> if enabled by default
768      * @since 3.0
769      */

770     public boolean isGoToNextNavigationTarget() {
771         return getBooleanValue(IS_GO_TO_NEXT_TARGET_VALUE);
772     }
773
774     /**
775      * Sets the default value for go to next navigation enablement.
776      *
777      * @param isGoToNextNavigationTarget <code>true</code> if enabled by default
778      * @since 3.0
779      */

780     public void setIsGoToNextNavigationTarget(boolean isGoToNextNavigationTarget) {
781         setValue(IS_GO_TO_NEXT_TARGET_VALUE, isGoToNextNavigationTarget);
782     }
783
784     /**
785      * Returns the preference key for go to next navigation enablement.
786      *
787      * @return the preference key or <code>null</code> if the key is undefined
788      * @since 3.0
789      */

790     public String JavaDoc getIsGoToNextNavigationTargetKey() {
791         return getStringValue(IS_GO_TO_NEXT_TARGET_KEY);
792     }
793
794     /**
795      * Sets the preference key for go to next navigation enablement.
796      *
797      * @param isGoToNextNavigationTargetKey <code>true</code> if enabled by default
798      * @since 3.0
799      */

800     public void setIsGoToNextNavigationTargetKey(String JavaDoc isGoToNextNavigationTargetKey) {
801         setValue(IS_GO_TO_NEXT_TARGET_KEY, isGoToNextNavigationTargetKey);
802     }
803
804     /**
805      * Returns the default value for go to previous navigation enablement.
806      *
807      * @return <code>true</code> if enabled by default
808      * @since 3.0
809      */

810     public boolean isGoToPreviousNavigationTarget() {
811         return getBooleanValue(IS_GO_TO_PREVIOUS_TARGET_VALUE);
812     }
813
814     /**
815      * Sets the default value for go to previous navigation enablement.
816      *
817      * @param isGoToPreviousNavigationTarget <code>true</code> if enabled by default
818      * @since 3.0
819      */

820     public void setIsGoToPreviousNavigationTarget(boolean isGoToPreviousNavigationTarget) {
821         setValue(IS_GO_TO_PREVIOUS_TARGET_VALUE, isGoToPreviousNavigationTarget);
822     }
823
824     /**
825      * Returns the preference key for go to previous navigation enablement.
826      *
827      * @return the preference key or <code>null</code> if the key is undefined
828      * @since 3.0
829      */

830     public String JavaDoc getIsGoToPreviousNavigationTargetKey() {
831         return getStringValue(IS_GO_TO_PREVIOUS_TARGET_KEY);
832     }
833
834     /**
835      * Sets the preference key for go to previous navigation enablement.
836      *
837      * @param isGoToPreviousNavigationTargetKey the preference key
838      * @since 3.0
839      */

840     public void setIsGoToPreviousNavigationTargetKey(String JavaDoc isGoToPreviousNavigationTargetKey) {
841         setValue(IS_GO_TO_PREVIOUS_TARGET_KEY, isGoToPreviousNavigationTargetKey);
842     }
843
844     /**
845      * Returns the preference key for the visibility in the next/previous drop down toolbar action.
846      *
847      * @return the preference key or <code>null</code> if the key is undefined
848      * @since 3.0
849      */

850     public String JavaDoc getShowInNextPrevDropdownToolbarActionKey() {
851         return getStringValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY);
852     }
853
854     /**
855      * Sets the preference key for the visibility in the next/previous drop down toolbar action.
856      *
857      * @param showInNextPrevDropdownToolbarActionKey the preference key
858      * @since 3.0
859      */

860     public void setShowInNextPrevDropdownToolbarActionKey(String JavaDoc showInNextPrevDropdownToolbarActionKey) {
861         setValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY, showInNextPrevDropdownToolbarActionKey);
862     }
863
864     /**
865      * Returns the default value for the visibility in the next/previous drop down toolbar action.
866      *
867      * @return <code>true</code> if enabled by default
868      * @since 3.0
869      */

870     public boolean isShowInNextPrevDropdownToolbarAction() {
871         return getBooleanValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE);
872     }
873
874     /**
875      * Sets the default value for the visibility in the next/previous drop down toolbar action.
876      *
877      * @param showInNextPrevDropdownToolbarAction <code>true</code> if enabled by default
878      * @since 3.0
879      */

880     public void setShowInNextPrevDropdownToolbarAction(boolean showInNextPrevDropdownToolbarAction) {
881         setValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE, showInNextPrevDropdownToolbarAction);
882     }
883
884     /**
885      * Sets the preference key for the text style property.
886      *
887      * @param key the new key
888      * @since 3.0
889      */

890     public void setTextStylePreferenceKey(String JavaDoc key) {
891         setValue(TEXT_STYLE_PREFERENCE_KEY, key);
892     }
893
894     /**
895      * Returns the preference key for the decoration style used when the annotation is shown in text.
896      *
897      * @return the preference key for the decoration style or <code>null</code> if the key is undefined
898      * @since 3.0
899      */

900     public String JavaDoc getTextStylePreferenceKey() {
901         return getStringValue(TEXT_STYLE_PREFERENCE_KEY);
902     }
903
904     /**
905      * Returns the value for the decoration style used when the annotation is shown in text.
906      *
907      * @return the value for the decoration style or <code>null</code> if the key is undefined
908      * @since 3.0
909      */

910     public String JavaDoc getTextStyleValue() {
911         return getStringValue(TEXT_STYLE_PREFERENCE_VALUE);
912     }
913
914     /**
915      * Sets the value for the text style property.
916      *
917      * @param value the new text decoration style
918      * @since 3.0
919      */

920     public void setTextStyleValue(String JavaDoc value) {
921         if (!STYLE_NONE.equals(value) && !STYLE_BOX.equals(value) && !STYLE_DASHED_BOX.equals(value)
922                 && !STYLE_IBEAM.equals(value) && !STYLE_SQUIGGLES.equals(value)
923                 && !STYLE_UNDERLINE.equals(value))
924             throw new IllegalArgumentException JavaDoc();
925
926         setValue(TEXT_STYLE_PREFERENCE_VALUE, value);
927     }
928
929     /**
930      * Returns the image descriptor for the image to be drawn in the vertical ruler. The provided
931      * image is only used, if <code>getAnnotationImageProvider</code> returns <code>null</code>.
932      *
933      * @return the image descriptor or <code>null</code>
934      * @since 3.0
935      */

936     public ImageDescriptor getImageDescriptor() {
937         return (ImageDescriptor) getValue(IMAGE_DESCRIPTOR);
938     }
939
940     /**
941      * Sets the image descriptor for the image to be drawn in the vertical ruler.
942      *
943      * @param descriptor the image descriptor
944      * @since 3.0
945      */

946     public void setImageDescriptor(ImageDescriptor descriptor) {
947         setValue(IMAGE_DESCRIPTOR, descriptor);
948     }
949
950     /**
951      * Returns the symbolic name of the image to be drawn in the vertical ruler.
952      * The image is only used if <code>getImageDescriptor</code> returns <code>null</code>.
953      *
954      * @return the symbolic name of the image or <code>null</code>
955      * @since 3.0
956      */

957     public String JavaDoc getSymbolicImageName() {
958         return getStringValue(SYMBOLIC_IMAGE_NAME);
959     }
960
961     /**
962      * Sets the symbolic name of the image to be drawn in the vertical ruler.
963      *
964      * @param symbolicImageName the symbolic image name
965      * @since 3.0
966      */

967     public void setSymbolicImageName(String JavaDoc symbolicImageName) {
968         setValue(SYMBOLIC_IMAGE_NAME, symbolicImageName);
969     }
970
971     /**
972      * Returns the annotation image provider. If no default annotation image
973      * provider has been set, this method checks whether the annotation image
974      * provider data has been set. If so, an annotation image provider is
975      * created if the configuration element's plug-in is loaded. When an
976      * annotation image provider has been created successfully, it is set as
977      * the default annotation image provider.
978      *
979      * @return the annotation image provider
980      * @since 3.0
981      */

982     public IAnnotationImageProvider getAnnotationImageProvider() {
983         if (fAnnotationImageProvider == null) {
984             if (fConfigurationElement != null && fAnnotationImageProviderAttribute != null) {
985                 Bundle bundle= Platform.getBundle( fConfigurationElement.getContributor().getName());
986                 if (bundle != null && bundle.getState() == Bundle.ACTIVE) {
987                     try {
988                         fAnnotationImageProvider= (IAnnotationImageProvider) fConfigurationElement.createExecutableExtension(fAnnotationImageProviderAttribute);
989                     } catch (CoreException x) {
990                         TextEditorPlugin.getDefault().getLog().log(x.getStatus());
991                     }
992                 }
993             }
994         }
995         return fAnnotationImageProvider;
996     }
997
998     /**
999      * Sets the annotation image provider who provides images for annotations
1000     * of the specified annotation type.
1001     *
1002     * @param provider the annotation image provider
1003     * @since 3.0
1004     */

1005    public void setAnnotationImageProvider(IAnnotationImageProvider provider) {
1006        fAnnotationImageProvider= provider;
1007        setValue(IMAGE_PROVIDER, provider != null);
1008    }
1009
1010    /**
1011     * Sets the data needed to create the annotation image provider.
1012     *
1013     * @param configurationElement the configuration element
1014     * @param annotationImageProviderAttribute the attribute of the
1015     * configuration element
1016     * @since 3.0
1017     */

1018    public void setAnnotationImageProviderData(IConfigurationElement configurationElement, String JavaDoc annotationImageProviderAttribute) {
1019        fConfigurationElement= configurationElement;
1020        fAnnotationImageProviderAttribute= annotationImageProviderAttribute;
1021        setValue(IMAGE_PROVIDER, annotationImageProviderAttribute != null);
1022    }
1023
1024    /**
1025     * Sets the property of this annotation preference whether it should be included
1026     * on the default annotation preference page.
1027     *
1028     * @param includeOnPreferencePage the new value
1029     * @since 3.0
1030     */

1031    public void setIncludeOnPreferencePage(boolean includeOnPreferencePage) {
1032        setValue(INCLUDE_ON_PREFERENCE_PAGE, includeOnPreferencePage);
1033    }
1034
1035    /**
1036     * Returns the property of the receiver of whether it should be included on
1037     * the default annotation preference page.
1038     *
1039     * @return the includeOnPreferencePage property
1040     * @since 3.0
1041     */

1042    public boolean isIncludeOnPreferencePage() {
1043        Object JavaDoc value= fAttributes.get(INCLUDE_ON_PREFERENCE_PAGE);
1044        if (value instanceof Boolean JavaDoc)
1045            return ((Boolean JavaDoc) value).booleanValue();
1046        return true;
1047    }
1048
1049    /**
1050     * Merges the values of the given preference into this preference. Existing
1051     * values will not be overwritten. Subclasses may extend.
1052     *
1053     * @param preference the preference to merge into this preference
1054     * @since 3.0
1055     */

1056    public void merge(AnnotationPreference preference) {
1057        if (!getAnnotationType().equals(preference.getAnnotationType()))
1058            return;
1059
1060        for (int i= 0; i < ATTRIBUTES.length; i++) {
1061            if (!hasValue(ATTRIBUTES[i]))
1062                setValue(ATTRIBUTES[i], preference.getValue(ATTRIBUTES[i]));
1063        }
1064
1065        if (fAnnotationImageProvider == null)
1066            fAnnotationImageProvider= preference.fAnnotationImageProvider;
1067        if (fConfigurationElement == null)
1068            fConfigurationElement= preference.fConfigurationElement;
1069        if (fAnnotationImageProviderAttribute == null)
1070            fAnnotationImageProviderAttribute= preference.fAnnotationImageProviderAttribute;
1071    }
1072
1073    /**
1074     * Sets the Quick Fix image descriptor for the image to be drawn in the vertical ruler.
1075     *
1076     * @param descriptor the image descriptor
1077     * @since 3.2
1078     */

1079    public void setQuickFixImageDescriptor(ImageDescriptor descriptor) {
1080        setValue(QUICK_FIX_IMAGE_DESCRIPTOR, descriptor);
1081    }
1082    
1083    /**
1084     * Returns the Quick Fix image descriptor for the image to be drawn in the vertical ruler. The provided
1085     * image is only used, if <code>getAnnotationImageProvider</code> returns <code>null</code>.
1086     *
1087     * @return the image descriptor or <code>null</code>
1088     * @since 3.2
1089     */

1090    public ImageDescriptor getQuickFixImageDescriptor() {
1091        return (ImageDescriptor) getValue(QUICK_FIX_IMAGE_DESCRIPTOR);
1092    }
1093    
1094}
1095
Popular Tags