KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > source > OverviewRulerHoverManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  *******************************************************************************/

11 package org.eclipse.jface.text.source;
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(IOverviewRuler ruler, ISourceViewer sourceViewer, IAnnotationHover annotationHover, IInformationControlCreator creator) {
40         super(ruler, sourceViewer, annotationHover, creator);
41         setAnchor(ANCHOR_LEFT);
42     }
43
44     /*
45      * @see AbstractHoverInformationControlManager#computeInformation()
46      */

47     protected void computeInformation() {
48         Point location= getHoverEventLocation();
49         int line= getVerticalRulerInfo().toDocumentLineNumber(location.y);
50         IAnnotationHover hover= getAnnotationHover();
51         
52         IInformationControlCreator controlCreator= null;
53         if (hover instanceof IAnnotationHoverExtension)
54             controlCreator= ((IAnnotationHoverExtension)hover).getHoverControlCreator();
55         setCustomInformationControlCreator(controlCreator);
56         
57         setInformation(hover.getHoverInfo(getSourceViewer(), line), computeArea(location.y));
58     }
59
60     /**
61      * Determines graphical area covered for which the hover is valid.
62      *
63      * @param y y-coordinate in the vertical ruler
64      * @return the graphical extend where the hover is valid
65      */

66     private Rectangle computeArea(int y) {
67         // This is OK (see constructor)
68
IOverviewRuler overviewRuler= (IOverviewRuler) getVerticalRulerInfo();
69
70         int hover_height= overviewRuler.getAnnotationHeight();
71         int hover_width= getVerticalRulerInfo().getControl().getSize().x;
72
73         // Calculate y-coordinate for hover
74
int hover_y= y;
75         boolean hasAnnotation= true;
76         while (hasAnnotation && hover_y > y - hover_height) {
77             hover_y--;
78             hasAnnotation= overviewRuler.hasAnnotation(hover_y);
79         }
80         hover_y++;
81
82         return new Rectangle(0, hover_y, hover_width, hover_height);
83     }
84 }
85
Popular Tags