3f8e79a6b60f5c0a5d5a24ffe16e068fe28fd69a
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPTextHover.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 v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
13
14
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;
21
22 /**
23  * Example implementation for an <code>ITextHover</code> 
24  * which hovers over PHP code.
25  */
26 public class PHPTextHover implements ITextHover {
27
28         /* (non-Javadoc)
29          * Method declared on ITextHover
30          */
31         public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
32                 if (hoverRegion != null) {
33                         try {
34                                 if (hoverRegion.getLength() > -1)
35                                         return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
36                         } catch (BadLocationException x) {
37                         }
38                 }
39                 return "empty selection";
40         }
41         
42         /* (non-Javadoc)
43          * Method declared on ITextHover
44          */
45         public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
46                 Point selection= textViewer.getSelectedRange();
47                 if (selection.x <= offset && offset < selection.x + selection.y)
48                         return new Region(selection.x, selection.y);
49                 return new Region(offset, 0);
50         }
51 }