comparison dwtx/jface/text/source/CompositeRuler.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
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.CompositeRuler;
14
15 import dwt.dwthelper.utils;
16
17
18 import java.util.ArrayList;
19 import java.util.EventListener;
20 import java.util.HashSet;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Set;
24
25 import dwt.DWT;
26 import dwt.custom.StyledText;
27 import dwt.events.ControlListener;
28 import dwt.events.DisposeEvent;
29 import dwt.events.DisposeListener;
30 import dwt.events.FocusListener;
31 import dwt.events.HelpListener;
32 import dwt.events.KeyListener;
33 import dwt.events.MouseListener;
34 import dwt.events.MouseMoveListener;
35 import dwt.events.MouseTrackListener;
36 import dwt.events.PaintListener;
37 import dwt.events.TraverseListener;
38 import dwt.graphics.Font;
39 import dwt.graphics.Point;
40 import dwt.graphics.Rectangle;
41 import dwt.widgets.Canvas;
42 import dwt.widgets.Composite;
43 import dwt.widgets.Control;
44 import dwt.widgets.Display;
45 import dwt.widgets.Event;
46 import dwt.widgets.Layout;
47 import dwt.widgets.Listener;
48 import dwt.widgets.Menu;
49 import dwtx.core.runtime.Assert;
50 import dwtx.jface.text.BadLocationException;
51 import dwtx.jface.text.IDocument;
52 import dwtx.jface.text.IRegion;
53 import dwtx.jface.text.ITextViewer;
54 import dwtx.jface.text.ITextViewerExtension;
55 import dwtx.jface.text.ITextViewerExtension5;
56
57
58 /**
59 * Standard implementation of
60 * {@link dwtx.jface.text.source.IVerticalRuler}.
61 * <p>
62 * This ruler does not have a a visual representation of its own. The
63 * presentation comes from the configurable list of vertical ruler columns. Such
64 * columns must implement the
65 * {@link dwtx.jface.text.source.IVerticalRulerColumn}. interface.</p>
66 * <p>
67 * Clients may instantiate and configure this class.</p>
68 *
69 * @see dwtx.jface.text.source.IVerticalRulerColumn
70 * @see dwtx.jface.text.ITextViewer
71 * @since 2.0
72 */
73 public class CompositeRuler : IVerticalRuler, IVerticalRulerExtension, IVerticalRulerInfoExtension {
74
75
76 /**
77 * Layout of the composite vertical ruler. Arranges the list of columns.
78 */
79 class RulerLayout : Layout {
80
81 /**
82 * Creates the new ruler layout.
83 */
84 protected RulerLayout() {
85 }
86
87 /*
88 * @see Layout#computeSize(Composite, int, int, bool)
89 */
90 protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) {
91 Control[] children= composite.getChildren();
92 Point size= new Point(0, 0);
93 for (int i= 0; i < children.length; i++) {
94 Point s= children[i].computeSize(DWT.DEFAULT, DWT.DEFAULT, flushCache);
95 size.x += s.x;
96 size.y= Math.max(size.y, s.y);
97 }
98 size.x += (Math.max(0, children.length -1) * fGap);
99 return size;
100 }
101
102 /*
103 * @see Layout#layout(Composite, bool)
104 */
105 protected void layout(Composite composite, bool flushCache) {
106 Rectangle clArea= composite.getClientArea();
107 int rulerHeight= clArea.height;
108
109 int x= 0;
110 Iterator e= fDecorators.iterator();
111 while (e.hasNext()) {
112 IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
113 int columnWidth= column.getWidth();
114 column.getControl().setBounds(x, 0, columnWidth, rulerHeight);
115 x += (columnWidth + fGap);
116 }
117 }
118 }
119
120 /**
121 * A canvas that adds listeners to all its children. Used by the implementation of the
122 * vertical ruler to propagate listener additions and removals to the ruler's columns.
123 */
124 static class CompositeRulerCanvas : Canvas {
125
126 /**
127 * Keeps the information for which event type a listener object has been added.
128 */
129 static class ListenerInfo {
130 Class fClass;
131 EventListener fListener;
132 }
133
134 /** The list of listeners added to this canvas. */
135 private List fCachedListeners= new ArrayList();
136 /**
137 * Internal listener for opening the context menu.
138 * @since 3.0
139 */
140 private Listener fMenuDetectListener;
141
142 /**
143 * Creates a new composite ruler canvas.
144 *
145 * @param parent the parent composite
146 * @param style the DWT styles
147 */
148 public CompositeRulerCanvas(Composite parent, int style) {
149 super(parent, style);
150 fMenuDetectListener= new Listener() {
151 public void handleEvent(Event event) {
152 if (event.type is DWT.MenuDetect) {
153 Menu menu= getMenu();
154 if (menu !is null) {
155 menu.setLocation(event.x, event.y);
156 menu.setVisible(true);
157 }
158 }
159 }
160 };
161 super.addDisposeListener(new DisposeListener() {
162 public void widgetDisposed(DisposeEvent e) {
163 if (fCachedListeners !is null) {
164 fCachedListeners.clear();
165 fCachedListeners= null;
166 }
167 }
168 });
169 }
170
171 /**
172 * Adds the given listener object as listener of the given type (<code>clazz</code>) to
173 * the given control.
174 *
175 * @param clazz the listener type
176 * @param control the control to add the listener to
177 * @param listener the listener to be added
178 */
179 private void addListener(Class clazz, Control control, EventListener listener) {
180 if (ControlListener.class.equals(clazz)) {
181 control. addControlListener((ControlListener) listener);
182 return;
183 }
184 if (FocusListener.class.equals(clazz)) {
185 control. addFocusListener((FocusListener) listener);
186 return;
187 }
188 if (HelpListener.class.equals(clazz)) {
189 control. addHelpListener((HelpListener) listener);
190 return;
191 }
192 if (KeyListener.class.equals(clazz)) {
193 control. addKeyListener((KeyListener) listener);
194 return;
195 }
196 if (MouseListener.class.equals(clazz)) {
197 control. addMouseListener((MouseListener) listener);
198 return;
199 }
200 if (MouseMoveListener.class.equals(clazz)) {
201 control. addMouseMoveListener((MouseMoveListener) listener);
202 return;
203 }
204 if (MouseTrackListener.class.equals(clazz)) {
205 control. addMouseTrackListener((MouseTrackListener) listener);
206 return;
207 }
208 if (PaintListener.class.equals(clazz)) {
209 control. addPaintListener((PaintListener) listener);
210 return;
211 }
212 if (TraverseListener.class.equals(clazz)) {
213 control. addTraverseListener((TraverseListener) listener);
214 return;
215 }
216 if (DisposeListener.class.equals(clazz)) {
217 control. addDisposeListener((DisposeListener) listener);
218 return;
219 }
220 }
221
222 /**
223 * Removes the given listener object as listener of the given type (<code>clazz</code>) from
224 * the given control.
225 *
226 * @param clazz the listener type
227 * @param control the control to remove the listener from
228 * @param listener the listener to be removed
229 */
230 private void removeListener(Class clazz, Control control, EventListener listener) {
231 if (ControlListener.class.equals(clazz)) {
232 control. removeControlListener((ControlListener) listener);
233 return;
234 }
235 if (FocusListener.class.equals(clazz)) {
236 control. removeFocusListener((FocusListener) listener);
237 return;
238 }
239 if (HelpListener.class.equals(clazz)) {
240 control. removeHelpListener((HelpListener) listener);
241 return;
242 }
243 if (KeyListener.class.equals(clazz)) {
244 control. removeKeyListener((KeyListener) listener);
245 return;
246 }
247 if (MouseListener.class.equals(clazz)) {
248 control. removeMouseListener((MouseListener) listener);
249 return;
250 }
251 if (MouseMoveListener.class.equals(clazz)) {
252 control. removeMouseMoveListener((MouseMoveListener) listener);
253 return;
254 }
255 if (MouseTrackListener.class.equals(clazz)) {
256 control. removeMouseTrackListener((MouseTrackListener) listener);
257 return;
258 }
259 if (PaintListener.class.equals(clazz)) {
260 control. removePaintListener((PaintListener) listener);
261 return;
262 }
263 if (TraverseListener.class.equals(clazz)) {
264 control. removeTraverseListener((TraverseListener) listener);
265 return;
266 }
267 if (DisposeListener.class.equals(clazz)) {
268 control. removeDisposeListener((DisposeListener) listener);
269 return;
270 }
271 }
272
273 /**
274 * Adds the given listener object to the internal book keeping under
275 * the given listener type (<code>clazz</code>).
276 *
277 * @param clazz the listener type
278 * @param listener the listener object
279 */
280 private void addListener(Class clazz, EventListener listener) {
281 Control[] children= getChildren();
282 for (int i= 0; i < children.length; i++) {
283 if (children[i] !is null && !children[i].isDisposed())
284 addListener(clazz, children[i], listener);
285 }
286
287 ListenerInfo info= new ListenerInfo();
288 info.fClass= clazz;
289 info.fListener= listener;
290 fCachedListeners.add(info);
291 }
292
293 /**
294 * Removes the given listener object from the internal book keeping under
295 * the given listener type (<code>clazz</code>).
296 *
297 * @param clazz the listener type
298 * @param listener the listener object
299 */
300 private void removeListener(Class clazz, EventListener listener) {
301 int length= fCachedListeners.size();
302 for (int i= 0; i < length; i++) {
303 ListenerInfo info= (ListenerInfo) fCachedListeners.get(i);
304 if (listener is info.fListener && clazz.equals(info.fClass)) {
305 fCachedListeners.remove(i);
306 break;
307 }
308 }
309
310 Control[] children= getChildren();
311 for (int i= 0; i < children.length; i++) {
312 if (children[i] !is null && !children[i].isDisposed())
313 removeListener(clazz, children[i], listener);
314 }
315 }
316
317 /**
318 * Tells this canvas that a child has been added.
319 *
320 * @param child the child
321 */
322 public void childAdded(Control child) {
323 if (child !is null && !child.isDisposed()) {
324 int length= fCachedListeners.size();
325 for (int i= 0; i < length; i++) {
326 ListenerInfo info= (ListenerInfo) fCachedListeners.get(i);
327 addListener(info.fClass, child, info.fListener);
328 }
329 child.addListener(DWT.MenuDetect, fMenuDetectListener);
330 }
331 }
332
333 /**
334 * Tells this canvas that a child has been removed.
335 *
336 * @param child the child
337 */
338 public void childRemoved(Control child) {
339 if (child !is null && !child.isDisposed()) {
340 int length= fCachedListeners.size();
341 for (int i= 0; i < length; i++) {
342 ListenerInfo info= (ListenerInfo) fCachedListeners.get(i);
343 removeListener(info.fClass, child, info.fListener);
344 }
345 child.removeListener(DWT.MenuDetect, fMenuDetectListener);
346 }
347 }
348
349 /*
350 * @see Control#removeControlListener(ControlListener)
351 */
352 public void removeControlListener(ControlListener listener) {
353 removeListener(ControlListener.class, listener);
354 super.removeControlListener(listener);
355 }
356
357 /*
358 * @see Control#removeFocusListener(FocusListener)
359 */
360 public void removeFocusListener(FocusListener listener) {
361 removeListener(FocusListener.class, listener);
362 super.removeFocusListener(listener);
363 }
364
365 /*
366 * @see Control#removeHelpListener(HelpListener)
367 */
368 public void removeHelpListener(HelpListener listener) {
369 removeListener(HelpListener.class, listener);
370 super.removeHelpListener(listener);
371 }
372
373 /*
374 * @see Control#removeKeyListener(KeyListener)
375 */
376 public void removeKeyListener(KeyListener listener) {
377 removeListener(KeyListener.class, listener);
378 super.removeKeyListener(listener);
379 }
380
381 /*
382 * @see Control#removeMouseListener(MouseListener)
383 */
384 public void removeMouseListener(MouseListener listener) {
385 removeListener(MouseListener.class, listener);
386 super.removeMouseListener(listener);
387 }
388
389 /*
390 * @see Control#removeMouseMoveListener(MouseMoveListener)
391 */
392 public void removeMouseMoveListener(MouseMoveListener listener) {
393 removeListener(MouseMoveListener.class, listener);
394 super.removeMouseMoveListener(listener);
395 }
396
397 /*
398 * @see Control#removeMouseTrackListener(MouseTrackListener)
399 */
400 public void removeMouseTrackListener(MouseTrackListener listener) {
401 removeListener(MouseTrackListener.class, listener);
402 super.removeMouseTrackListener(listener);
403 }
404
405 /*
406 * @see Control#removePaintListener(PaintListener)
407 */
408 public void removePaintListener(PaintListener listener) {
409 removeListener(PaintListener.class, listener);
410 super.removePaintListener(listener);
411 }
412
413 /*
414 * @see Control#removeTraverseListener(TraverseListener)
415 */
416 public void removeTraverseListener(TraverseListener listener) {
417 removeListener(TraverseListener.class, listener);
418 super.removeTraverseListener(listener);
419 }
420
421 /*
422 * @see Widget#removeDisposeListener(DisposeListener)
423 */
424 public void removeDisposeListener(DisposeListener listener) {
425 removeListener(DisposeListener.class, listener);
426 super.removeDisposeListener(listener);
427 }
428
429 /*
430 * @seeControl#addControlListener(ControlListener)
431 */
432 public void addControlListener(ControlListener listener) {
433 super.addControlListener(listener);
434 addListener(ControlListener.class, listener);
435 }
436
437 /*
438 * @see Control#addFocusListener(FocusListener)
439 */
440 public void addFocusListener(FocusListener listener) {
441 super.addFocusListener(listener);
442 addListener(FocusListener.class, listener);
443 }
444
445 /*
446 * @see Control#addHelpListener(HelpListener)
447 */
448 public void addHelpListener(HelpListener listener) {
449 super.addHelpListener(listener);
450 addListener(HelpListener.class, listener);
451 }
452
453 /*
454 * @see Control#addKeyListener(KeyListener)
455 */
456 public void addKeyListener(KeyListener listener) {
457 super.addKeyListener(listener);
458 addListener(KeyListener.class, listener);
459 }
460
461 /*
462 * @see Control#addMouseListener(MouseListener)
463 */
464 public void addMouseListener(MouseListener listener) {
465 super.addMouseListener(listener);
466 addListener(MouseListener.class, listener);
467 }
468
469 /*
470 * @see Control#addMouseMoveListener(MouseMoveListener)
471 */
472 public void addMouseMoveListener(MouseMoveListener listener) {
473 super.addMouseMoveListener(listener);
474 addListener(MouseMoveListener.class, listener);
475 }
476
477 /*
478 * @see Control#addMouseTrackListener(MouseTrackListener)
479 */
480 public void addMouseTrackListener(MouseTrackListener listener) {
481 super.addMouseTrackListener(listener);
482 addListener(MouseTrackListener.class, listener);
483 }
484
485 /*
486 * @seeControl#addPaintListener(PaintListener)
487 */
488 public void addPaintListener(PaintListener listener) {
489 super.addPaintListener(listener);
490 addListener(PaintListener.class, listener);
491 }
492
493 /*
494 * @see Control#addTraverseListener(TraverseListener)
495 */
496 public void addTraverseListener(TraverseListener listener) {
497 super.addTraverseListener(listener);
498 addListener(TraverseListener.class, listener);
499 }
500
501 /*
502 * @see Widget#addDisposeListener(DisposeListener)
503 */
504 public void addDisposeListener(DisposeListener listener) {
505 super.addDisposeListener(listener);
506 addListener(DisposeListener.class, listener);
507 }
508 }
509
510 /** The ruler's viewer */
511 private ITextViewer fTextViewer;
512 /** The ruler's canvas to which to add the ruler columns */
513 private CompositeRulerCanvas fComposite;
514 /** The ruler's annotation model */
515 private IAnnotationModel fModel;
516 /** The list of columns */
517 private List fDecorators= new ArrayList(2);
518 /** The cached location of the last mouse button activity */
519 private Point fLocation= new Point(-1, -1);
520 /** The cached line of the list mouse button activity */
521 private int fLastMouseButtonActivityLine= -1;
522 /** The gap between the individual columns of this composite ruler */
523 private int fGap;
524 /**
525 * The set of annotation listeners.
526 * @since 3.0
527 */
528 private Set fAnnotationListeners= new HashSet();
529
530
531 /**
532 * Constructs a new composite vertical ruler.
533 */
534 public CompositeRuler() {
535 this(0);
536 }
537
538 /**
539 * Constructs a new composite ruler with the given gap between its columns.
540 *
541 * @param gap
542 */
543 public CompositeRuler(int gap) {
544 fGap= gap;
545 }
546
547 /**
548 * Inserts the given column at the specified slot to this composite ruler.
549 * Columns are counted from left to right.
550 *
551 * @param index the index
552 * @param rulerColumn the decorator to be inserted
553 */
554 public void addDecorator(int index, IVerticalRulerColumn rulerColumn) {
555 rulerColumn.setModel(getModel());
556
557 if (index > fDecorators.size())
558 fDecorators.add(rulerColumn);
559 else
560 fDecorators.add(index, rulerColumn);
561
562 if (fComposite !is null && !fComposite.isDisposed()) {
563 rulerColumn.createControl(this, fComposite);
564 fComposite.childAdded(rulerColumn.getControl());
565 layoutTextViewer();
566 }
567 }
568
569 /**
570 * Removes the decorator in the specified slot from this composite ruler.
571 *
572 * @param index the index
573 */
574 public void removeDecorator(int index) {
575 IVerticalRulerColumn rulerColumn= (IVerticalRulerColumn) fDecorators.get(index);
576 removeDecorator(rulerColumn);
577 }
578
579 /**
580 * Removes the given decorator from the composite ruler.
581 *
582 * @param rulerColumn the ruler column to be removed
583 * @since 3.0
584 */
585 public void removeDecorator(IVerticalRulerColumn rulerColumn) {
586 fDecorators.remove(rulerColumn);
587 if (rulerColumn !is null) {
588 Control cc= rulerColumn.getControl();
589 if (cc !is null && !cc.isDisposed()) {
590 fComposite.childRemoved(cc);
591 cc.dispose();
592 }
593 }
594 layoutTextViewer();
595 }
596
597 /**
598 * Layouts the text viewer. This also causes this ruler to get
599 * be layouted.
600 */
601 private void layoutTextViewer() {
602
603 Control parent= fTextViewer.getTextWidget();
604
605 if (fTextViewer instanceof ITextViewerExtension) {
606 ITextViewerExtension extension= (ITextViewerExtension) fTextViewer;
607 parent= extension.getControl();
608 }
609
610 if (parent instanceof Composite && !parent.isDisposed())
611 ((Composite) parent).layout(true);
612 }
613
614 /*
615 * @see IVerticalRuler#getControl()
616 */
617 public Control getControl() {
618 return fComposite;
619 }
620
621 /*
622 * @see IVerticalRuler#createControl(Composite, ITextViewer)
623 */
624 public Control createControl(Composite parent, ITextViewer textViewer) {
625
626 fTextViewer= textViewer;
627
628 fComposite= new CompositeRulerCanvas(parent, DWT.NONE);
629 fComposite.setLayout(new RulerLayout());
630
631 Iterator iter= fDecorators.iterator();
632 while (iter.hasNext()) {
633 IVerticalRulerColumn column= (IVerticalRulerColumn) iter.next();
634 column.createControl(this, fComposite);
635 fComposite.childAdded(column.getControl());
636 }
637
638 return fComposite;
639 }
640
641 /*
642 * @see IVerticalRuler#setModel(IAnnotationModel)
643 */
644 public void setModel(IAnnotationModel model) {
645
646 fModel= model;
647
648 Iterator e= fDecorators.iterator();
649 while (e.hasNext()) {
650 IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
651 column.setModel(model);
652 }
653 }
654
655 /*
656 * @see IVerticalRuler#getModel()
657 */
658 public IAnnotationModel getModel() {
659 return fModel;
660 }
661
662 /*
663 * @see IVerticalRuler#update()
664 */
665 public void update() {
666 if (fComposite !is null && !fComposite.isDisposed()) {
667 Display d= fComposite.getDisplay();
668 if (d !is null) {
669 d.asyncExec(new Runnable() {
670 public void run() {
671 immediateUpdate();
672 }
673 });
674 }
675 }
676 }
677
678 /**
679 * Immediately redraws the entire ruler (without asynchronous posting).
680 *
681 * @since 3.2
682 */
683 public void immediateUpdate() {
684 Iterator e= fDecorators.iterator();
685 while (e.hasNext()) {
686 IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
687 column.redraw();
688 }
689 }
690
691 /*
692 * @see IVerticalRulerExtension#setFont(Font)
693 */
694 public void setFont(Font font) {
695 Iterator e= fDecorators.iterator();
696 while (e.hasNext()) {
697 IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
698 column.setFont(font);
699 }
700 }
701
702 /*
703 * @see IVerticalRulerInfo#getWidth()
704 */
705 public int getWidth() {
706 int width= 0;
707 Iterator e= fDecorators.iterator();
708 while (e.hasNext()) {
709 IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
710 width += (column.getWidth() + fGap);
711 }
712 return Math.max(0, width - fGap);
713 }
714
715 /*
716 * @see IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
717 */
718 public int getLineOfLastMouseButtonActivity() {
719 if (fLastMouseButtonActivityLine is -1)
720 fLastMouseButtonActivityLine= toDocumentLineNumber(fLocation.y);
721 else if (fTextViewer.getDocument() is null || fLastMouseButtonActivityLine >= fTextViewer.getDocument().getNumberOfLines())
722 fLastMouseButtonActivityLine= -1;
723 return fLastMouseButtonActivityLine;
724 }
725
726 /*
727 * @see IVerticalRulerInfo#toDocumentLineNumber(int)
728 */
729 public int toDocumentLineNumber(int y_coordinate) {
730 if (fTextViewer is null || y_coordinate is -1)
731 return -1;
732
733 StyledText text= fTextViewer.getTextWidget();
734 int line= text.getLineIndex(y_coordinate);
735
736 if (line is text.getLineCount() - 1) {
737 // check whether y_coordinate exceeds last line
738 if (y_coordinate > text.getLinePixel(line + 1))
739 return -1;
740 }
741
742 return widgetLine2ModelLine(fTextViewer, line);
743 }
744
745 /**
746 * Returns the line in the given viewer's document that correspond to the given
747 * line of the viewer's widget.
748 *
749 * @param viewer the viewer
750 * @param widgetLine the widget line
751 * @return the corresponding line the viewer's document
752 * @since 2.1
753 */
754 protected final static int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) {
755
756 if (viewer instanceof ITextViewerExtension5) {
757 ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
758 return extension.widgetLine2ModelLine(widgetLine);
759 }
760
761 try {
762 IRegion r= viewer.getVisibleRegion();
763 IDocument d= viewer.getDocument();
764 return widgetLine += d.getLineOfOffset(r.getOffset());
765 } catch (BadLocationException x) {
766 }
767 return widgetLine;
768 }
769
770 /**
771 * Returns this ruler's text viewer.
772 *
773 * @return this ruler's text viewer
774 */
775 public ITextViewer getTextViewer() {
776 return fTextViewer;
777 }
778
779 /*
780 * @see IVerticalRulerExtension#setLocationOfLastMouseButtonActivity(int, int)
781 */
782 public void setLocationOfLastMouseButtonActivity(int x, int y) {
783 fLocation.x= x;
784 fLocation.y= y;
785 fLastMouseButtonActivityLine= -1;
786 }
787
788 /**
789 * Returns an iterator over the <code>IVerticalRulerColumns</code> that make up this
790 * composite column.
791 *
792 * @return an iterator over the contained columns.
793 * @since 3.0
794 */
795 public Iterator getDecoratorIterator() {
796 Assert.isNotNull(fDecorators, "fDecorators must be initialized"); //$NON-NLS-1$
797 return fDecorators.iterator();
798 }
799
800 /*
801 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getHover()
802 * @since 3.0
803 */
804 public IAnnotationHover getHover() {
805 return null;
806 }
807
808 /*
809 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener)
810 * @since 3.0
811 */
812 public void addVerticalRulerListener(IVerticalRulerListener listener) {
813 fAnnotationListeners.add(listener);
814 }
815
816 /*
817 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener)
818 * @since 3.0
819 */
820 public void removeVerticalRulerListener(IVerticalRulerListener listener) {
821 fAnnotationListeners.remove(listener);
822 }
823
824 /**
825 * Fires the annotation selected event to all registered vertical ruler
826 * listeners.
827 * TODO use robust iterators
828 *
829 * @param event the event to fire
830 * @since 3.0
831 */
832 public void fireAnnotationSelected(VerticalRulerEvent event) {
833 // forward to listeners
834 for (Iterator it= fAnnotationListeners.iterator(); it.hasNext();) {
835 IVerticalRulerListener listener= (IVerticalRulerListener) it.next();
836 listener.annotationSelected(event);
837 }
838 }
839
840 /**
841 * Fires the annotation default selected event to all registered vertical
842 * ruler listeners.
843 * TODO use robust iterators
844 *
845 * @param event the event to fire
846 * @since 3.0
847 */
848 public void fireAnnotationDefaultSelected(VerticalRulerEvent event) {
849 // forward to listeners
850 for (Iterator it= fAnnotationListeners.iterator(); it.hasNext();) {
851 IVerticalRulerListener listener= (IVerticalRulerListener) it.next();
852 listener.annotationDefaultSelected(event);
853 }
854 }
855
856 /**
857 * Informs all registered vertical ruler listeners that the content menu on a selected annotation\
858 * is about to be shown.
859 * TODO use robust iterators
860 *
861 * @param event the event to fire
862 * @param menu the menu that is about to be shown
863 * @since 3.0
864 */
865 public void fireAnnotationContextMenuAboutToShow(VerticalRulerEvent event, Menu menu) {
866 // forward to listeners
867 for (Iterator it= fAnnotationListeners.iterator(); it.hasNext();) {
868 IVerticalRulerListener listener= (IVerticalRulerListener) it.next();
869 listener.annotationContextMenuAboutToShow(event, menu);
870 }
871 }
872
873 /**
874 * Relayouts the receiver.
875 *
876 * @since 3.3
877 */
878 public void relayout() {
879 layoutTextViewer();
880 }
881 }