1 11 package org.eclipse.ant.internal.ui.editor.text; 12 13 14 import java.util.Iterator ; 15 16 import org.eclipse.core.resources.IMarker; 17 import org.eclipse.jface.resource.ImageRegistry; 18 import org.eclipse.jface.text.Assert; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.graphics.Image; 21 import org.eclipse.swt.widgets.Display; 22 import org.eclipse.ui.texteditor.MarkerAnnotation; 23 24 public class XMLMarkerAnnotation extends MarkerAnnotation implements IXMLAnnotation { 25 private static final int NO_IMAGE= 0; 26 private static final int ORIGINAL_MARKER_IMAGE= 1; 27 private static final int OVERLAY_IMAGE= 4; 28 private static final int GRAY_IMAGE= 5; 29 30 private static ImageRegistry fgGrayMarkersImageRegistry; 31 32 private IXMLAnnotation fOverlay; 33 private boolean fNotRelevant= false; 34 private int fImageType; 35 36 public XMLMarkerAnnotation(String annotationType, IMarker marker) { 37 super(annotationType, marker); 38 } 39 40 43 protected void initialize() { 44 fImageType= NO_IMAGE; 45 46 super.initialize(); 47 } 48 49 52 public String getMessage() { 53 IMarker marker= getMarker(); 54 if (marker == null || !marker.exists()) { 55 return ""; } 57 58 return marker.getAttribute(IMarker.MESSAGE, ""); } 60 61 64 public boolean isTemporary() { 65 return false; 66 } 67 68 71 public boolean isProblem() { 72 return WARNING_ANNOTATION_TYPE.equals(getType()) || ERROR_ANNOTATION_TYPE.equals(getType()); 73 } 74 75 78 public boolean isRelevant() { 79 return !fNotRelevant; 80 } 81 82 87 public void setOverlay(IXMLAnnotation xmlAnnotation) { 88 if (fOverlay != null) { 89 fOverlay.removeOverlaid(this); 90 } 91 92 fOverlay= xmlAnnotation; 93 fNotRelevant= (fNotRelevant || fOverlay != null); 94 95 if (xmlAnnotation != null) { 96 xmlAnnotation.addOverlaid(this); 97 } 98 } 99 100 103 public boolean hasOverlay() { 104 return fOverlay != null; 105 } 106 107 110 public Image getImage(Display display) { 111 int newImageType= NO_IMAGE; 112 113 if (hasOverlay()) { 114 newImageType= OVERLAY_IMAGE; 115 } else if (isRelevant()) { 116 newImageType= ORIGINAL_MARKER_IMAGE; 117 } else { 118 newImageType= GRAY_IMAGE; 119 } 120 121 if (fImageType == newImageType && newImageType != OVERLAY_IMAGE) { 122 return super.getImage(display); 124 } 125 126 Image newImage= null; 127 switch (newImageType) { 128 case ORIGINAL_MARKER_IMAGE: 129 newImage= null; 130 break; 131 case OVERLAY_IMAGE: 132 newImage= fOverlay.getImage(display); 133 break; 134 case GRAY_IMAGE: 135 if (fImageType != ORIGINAL_MARKER_IMAGE) { 136 setImage(null); 137 } 138 Image originalImage= super.getImage(display); 139 if (originalImage != null) { 140 ImageRegistry imageRegistry= getGrayMarkerImageRegistry(display); 141 if (imageRegistry != null) { 142 String key= Integer.toString(originalImage.hashCode()); 143 Image grayImage= imageRegistry.get(key); 144 if (grayImage == null) { 145 grayImage= new Image(display, originalImage, SWT.IMAGE_GRAY); 146 imageRegistry.put(key, grayImage); 147 } 148 newImage= grayImage; 149 } 150 } 151 break; 152 default: 153 Assert.isLegal(false); 154 } 155 156 fImageType= newImageType; 157 setImage(newImage); 158 return super.getImage(display); 159 } 160 161 private ImageRegistry getGrayMarkerImageRegistry(Display display) { 162 if (fgGrayMarkersImageRegistry == null) { 163 fgGrayMarkersImageRegistry= new ImageRegistry(display); 164 } 165 return fgGrayMarkersImageRegistry; 166 } 167 168 171 public void addOverlaid(IXMLAnnotation annotation) { 172 } 174 175 178 public void removeOverlaid(IXMLAnnotation annotation) { 179 } 181 182 185 public Iterator getOverlaidIterator() { 186 return null; 188 } 189 } | Popular Tags |