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
9 * IBM Corporation - initial API and implementation
11 package net.sourceforge.phpeclipse.phpeditor;
13 import org.eclipse.swt.graphics.Point;
14 import org.eclipse.swt.graphics.Rectangle;
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;
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
28 class OverviewRulerHoverManager extends AnnotationBarHoverManager {
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.
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
39 public OverviewRulerHoverManager(OverviewRuler ruler, ISourceViewer sourceViewer, IAnnotationHover annotationHover, IInformationControlCreator creator) {
40 super(ruler, sourceViewer, annotationHover, creator);
44 * @see AbstractHoverInformationControlManager#computeInformation()
46 protected void computeInformation() {
47 Point location= getHoverEventLocation();
48 int line= getVerticalRulerInfo().toDocumentLineNumber(location.y);
49 setInformation(getAnnotationHover().getHoverInfo(getSourceViewer(), line), computeArea(location.y));
53 * Determines graphical area covered for which the hover is valid.
55 * @param y-coordinate in the vertical ruler
56 * @return the graphical extend where the hover is valid
58 private Rectangle computeArea(int y) {
59 // This is ok (see constructor)
60 OverviewRuler overviewRuler= (OverviewRuler)getVerticalRulerInfo();
62 int hover_height= overviewRuler.getAnnotationHeight();
63 int hover_width= getVerticalRulerInfo().getControl().getSize().x;
65 // Calculate y-coordinate for hover
67 boolean hasAnnotation= true;
68 while (hasAnnotation && hover_y > y - hover_height) {
70 hasAnnotation= overviewRuler.hasAnnotationAt(hover_y);
74 return new Rectangle(0, hover_y, hover_width, hover_height);