Added: PreferencePage; External Browser startup; extended syntax highlighting
[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> which hovers over Java code.
24  */
25 public class PHPTextHover implements ITextHover {
26
27         /* (non-Javadoc)
28          * Method declared on ITextHover
29          */
30         public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
31                 if (hoverRegion != null) {
32                         try {
33                                 if (hoverRegion.getLength() > -1)
34                                         return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
35                         } catch (BadLocationException x) {
36                         }
37                 }
38                 return "empty selection";
39         }
40         
41         /* (non-Javadoc)
42          * Method declared on ITextHover
43          */
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);
49         }
50 }