new icons
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / OverviewRulerHoverManager.java
1 /*
2  * Copyright (c) 2000, 2002 IBM Corp. and others..
3  * All rights reserved.   This program and the accompanying materials
4  * are made available under the terms of the Common Public License v0.5
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  */
11 package net.sourceforge.phpeclipse.phpeditor;
12
13 import org.eclipse.swt.graphics.Point;
14 import org.eclipse.swt.graphics.Rectangle;
15
16 import org.eclipse.jface.text.IInformationControlCreator;
17 import org.eclipse.jface.text.source.AnnotationBarHoverManager;
18 import org.eclipse.jface.text.source.IAnnotationHover;
19 import org.eclipse.jface.text.source.ISourceViewer;
20
21 /**
22  * This manager controls the layout, content, and visibility of an information
23  * control in reaction to mouse hover events issued by the overview ruler of a
24  * source viewer.
25  * 
26  * @since 2.1
27  */
28 class OverviewRulerHoverManager extends AnnotationBarHoverManager {
29
30         /**
31          * Creates an overview hover manager with the given parameters. In addition,
32          * the hovers anchor is RIGHT and the margin is 5 points to the right.
33          *
34          * @param ruler the overview ruler this manager connects to
35          * @param sourceViewer the source viewer this manager connects to
36          * @param annotationHover the annotation hover providing the information to be displayed
37          * @param creator the information control creator
38          */
39         public OverviewRulerHoverManager(OverviewRuler ruler, ISourceViewer sourceViewer, IAnnotationHover annotationHover, IInformationControlCreator creator) {
40                 super(ruler, sourceViewer, annotationHover, creator);
41         }
42         
43         /*
44          * @see AbstractHoverInformationControlManager#computeInformation()
45          */
46         protected void computeInformation() {
47                 Point location= getHoverEventLocation();
48                 int line= getVerticalRulerInfo().toDocumentLineNumber(location.y);
49                 setInformation(getAnnotationHover().getHoverInfo(getSourceViewer(), line), computeArea(location.y));
50         }
51
52         /**
53          * Determines graphical area covered for which the hover is valid.
54          *
55          * @param y-coordinate in the vertical ruler
56          * @return the graphical extend where the hover is valid
57          */
58         private Rectangle computeArea(int y) {
59                 // This is ok (see constructor)
60                 OverviewRuler overviewRuler= (OverviewRuler)getVerticalRulerInfo();
61
62                 int hover_height= overviewRuler.getAnnotationHeight();
63                 int hover_width= getVerticalRulerInfo().getControl().getSize().x;
64
65                 // Calculate y-coordinate for hover
66                 int hover_y= y;
67                 boolean hasAnnotation= true;
68                 while (hasAnnotation && hover_y > y - hover_height) {
69                         hover_y--;
70                         hasAnnotation= overviewRuler.hasAnnotationAt(hover_y);
71                 }
72                 hover_y++;
73                         
74                 return new Rectangle(0, hover_y, hover_width, hover_height);
75         }
76 }