JavaTextHover.java :  » IDE-Eclipse » ui-examples » org » eclipse » ui » examples » javaeditor » Java Open Source

Java Open Source » IDE Eclipse » ui examples 
ui examples » org » eclipse » ui » examples » javaeditor » JavaTextHover.java
/*******************************************************************************
 * Copyright (c) 2000, 2005 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.eclipse.ui.examples.javaeditor;


import org.eclipse.jface.text.*;
import org.eclipse.swt.graphics.Point;

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

  /* (non-Javadoc)
   * Method declared on ITextHover
   */
  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);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.