1 11 12 package org.eclipse.ui.internal.editors.text; 13 14 import com.ibm.icu.text.Collator; 15 import java.util.ArrayList ; 16 import java.util.Collections ; 17 import java.util.Comparator ; 18 import java.util.HashMap ; 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 import java.util.Set ; 23 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.events.SelectionEvent; 26 import org.eclipse.swt.events.SelectionListener; 27 import org.eclipse.swt.graphics.Color; 28 import org.eclipse.swt.graphics.Image; 29 import org.eclipse.swt.graphics.ImageData; 30 import org.eclipse.swt.graphics.RGB; 31 import org.eclipse.swt.layout.GridData; 32 import org.eclipse.swt.layout.GridLayout; 33 import org.eclipse.swt.widgets.Button; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Control; 36 import org.eclipse.swt.widgets.Display; 37 import org.eclipse.swt.widgets.Label; 38 39 import org.eclipse.core.runtime.Assert; 40 41 import org.eclipse.jface.preference.ColorSelector; 42 import org.eclipse.jface.preference.PreferenceConverter; 43 import org.eclipse.jface.resource.ImageDescriptor; 44 import org.eclipse.jface.resource.ImageRegistry; 45 import org.eclipse.jface.viewers.ArrayContentProvider; 46 import org.eclipse.jface.viewers.ComboViewer; 47 import org.eclipse.jface.viewers.IColorProvider; 48 import org.eclipse.jface.viewers.ISelectionChangedListener; 49 import org.eclipse.jface.viewers.IStructuredContentProvider; 50 import org.eclipse.jface.viewers.IStructuredSelection; 51 import org.eclipse.jface.viewers.LabelProvider; 52 import org.eclipse.jface.viewers.SelectionChangedEvent; 53 import org.eclipse.jface.viewers.StructuredSelection; 54 import org.eclipse.jface.viewers.StructuredViewer; 55 import org.eclipse.jface.viewers.TableViewer; 56 import org.eclipse.jface.viewers.Viewer; 57 58 59 import org.eclipse.ui.ISharedImages; 60 import org.eclipse.ui.PlatformUI; 61 import org.eclipse.ui.ide.IDE; 62 import org.eclipse.ui.texteditor.AnnotationPreference; 63 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; 64 65 66 71 class AnnotationsConfigurationBlock implements IPreferenceConfigurationBlock { 72 private static final class ListItem { 73 final String label; 74 final Image image; 75 final String colorKey; 76 final String highlightKey; 77 final String overviewRulerKey; 78 final String textStyleKey; 79 final String textKey; 80 final String verticalRulerKey; 81 82 ListItem(String label, Image image, String colorKey, String textKey, String overviewRulerKey, String highlightKey, String verticalRulerKey, String textStyleKey) { 83 this.label= label; 84 this.image= image; 85 this.colorKey= colorKey; 86 this.highlightKey= highlightKey; 87 this.overviewRulerKey= overviewRulerKey; 88 this.textKey= textKey; 89 this.textStyleKey= textStyleKey; 90 this.verticalRulerKey= verticalRulerKey; 91 } 92 } 93 94 private static final class ItemContentProvider implements IStructuredContentProvider { 95 96 public Object [] getElements(Object inputElement) { 97 return (ListItem[]) inputElement; 98 } 99 100 public void dispose() { 101 } 102 103 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 104 } 105 } 106 107 private final class ItemLabelProvider extends LabelProvider implements IColorProvider { 108 109 public String getText(Object element) { 110 return ((ListItem) element).label; 111 } 112 113 114 public Image getImage(Object element) { 115 ListItem item= (ListItem) element; 116 if (item.verticalRulerKey != null && fStore.getBoolean(item.verticalRulerKey)) 117 return item.image; 118 119 return null; } 121 122 123 public Color getForeground(Object element) { 124 return null; 125 } 126 127 130 public Color getBackground(Object element) { 131 String key= ((ListItem) element).highlightKey; 132 if (key != null && fStore.getBoolean(key)) { 133 RGB color= PreferenceConverter.getColor(fStore, ((ListItem)element).colorKey); 134 color= interpolate(color, new RGB(255, 255, 255), 0.6); 135 return EditorsPlugin.getDefault().getSharedTextColors().getColor(color); 136 } 137 return null; 138 } 139 140 149 private RGB interpolate(RGB fg, RGB bg, double scale) { 150 return new RGB( 151 (int) ((1.0-scale) * fg.red + scale * bg.red), 152 (int) ((1.0-scale) * fg.green + scale * bg.green), 153 (int) ((1.0-scale) * fg.blue + scale * bg.blue) 154 ); 155 } 156 } 157 158 private static class ArrayLabelProvider extends LabelProvider { 159 public String getText(Object element) { 160 return ((String []) element)[0].toString(); 161 } 162 } 163 164 165 public static final String ERROR_SYSTEM_IMAGE= "error"; public static final String WARNING_SYSTEM_IMAGE= "warning"; public static final String INFO_SYSTEM_IMAGE= "info"; public static final String TASK_SYSTEM_IMAGE= "task"; public static final String BOOKMARK_SYSTEM_IMAGE= "bookmark"; 171 private final static Map MAPPING; 172 173 static { 174 MAPPING= new HashMap (); 175 MAPPING.put(ERROR_SYSTEM_IMAGE, ISharedImages.IMG_OBJS_ERROR_TSK); 176 MAPPING.put(WARNING_SYSTEM_IMAGE, ISharedImages.IMG_OBJS_WARN_TSK); 177 MAPPING.put(INFO_SYSTEM_IMAGE, ISharedImages.IMG_OBJS_INFO_TSK); 178 MAPPING.put(TASK_SYSTEM_IMAGE, IDE.SharedImages.IMG_OBJS_TASK_TSK); 179 MAPPING.put(BOOKMARK_SYSTEM_IMAGE, IDE.SharedImages.IMG_OBJS_BKMRK_TSK); 180 } 181 182 final static String [] HIGHLIGHT= new String [] {TextEditorMessages.AnnotationsConfigurationBlock_HIGHLIGHT, "not used"}; final static String [] UNDERLINE= new String [] {TextEditorMessages.AnnotationsConfigurationBlock_UNDERLINE, AnnotationPreference.STYLE_UNDERLINE}; 184 final static String [] BOX= new String [] {TextEditorMessages.AnnotationsConfigurationBlock_BOX, AnnotationPreference.STYLE_BOX}; 185 final static String [] DASHED_BOX= new String [] {TextEditorMessages.AnnotationsConfigurationBlock_DASHED_BOX, AnnotationPreference.STYLE_DASHED_BOX}; 186 final static String [] IBEAM= new String [] {TextEditorMessages.AnnotationsConfigurationBlock_IBEAM, AnnotationPreference.STYLE_IBEAM}; 187 final static String [] SQUIGGLES= new String [] {TextEditorMessages.AnnotationsConfigurationBlock_SQUIGGLES, AnnotationPreference.STYLE_SQUIGGLES}; 188 189 190 191 private OverlayPreferenceStore fStore; 192 private ColorSelector fAnnotationForegroundColorEditor; 193 194 private Button fShowInTextCheckBox; 195 private Button fShowInOverviewRulerCheckBox; 196 private Button fShowInVerticalRulerCheckBox; 197 198 private StructuredViewer fAnnotationTypeViewer; 199 private final ListItem[] fListModel; 200 201 private ComboViewer fDecorationViewer; 202 private final Set fImageKeys= new HashSet (); 203 204 public AnnotationsConfigurationBlock(OverlayPreferenceStore store) { 205 Assert.isNotNull(store); 206 MarkerAnnotationPreferences markerAnnotationPreferences= EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); 207 fStore= store; 208 fStore.addKeys(createOverlayStoreKeys(markerAnnotationPreferences)); 209 fListModel= createAnnotationTypeListModel(markerAnnotationPreferences); 210 } 211 212 private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys(MarkerAnnotationPreferences preferences) { 213 214 ArrayList overlayKeys= new ArrayList (); 215 Iterator e= preferences.getAnnotationPreferences().iterator(); 216 217 while (e.hasNext()) { 218 AnnotationPreference info= (AnnotationPreference) e.next(); 219 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, info.getColorPreferenceKey())); 220 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getTextPreferenceKey())); 221 if (info.getHighlightPreferenceKey() != null) 222 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getHighlightPreferenceKey())); 223 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getOverviewRulerPreferenceKey())); 224 if (info.getVerticalRulerPreferenceKey() != null) 225 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getVerticalRulerPreferenceKey())); 226 if (info.getTextStylePreferenceKey() != null) 227 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, info.getTextStylePreferenceKey())); 228 } 229 OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; 230 overlayKeys.toArray(keys); 231 return keys; 232 } 233 234 237 public Control createControl(Composite parent) { 238 239 PixelConverter pixelConverter= new PixelConverter(parent); 240 241 Composite composite= new Composite(parent, SWT.NULL); 242 GridLayout layout= new GridLayout(); 243 layout.numColumns= 2; 244 layout.marginHeight= 0; 245 layout.marginWidth= 0; 246 composite.setLayout(layout); 247 248 Label label= new Label(composite, SWT.LEFT); 249 label.setText(TextEditorMessages.AnnotationsConfigurationBlock_annotationPresentationOptions); 250 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 251 gd.horizontalSpan= 2; 252 label.setLayoutData(gd); 253 254 Composite editorComposite= new Composite(composite, SWT.NONE); 255 layout= new GridLayout(); 256 layout.numColumns= 2; 257 layout.marginHeight= 0; 258 layout.marginWidth= 0; 259 editorComposite.setLayout(layout); 260 gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); 261 gd.horizontalSpan= 2; 262 editorComposite.setLayoutData(gd); 263 264 fAnnotationTypeViewer= new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); 265 fAnnotationTypeViewer.setLabelProvider(new ItemLabelProvider()); 266 fAnnotationTypeViewer.setContentProvider(new ItemContentProvider()); 267 gd= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); 268 gd.heightHint= pixelConverter.convertHeightInCharsToPixels(20); 269 fAnnotationTypeViewer.getControl().setLayoutData(gd); 270 271 Composite optionsComposite= new Composite(editorComposite, SWT.NONE); 272 layout= new GridLayout(); 273 layout.marginHeight= 0; 274 layout.marginWidth= 0; 275 layout.numColumns= 2; 276 optionsComposite.setLayout(layout); 277 optionsComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); 278 279 label= new Label(optionsComposite, SWT.LEFT); 280 label.setText(TextEditorMessages.AnnotationsConfigurationBlock_labels_showIn); 281 gd= new GridData(GridData.FILL_HORIZONTAL); 282 gd.horizontalAlignment= GridData.BEGINNING; 283 gd.horizontalSpan= 2; 284 label.setLayoutData(gd); 285 286 288 fShowInTextCheckBox= new Button(optionsComposite, SWT.CHECK); 289 fShowInTextCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInText); 290 gd= new GridData(GridData.FILL_HORIZONTAL); 291 gd.horizontalAlignment= GridData.BEGINNING; 292 gd.horizontalIndent= 20; 293 fShowInTextCheckBox.setLayoutData(gd); 294 295 fDecorationViewer= new ComboViewer(optionsComposite, SWT.READ_ONLY); 296 fDecorationViewer.setContentProvider(new ArrayContentProvider()); 297 fDecorationViewer.setLabelProvider(new ArrayLabelProvider()); 298 gd= new GridData(GridData.FILL_HORIZONTAL); 299 gd.horizontalAlignment= GridData.BEGINNING; 300 fDecorationViewer.getControl().setLayoutData(gd); 301 fDecorationViewer.setInput(new Object [] {HIGHLIGHT, SQUIGGLES, BOX, DASHED_BOX, UNDERLINE, IBEAM}); 302 303 fShowInOverviewRulerCheckBox= new Button(optionsComposite, SWT.CHECK); 304 fShowInOverviewRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInOverviewRuler); 305 gd= new GridData(GridData.FILL_HORIZONTAL); 306 gd.horizontalAlignment= GridData.BEGINNING; 307 gd.horizontalSpan= 2; 308 gd.horizontalIndent= 20; 309 fShowInOverviewRulerCheckBox.setLayoutData(gd); 310 311 fShowInVerticalRulerCheckBox= new Button(optionsComposite, SWT.CHECK); 312 fShowInVerticalRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInVerticalRuler); 313 gd= new GridData(GridData.FILL_HORIZONTAL); 314 gd.horizontalAlignment= GridData.BEGINNING; 315 gd.horizontalSpan= 2; 316 gd.horizontalIndent= 20; 317 fShowInVerticalRulerCheckBox.setLayoutData(gd); 318 319 label= new Label(optionsComposite, SWT.LEFT); 320 label.setText(TextEditorMessages.AnnotationsConfigurationBlock_color); 321 gd= new GridData(); 322 gd.horizontalAlignment= GridData.BEGINNING; 323 gd.horizontalIndent= 20; 324 label.setLayoutData(gd); 325 326 fAnnotationForegroundColorEditor= new ColorSelector(optionsComposite); 327 Button foregroundColorButton= fAnnotationForegroundColorEditor.getButton(); 328 gd= new GridData(GridData.FILL_HORIZONTAL); 329 gd.horizontalAlignment= GridData.BEGINNING; 330 foregroundColorButton.setLayoutData(gd); 331 332 fAnnotationTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() { 333 public void selectionChanged(SelectionChangedEvent event) { 334 handleAnnotationListSelection(); 335 } 336 }); 337 338 fShowInTextCheckBox.addSelectionListener(new SelectionListener() { 339 public void widgetDefaultSelected(SelectionEvent e) { 340 } 342 343 public void widgetSelected(SelectionEvent e) { 344 ListItem item= getSelectedItem(); 345 final boolean value= fShowInTextCheckBox.getSelection(); 346 if (value) { 347 String [] decoration= (String []) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement(); 349 if (HIGHLIGHT.equals(decoration)) 350 fStore.setValue(item.highlightKey, true); 351 else 352 fStore.setValue(item.textKey, true); 353 } else { 354 if (item.textKey != null) 356 fStore.setValue(item.textKey, false); 357 if (item.highlightKey != null) 358 fStore.setValue(item.highlightKey, false); 359 } 360 fStore.setValue(item.textKey, value); 361 updateDecorationViewer(item, false); 362 fAnnotationTypeViewer.refresh(item); 363 } 364 }); 365 366 fShowInOverviewRulerCheckBox.addSelectionListener(new SelectionListener() { 367 public void widgetDefaultSelected(SelectionEvent e) { 368 } 370 371 public void widgetSelected(SelectionEvent e) { 372 ListItem item= getSelectedItem(); 373 fStore.setValue(item.overviewRulerKey, fShowInOverviewRulerCheckBox.getSelection()); 374 fAnnotationTypeViewer.refresh(item); 375 } 376 }); 377 378 fShowInVerticalRulerCheckBox.addSelectionListener(new SelectionListener() { 379 public void widgetDefaultSelected(SelectionEvent e) { 380 } 382 383 public void widgetSelected(SelectionEvent e) { 384 ListItem item= getSelectedItem(); 385 fStore.setValue(item.verticalRulerKey, fShowInVerticalRulerCheckBox.getSelection()); 386 fAnnotationTypeViewer.refresh(item); 387 } 388 }); 389 390 foregroundColorButton.addSelectionListener(new SelectionListener() { 391 public void widgetDefaultSelected(SelectionEvent e) { 392 } 394 395 public void widgetSelected(SelectionEvent e) { 396 ListItem item= getSelectedItem(); 397 PreferenceConverter.setValue(fStore, item.colorKey, fAnnotationForegroundColorEditor.getColorValue()); 398 fAnnotationTypeViewer.refresh(item); 399 } 400 }); 401 402 fDecorationViewer.addSelectionChangedListener(new ISelectionChangedListener() { 403 404 407 public void selectionChanged(SelectionChangedEvent event) { 408 String [] decoration= (String []) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement(); 409 ListItem item= getSelectedItem(); 410 411 if (fShowInTextCheckBox.getSelection()) { 412 if (HIGHLIGHT.equals(decoration)) { 413 fStore.setValue(item.highlightKey, true); 414 if (item.textKey != null) { 415 fStore.setValue(item.textKey, false); 416 if (item.textStyleKey != null) 417 fStore.setValue(item.textStyleKey, AnnotationPreference.STYLE_NONE); 418 } 419 } else { 420 if (item.highlightKey != null) 421 fStore.setValue(item.highlightKey, false); 422 if (item.textKey != null) { 423 fStore.setValue(item.textKey, true); 424 if (item.textStyleKey != null) 425 fStore.setValue(item.textStyleKey, decoration[1]); 426 } 427 } 428 } 429 430 fAnnotationTypeViewer.refresh(item); 431 } 432 }); 433 434 composite.layout(); 435 return composite; 436 } 437 438 441 public boolean canPerformOk() { 442 return true; 443 } 444 445 448 public void performOk() { 449 } 450 451 454 public void performDefaults() { 455 fStore.loadDefaults(); 456 fAnnotationTypeViewer.refresh(); 457 handleAnnotationListSelection(); 458 } 459 460 private void handleAnnotationListSelection() { 461 ListItem item= getSelectedItem(); 462 463 RGB rgb= PreferenceConverter.getColor(fStore, item.colorKey); 464 fAnnotationForegroundColorEditor.setColorValue(rgb); 465 466 boolean highlight= item.highlightKey == null ? false : fStore.getBoolean(item.highlightKey); 467 boolean showInText = item.textKey == null ? false : fStore.getBoolean(item.textKey); 468 fShowInTextCheckBox.setSelection(showInText || highlight); 469 470 updateDecorationViewer(item, true); 471 472 fShowInOverviewRulerCheckBox.setSelection(fStore.getBoolean(item.overviewRulerKey)); 473 474 if (item.verticalRulerKey != null) { 475 fShowInVerticalRulerCheckBox.setSelection(fStore.getBoolean(item.verticalRulerKey)); 476 fShowInVerticalRulerCheckBox.setEnabled(true); 477 } else { 478 fShowInVerticalRulerCheckBox.setSelection(true); 479 fShowInVerticalRulerCheckBox.setEnabled(false); 480 } 481 } 482 483 484 485 public void initialize() { 486 487 fAnnotationTypeViewer.setInput(fListModel); 488 fAnnotationTypeViewer.getControl().getDisplay().asyncExec(new Runnable () { 489 public void run() { 490 if (fAnnotationTypeViewer != null && !fAnnotationTypeViewer.getControl().isDisposed()) { 491 fAnnotationTypeViewer.setSelection(new StructuredSelection(fListModel[0])); 492 } 493 } 494 }); 495 496 } 497 498 private ListItem[] createAnnotationTypeListModel(MarkerAnnotationPreferences preferences) { 499 ArrayList listModelItems= new ArrayList (); 500 Iterator e= preferences.getAnnotationPreferences().iterator(); 501 502 while (e.hasNext()) { 503 AnnotationPreference info= (AnnotationPreference) e.next(); 504 if (info.isIncludeOnPreferencePage()) { 505 String label= info.getPreferenceLabel(); 506 if (containsMoreThanOne(preferences.getAnnotationPreferences().iterator(), label)) 507 label += " (" + info.getAnnotationType() + ")"; 509 Image image= getImage(info); 510 511 listModelItems.add(new ListItem(label, image, info.getColorPreferenceKey(), info.getTextPreferenceKey(), info.getOverviewRulerPreferenceKey(), info.getHighlightPreferenceKey(), info.getVerticalRulerPreferenceKey(), info.getTextStylePreferenceKey())); 512 } 513 } 514 515 Comparator comparator= new Comparator () { 516 519 public int compare(Object o1, Object o2) { 520 if (!(o2 instanceof ListItem)) 521 return -1; 522 if (!(o1 instanceof ListItem)) 523 return 1; 524 525 String label1= ((ListItem)o1).label; 526 String label2= ((ListItem)o2).label; 527 528 return Collator.getInstance().compare(label1, label2); 529 530 } 531 }; 532 Collections.sort(listModelItems, comparator); 533 534 ListItem[] items= new ListItem[listModelItems.size()]; 535 listModelItems.toArray(items); 536 return items; 537 } 538 539 547 private Image getImage(AnnotationPreference preference) { 548 549 ImageRegistry registry= EditorsPlugin.getDefault().getImageRegistry(); 550 551 String annotationType= (String ) preference.getAnnotationType(); 552 if (annotationType == null) 553 return null; 554 555 String customImage= annotationType + "__AnnotationsConfigurationBlock_Image"; 557 Image image; 558 image= registry.get(customImage); 559 if (image != null) 560 return image; 561 562 image= registry.get(annotationType); 563 if (image == null) { 564 ImageDescriptor descriptor= preference.getImageDescriptor(); 565 if (descriptor != null) { 566 registry.put(annotationType, descriptor); 567 image= registry.get(annotationType); 568 } else { 569 String key= translateSymbolicImageName(preference.getSymbolicImageName()); 570 if (key != null) { 571 ISharedImages sharedImages= PlatformUI.getWorkbench().getSharedImages(); 572 image= sharedImages.getImage(key); 573 } 574 } 575 } 576 577 if (image == null) 578 return image; 579 580 final int SIZE= 16; ImageData data= image.getImageData(); 583 Image copy; 584 if (data.height > SIZE || data.width > SIZE) { 585 copy= new Image(Display.getCurrent(), data.scaledTo(SIZE, SIZE)); 587 } else { 588 ImageData mask= data.getTransparencyMask(); 590 ImageData resized= new ImageData(SIZE, SIZE, data.depth, data.palette); 591 ImageData resizedMask= new ImageData(SIZE, SIZE, mask.depth, mask.palette); 592 593 int xo= Math.max(0, (SIZE - data.width) / 2); 594 int yo= Math.max(0, (SIZE - data.height) / 2); 595 596 for (int y= 0; y < SIZE; y++) { 597 for (int x= 0; x < SIZE; x++) { 598 if (y >= yo && x >= xo && y < yo + data.height && x < xo + data.width) { 599 resized.setPixel(x, y, data.getPixel(x - xo, y - yo)); 600 resizedMask.setPixel(x, y, mask.getPixel(x - xo, y - yo)); 601 } 602 } 603 } 604 605 copy= new Image(Display.getCurrent(), resized, resizedMask); 606 } 607 608 fImageKeys.add(customImage); 609 registry.put(customImage, copy); 610 return copy; 611 } 612 613 621 private String translateSymbolicImageName(String symbolicImageName) { 622 return (String ) MAPPING.get(symbolicImageName); 623 } 624 625 private boolean containsMoreThanOne(Iterator annotationPrefernceIterator, String label) { 626 if (label == null) 627 return false; 628 629 int count= 0; 630 while (annotationPrefernceIterator.hasNext()) { 631 if (label.equals(((AnnotationPreference)annotationPrefernceIterator.next()).getPreferenceLabel())) 632 count++; 633 634 if (count == 2) 635 return true; 636 } 637 return false; 638 } 639 640 643 public void dispose() { 644 ImageRegistry registry= EditorsPlugin.getDefault().getImageRegistry(); 645 646 for (Iterator it= fImageKeys.iterator(); it.hasNext();) { 647 String string= (String ) it.next(); 648 registry.remove(string); 649 } 650 651 fImageKeys.clear(); 652 } 653 654 private ListItem getSelectedItem() { 655 return (ListItem) ((IStructuredSelection) fAnnotationTypeViewer.getSelection()).getFirstElement(); 656 } 657 658 private void updateDecorationViewer(ListItem item, boolean changed) { 659 final boolean enabled= fShowInTextCheckBox.getSelection() && !(item.highlightKey == null && item.textStyleKey == null); 662 fDecorationViewer.getControl().setEnabled(enabled); 663 664 if (changed) { 665 String [] selection= null; 666 ArrayList list= new ArrayList (); 667 668 if (item.highlightKey != null) { 670 list.add(HIGHLIGHT); 671 if (fStore.getBoolean(item.highlightKey)) 672 selection= HIGHLIGHT; 673 } 674 675 list.add(SQUIGGLES); 677 678 if (item.textStyleKey != null) { 680 list.add(UNDERLINE); 681 list.add(BOX); 682 list.add(DASHED_BOX); 683 list.add(IBEAM); 684 } 685 686 if (selection == null) { 688 String val= item.textStyleKey == null ? SQUIGGLES[1] : fStore.getString(item.textStyleKey); 689 for (Iterator iter= list.iterator(); iter.hasNext();) { 690 String [] elem= (String []) iter.next(); 691 if (elem[1].equals(val)) { 692 selection= elem; 693 break; 694 } 695 } 696 } 697 698 fDecorationViewer.setInput(list.toArray(new Object [list.size()])); 699 if (selection != null) 700 fDecorationViewer.setSelection(new StructuredSelection((Object ) selection), true); 701 } 702 } 703 } 704 | Popular Tags |