2 * Copyright (c) 2003-2004 Christopher Lenz 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
9 * Christopher Lenz - initial API and implementation
11 * $Id: CssTextHover.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.ui.internal.text;
16 import java.util.Iterator;
18 import org.eclipse.jface.text.IRegion;
19 import org.eclipse.jface.text.ITextHover;
20 import org.eclipse.jface.text.ITextViewer;
21 import org.eclipse.jface.text.Position;
22 import org.eclipse.jface.text.source.Annotation;
23 import org.eclipse.jface.text.source.IAnnotationModel;
27 * Implements simple annotation hover to show the associated messages.
29 public class CssTextHover implements ITextHover {
31 * This hovers annotation model.
33 private IAnnotationModel model;
36 * Creates a new annotation hover.
38 * @param model this hover's annotation model
40 public CssTextHover(IAnnotationModel model) {
45 * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
47 public String getHoverInfo(ITextViewer textViewer, IRegion region) {
48 Iterator e = model.getAnnotationIterator();
50 Annotation a = (Annotation) e.next();
51 Position p = model.getPosition(a);
52 if (p.overlapsWith(region.getOffset(), region.getLength())) {
53 String text = a.getText();
54 if ((text != null) && (text.trim().length() > 0)) {
64 * @see ITextHover#getHoverRegion(ITextViewer, int)
66 public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
67 return CssWordFinder.findWord(textViewer.getDocument(), offset);