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 v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
15 import org.eclipse.swt.graphics.Point;
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IRegion;
18 import org.eclipse.jface.text.ITextHover;
19 import org.eclipse.jface.text.ITextViewer;
20 import org.eclipse.jface.text.Region;
23 * Example implementation for an <code>ITextHover</code> which hovers over Java code.
25 public class PHPTextHover implements ITextHover {
28 * Method declared on ITextHover
30 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
31 if (hoverRegion != null) {
33 if (hoverRegion.getLength() > -1)
34 return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
35 } catch (BadLocationException x) {
38 return "empty selection";
42 * Method declared on ITextHover
44 public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
45 Point selection= textViewer.getSelectedRange();
46 if (selection.x <= offset && offset < selection.x + selection.y)
47 return new Region(selection.x, selection.y);
48 return new Region(offset, 0);