Mercurial > projects > dwt-addons
annotate dwtx/jface/text/source/VerticalRuler.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | 7926b636c282 |
children |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.text.source.VerticalRuler; | |
14 | |
131 | 15 import dwtx.jface.text.source.ISharedTextColors; // packageimport |
16 import dwtx.jface.text.source.ILineRange; // packageimport | |
17 import dwtx.jface.text.source.IAnnotationPresentation; // packageimport | |
18 import dwtx.jface.text.source.IVerticalRulerInfoExtension; // packageimport | |
19 import dwtx.jface.text.source.ICharacterPairMatcher; // packageimport | |
20 import dwtx.jface.text.source.TextInvocationContext; // packageimport | |
21 import dwtx.jface.text.source.LineChangeHover; // packageimport | |
22 import dwtx.jface.text.source.IChangeRulerColumn; // packageimport | |
23 import dwtx.jface.text.source.IAnnotationMap; // packageimport | |
24 import dwtx.jface.text.source.IAnnotationModelListenerExtension; // packageimport | |
25 import dwtx.jface.text.source.ISourceViewerExtension2; // packageimport | |
26 import dwtx.jface.text.source.IAnnotationHover; // packageimport | |
27 import dwtx.jface.text.source.ContentAssistantFacade; // packageimport | |
28 import dwtx.jface.text.source.IAnnotationAccess; // packageimport | |
29 import dwtx.jface.text.source.IVerticalRulerExtension; // packageimport | |
30 import dwtx.jface.text.source.IVerticalRulerColumn; // packageimport | |
31 import dwtx.jface.text.source.LineNumberRulerColumn; // packageimport | |
32 import dwtx.jface.text.source.MatchingCharacterPainter; // packageimport | |
33 import dwtx.jface.text.source.IAnnotationModelExtension; // packageimport | |
34 import dwtx.jface.text.source.ILineDifferExtension; // packageimport | |
35 import dwtx.jface.text.source.DefaultCharacterPairMatcher; // packageimport | |
36 import dwtx.jface.text.source.LineNumberChangeRulerColumn; // packageimport | |
37 import dwtx.jface.text.source.IAnnotationAccessExtension; // packageimport | |
38 import dwtx.jface.text.source.ISourceViewer; // packageimport | |
39 import dwtx.jface.text.source.AnnotationModel; // packageimport | |
40 import dwtx.jface.text.source.ILineDifferExtension2; // packageimport | |
41 import dwtx.jface.text.source.IAnnotationModelListener; // packageimport | |
42 import dwtx.jface.text.source.IVerticalRuler; // packageimport | |
43 import dwtx.jface.text.source.DefaultAnnotationHover; // packageimport | |
44 import dwtx.jface.text.source.SourceViewer; // packageimport | |
45 import dwtx.jface.text.source.SourceViewerConfiguration; // packageimport | |
46 import dwtx.jface.text.source.AnnotationBarHoverManager; // packageimport | |
47 import dwtx.jface.text.source.CompositeRuler; // packageimport | |
48 import dwtx.jface.text.source.ImageUtilities; // packageimport | |
49 import dwtx.jface.text.source.VisualAnnotationModel; // packageimport | |
50 import dwtx.jface.text.source.IAnnotationModel; // packageimport | |
51 import dwtx.jface.text.source.ISourceViewerExtension3; // packageimport | |
52 import dwtx.jface.text.source.ILineDiffInfo; // packageimport | |
53 import dwtx.jface.text.source.VerticalRulerEvent; // packageimport | |
54 import dwtx.jface.text.source.ChangeRulerColumn; // packageimport | |
55 import dwtx.jface.text.source.ILineDiffer; // packageimport | |
56 import dwtx.jface.text.source.AnnotationModelEvent; // packageimport | |
57 import dwtx.jface.text.source.AnnotationColumn; // packageimport | |
58 import dwtx.jface.text.source.AnnotationRulerColumn; // packageimport | |
59 import dwtx.jface.text.source.IAnnotationHoverExtension; // packageimport | |
60 import dwtx.jface.text.source.AbstractRulerColumn; // packageimport | |
61 import dwtx.jface.text.source.ISourceViewerExtension; // packageimport | |
62 import dwtx.jface.text.source.AnnotationMap; // packageimport | |
63 import dwtx.jface.text.source.IVerticalRulerInfo; // packageimport | |
64 import dwtx.jface.text.source.IAnnotationModelExtension2; // packageimport | |
65 import dwtx.jface.text.source.LineRange; // packageimport | |
66 import dwtx.jface.text.source.IAnnotationAccessExtension2; // packageimport | |
67 import dwtx.jface.text.source.JFaceTextMessages; // packageimport | |
68 import dwtx.jface.text.source.IOverviewRuler; // packageimport | |
69 import dwtx.jface.text.source.Annotation; // packageimport | |
70 import dwtx.jface.text.source.IVerticalRulerListener; // packageimport | |
71 import dwtx.jface.text.source.ISourceViewerExtension4; // packageimport | |
72 import dwtx.jface.text.source.AnnotationPainter; // packageimport | |
73 import dwtx.jface.text.source.IAnnotationHoverExtension2; // packageimport | |
74 import dwtx.jface.text.source.OverviewRuler; // packageimport | |
75 import dwtx.jface.text.source.OverviewRulerHoverManager; // packageimport | |
76 | |
77 | |
129 | 78 import dwt.dwthelper.utils; |
79 | |
80 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
81 import dwtx.dwtxhelper.Collection; |
129 | 82 |
83 import dwt.DWT; | |
84 import dwt.custom.StyledText; | |
85 import dwt.events.DisposeEvent; | |
86 import dwt.events.DisposeListener; | |
87 import dwt.events.MouseEvent; | |
88 import dwt.events.MouseListener; | |
89 import dwt.events.PaintEvent; | |
90 import dwt.events.PaintListener; | |
91 import dwt.graphics.Font; | |
92 import dwt.graphics.GC; | |
93 import dwt.graphics.Image; | |
94 import dwt.graphics.Point; | |
95 import dwt.graphics.Rectangle; | |
96 import dwt.widgets.Canvas; | |
97 import dwt.widgets.Composite; | |
98 import dwt.widgets.Control; | |
99 import dwt.widgets.Display; | |
100 import dwtx.jface.text.BadLocationException; | |
101 import dwtx.jface.text.IDocument; | |
102 import dwtx.jface.text.IRegion; | |
103 import dwtx.jface.text.ITextListener; | |
104 import dwtx.jface.text.ITextViewer; | |
105 import dwtx.jface.text.ITextViewerExtension5; | |
106 import dwtx.jface.text.IViewportListener; | |
107 import dwtx.jface.text.JFaceTextUtil; | |
108 import dwtx.jface.text.Position; | |
109 import dwtx.jface.text.Region; | |
110 import dwtx.jface.text.TextEvent; | |
111 | |
112 | |
113 /** | |
114 * A vertical ruler which is connected to a text viewer. Single column standard | |
115 * implementation of {@link dwtx.jface.text.source.IVerticalRuler}. | |
116 * <p> | |
117 * The same can be achieved by using <code>CompositeRuler</code> configured | |
118 * with an <code>AnnotationRulerColumn</code>. Clients may use this class as | |
119 * is. | |
120 * | |
121 * @see dwtx.jface.text.ITextViewer | |
122 */ | |
123 public final class VerticalRuler : IVerticalRuler, IVerticalRulerExtension { | |
124 | |
125 /** | |
126 * Internal listener class. | |
127 */ | |
128 class InternalListener : IViewportListener, IAnnotationModelListener, ITextListener { | |
129 | |
130 /* | |
131 * @see IViewportListener#viewportChanged(int) | |
132 */ | |
133 public void viewportChanged(int verticalPosition) { | |
134 if (verticalPosition !is fScrollPos) | |
135 redraw(); | |
136 } | |
137 | |
138 /* | |
139 * @see IAnnotationModelListener#modelChanged(IAnnotationModel) | |
140 */ | |
141 public void modelChanged(IAnnotationModel model) { | |
142 update(); | |
143 } | |
144 | |
145 /* | |
146 * @see ITextListener#textChanged(TextEvent) | |
147 */ | |
148 public void textChanged(TextEvent e) { | |
149 if (fTextViewer !is null && e.getViewerRedrawState()) | |
150 redraw(); | |
151 } | |
152 } | |
153 | |
154 /** The vertical ruler's text viewer */ | |
155 private ITextViewer fTextViewer; | |
156 /** The ruler's canvas */ | |
157 private Canvas fCanvas; | |
158 /** The vertical ruler's model */ | |
159 private IAnnotationModel fModel; | |
160 /** Cache for the actual scroll position in pixels */ | |
161 private int fScrollPos; | |
162 /** The buffer for double buffering */ | |
163 private Image fBuffer; | |
164 /** The line of the last mouse button activity */ | |
165 private int fLastMouseButtonActivityLine= -1; | |
166 /** The internal listener */ | |
159 | 167 private InternalListener fInternalListener; |
129 | 168 /** The width of this vertical ruler */ |
169 private int fWidth; | |
170 /** | |
171 * The annotation access of this vertical ruler | |
172 * @since 3.0 | |
173 */ | |
174 private IAnnotationAccess fAnnotationAccess; | |
175 | |
176 /** | |
177 * Constructs a vertical ruler with the given width. | |
178 * | |
179 * @param width the width of the vertical ruler | |
180 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
181 public this(int width) { |
129 | 182 this(width, null); |
183 } | |
184 | |
185 /** | |
186 * Constructs a vertical ruler with the given width and the given annotation | |
187 * access. | |
188 * | |
189 * @param width the width of the vertical ruler | |
190 * @param annotationAcccess the annotation access | |
191 * @since 3.0 | |
192 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
193 public this(int width, IAnnotationAccess annotationAcccess) { |
159 | 194 |
195 fInternalListener= new InternalListener(); | |
196 | |
129 | 197 fWidth= width; |
198 fAnnotationAccess= annotationAcccess; | |
199 } | |
200 | |
201 /* | |
202 * @see IVerticalRuler#getControl() | |
203 */ | |
204 public Control getControl() { | |
205 return fCanvas; | |
206 } | |
207 | |
208 /* | |
209 * @see IVerticalRuler#createControl(Composite, ITextViewer) | |
210 */ | |
211 public Control createControl(Composite parent, ITextViewer textViewer) { | |
212 | |
213 fTextViewer= textViewer; | |
214 | |
215 fCanvas= new Canvas(parent, DWT.NO_BACKGROUND); | |
216 | |
135 | 217 fCanvas.addPaintListener(new class() PaintListener { |
129 | 218 public void paintControl(PaintEvent event) { |
219 if (fTextViewer !is null) | |
220 doubleBufferPaint(event.gc); | |
221 } | |
222 }); | |
223 | |
135 | 224 fCanvas.addDisposeListener(new class() DisposeListener { |
129 | 225 public void widgetDisposed(DisposeEvent e) { |
226 handleDispose(); | |
227 fTextViewer= null; | |
228 } | |
229 }); | |
230 | |
135 | 231 fCanvas.addMouseListener(new class() MouseListener { |
129 | 232 public void mouseUp(MouseEvent event) { |
233 } | |
234 | |
235 public void mouseDown(MouseEvent event) { | |
236 fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); | |
237 } | |
238 | |
239 public void mouseDoubleClick(MouseEvent event) { | |
240 fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); | |
241 } | |
242 }); | |
243 | |
244 if (fTextViewer !is null) { | |
245 fTextViewer.addViewportListener(fInternalListener); | |
246 fTextViewer.addTextListener(fInternalListener); | |
247 } | |
248 | |
249 return fCanvas; | |
250 } | |
251 | |
252 /** | |
253 * Disposes the ruler's resources. | |
254 */ | |
255 private void handleDispose() { | |
256 | |
257 if (fTextViewer !is null) { | |
258 fTextViewer.removeViewportListener(fInternalListener); | |
259 fTextViewer.removeTextListener(fInternalListener); | |
260 fTextViewer= null; | |
261 } | |
262 | |
263 if (fModel !is null) | |
264 fModel.removeAnnotationModelListener(fInternalListener); | |
265 | |
266 if (fBuffer !is null) { | |
267 fBuffer.dispose(); | |
268 fBuffer= null; | |
269 } | |
270 } | |
271 | |
272 | |
273 /** | |
274 * Double buffer drawing. | |
275 * | |
276 * @param dest the GC to draw into | |
277 */ | |
278 private void doubleBufferPaint(GC dest) { | |
279 | |
280 Point size= fCanvas.getSize(); | |
281 | |
282 if (size.x <= 0 || size.y <= 0) | |
283 return; | |
284 | |
285 if (fBuffer !is null) { | |
286 Rectangle r= fBuffer.getBounds(); | |
287 if (r.width !is size.x || r.height !is size.y) { | |
288 fBuffer.dispose(); | |
289 fBuffer= null; | |
290 } | |
291 } | |
292 if (fBuffer is null) | |
293 fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); | |
294 | |
295 GC gc= new GC(fBuffer); | |
296 gc.setFont(fTextViewer.getTextWidget().getFont()); | |
297 try { | |
298 gc.setBackground(fCanvas.getBackground()); | |
299 gc.fillRectangle(0, 0, size.x, size.y); | |
300 | |
138 | 301 if ( cast(ITextViewerExtension5)fTextViewer ) |
129 | 302 doPaint1(gc); |
303 else | |
304 doPaint(gc); | |
305 | |
306 } finally { | |
307 gc.dispose(); | |
308 } | |
309 | |
310 dest.drawImage(fBuffer, 0, 0); | |
311 } | |
312 | |
313 /** | |
314 * Returns the document offset of the upper left corner of the | |
315 * widgets view port, possibly including partially visible lines. | |
316 * | |
317 * @return the document offset of the upper left corner including partially visible lines | |
318 * @since 2.0 | |
319 */ | |
320 private int getInclusiveTopIndexStartOffset() { | |
321 | |
322 StyledText textWidget= fTextViewer.getTextWidget(); | |
323 if (textWidget !is null && !textWidget.isDisposed()) { | |
324 int top= JFaceTextUtil.getPartialTopIndex(fTextViewer); | |
325 try { | |
326 IDocument document= fTextViewer.getDocument(); | |
327 return document.getLineOffset(top); | |
328 } catch (BadLocationException x) { | |
329 } | |
330 } | |
331 | |
332 return -1; | |
333 } | |
334 | |
335 | |
336 | |
337 /** | |
338 * Draws the vertical ruler w/o drawing the Canvas background. | |
339 * | |
340 * @param gc the GC to draw into | |
341 */ | |
342 protected void doPaint(GC gc) { | |
343 | |
344 if (fModel is null || fTextViewer is null) | |
345 return; | |
346 | |
347 IAnnotationAccessExtension annotationAccessExtension= null; | |
138 | 348 if ( cast(IAnnotationAccessExtension)fAnnotationAccess ) |
134 | 349 annotationAccessExtension= cast(IAnnotationAccessExtension) fAnnotationAccess; |
129 | 350 |
351 StyledText styledText= fTextViewer.getTextWidget(); | |
352 IDocument doc= fTextViewer.getDocument(); | |
353 | |
354 int topLeft= getInclusiveTopIndexStartOffset(); | |
355 int bottomRight= fTextViewer.getBottomIndexEndOffset(); | |
356 int viewPort= bottomRight - topLeft; | |
357 | |
358 Point d= fCanvas.getSize(); | |
359 fScrollPos= styledText.getTopPixel(); | |
360 | |
361 int topLine= -1, bottomLine= -1; | |
362 try { | |
363 IRegion region= fTextViewer.getVisibleRegion(); | |
364 topLine= doc.getLineOfOffset(region.getOffset()); | |
365 bottomLine= doc.getLineOfOffset(region.getOffset() + region.getLength()); | |
366 } catch (BadLocationException x) { | |
367 return; | |
368 } | |
369 | |
370 // draw Annotations | |
371 Rectangle r= new Rectangle(0, 0, 0, 0); | |
372 int maxLayer= 1; // loop at least once though layers. | |
373 | |
374 for (int layer= 0; layer < maxLayer; layer++) { | |
375 Iterator iter= fModel.getAnnotationIterator(); | |
376 while (iter.hasNext()) { | |
377 IAnnotationPresentation annotationPresentation= null; | |
134 | 378 Annotation annotation= cast(Annotation) iter.next(); |
129 | 379 |
380 int lay= IAnnotationAccessExtension.DEFAULT_LAYER; | |
381 if (annotationAccessExtension !is null) | |
382 lay= annotationAccessExtension.getLayer(annotation); | |
138 | 383 else if ( cast(IAnnotationPresentation)annotation ) { |
134 | 384 annotationPresentation= cast(IAnnotationPresentation)annotation; |
129 | 385 lay= annotationPresentation.getLayer(); |
386 } | |
387 maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum | |
388 if (lay !is layer) // wrong layer: skip annotation | |
389 continue; | |
390 | |
391 Position position= fModel.getPosition(annotation); | |
392 if (position is null) | |
393 continue; | |
394 | |
395 if (!position.overlapsWith(topLeft, viewPort)) | |
396 continue; | |
397 | |
398 try { | |
399 | |
400 int offset= position.getOffset(); | |
401 int length= position.getLength(); | |
402 | |
403 int startLine= doc.getLineOfOffset(offset); | |
404 if (startLine < topLine) | |
405 startLine= topLine; | |
406 | |
407 int endLine= startLine; | |
408 if (length > 0) | |
409 endLine= doc.getLineOfOffset(offset + length - 1); | |
410 if (endLine > bottomLine) | |
411 endLine= bottomLine; | |
412 | |
413 startLine -= topLine; | |
414 endLine -= topLine; | |
415 | |
416 r.x= 0; | |
417 r.y= JFaceTextUtil.computeLineHeight(styledText, 0, startLine, startLine) - fScrollPos; | |
159 | 418 |
129 | 419 r.width= d.x; |
420 int lines= endLine - startLine; | |
159 | 421 |
129 | 422 r.height= JFaceTextUtil.computeLineHeight(styledText, startLine, endLine + 1, (lines+1)); |
423 | |
424 if (r.y < d.y && annotationAccessExtension !is null) // annotation within visible area | |
425 annotationAccessExtension.paint(annotation, gc, fCanvas, r); | |
426 else if (annotationPresentation !is null) | |
427 annotationPresentation.paint(gc, fCanvas, r); | |
428 | |
429 } catch (BadLocationException e) { | |
430 } | |
431 } | |
432 } | |
433 } | |
434 | |
435 /** | |
436 * Draws the vertical ruler w/o drawing the Canvas background. Uses | |
437 * <code>ITextViewerExtension5</code> for its implementation. Will replace | |
438 * <code>doPaint(GC)</code>. | |
439 * | |
440 * @param gc the GC to draw into | |
441 */ | |
442 protected void doPaint1(GC gc) { | |
443 | |
444 if (fModel is null || fTextViewer is null) | |
445 return; | |
446 | |
447 IAnnotationAccessExtension annotationAccessExtension= null; | |
138 | 448 if ( cast(IAnnotationAccessExtension)fAnnotationAccess ) |
134 | 449 annotationAccessExtension= cast(IAnnotationAccessExtension) fAnnotationAccess; |
129 | 450 |
134 | 451 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fTextViewer; |
129 | 452 StyledText textWidget= fTextViewer.getTextWidget(); |
453 | |
454 fScrollPos= textWidget.getTopPixel(); | |
455 Point dimension= fCanvas.getSize(); | |
456 | |
457 // draw Annotations | |
458 Rectangle r= new Rectangle(0, 0, 0, 0); | |
459 int maxLayer= 1; // loop at least once through layers. | |
460 | |
461 for (int layer= 0; layer < maxLayer; layer++) { | |
462 Iterator iter= fModel.getAnnotationIterator(); | |
463 while (iter.hasNext()) { | |
464 IAnnotationPresentation annotationPresentation= null; | |
134 | 465 Annotation annotation= cast(Annotation) iter.next(); |
129 | 466 |
467 int lay= IAnnotationAccessExtension.DEFAULT_LAYER; | |
468 if (annotationAccessExtension !is null) | |
469 lay= annotationAccessExtension.getLayer(annotation); | |
138 | 470 else if ( cast(IAnnotationPresentation)annotation ) { |
134 | 471 annotationPresentation= cast(IAnnotationPresentation)annotation; |
129 | 472 lay= annotationPresentation.getLayer(); |
473 } | |
474 maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum | |
475 if (lay !is layer) // wrong layer: skip annotation | |
476 continue; | |
477 | |
478 Position position= fModel.getPosition(annotation); | |
479 if (position is null) | |
480 continue; | |
481 | |
482 IRegion widgetRegion= extension.modelRange2WidgetRange(new Region(position.getOffset(), position.getLength())); | |
483 if (widgetRegion is null) | |
484 continue; | |
485 | |
486 int startLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset()); | |
487 if (startLine is -1) | |
488 continue; | |
489 | |
490 int endLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() -1, 0)); | |
491 if (endLine is -1) | |
492 continue; | |
493 | |
494 r.x= 0; | |
495 r.y= JFaceTextUtil.computeLineHeight(textWidget, 0, startLine, startLine) - fScrollPos; | |
159 | 496 |
129 | 497 r.width= dimension.x; |
498 int lines= endLine - startLine; | |
159 | 499 |
129 | 500 r.height= JFaceTextUtil.computeLineHeight(textWidget, startLine, endLine + 1, lines+1); |
501 | |
502 if (r.y < dimension.y && annotationAccessExtension !is null) // annotation within visible area | |
503 annotationAccessExtension.paint(annotation, gc, fCanvas, r); | |
504 else if (annotationPresentation !is null) | |
505 annotationPresentation.paint(gc, fCanvas, r); | |
506 } | |
507 } | |
508 } | |
509 | |
510 /** | |
511 * Thread-safe implementation. | |
512 * Can be called from any thread. | |
513 */ | |
514 /* | |
515 * @see IVerticalRuler#update() | |
516 */ | |
517 public void update() { | |
518 if (fCanvas !is null && !fCanvas.isDisposed()) { | |
519 Display d= fCanvas.getDisplay(); | |
520 if (d !is null) { | |
135 | 521 d.asyncExec(new class() Runnable { |
129 | 522 public void run() { |
523 redraw(); | |
524 } | |
525 }); | |
526 } | |
527 } | |
528 } | |
529 | |
530 /** | |
531 * Redraws the vertical ruler. | |
532 */ | |
533 private void redraw() { | |
534 if (fCanvas !is null && !fCanvas.isDisposed()) { | |
535 GC gc= new GC(fCanvas); | |
536 doubleBufferPaint(gc); | |
537 gc.dispose(); | |
538 } | |
539 } | |
540 | |
541 /* | |
542 * @see IVerticalRuler#setModel(IAnnotationModel) | |
543 */ | |
544 public void setModel(IAnnotationModel model) { | |
545 if (model !is fModel) { | |
546 | |
547 if (fModel !is null) | |
548 fModel.removeAnnotationModelListener(fInternalListener); | |
549 | |
550 fModel= model; | |
551 | |
552 if (fModel !is null) | |
553 fModel.addAnnotationModelListener(fInternalListener); | |
554 | |
555 update(); | |
556 } | |
557 } | |
558 | |
559 /* | |
560 * @see IVerticalRuler#getModel() | |
561 */ | |
562 public IAnnotationModel getModel() { | |
563 return fModel; | |
564 } | |
565 | |
566 /* | |
567 * @see IVerticalRulerInfo#getWidth() | |
568 */ | |
569 public int getWidth() { | |
570 return fWidth; | |
571 } | |
572 | |
573 /* | |
574 * @see IVerticalRulerInfo#getLineOfLastMouseButtonActivity() | |
575 */ | |
576 public int getLineOfLastMouseButtonActivity() { | |
577 IDocument doc= fTextViewer.getDocument(); | |
578 if (doc is null || fLastMouseButtonActivityLine >= fTextViewer.getDocument().getNumberOfLines()) | |
579 fLastMouseButtonActivityLine= -1; | |
580 return fLastMouseButtonActivityLine; | |
581 } | |
582 | |
583 /* | |
584 * @see IVerticalRulerInfo#toDocumentLineNumber(int) | |
585 */ | |
586 public int toDocumentLineNumber(int y_coordinate) { | |
587 if (fTextViewer is null || y_coordinate is -1) | |
588 return -1; | |
589 | |
590 StyledText text= fTextViewer.getTextWidget(); | |
591 int line= text.getLineIndex(y_coordinate); | |
159 | 592 |
129 | 593 if (line is text.getLineCount() - 1) { |
594 // check whether y_coordinate exceeds last line | |
595 if (y_coordinate > text.getLinePixel(line + 1)) | |
596 return -1; | |
597 } | |
159 | 598 |
129 | 599 return widgetLine2ModelLine(fTextViewer, line); |
600 } | |
601 | |
602 /** | |
603 * Returns the line of the viewer's document that corresponds to the given widget line. | |
604 * | |
605 * @param viewer the viewer | |
606 * @param widgetLine the widget line | |
607 * @return the corresponding line of the viewer's document | |
608 * @since 2.1 | |
609 */ | |
610 protected final static int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) { | |
611 | |
138 | 612 if ( cast(ITextViewerExtension5)viewer ) { |
134 | 613 ITextViewerExtension5 extension= cast(ITextViewerExtension5) viewer; |
129 | 614 return extension.widgetLine2ModelLine(widgetLine); |
615 } | |
616 | |
617 try { | |
618 IRegion r= viewer.getVisibleRegion(); | |
619 IDocument d= viewer.getDocument(); | |
620 return widgetLine += d.getLineOfOffset(r.getOffset()); | |
621 } catch (BadLocationException x) { | |
622 } | |
623 return widgetLine; | |
624 } | |
625 | |
626 /* | |
627 * @see IVerticalRulerExtension#setFont(Font) | |
628 * @since 2.0 | |
629 */ | |
630 public void setFont(Font font) { | |
631 } | |
632 | |
633 /* | |
634 * @see IVerticalRulerExtension#setLocationOfLastMouseButtonActivity(int, int) | |
635 * @since 2.0 | |
636 */ | |
637 public void setLocationOfLastMouseButtonActivity(int x, int y) { | |
638 fLastMouseButtonActivityLine= toDocumentLineNumber(y); | |
639 } | |
640 | |
641 /** | |
642 * Adds the given mouse listener. | |
643 * | |
644 * @param listener the listener to be added | |
645 * @deprecated will be removed | |
646 * @since 2.0 | |
647 */ | |
648 public void addMouseListener(MouseListener listener) { | |
649 if (fCanvas !is null && !fCanvas.isDisposed()) | |
650 fCanvas.addMouseListener(listener); | |
651 } | |
652 | |
653 /** | |
654 * Removes the given mouse listener. | |
655 * | |
656 * @param listener the listener to be removed | |
657 * @deprecated will be removed | |
658 * @since 2.0 | |
659 */ | |
660 public void removeMouseListener(MouseListener listener) { | |
661 if (fCanvas !is null && !fCanvas.isDisposed()) | |
662 fCanvas.removeMouseListener(listener); | |
663 } | |
664 } |