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;
14 import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
15 import org.eclipse.jface.text.BadLocationException;
16 import org.eclipse.jface.text.IRegion;
17 import org.eclipse.jface.text.ITextHover;
18 import org.eclipse.jface.text.ITextViewer;
19 import org.eclipse.jface.text.Region;
20 import org.eclipse.swt.graphics.Point;
23 * Example implementation for an <code>ITextHover</code>
24 * which hovers over PHP code.
26 public class PHPTextHover implements ITextHover {
27 private static PHPWordExtractor phpWordDetector = new PHPWordExtractor();
29 * Method declared on ITextHover
31 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
32 if (hoverRegion != null) {
34 if (hoverRegion.getLength() > -1) {
35 return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
37 } catch (BadLocationException x) {
40 return "empty selection";
44 * Method declared on ITextHover
46 public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
47 Point selection = PHPWordExtractor.findWord(textViewer.getDocument(), offset);
48 // show the extracted word as a tooltip
49 if (selection!=null && selection.x <= offset && offset < selection.x + selection.y)
50 return new Region(selection.x, selection.y);
51 return new Region(offset, 0);