Skip to main content
summaryrefslogtreecommitdiffstats
blob: 96183bb9ccf8c73c8573287b950a4669ac3158a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.texteditor;

import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.Bundle;

import org.eclipse.swt.graphics.RGB;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;

import org.eclipse.jface.resource.ImageDescriptor;

import org.eclipse.ui.internal.texteditor.TextEditorPlugin;


/**
 * An annotation preference provides all the information required for handing
 * the preferences for the presentation of annotations of a specified type. The
 * type can be changed and retrieved using the <code>getAnnotationType</code>
 * and <code>setAnnotationType</code> methods. For each preference, getter and
 * setter methods are provided.
 * <p>
 * Preferences that may be changed by the user also have a corresponding key
 * that can be used to obtain the currently set value from an
 * <code>IPreferenceStore</code>.
 * </p>
 * <h3>The following annotation preferences are covered:</h4>
 * <h4>Display Preferences controlling how and where annotations are shown</h4>
 * <ul>
 * <li>as text background highlighting (and respective preference key),</li>
 * <li>as text decorations (and respective preference key),</li>
 * <li>on the overview ruler (and respective preference key),</li>
 * <li>on the overview ruler header,</li>
 * <li>on the vertical ruler (and respective preference key),</li>
 * </li>
 * </ul>
 * <h4>Additional Display Preferences</h4>
 * <ul>
 * <li>the base color for annotations of this type (and respective preference key),
 * <li>the style of text decorations that are drawn (and respective preference
 * key),</li>
 * <li>the annotation image provider,</li>
 * <li>the quick fix image descriptor,</li>
 * <li>the image descriptor,</li>
 * <li>the symbolic image name,</li>
 * <li>the presentation layer.</li>
 * </ul>
 * <h4>Navigation Preferences</h4>
 * <ul>
 * <li>whether included in the "Go to Next Annotation" navigation action (and
 * respective preference key),</li>
 * <li>whether included in the "Go to Previous Annotation" navigation action
 * (and respective preference key),</li>
 * <li>whether to be shown in the "Go to Next/Previous Annotation" navigation
 * toolbar drop down (and respective preference key).</li>
 * </ul>
 * <h4>Preference Page Preferences</h4>
 * <ul>
 * <li>whether the annotation type should be included on the generic annotation
 * preference page,</li>
 * <li>preference label.</li>
 * </ul>
 *
 * @since 2.1
 */
public class AnnotationPreference {

	/* String constants for style enumeration */

	/**
	 * Constant defining no decoration for the show in text style preference.
	 * @since 3.0
	 */
	public static final String STYLE_NONE= "NONE"; //$NON-NLS-1$
	/**
	 * Constant defining squiggly decoration for the show in text style preference.
	 * @since 3.0
	 */
	public static final String STYLE_SQUIGGLES= "SQUIGGLES"; //$NON-NLS-1$
	/**
	 * Constant defining the native problem underline decoration for the show in
	 * text style preference.
	 * <p>
	 * The look of this style is platform dependent.
	 * </p>
	 * @since 3.4
	 */
	public static final String STYLE_PROBLEM_UNDERLINE= "PROBLEM_UNDERLINE"; //$NON-NLS-1$

	/**
	 * Constant defining box decoration for the show in text style preference.
	 * @since 3.0
	 */
	public static final String STYLE_BOX= "BOX"; //$NON-NLS-1$

	/**
	 * Constant defining dashed box decoration for the show in text style preference.
	 * @since 3.3
	 */
	public static final String STYLE_DASHED_BOX= "DASHED_BOX"; //$NON-NLS-1$

	/**
	 * Constant defining underline decoration for the show in text style preference.
	 * @since 3.0
	 */
	public static final String STYLE_UNDERLINE= "UNDERLINE"; //$NON-NLS-1$
	/**
	 * Constant defining i-beam decoration for the show in text style preference.
	 * @since 3.0
	 */
	public static final String STYLE_IBEAM= "IBEAM"; //$NON-NLS-1$

	/* IDs for presentation preference attributes */

	/**
	 * The image to be used for drawing in the vertical ruler.
	 * @since 3.0
	 */
	protected static final Object IMAGE_DESCRIPTOR= new Object();
	/**
	 * The Quick Fix image to be used for drawing in the vertical ruler.
	 * @since 3.2
	 */
	protected static final Object QUICK_FIX_IMAGE_DESCRIPTOR= new Object();
	/**
	 * The preference label.
	 * @since 3.0
	 */
	protected static final Object PREFERENCE_LABEL= new Object();
	/**
	 * The presentation layer.
	 * @since 3.0
	 */
	protected static final Object PRESENTATION_LAYER= new Object();
	/**
	 * The symbolic name of the image to be drawn in the vertical ruler.
	 * @since 3.0
	 */
	protected static final Object SYMBOLIC_IMAGE_NAME= new Object();
	/**
	 * Indicates whether the annotation type contributed to the overview ruler's header.
	 * @since 3.0
	 */
	protected static final Object HEADER_VALUE= new Object();
	/**
	 * The annotation image provider.
	 * @since 3.0
	 */
	protected static final Object IMAGE_PROVIDER= new Object();
	/**
	 * The value for the includeOnPreferencePage property.
	 * @since 3.0
	 */
	protected static final Object INCLUDE_ON_PREFERENCE_PAGE= new Object();

	/* IDs for preference store access and initialization */

	/**
	 * The preference key for the visibility inside text.
	 * @since 3.0
	 */
	protected static final Object TEXT_PREFERENCE_KEY= new Object();
	/**
	 * The visibility inside text.
	 * @since 3.0
	 */
	protected static final Object TEXT_PREFERENCE_VALUE= new Object();
	/**
	 * The preference key for the presentation color.
	 * @since 3.0
	 */
	protected static final Object COLOR_PREFERENCE_KEY= new Object();
	/** The presentation color.
	 * @since 3.0
	 */
	protected static final Object COLOR_PREFERENCE_VALUE= new Object();
	/**
	 * The preference key for highlighting inside text.
	 * @since 3.0
	 */
	protected static final Object HIGHLIGHT_PREFERENCE_KEY= new Object();
	/**
	 * The value for highlighting inside text.
	 * @since 3.0
	 */
	protected static final Object HIGHLIGHT_PREFERENCE_VALUE= new Object();
	/**
	 * The preference key for go to next navigation enablement.
	 * @since 3.0
	 */
	protected static final Object IS_GO_TO_NEXT_TARGET_KEY= new Object();
	/**
	 * The value for go to next navigation enablement.
	 * @since 3.0
	 */
	protected static final Object IS_GO_TO_NEXT_TARGET_VALUE= new Object();
	/**
	 * The preference key for go to previous navigation enablement.
	 * @since 3.0
	 */
	protected static final Object IS_GO_TO_PREVIOUS_TARGET_KEY= new Object();
	/**
	 * The value for go to previous navigation enablement.
	 * @since 3.0
	 */
	protected static final Object IS_GO_TO_PREVIOUS_TARGET_VALUE= new Object();
	/**
	 * The preference key for the visibility in the vertical ruler.
	 * @since 3.0
	 */
	protected static final Object VERTICAL_RULER_PREFERENCE_KEY= new Object();
	/**
	 * The visibility in the vertical ruler.
	 * @since 3.0
	 */
	protected static final Object VERTICAL_RULER_PREFERENCE_VALUE= new Object();
	/**
	 * The preference key for the visibility in the overview ruler.
	 * @since 3.0
	 */
	protected static final Object OVERVIEW_RULER_PREFERENCE_KEY= new Object();
	/**
	 * The visibility in the overview ruler.
	 * @since 3.0
	 */
	protected static final Object OVERVIEW_RULER_PREFERENCE_VALUE= new Object();
	/**
	 * The preference key for the visibility in the next/previous drop down toolbar action.
	 * @since 3.0
	 */
	protected static final Object SHOW_IN_NAVIGATION_DROPDOWN_KEY= new Object();
	/**
	 * The value for the visibility in the next/previous drop down toolbar action.
	 * @since 3.0
	 */
	protected static final Object SHOW_IN_NAVIGATION_DROPDOWN_VALUE= new Object();
	/**
	 * The preference key for the decoration style.
	 * @since 3.0
	 */
	protected static final Object TEXT_STYLE_PREFERENCE_KEY= new Object();
	/**
	 * The value for the text decoration style.
	 * @since 3.0
	 */
	protected static final Object TEXT_STYLE_PREFERENCE_VALUE= new Object();

	/**
	 * Array of all supported attributes.
	 * @since 3.0
	 */
	protected static final Object[] ATTRIBUTES= new Object[] {
			IMAGE_DESCRIPTOR,
			QUICK_FIX_IMAGE_DESCRIPTOR,
			PREFERENCE_LABEL,
			PRESENTATION_LAYER,
			SYMBOLIC_IMAGE_NAME,
			HEADER_VALUE,
			IMAGE_PROVIDER,
			TEXT_PREFERENCE_KEY,
			TEXT_PREFERENCE_VALUE,
			COLOR_PREFERENCE_KEY,
			COLOR_PREFERENCE_VALUE,
			HIGHLIGHT_PREFERENCE_KEY,
			HIGHLIGHT_PREFERENCE_VALUE,
			IS_GO_TO_NEXT_TARGET_KEY,
			IS_GO_TO_NEXT_TARGET_VALUE,
			IS_GO_TO_PREVIOUS_TARGET_KEY,
			IS_GO_TO_PREVIOUS_TARGET_VALUE,
			VERTICAL_RULER_PREFERENCE_KEY,
			VERTICAL_RULER_PREFERENCE_VALUE,
			OVERVIEW_RULER_PREFERENCE_KEY,
			OVERVIEW_RULER_PREFERENCE_VALUE,
			SHOW_IN_NAVIGATION_DROPDOWN_KEY,
			SHOW_IN_NAVIGATION_DROPDOWN_VALUE,
			TEXT_STYLE_PREFERENCE_KEY,
			TEXT_STYLE_PREFERENCE_VALUE,
			INCLUDE_ON_PREFERENCE_PAGE
	};

	/** The annotation type */
	private Object fAnnotationType;
	/** The marker type */
	private String fMarkerType;
	/** The marker severity */
	private int fSeverity;
	/**
	 * The annotation image provider.
	 * @since 3.0
	 */
	public IAnnotationImageProvider fAnnotationImageProvider;
	/**
	 * The configuration element from which to create the annotation image provider.
	 * @since 3.0
	 */
	public IConfigurationElement fConfigurationElement;
	/**
	 * The name of the attribute used to load the annotation image provider
	 * from the configuration element.
	 * @since 3.0
	 */
	public String fAnnotationImageProviderAttribute;
	/**
	 * The map of attributes.
	 * @since 3.0
	 */
	private Map<Object, Object> fAttributes= new HashMap<>();



	/**
	 * Creates a new un-initialized annotation preference. Note that instances
	 * with a <code>null</code> annotation type are invalid and should not be
	 * used.
	 */
	public AnnotationPreference() {
	}

	/**
	 * Creates a new annotation preference for the given annotation type.
	 *
	 * @param annotationType the annotation type
	 * @param colorKey the preference key for the presentation color
	 * @param textKey the preference key for the visibility inside text
	 * @param overviewRulerKey the preference key for the visibility in the
	 *        overview ruler
	 * @param presentationLayer the presentation layer
	 */
	public AnnotationPreference(Object annotationType, String colorKey, String textKey, String overviewRulerKey, int presentationLayer) {
		fAnnotationType= annotationType;
		setValue(COLOR_PREFERENCE_KEY, colorKey);
		setValue(TEXT_PREFERENCE_KEY, textKey);
		setValue(OVERVIEW_RULER_PREFERENCE_KEY, overviewRulerKey);
		setValue(PRESENTATION_LAYER, presentationLayer);
	}

	/**
	 * Sets the given value for the given attribute.
	 *
	 * @param attribute the attribute
	 * @param value the attribute value
	 * @since 3.0
	 */
	protected void setValue(Object attribute, Object value) {
		fAttributes.put(attribute, value);
	}

	/**
	 * Sets the given value for the given attribute.
	 *
	 * @param attribute the attribute
	 * @param value the attribute value
	 * @since 3.0
	 */
	protected void setValue(Object attribute, int value) {
		fAttributes.put(attribute, new Integer(value));
	}

	/**
	 * Sets the given value for the given attribute.
	 *
	 * @param attribute the attribute
	 * @param value the attribute value
	 * @since 3.0
	 */
	protected void setValue(Object attribute, boolean value) {
		fAttributes.put(attribute, value ? Boolean.TRUE : Boolean.FALSE);
	}

	/**
	 * Returns the value of the given attribute as string.
	 *
	 * @param attribute the attribute
	 * @return the attribute value
	 * @since 3.0
	 */
	protected String getStringValue(Object attribute) {
		Object value= fAttributes.get(attribute);
		if (value instanceof String)
			return (String) value;
		return null;
	}

	/**
	 * Returns the value of the given attribute as boolean.
	 *
	 * @param attribute the attribute
	 * @return the attribute value
	 * @since 3.0
	 */
	protected boolean getBooleanValue(Object attribute) {
		Object value= fAttributes.get(attribute);
		if (value instanceof Boolean)
			return ((Boolean) value).booleanValue();
		return false;
	}

	/**
	 * Returns the value of the given attribute as integer.
	 *
	 * @param attribute the attribute
	 * @return the attribute value
	 * @since 3.0
	 */
	protected int getIntegerValue(Object attribute) {
		Object value= fAttributes.get(attribute);
		if (value instanceof Integer)
			return ((Integer) value).intValue();
		return 0;
	}

	/**
	 * Returns the value of the given attribute.
	 *
	 * @param attribute the attribute
	 * @return the attribute value
	 * @since 3.0
	 */
	public Object getValue(Object attribute) {
		return fAttributes.get(attribute);
	}

	/**
	 * Returns whether the given attribute is defined.
	 *
	 * @param attribute the attribute
	 * @return <code>true</code> if the attribute has a value <code>false</code> otherwise
	 * @since 3.0
	 */
	public boolean hasValue(Object attribute) {
		return fAttributes.get(attribute) != null;
	}

	/**
	 * Returns whether the given string is a preference key.
	 *
	 * @param key the string to test
	 * @return <code>true</code> if the string is a preference key
	 */
	public boolean isPreferenceKey(String key) {
		if (key == null)
			return false;

		return key.equals(getStringValue(COLOR_PREFERENCE_KEY)) ||
				key.equals(getStringValue(OVERVIEW_RULER_PREFERENCE_KEY)) ||
				key.equals(getStringValue(TEXT_PREFERENCE_KEY)) ||
				key.equals(getStringValue(HIGHLIGHT_PREFERENCE_KEY)) ||
				key.equals(getStringValue(TEXT_STYLE_PREFERENCE_KEY)) ||
				key.equals(getStringValue(VERTICAL_RULER_PREFERENCE_KEY));
	}

	/**
	 * Returns the annotation type. Should not be null in a completely set up
	 * instance.
	 *
	 * @return the annotation type, <code>null</code> if the receiver has not
	 *         been initialized yet
	 */
	public Object getAnnotationType() {
		return fAnnotationType;
	}

	/**
	 * Returns the marker type.
	 *
	 * @return the marker type, or <code>null</code> if none is set
	 * @deprecated since 3.0
	 */
	@Deprecated
	public String getMarkerType() {
		return fMarkerType;
	}

	/**
	 * Returns the marker severity.
	 *
	 * @return the marker severity
	 * @deprecated since 3.0
	 */
	@Deprecated
	public int getSeverity() {
		return fSeverity;
	}

	/**
	 * Sets the annotation type. Note that instances with a <code>null</code>
	 * annotation type are considered invalid and should not be used with the
	 * framework.
	 *
	 * @param annotationType the annotation type
	 */
	public void setAnnotationType(Object annotationType) {
		fAnnotationType= annotationType;
	}

	/**
	 * Sets the marker type.
	 *
	 * @param markerType the marker type
	 */
	public void setMarkerType(String markerType) {
		fMarkerType= markerType;
	}

	/**
	 * Sets the marker severity.
	 *
	 * @param severity the marker severity
	 */
	public void setSeverity(int severity) {
		fSeverity= severity;
	}

	/**
	 * Returns the preference key for the presentation color.
	 *
	 * @return the preference key for the presentation color or <code>null</code>
	 *         if none is set
	 */
	public String getColorPreferenceKey() {
		return getStringValue(COLOR_PREFERENCE_KEY);
	}

	/**
	 * Returns the default presentation color.
	 *
	 * @return the default presentation color or <code>null</code> if none is
	 *         set
	 */
	public RGB getColorPreferenceValue() {
		return (RGB) getValue(COLOR_PREFERENCE_VALUE);
	}

	/**
	 * Returns the presentation string for this annotation type.
	 *
	 * @return the presentation string for this annotation type or <code>null</code>
	 *         if none is set
	 */
	public String getPreferenceLabel() {
		return getStringValue(PREFERENCE_LABEL);
	}

	/**
	 * Returns the preference key for the visibility in the overview ruler.
	 *
	 * @return the preference key for the visibility in the overview ruler or
	 *         <code>null</code> if none is set
	 */
	public String getOverviewRulerPreferenceKey() {
		return getStringValue(OVERVIEW_RULER_PREFERENCE_KEY);
	}

	/**
	 * Returns the default visibility in the overview ruler.
	 *
	 * @return the default visibility in the overview ruler
	 */
	public boolean getOverviewRulerPreferenceValue() {
		return getBooleanValue(OVERVIEW_RULER_PREFERENCE_VALUE);
	}

	/**
	 * Returns the preference key for the visibility in the vertical ruler.
	 *
	 * @return the preference key for the visibility in the vertical ruler or
	 *         <code>null</code> if none is set
	 * @since 3.0
	 */
	public String getVerticalRulerPreferenceKey() {
		return getStringValue(VERTICAL_RULER_PREFERENCE_KEY);
	}

	/**
	 * Returns the default visibility in the vertical ruler.
	 *
	 * @return the default visibility in the vertical ruler
	 * @since 3.0
	 */
	public boolean getVerticalRulerPreferenceValue() {
		return getBooleanValue(VERTICAL_RULER_PREFERENCE_VALUE);
	}

	/**
	 * Returns the presentation layer.
	 *
	 * @return the presentation layer
	 */
	public int getPresentationLayer() {
		return getIntegerValue(PRESENTATION_LAYER);
	}

	/**
	 * Returns the preference key for the visibility inside text.
	 *
	 * @return the preference key for the visibility inside text or <code>null</code>
	 *         if none is set
	 */
	public String getTextPreferenceKey() {
		return getStringValue(TEXT_PREFERENCE_KEY);
	}

	/**
	 * Returns the default visibility inside text.
	 *
	 * @return the default visibility inside text
	 */
	public boolean getTextPreferenceValue() {
		return getBooleanValue(TEXT_PREFERENCE_VALUE);
	}

	/**
	 * Returns the preference key for highlighting inside text.
	 *
	 * @return the preference key for highlighting inside text or <code>null</code>
	 *         if none is set
	 * @since 3.0
	 */
	public String getHighlightPreferenceKey() {
		return getStringValue(HIGHLIGHT_PREFERENCE_KEY);
	}

	/**
	 * Returns the default value for highlighting inside text.
	 *
	 * @return the default value for highlighting inside text
	 * @since 3.0
	 */
	public boolean getHighlightPreferenceValue() {
		return getBooleanValue(HIGHLIGHT_PREFERENCE_VALUE);
	}

	/**
	 * Returns whether the annotation type contributes to the header of the overview ruler.
	 *
	 * @return <code>true</code> if the annotation type contributes to the header of the overview ruler
	 */
	public boolean contributesToHeader() {
		return getBooleanValue(HEADER_VALUE);
	}

	/**
	 * Sets the preference key for the presentation color.
	 *
	 * @param colorKey the preference key
	 */
	public void setColorPreferenceKey(String colorKey) {
		setValue(COLOR_PREFERENCE_KEY, colorKey);
	}

	/**
	 * Sets the default presentation color.
	 *
	 * @param colorValue the default color
	 */
	public void setColorPreferenceValue(RGB colorValue) {
		setValue(COLOR_PREFERENCE_VALUE, colorValue);
	}

	/**
	 * Sets the presentation label of this annotation type.
	 *
	 * @param label the presentation label
	 */
	public void setPreferenceLabel(String label) {
		setValue(PREFERENCE_LABEL, label);
	}

	/**
	 * Sets the preference key for the visibility in the overview ruler.
	 *
	 * @param overviewRulerKey the preference key
	 */
	public void setOverviewRulerPreferenceKey(String overviewRulerKey) {
		setValue(OVERVIEW_RULER_PREFERENCE_KEY, overviewRulerKey);
	}

	/**
	 * Sets the default visibility in the overview ruler.
	 *
	 * @param overviewRulerValue <code>true</code> if visible by default, <code>false</code> otherwise
	 */
	public void setOverviewRulerPreferenceValue(boolean overviewRulerValue) {
		setValue(OVERVIEW_RULER_PREFERENCE_VALUE, overviewRulerValue);
	}

	/**
	 * Sets the preference key for the visibility in the vertical ruler.
	 *
	 * @param verticalRulerKey the preference key
	 * @since 3.0
	 */
	public void setVerticalRulerPreferenceKey(String verticalRulerKey) {
		setValue(VERTICAL_RULER_PREFERENCE_KEY, verticalRulerKey);
	}

	/**
	 * Sets the default visibility in the vertical ruler.
	 *
	 * @param verticalRulerValue <code>true</code> if visible by default, <code>false</code> otherwise
	 * @since 3.0
	 */
	public void setVerticalRulerPreferenceValue(boolean verticalRulerValue) {
		setValue(VERTICAL_RULER_PREFERENCE_VALUE, verticalRulerValue);
	}

	/**
	 * Sets the presentation layer.
	 *
	 * @param presentationLayer the presentation layer
	 */
	public void setPresentationLayer(int presentationLayer) {
		setValue(PRESENTATION_LAYER, presentationLayer);
	}

	/**
	 * Sets the preference key for the visibility of squiggles inside text.
	 *
	 * @param textKey the preference key
	 */
	public void setTextPreferenceKey(String textKey) {
		setValue(TEXT_PREFERENCE_KEY, textKey);
	}

	/**
	 * Sets the default visibility inside text.
	 *
	 * @param textValue <code>true</code> if visible by default, <code>false</code> otherwise
	 */
	public void setTextPreferenceValue(boolean textValue) {
		setValue(TEXT_PREFERENCE_VALUE, textValue);
	}

	/**
	 * Sets the preference key for highlighting inside text.
	 *
	 * @param highlightKey the preference key
	 * @since 3.0
	 */
	public void setHighlightPreferenceKey(String highlightKey) {
		setValue(HIGHLIGHT_PREFERENCE_KEY, highlightKey);
	}

	/**
	 * Sets the default value for highlighting inside text.
	 *
	 * @param highlightValue <code>true</code> if highlighted in text by default, <code>false</code> otherwise
	 * @since 3.0
	 */
	public void setHighlightPreferenceValue(boolean highlightValue) {
		setValue(HIGHLIGHT_PREFERENCE_VALUE, highlightValue);
	}

	/**
	 * Sets whether the annotation type contributes to the overview ruler's header.
	 *
	 * @param contributesToHeader <code>true</code> if in header, <code>false</code> otherwise
	 */
	public void setContributesToHeader(boolean contributesToHeader) {
		setValue(HEADER_VALUE, contributesToHeader);
	}

	/**
	 * Returns the default value for go to next navigation enablement.
	 *
	 * @return <code>true</code> if enabled by default
	 * @since 3.0
	 */
	public boolean isGoToNextNavigationTarget() {
		return getBooleanValue(IS_GO_TO_NEXT_TARGET_VALUE);
	}

	/**
	 * Sets the default value for go to next navigation enablement.
	 *
	 * @param isGoToNextNavigationTarget <code>true</code> if enabled by default
	 * @since 3.0
	 */
	public void setIsGoToNextNavigationTarget(boolean isGoToNextNavigationTarget) {
		setValue(IS_GO_TO_NEXT_TARGET_VALUE, isGoToNextNavigationTarget);
	}

	/**
	 * Returns the preference key for go to next navigation enablement.
	 *
	 * @return the preference key or <code>null</code> if the key is undefined
	 * @since 3.0
	 */
	public String getIsGoToNextNavigationTargetKey() {
		return getStringValue(IS_GO_TO_NEXT_TARGET_KEY);
	}

	/**
	 * Sets the preference key for go to next navigation enablement.
	 *
	 * @param isGoToNextNavigationTargetKey <code>true</code> if enabled by default
	 * @since 3.0
	 */
	public void setIsGoToNextNavigationTargetKey(String isGoToNextNavigationTargetKey) {
		setValue(IS_GO_TO_NEXT_TARGET_KEY, isGoToNextNavigationTargetKey);
	}

	/**
	 * Returns the default value for go to previous navigation enablement.
	 *
	 * @return <code>true</code> if enabled by default
	 * @since 3.0
	 */
	public boolean isGoToPreviousNavigationTarget() {
		return getBooleanValue(IS_GO_TO_PREVIOUS_TARGET_VALUE);
	}

	/**
	 * Sets the default value for go to previous navigation enablement.
	 *
	 * @param isGoToPreviousNavigationTarget <code>true</code> if enabled by default
	 * @since 3.0
	 */
	public void setIsGoToPreviousNavigationTarget(boolean isGoToPreviousNavigationTarget) {
		setValue(IS_GO_TO_PREVIOUS_TARGET_VALUE, isGoToPreviousNavigationTarget);
	}

	/**
	 * Returns the preference key for go to previous navigation enablement.
	 *
	 * @return the preference key or <code>null</code> if the key is undefined
	 * @since 3.0
	 */
	public String getIsGoToPreviousNavigationTargetKey() {
		return getStringValue(IS_GO_TO_PREVIOUS_TARGET_KEY);
	}

	/**
 	 * Sets the preference key for go to previous navigation enablement.
 	 *
 	 * @param isGoToPreviousNavigationTargetKey the preference key
	 * @since 3.0
	 */
	public void setIsGoToPreviousNavigationTargetKey(String isGoToPreviousNavigationTargetKey) {
		setValue(IS_GO_TO_PREVIOUS_TARGET_KEY, isGoToPreviousNavigationTargetKey);
	}

	/**
	 * Returns the preference key for the visibility in the next/previous drop down toolbar action.
	 *
	 * @return the preference key or <code>null</code> if the key is undefined
	 * @since 3.0
	 */
	public String getShowInNextPrevDropdownToolbarActionKey() {
		return getStringValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY);
	}

	/**
	 * Sets the preference key for the visibility in the next/previous drop down toolbar action.
	 *
	 * @param showInNextPrevDropdownToolbarActionKey the preference key
	 * @since 3.0
	 */
	public void setShowInNextPrevDropdownToolbarActionKey(String showInNextPrevDropdownToolbarActionKey) {
		setValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY, showInNextPrevDropdownToolbarActionKey);
	}

	/**
	 * Returns the default value for the visibility in the next/previous drop down toolbar action.
	 *
	 * @return <code>true</code> if enabled by default
	 * @since 3.0
	 */
	public boolean isShowInNextPrevDropdownToolbarAction() {
		return getBooleanValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE);
	}

	/**
	 * Sets the default value for the visibility in the next/previous drop down toolbar action.
	 *
	 * @param showInNextPrevDropdownToolbarAction <code>true</code> if enabled by default
	 * @since 3.0
	 */
	public void setShowInNextPrevDropdownToolbarAction(boolean showInNextPrevDropdownToolbarAction) {
		setValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE, showInNextPrevDropdownToolbarAction);
	}

	/**
	 * Sets the preference key for the text style property.
	 *
	 * @param key the new key
	 * @since 3.0
	 */
	public void setTextStylePreferenceKey(String key) {
		setValue(TEXT_STYLE_PREFERENCE_KEY, key);
	}

	/**
	 * Returns the preference key for the decoration style used when the annotation is shown in text.
	 *
	 * @return the preference key for the decoration style or <code>null</code> if the key is undefined
	 * @since 3.0
	 */
	public String getTextStylePreferenceKey() {
		return getStringValue(TEXT_STYLE_PREFERENCE_KEY);
	}

	/**
	 * Returns the value for the decoration style used when the annotation is shown in text.
	 *
	 * @return the value for the decoration style or <code>null</code> if the key is undefined
	 * @since 3.0
	 */
	public String getTextStyleValue() {
		return getStringValue(TEXT_STYLE_PREFERENCE_VALUE);
	}

	/**
	 * Sets the value for the text style property.
	 *
	 * @param value the new text decoration style
	 * @since 3.0
	 */
	public void setTextStyleValue(String value) {
		if (!STYLE_NONE.equals(value) && !STYLE_BOX.equals(value) && !STYLE_DASHED_BOX.equals(value)
				&& !STYLE_IBEAM.equals(value) && !STYLE_SQUIGGLES.equals(value)
				&& !STYLE_PROBLEM_UNDERLINE.equals(value) && !STYLE_UNDERLINE.equals(value))
			throw new IllegalArgumentException();

		setValue(TEXT_STYLE_PREFERENCE_VALUE, value);
	}

	/**
	 * Returns the image descriptor for the image to be drawn in the vertical ruler. The provided
	 * image is only used, if <code>getAnnotationImageProvider</code> returns <code>null</code>.
	 *
	 * @return the image descriptor or <code>null</code>
	 * @since 3.0
	 */
	public ImageDescriptor getImageDescriptor() {
		return (ImageDescriptor) getValue(IMAGE_DESCRIPTOR);
	}

	/**
	 * Sets the image descriptor for the image to be drawn in the vertical ruler.
	 *
	 * @param descriptor the image descriptor
	 * @since 3.0
	 */
	public void setImageDescriptor(ImageDescriptor descriptor) {
		setValue(IMAGE_DESCRIPTOR, descriptor);
	}

	/**
	 * Returns the symbolic name of the image to be drawn in the vertical ruler.
	 * The image is only used if <code>getImageDescriptor</code> returns <code>null</code>.
	 *
	 * @return the symbolic name of the image or <code>null</code>
	 * @since 3.0
	 */
	public String getSymbolicImageName() {
		return getStringValue(SYMBOLIC_IMAGE_NAME);
	}

	/**
	 * Sets the symbolic name of the image to be drawn in the vertical ruler.
	 *
	 * @param symbolicImageName the symbolic image name
	 * @since 3.0
	 */
	public void setSymbolicImageName(String symbolicImageName) {
		setValue(SYMBOLIC_IMAGE_NAME, symbolicImageName);
	}

	/**
	 * Returns the annotation image provider. If no default annotation image
	 * provider has been set, this method checks whether the annotation image
	 * provider data has been set. If so, an annotation image provider is
	 * created if the configuration element's plug-in is loaded. When an
	 * annotation image provider has been created successfully, it is set as
	 * the default annotation image provider.
	 *
	 * @return the annotation image provider
	 * @since 3.0
	 */
	public IAnnotationImageProvider getAnnotationImageProvider() {
		if (fAnnotationImageProvider == null) {
			if (fConfigurationElement != null && fAnnotationImageProviderAttribute != null) {
				Bundle bundle= Platform.getBundle( fConfigurationElement.getContributor().getName());
				if (bundle != null && bundle.getState() == Bundle.ACTIVE) {
					try {
						fAnnotationImageProvider= (IAnnotationImageProvider) fConfigurationElement.createExecutableExtension(fAnnotationImageProviderAttribute);
					} catch (CoreException x) {
						TextEditorPlugin.getDefault().getLog().log(x.getStatus());
					}
				}
			}
		}
		return fAnnotationImageProvider;
	}

	/**
	 * Sets the annotation image provider who provides images for annotations
	 * of the specified annotation type.
	 *
	 * @param provider the annotation image provider
	 * @since 3.0
	 */
	public void setAnnotationImageProvider(IAnnotationImageProvider provider) {
		fAnnotationImageProvider= provider;
		setValue(IMAGE_PROVIDER, provider != null);
	}

	/**
	 * Sets the data needed to create the annotation image provider.
	 *
	 * @param configurationElement the configuration element
	 * @param annotationImageProviderAttribute the attribute of the
	 *            configuration element
	 * @since 3.0
	 */
	public void setAnnotationImageProviderData(IConfigurationElement configurationElement, String annotationImageProviderAttribute) {
		fConfigurationElement= configurationElement;
		fAnnotationImageProviderAttribute= annotationImageProviderAttribute;
		setValue(IMAGE_PROVIDER, annotationImageProviderAttribute != null);
	}

	/**
	 * Sets the property of this annotation preference whether it should be included
	 * on the default annotation preference page.
	 *
	 * @param includeOnPreferencePage the new value
	 * @since 3.0
	 */
	public void setIncludeOnPreferencePage(boolean includeOnPreferencePage) {
		setValue(INCLUDE_ON_PREFERENCE_PAGE, includeOnPreferencePage);
	}

	/**
	 * Returns the property of the receiver of whether it should be included on
	 * the default annotation preference page.
	 *
	 * @return the includeOnPreferencePage property
	 * @since 3.0
	 */
	public boolean isIncludeOnPreferencePage() {
		Object value= fAttributes.get(INCLUDE_ON_PREFERENCE_PAGE);
		if (value instanceof Boolean)
			return ((Boolean) value).booleanValue();
		return true;
	}

	/**
	 * Merges the values of the given preference into this preference. Existing
	 * values will not be overwritten. Subclasses may extend.
	 *
	 * @param preference the preference to merge into this preference
	 * @since 3.0
	 */
	public void merge(AnnotationPreference preference) {
		if (!getAnnotationType().equals(preference.getAnnotationType()))
			return;

		for (int i= 0; i < ATTRIBUTES.length; i++) {
			if (!hasValue(ATTRIBUTES[i]))
				setValue(ATTRIBUTES[i], preference.getValue(ATTRIBUTES[i]));
		}

		if (fAnnotationImageProvider == null)
			fAnnotationImageProvider= preference.fAnnotationImageProvider;
		if (fConfigurationElement == null)
			fConfigurationElement= preference.fConfigurationElement;
		if (fAnnotationImageProviderAttribute == null)
			fAnnotationImageProviderAttribute= preference.fAnnotationImageProviderAttribute;
	}

	/**
	 * Sets the Quick Fix image descriptor for the image to be drawn in the vertical ruler.
	 *
	 * @param descriptor the image descriptor
	 * @since 3.2
	 */
	public void setQuickFixImageDescriptor(ImageDescriptor descriptor) {
		setValue(QUICK_FIX_IMAGE_DESCRIPTOR, descriptor);
	}

	/**
	 * Returns the Quick Fix image descriptor for the image to be drawn in the vertical ruler. The provided
	 * image is only used, if <code>getAnnotationImageProvider</code> returns <code>null</code>.
	 *
	 * @return the image descriptor or <code>null</code>
	 * @since 3.2
	 */
	public ImageDescriptor getQuickFixImageDescriptor() {
		return (ImageDescriptor) getValue(QUICK_FIX_IMAGE_DESCRIPTOR);
	}

}

Back to the top