01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.javaeditor;
11:
12: import org.eclipse.jface.text.*;
13: import org.eclipse.swt.graphics.Point;
14:
15: /**
16: * Example implementation for an <code>ITextHover</code> which hovers over Java code.
17: */
18: public class JavaTextHover implements ITextHover {
19:
20: /* (non-Javadoc)
21: * Method declared on ITextHover
22: */
23: public String getHoverInfo(ITextViewer textViewer,
24: IRegion hoverRegion) {
25: if (hoverRegion != null) {
26: try {
27: if (hoverRegion.getLength() > -1)
28: return textViewer.getDocument().get(
29: hoverRegion.getOffset(),
30: hoverRegion.getLength());
31: } catch (BadLocationException x) {
32: }
33: }
34: return JavaEditorMessages
35: .getString("JavaTextHover.emptySelection"); //$NON-NLS-1$
36: }
37:
38: /* (non-Javadoc)
39: * Method declared on ITextHover
40: */
41: public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
42: Point selection = textViewer.getSelectedRange();
43: if (selection.x <= offset && offset < selection.x + selection.y)
44: return new Region(selection.x, selection.y);
45: return new Region(offset, 0);
46: }
47: }
|