Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.Position


    ArrayList annotationList= new ArrayList();
    Iterator iter= model.getAnnotationIterator();
    while (iter.hasNext()) {
      Annotation annotation= (Annotation)iter.next();
      if (canFix(annotation)) {
        Position pos= model.getPosition(annotation);
        if (isAtPosition(offset, pos)) {
          collectSpellingProblems(annotation, pos, annotationList);
        }
      }
    }
View Full Code Here


  public void run() {
    EditPosition editPosition= TextEditorPlugin.getDefault().getLastEditPosition();
    if (editPosition == null)
      return;

    final Position pos= editPosition.getPosition();
    if (pos == null || pos.isDeleted)
      return;

    IWorkbenchWindow window= getWindow();
    if (window == null)
View Full Code Here

  public Position getPosition(Annotation annotation) {
    if (fRightDocument != null && annotation instanceof DiffRegion) {
      RangeDifference difference= ((DiffRegion)annotation).getDifference();
      try {
        int offset= fRightDocument.getLineOffset(difference.rightStart());
        return new Position(offset, fRightDocument.getLineOffset(difference.rightEnd() - 1) + fRightDocument.getLineLength(difference.rightEnd() - 1) - offset);
      } catch (BadLocationException e) {
        // ignore and return null;
      }
    }
    return null;
View Full Code Here

   * @see #findAnnotation(int, int, boolean, Position)
   * @since 3.2
   */
  public Annotation gotoAnnotation(boolean forward) {
    ITextSelection selection= (ITextSelection) getSelectionProvider().getSelection();
    Position position= new Position(0, 0);
    Annotation annotation= findAnnotation(selection.getOffset(), selection.getLength(), forward, position);
    setStatusLineErrorMessage(null);
    setStatusLineMessage(null);
   
    if (annotation != null) {
      selectAndReveal(position.getOffset(), position.getLength());
      setStatusLineMessage(annotation.getText());
    }
    return annotation;
  }
View Full Code Here

   * @since 3.2
   */
  protected Annotation findAnnotation(final int offset, final int length, boolean forward, Position annotationPosition) {

    Annotation nextAnnotation= null;
    Position nextAnnotationPosition= null;
    Annotation containingAnnotation= null;
    Position containingAnnotationPosition= null;
    boolean currentAnnotation= false;

    IDocument document= getDocumentProvider().getDocument(getEditorInput());
    int endOfDocument= document.getLength();
    int distance= Integer.MAX_VALUE;

    IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput());
    Iterator e= model.getAnnotationIterator();
    while (e.hasNext()) {
      Annotation a= (Annotation) e.next();
      if (!isNavigationTarget(a))
        continue;

      Position p= model.getPosition(a);
      if (p == null)
        continue;

      if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {// || p.includes(offset)) {
        if (containingAnnotation == null || (forward && p.length >= containingAnnotationPosition.length || !forward && p.length >= containingAnnotationPosition.length)) {
          containingAnnotation= a;
          containingAnnotationPosition= p;
          currentAnnotation= p.length == length;
        }
      } else {
        int currentDistance= 0;

        if (forward) {
          currentDistance= p.getOffset() - offset;
          if (currentDistance < 0)
            currentDistance= endOfDocument + currentDistance;

          if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
            distance= currentDistance;
            nextAnnotation= a;
            nextAnnotationPosition= p;
          }
        } else {
          currentDistance= offset + length - (p.getOffset() + p.length);
          if (currentDistance < 0)
            currentDistance= endOfDocument + currentDistance;

          if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
            distance= currentDistance;
View Full Code Here

        boolean doRemove= word == null;
        if (word == null)
          doRemove= true;
        else {
          String annotationWord= null;
          Position pos= model.getPosition(annotation);
          try {
            annotationWord= document.get(pos.getOffset(), pos.getLength());
          } catch (BadLocationException e) {
            continue;
          }
          doRemove= word.equals(annotationWord);
        }
View Full Code Here

    /*
     * @see org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector#accept(org.eclipse.ui.texteditor.spelling.SpellingProblem)
     */
    public void accept(SpellingProblem problem) {
      fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
    }
View Full Code Here

    // look up the current range of the marker when the document has been edited
    IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput());
    if (model instanceof AbstractMarkerAnnotationModel) {

      AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model;
      Position pos= markerModel.getMarkerPosition(marker);
      if (pos != null && !pos.isDeleted()) {
        // use position instead of marker values
        start= pos.getOffset();
        end= pos.getOffset() + pos.getLength();
      }

      if (pos != null && pos.isDeleted()) {
        // do nothing if position has been deleted
        return;
      }
    }
View Full Code Here

    // look up the current range of the marker when the document has been edited
    IAnnotationModel model= documentProvider.getAnnotationModel(editorInput);
    if (model instanceof AbstractMarkerAnnotationModel) {

      AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model;
      Position pos= markerModel.getMarkerPosition(marker);
      if (pos != null && !pos.isDeleted()) {
        // use position instead of marker values
        start= pos.getOffset();
        end= pos.getOffset() + pos.getLength();
      }

      if (pos != null && pos.isDeleted()) {
        // do nothing if position has been deleted
        return;
      }
    }
View Full Code Here

    final int activeLine= fRuler.getLineOfLastMouseButtonActivity();
    List markers= null;
    for (Iterator it= model.getAnnotationIterator(); it.hasNext();) {
      Annotation annotation= (Annotation) it.next();
      if (annotation instanceof MarkerAnnotation) {
        Position position= model.getPosition(annotation);
        if (includesLine(position, document, activeLine)) {
          if (markers == null)
            markers= new ArrayList(10);

          markers.add(((MarkerAnnotation) annotation).getMarker());
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.Position

Copyright © 2018 www.massapicom. 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.