Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.Position


        // set up position tracking for our magic peers
        if (fBracketLevelStack.size() == 1) {
            document.addPositionCategory(CATEGORY);
            document.addPositionUpdater(fUpdater);
        }
        level.fFirstPosition = new Position(offset, 1);
        level.fSecondPosition = new Position(offset + 1, 1);
        document.addPosition(CATEGORY, level.fFirstPosition);
        document.addPosition(CATEGORY, level.fSecondPosition);

        level.fUI = new EditorLinkedModeUI(model, sourceViewer);
        level.fUI.setSimpleMode(true);
View Full Code Here


            try {
                final Position[] positions = event.getDocument().getPositions(fCategory);

                for (int i = 0; i != positions.length; i++) {

                    final Position position = positions[i];

                    if (position.isDeleted()) {
                        continue;
                    }

                    final int offset = position.getOffset();
                    final int length = position.getLength();
                    final int end = offset + length;

                    if (offset >= eventOffset + eventOldLength) {
                        // position comes after change - shift
                        position.setOffset(offset + deltaLength);
                    } else if (end <= eventOffset) {
                        // position comes way before change - leave alone
                    } else if (offset <= eventOffset
                            && end >= eventOffset + eventOldLength) {
                        // event completely internal to the position - adjust
                        // length
                        position.setLength(length + deltaLength);
                    } else if (offset < eventOffset) {
                        // event extends over end of position - adjust length
                        final int newEnd = eventOffset;
                        position.setLength(newEnd - offset);
                    } else if (end > eventOffset + eventOldLength) {
                        // event extends from before position into it - adjust
                        // offset and length offset becomes end of event, length
                        // adjusted accordingly
                        final int newOffset = eventOffset + eventNewLength;
                        position.setOffset(newOffset);
                        position.setLength(end - newOffset);
                    } else {
                        // event consumes the position - delete it
                        position.delete();
                    }
                }
            } catch (final BadPositionCategoryException e) {
                // ignore and return
            }
View Full Code Here

        try {

            final IRegion reg = doc.getLineInformation(lr.getLineNum() - 1);
            final int length = reg.getLength();
            final int offset = reg.getOffset();
            final Position pos = new Position(offset, length);

            Annotation annotation;
            if (lr.called()) {
                annotation = CoverageAnnotationFactory
                        .create(CoverageTypes.FULL_COVERAGE);
View Full Code Here

    }

    public Annotation gotoAnnotation(final boolean forward) {
        final ITextSelection selection = (ITextSelection) editor.getSelectionProvider()
                .getSelection();
        final Position position = new Position(0, 0);
        final Annotation annotation = getNextAnnotation(selection.getOffset(),
                selection.getLength(), forward, position);
        editor.setStatusLineErrorMessage(null);
        editor.setStatusLineMessage(null);
        if (annotation != null) {
            updateAnnotationViews(annotation);
            editor.selectAndReveal(position.getOffset(), position.getLength());
            editor.setStatusLineMessage(annotation.getText());
        }
        return annotation;
    }
View Full Code Here

     */
    private Annotation getNextAnnotation(final int offset, final int length,
            final boolean forward, final Position annotationPosition) {

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

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

        final IAnnotationModel model = editor.getDocumentProvider().getAnnotationModel(
                editor.getEditorInput());
        final Iterator<Annotation> e = new ErlangAnnotationIterator(model, true, true);
        while (e.hasNext()) {
            final Annotation a = e.next();
            if (a instanceof IErlangAnnotation && ((IErlangAnnotation) a).hasOverlay()
                    || !isNavigationTarget(a)) {
                continue;
            }

            final 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
                        || containingAnnotationPosition != 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
                            && nextAnnotationPosition != null
                            && 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
View Full Code Here

        final ITextSelection pos = (ITextSelection) getSelectionProvider().getSelection();
        final MarkCallLocation location = new MarkCallLocation(getSourceViewer()
                .getDocument(), pos.getStartLine());

        final Position position = new Position(location.getOffset(), location.getLength());
        final String description = location.getDescription();

        final Annotation oldAnnotation = callMatchingLine;
        if (position.getOffset() != 0) {
            callMatchingLine = new Annotation("org.erlide.test_support.trace.call",
                    false, description);
        } else {
            callMatchingLine = null;
        }
View Full Code Here

    IStructuredDocumentRegion sdRegion = xmlNode.getFirstStructuredDocumentRegion();
    ITextRegionList regions = sdRegion.getRegions();
    ITextRegion r = null;
    String attrName = ""; //$NON-NLS-1$
    Object temp = null;
    Position p = null;
    HashMap map = ((AttributeContextInformation) fInfo).getAttr2RangeMap();

    // so we can add ranges in order
    StyleRange[] sorted = new StyleRange[fInfo.getInformationDisplayString().length()];
    for (int i = 0; i < regions.size(); i++) {
View Full Code Here

          attrInfo.append(" "); //$NON-NLS-1$
          if ((i != 0) && (i % numPerLine == 0)) {
            attrInfo.append("\n "); //$NON-NLS-1$
          }
        }
        attrPosMap.put(name, new Position(pos, length));
      }
      if (!attrInfo.toString().trim().equals("")) {
        return new IContextInformation[]{new AttributeContextInformation(attrContextString, attrInfo.toString(), attrPosMap)};
      }
    }
View Full Code Here

        IStructuredDocumentRegion matchRegion = null;
        if (((Node) o).getNodeType() == Node.ATTRIBUTE_NODE) {
          o = ((Attr) o).getOwnerElement();
        }

        Position pStart = null;
        Position pEnd = null;
        String tag = ""; //$NON-NLS-1$
        if (o instanceof IDOMNode) {
          IDOMNode node = (IDOMNode) o;
          IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
          if (startStructuredDocumentRegion != null && startStructuredDocumentRegion.containsOffset(offset)) {
            if (startStructuredDocumentRegion.getNumberOfRegions() > 1) {
              ITextRegion nameRegion = startStructuredDocumentRegion.getRegions().get(1);
              pStart = new Position(startStructuredDocumentRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
              tag = startStructuredDocumentRegion.getText(nameRegion);
            }
            matchRegion = ((IDOMNode) o).getEndStructuredDocumentRegion();
            if (matchRegion != null && matchRegion.getNumberOfRegions() > 1) {
              ITextRegion nameRegion = matchRegion.getRegions().get(1);
              pEnd = new Position(matchRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
            }
          }
          else {
            IStructuredDocumentRegion endStructuredDocumentRegion = node.getEndStructuredDocumentRegion();
            if (endStructuredDocumentRegion != null && endStructuredDocumentRegion.containsOffset(offset)) {
              if (endStructuredDocumentRegion.getNumberOfRegions() > 1) {
                ITextRegion nameRegion = endStructuredDocumentRegion.getRegions().get(1);
                pEnd = new Position(endStructuredDocumentRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
                tag = endStructuredDocumentRegion.getText(nameRegion);
              }
              matchRegion = ((IDOMNode) o).getStartStructuredDocumentRegion();
              if (matchRegion != null && matchRegion.getNumberOfRegions() > 1) {
                ITextRegion nameRegion = matchRegion.getRegions().get(1);
                pStart = new Position(matchRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
              }
            }
          }
        }
        if (pStart != null && pEnd != null) {
View Full Code Here

      for (int i = 0; i < length; i++) {
        if (isCanceled())
          return Status.CANCEL_STATUS;

        String message;
        Position position = fPositions[i];

        // Create & add annotation
        try {
          message = document.get(position.offset, position.length);
        } catch (BadLocationException ex) {
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.