1 11 package org.eclipse.ui.texteditor; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 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 79 public class AnnotationPreference { 80 81 82 83 87 public static final String STYLE_NONE= "NONE"; 92 public static final String STYLE_SQUIGGLES= "SQUIGGLES"; 97 public static final String STYLE_BOX= "BOX"; 99 103 public static final String STYLE_DASHED_BOX= "DASHED_BOX"; 105 109 public static final String STYLE_UNDERLINE= "UNDERLINE"; 114 public static final String STYLE_IBEAM= "IBEAM"; 116 117 118 122 protected final static Object IMAGE_DESCRIPTOR= new Object (); 123 127 protected final static Object QUICK_FIX_IMAGE_DESCRIPTOR= new Object (); 128 132 protected final static Object PREFERENCE_LABEL= new Object (); 133 137 protected final static Object PRESENTATION_LAYER= new Object (); 138 142 protected final static Object SYMBOLIC_IMAGE_NAME= new Object (); 143 147 protected final static Object HEADER_VALUE= new Object (); 148 152 protected final static Object IMAGE_PROVIDER= new Object (); 153 157 protected final static Object INCLUDE_ON_PREFERENCE_PAGE= new Object (); 158 159 160 161 165 protected final static Object TEXT_PREFERENCE_KEY= new Object (); 166 170 protected final static Object TEXT_PREFERENCE_VALUE= new Object (); 171 175 protected final static Object COLOR_PREFERENCE_KEY= new Object (); 176 179 protected final static Object COLOR_PREFERENCE_VALUE= new Object (); 180 184 protected final static Object HIGHLIGHT_PREFERENCE_KEY= new Object (); 185 189 protected final static Object HIGHLIGHT_PREFERENCE_VALUE= new Object (); 190 194 protected final static Object IS_GO_TO_NEXT_TARGET_KEY= new Object (); 195 199 protected final static Object IS_GO_TO_NEXT_TARGET_VALUE= new Object (); 200 204 protected final static Object IS_GO_TO_PREVIOUS_TARGET_KEY= new Object (); 205 209 protected final static Object IS_GO_TO_PREVIOUS_TARGET_VALUE= new Object (); 210 214 protected final static Object VERTICAL_RULER_PREFERENCE_KEY= new Object (); 215 219 protected final static Object VERTICAL_RULER_PREFERENCE_VALUE= new Object (); 220 224 protected final static Object OVERVIEW_RULER_PREFERENCE_KEY= new Object (); 225 229 protected final static Object OVERVIEW_RULER_PREFERENCE_VALUE= new Object (); 230 234 protected final static Object SHOW_IN_NAVIGATION_DROPDOWN_KEY= new Object (); 235 239 protected final static Object SHOW_IN_NAVIGATION_DROPDOWN_VALUE= new Object (); 240 244 protected final static Object TEXT_STYLE_PREFERENCE_KEY= new Object (); 245 249 protected final static Object TEXT_STYLE_PREFERENCE_VALUE= new Object (); 250 251 255 protected final static Object [] ATTRIBUTES= new Object [] { 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 285 private Object fAnnotationType; 286 287 private String fMarkerType; 288 289 private int fSeverity; 290 294 public IAnnotationImageProvider fAnnotationImageProvider; 295 299 public IConfigurationElement fConfigurationElement; 300 305 public String fAnnotationImageProviderAttribute; 306 310 private Map fAttributes= new HashMap (); 311 312 313 314 319 public AnnotationPreference() { 320 } 321 322 332 public AnnotationPreference(Object annotationType, String colorKey, String textKey, String 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 347 protected void setValue(Object attribute, Object value) { 348 fAttributes.put(attribute, value); 349 } 350 351 358 protected void setValue(Object attribute, int value) { 359 fAttributes.put(attribute, new Integer (value)); 360 } 361 362 369 protected void setValue(Object attribute, boolean value) { 370 fAttributes.put(attribute, value ? Boolean.TRUE : Boolean.FALSE); 371 } 372 373 380 protected String getStringValue(Object attribute) { 381 Object value= fAttributes.get(attribute); 382 if (value instanceof String ) 383 return (String ) value; 384 return null; 385 } 386 387 394 protected boolean getBooleanValue(Object attribute) { 395 Object value= fAttributes.get(attribute); 396 if (value instanceof Boolean ) 397 return ((Boolean ) value).booleanValue(); 398 return false; 399 } 400 401 408 protected int getIntegerValue(Object attribute) { 409 Object value= fAttributes.get(attribute); 410 if (value instanceof Integer ) 411 return ((Integer ) value).intValue(); 412 return 0; 413 } 414 415 422 public Object getValue(Object attribute) { 423 return fAttributes.get(attribute); 424 } 425 426 433 public boolean hasValue(Object attribute) { 434 return fAttributes.get(attribute) != null; 435 } 436 437 443 public boolean isPreferenceKey(String 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 462 public Object getAnnotationType() { 463 return fAnnotationType; 464 } 465 466 472 public String getMarkerType() { 473 return fMarkerType; 474 } 475 476 482 public int getSeverity() { 483 return fSeverity; 484 } 485 486 493 public void setAnnotationType(Object annotationType) { 494 fAnnotationType= annotationType; 495 } 496 497 502 public void setMarkerType(String markerType) { 503 fMarkerType= markerType; 504 } 505 506 511 public void setSeverity(int severity) { 512 fSeverity= severity; 513 } 514 515 521 public String getColorPreferenceKey() { 522 return getStringValue(COLOR_PREFERENCE_KEY); 523 } 524 525 531 public RGB getColorPreferenceValue() { 532 return (RGB) getValue(COLOR_PREFERENCE_VALUE); 533 } 534 535 541 public String getPreferenceLabel() { 542 return getStringValue(PREFERENCE_LABEL); 543 } 544 545 551 public String getOverviewRulerPreferenceKey() { 552 return getStringValue(OVERVIEW_RULER_PREFERENCE_KEY); 553 } 554 555 560 public boolean getOverviewRulerPreferenceValue() { 561 return getBooleanValue(OVERVIEW_RULER_PREFERENCE_VALUE); 562 } 563 564 571 public String getVerticalRulerPreferenceKey() { 572 return getStringValue(VERTICAL_RULER_PREFERENCE_KEY); 573 } 574 575 581 public boolean getVerticalRulerPreferenceValue() { 582 return getBooleanValue(VERTICAL_RULER_PREFERENCE_VALUE); 583 } 584 585 590 public int getPresentationLayer() { 591 return getIntegerValue(PRESENTATION_LAYER); 592 } 593 594 600 public String getTextPreferenceKey() { 601 return getStringValue(TEXT_PREFERENCE_KEY); 602 } 603 604 609 public boolean getTextPreferenceValue() { 610 return getBooleanValue(TEXT_PREFERENCE_VALUE); 611 } 612 613 620 public String getHighlightPreferenceKey() { 621 return getStringValue(HIGHLIGHT_PREFERENCE_KEY); 622 } 623 624 630 public boolean getHighlightPreferenceValue() { 631 return getBooleanValue(HIGHLIGHT_PREFERENCE_VALUE); 632 } 633 634 639 public boolean contributesToHeader() { 640 return getBooleanValue(HEADER_VALUE); 641 } 642 643 648 public void setColorPreferenceKey(String colorKey) { 649 setValue(COLOR_PREFERENCE_KEY, colorKey); 650 } 651 652 657 public void setColorPreferenceValue(RGB colorValue) { 658 setValue(COLOR_PREFERENCE_VALUE, colorValue); 659 } 660 661 666 public void setPreferenceLabel(String label) { 667 setValue(PREFERENCE_LABEL, label); 668 } 669 670 675 public void setOverviewRulerPreferenceKey(String overviewRulerKey) { 676 setValue(OVERVIEW_RULER_PREFERENCE_KEY, overviewRulerKey); 677 } 678 679 684 public void setOverviewRulerPreferenceValue(boolean overviewRulerValue) { 685 setValue(OVERVIEW_RULER_PREFERENCE_VALUE, overviewRulerValue); 686 } 687 688 694 public void setVerticalRulerPreferenceKey(String verticalRulerKey) { 695 setValue(VERTICAL_RULER_PREFERENCE_KEY, verticalRulerKey); 696 } 697 698 704 public void setVerticalRulerPreferenceValue(boolean verticalRulerValue) { 705 setValue(VERTICAL_RULER_PREFERENCE_VALUE, verticalRulerValue); 706 } 707 708 713 public void setPresentationLayer(int presentationLayer) { 714 setValue(PRESENTATION_LAYER, presentationLayer); 715 } 716 717 722 public void setTextPreferenceKey(String textKey) { 723 setValue(TEXT_PREFERENCE_KEY, textKey); 724 } 725 726 731 public void setTextPreferenceValue(boolean textValue) { 732 setValue(TEXT_PREFERENCE_VALUE, textValue); 733 } 734 735 741 public void setHighlightPreferenceKey(String highlightKey) { 742 setValue(HIGHLIGHT_PREFERENCE_KEY, highlightKey); 743 } 744 745 751 public void setHighlightPreferenceValue(boolean highlightValue) { 752 setValue(HIGHLIGHT_PREFERENCE_VALUE, highlightValue); 753 } 754 755 760 public void setContributesToHeader(boolean contributesToHeader) { 761 setValue(HEADER_VALUE, contributesToHeader); 762 } 763 764 770 public boolean isGoToNextNavigationTarget() { 771 return getBooleanValue(IS_GO_TO_NEXT_TARGET_VALUE); 772 } 773 774 780 public void setIsGoToNextNavigationTarget(boolean isGoToNextNavigationTarget) { 781 setValue(IS_GO_TO_NEXT_TARGET_VALUE, isGoToNextNavigationTarget); 782 } 783 784 790 public String getIsGoToNextNavigationTargetKey() { 791 return getStringValue(IS_GO_TO_NEXT_TARGET_KEY); 792 } 793 794 800 public void setIsGoToNextNavigationTargetKey(String isGoToNextNavigationTargetKey) { 801 setValue(IS_GO_TO_NEXT_TARGET_KEY, isGoToNextNavigationTargetKey); 802 } 803 804 810 public boolean isGoToPreviousNavigationTarget() { 811 return getBooleanValue(IS_GO_TO_PREVIOUS_TARGET_VALUE); 812 } 813 814 820 public void setIsGoToPreviousNavigationTarget(boolean isGoToPreviousNavigationTarget) { 821 setValue(IS_GO_TO_PREVIOUS_TARGET_VALUE, isGoToPreviousNavigationTarget); 822 } 823 824 830 public String getIsGoToPreviousNavigationTargetKey() { 831 return getStringValue(IS_GO_TO_PREVIOUS_TARGET_KEY); 832 } 833 834 840 public void setIsGoToPreviousNavigationTargetKey(String isGoToPreviousNavigationTargetKey) { 841 setValue(IS_GO_TO_PREVIOUS_TARGET_KEY, isGoToPreviousNavigationTargetKey); 842 } 843 844 850 public String getShowInNextPrevDropdownToolbarActionKey() { 851 return getStringValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY); 852 } 853 854 860 public void setShowInNextPrevDropdownToolbarActionKey(String showInNextPrevDropdownToolbarActionKey) { 861 setValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY, showInNextPrevDropdownToolbarActionKey); 862 } 863 864 870 public boolean isShowInNextPrevDropdownToolbarAction() { 871 return getBooleanValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE); 872 } 873 874 880 public void setShowInNextPrevDropdownToolbarAction(boolean showInNextPrevDropdownToolbarAction) { 881 setValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE, showInNextPrevDropdownToolbarAction); 882 } 883 884 890 public void setTextStylePreferenceKey(String key) { 891 setValue(TEXT_STYLE_PREFERENCE_KEY, key); 892 } 893 894 900 public String getTextStylePreferenceKey() { 901 return getStringValue(TEXT_STYLE_PREFERENCE_KEY); 902 } 903 904 910 public String getTextStyleValue() { 911 return getStringValue(TEXT_STYLE_PREFERENCE_VALUE); 912 } 913 914 920 public void setTextStyleValue(String 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 (); 925 926 setValue(TEXT_STYLE_PREFERENCE_VALUE, value); 927 } 928 929 936 public ImageDescriptor getImageDescriptor() { 937 return (ImageDescriptor) getValue(IMAGE_DESCRIPTOR); 938 } 939 940 946 public void setImageDescriptor(ImageDescriptor descriptor) { 947 setValue(IMAGE_DESCRIPTOR, descriptor); 948 } 949 950 957 public String getSymbolicImageName() { 958 return getStringValue(SYMBOLIC_IMAGE_NAME); 959 } 960 961 967 public void setSymbolicImageName(String symbolicImageName) { 968 setValue(SYMBOLIC_IMAGE_NAME, symbolicImageName); 969 } 970 971 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 1005 public void setAnnotationImageProvider(IAnnotationImageProvider provider) { 1006 fAnnotationImageProvider= provider; 1007 setValue(IMAGE_PROVIDER, provider != null); 1008 } 1009 1010 1018 public void setAnnotationImageProviderData(IConfigurationElement configurationElement, String annotationImageProviderAttribute) { 1019 fConfigurationElement= configurationElement; 1020 fAnnotationImageProviderAttribute= annotationImageProviderAttribute; 1021 setValue(IMAGE_PROVIDER, annotationImageProviderAttribute != null); 1022 } 1023 1024 1031 public void setIncludeOnPreferencePage(boolean includeOnPreferencePage) { 1032 setValue(INCLUDE_ON_PREFERENCE_PAGE, includeOnPreferencePage); 1033 } 1034 1035 1042 public boolean isIncludeOnPreferencePage() { 1043 Object value= fAttributes.get(INCLUDE_ON_PREFERENCE_PAGE); 1044 if (value instanceof Boolean ) 1045 return ((Boolean ) value).booleanValue(); 1046 return true; 1047 } 1048 1049 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 1079 public void setQuickFixImageDescriptor(ImageDescriptor descriptor) { 1080 setValue(QUICK_FIX_IMAGE_DESCRIPTOR, descriptor); 1081 } 1082 1083 1090 public ImageDescriptor getQuickFixImageDescriptor() { 1091 return (ImageDescriptor) getValue(QUICK_FIX_IMAGE_DESCRIPTOR); 1092 } 1093 1094} 1095 | Popular Tags |