comparison dwtx/jface/text/source/AnnotationPainter.d @ 158:25f1f92fa3df

...
author Frank Benoit <benoit@tionex.de>
date Tue, 26 Aug 2008 02:46:34 +0200
parents 7f75eaa8103a
children 7926b636c282
comparison
equal deleted inserted replaced
157:7f75eaa8103a 158:25f1f92fa3df
116 import dwtx.jface.text.Position; 116 import dwtx.jface.text.Position;
117 import dwtx.jface.text.Region; 117 import dwtx.jface.text.Region;
118 import dwtx.jface.text.TextPresentation; 118 import dwtx.jface.text.TextPresentation;
119 119
120 120
121 /**
122 * Paints decorations for annotations provided by an annotation model and/or
123 * highlights them in the associated source viewer.
124 * <p>
125 * The annotation painter can be configured with drawing strategies. A drawing
126 * strategy defines the visual presentation of a particular type of annotation
127 * decoration.</p>
128 * <p>
129 * Clients usually instantiate and configure objects of this class.</p>
130 *
131 * @since 2.1
132 */
133 public class AnnotationPainter : IPainter, PaintListener, IAnnotationModelListener, IAnnotationModelListenerExtension, ITextPresentationListener {
134
135
136 /** 121 /**
137 * A drawing strategy draws the decoration for an annotation onto the text widget. 122 * A drawing strategy draws the decoration for an annotation onto the text widget.
138 * 123 *
139 * @since 3.0 124 * @since 3.0
140 */ 125 */
161 * @param color the color of the line 146 * @param color the color of the line
162 */ 147 */
163 void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color); 148 void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color);
164 } 149 }
165 150
151 alias IDrawingStrategy AnnotationPainter_IDrawingStrategy;
152
153 /**
154 * Paints decorations for annotations provided by an annotation model and/or
155 * highlights them in the associated source viewer.
156 * <p>
157 * The annotation painter can be configured with drawing strategies. A drawing
158 * strategy defines the visual presentation of a particular type of annotation
159 * decoration.</p>
160 * <p>
161 * Clients usually instantiate and configure objects of this class.</p>
162 *
163 * @since 2.1
164 */
165 public class AnnotationPainter : IPainter, PaintListener, IAnnotationModelListener, IAnnotationModelListenerExtension, ITextPresentationListener {
166
166 /** 167 /**
167 * Squiggles drawing strategy. 168 * Squiggles drawing strategy.
168 * 169 *
169 * @since 3.0 170 * @since 3.0
170 * @deprecated As of 3.4, replaced by {@link AnnotationPainter.UnderlineStrategy} 171 * @deprecated As of 3.4, replaced by {@link AnnotationPainter.UnderlineStrategy}
929 * 930 *
930 * @param type the annotation type 931 * @param type the annotation type
931 * @return the annotation painter 932 * @return the annotation painter
932 * @since 3.0 933 * @since 3.0
933 */ 934 */
934 private Object getPaintingStrategy(final String type) { 935 private Object getPaintingStrategy(String type) {
935 Object strategy= fCachedAnnotationType2PaintingStrategy.get(type); 936 Object strategy= fCachedAnnotationType2PaintingStrategy.get(type);
936 if (strategy !is null) 937 if (strategy !is null)
937 return strategy; 938 return strategy;
938 939
939 strategy= fPaintingStrategyId2PaintingStrategy.get(fAnnotationType2PaintingStrategyId.get(type)); 940 strategy= fPaintingStrategyId2PaintingStrategy.get(fAnnotationType2PaintingStrategyId.get(type));
964 * 965 *
965 * @param annotationType the annotation type 966 * @param annotationType the annotation type
966 * @return the color 967 * @return the color
967 * @since 3.0 968 * @since 3.0
968 */ 969 */
969 private Color getColor(final Object annotationType) { 970 private Color getColor(Object annotationType) {
970 Color color= cast(Color)fCachedAnnotationType2Color.get(annotationType); 971 Color color= cast(Color)fCachedAnnotationType2Color.get(annotationType);
971 if (color !is null) 972 if (color !is null)
972 return color; 973 return color;
973 974
974 color= cast(Color)fAnnotationType2Color.get(annotationType); 975 color= cast(Color)fAnnotationType2Color.get(annotationType);
1089 } 1090 }
1090 1091
1091 /* 1092 /*
1092 * @see dwtx.jface.text.source.IAnnotationModelListener#modelChanged(dwtx.jface.text.source.IAnnotationModel) 1093 * @see dwtx.jface.text.source.IAnnotationModelListener#modelChanged(dwtx.jface.text.source.IAnnotationModel)
1093 */ 1094 */
1094 public synchronized void modelChanged(final IAnnotationModel model) { 1095 public synchronized void modelChanged(IAnnotationModel model) {
1095 if (DEBUG) 1096 if (DEBUG)
1096 System.err.println("AP: OLD API of AnnotationModelListener called"); //$NON-NLS-1$ 1097 System.err.println("AP: OLD API of AnnotationModelListener called"); //$NON-NLS-1$
1097 1098
1098 modelChanged(new AnnotationModelEvent(model)); 1099 modelChanged(new AnnotationModelEvent(model));
1099 } 1100 }
1100 1101
1101 /* 1102 /*
1102 * @see dwtx.jface.text.source.IAnnotationModelListenerExtension#modelChanged(dwtx.jface.text.source.AnnotationModelEvent) 1103 * @see dwtx.jface.text.source.IAnnotationModelListenerExtension#modelChanged(dwtx.jface.text.source.AnnotationModelEvent)
1103 */ 1104 */
1104 public void modelChanged(final AnnotationModelEvent event) { 1105 public void modelChanged(AnnotationModelEvent event) {
1105 Display textWidgetDisplay; 1106 Display textWidgetDisplay;
1106 try { 1107 try {
1107 StyledText textWidget= fTextWidget; 1108 StyledText textWidget= fTextWidget;
1108 if (textWidget is null || textWidget.isDisposed()) 1109 if (textWidget is null || textWidget.isDisposed())
1109 return; 1110 return;
1134 // XXX: posting here is a problem for annotations that are being 1135 // XXX: posting here is a problem for annotations that are being
1135 // removed and the positions of which are not updated to document 1136 // removed and the positions of which are not updated to document
1136 // changes any more. If the document gets modified between 1137 // changes any more. If the document gets modified between
1137 // now and running the posted runnable, the position information 1138 // now and running the posted runnable, the position information
1138 // is not accurate any longer. 1139 // is not accurate any longer.
1139 textWidgetDisplay.asyncExec(new class() Runnable { 1140 textWidgetDisplay.asyncExec( dgRunnable( (Event event_){
1140 public void run() { 1141 if (fTextWidget !is null && !fTextWidget.isDisposed())
1141 if (fTextWidget !is null && !fTextWidget.isDisposed()) 1142 updatePainting(event_);
1142 updatePainting(event); 1143 }, event ));
1143 }
1144 });
1145 } 1144 }
1146 } 1145 }
1147 1146
1148 /** 1147 /**
1149 * Sets the color in which the squiggly for the given annotation type should be drawn. 1148 * Sets the color in which the squiggly for the given annotation type should be drawn.