Package org.locationtech.udig.jconsole

Source Code of org.locationtech.udig.jconsole.JavaTextHover

/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     IBM Corporation - initial API and implementation
*******************************************************************************/
package org.locationtech.udig.jconsole;


import org.eclipse.swt.graphics.Point;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextHoverExtension2;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;

/**
* Example implementation for an <code>ITextHover</code> which hovers over Java code.
*/
public class JavaTextHover implements ITextHover {

  /**
   * {@inheritDoc}
   *
   * @deprecated As of 3.4, replaced by
   *             {@link ITextHoverExtension2#getHoverInfo2(ITextViewer, IRegion)}
   */
  public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
    if (hoverRegion != null) {
      try {
        if (hoverRegion.getLength() > -1)
          return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
      } catch (BadLocationException x) {
      }
    }
    return JavaEditorMessages.getString("JavaTextHover.emptySelection"); //$NON-NLS-1$
  }

  /* (non-Javadoc)
   * Method declared on ITextHover
   */
  public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
    Point selection= textViewer.getSelectedRange();
    if (selection.x <= offset && offset < selection.x + selection.y)
      return new Region(selection.x, selection.y);
    return new Region(offset, 0);
  }
}
TOP

Related Classes of org.locationtech.udig.jconsole.JavaTextHover

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.