protected void gotoPrevious()

in CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/document/AnnotatedTextComposite.java [759:815]


    protected void gotoPrevious ()
    {
        int newLength;
        Point selectedRange = sourceViewer.getSelectedRange();
        currOffset= selectedRange.x;
        currLength= selectedRange.y;
         
        IRegion lineInfo = null;
        try {
            lineInfo = documentObject.getLineInformationOfOffset(currOffset);
        } catch (BadLocationException e) {
            e.printStackTrace();
            return;
        }
        int rangeStart = lineInfo.getOffset();
        int rangeEnd   = rangeStart + lineInfo.getLength();
        // Trace.err("rangeStart: " + rangeStart + " ; rangeEnd: " + rangeEnd);
        
        ArrayList<Annotation> allAnnotations = new ArrayList<Annotation>();
        ArrayList<Position> allPositions   = new ArrayList<Position>();
        int bestOffset           = Integer.MAX_VALUE;
        newLength = currLength;
        Iterator annotationIterator = model.getAnnotationIterator();
        while (annotationIterator.hasNext()) {
            Annotation annot= (Annotation) annotationIterator.next();
            Position pos= model.getPosition(annot);
            if (pos != null && isInside(pos.offset, rangeStart, rangeEnd)) { // inside our range?
                allAnnotations.add(annot);
                allPositions.add(pos);
                bestOffset= processAnnotation(annot, pos, currOffset, bestOffset);
                newLength = pos.length;
            }
        }
        
        int newOffset;
        ArrayList<Annotation> resultingAnnotations= new ArrayList<Annotation>(20);
        
        if (bestOffset == Integer.MAX_VALUE) {
            newOffset =  currOffset;
        } else {
            int i=0;
            for (Position pos: allPositions) {
                if (isInside(bestOffset, pos.offset, pos.offset + pos.length)) {
                    resultingAnnotations.add(allAnnotations.get(i));
                }
                ++i;
            }
            newOffset = bestOffset;
        }

        if (newOffset != currOffset) {
            sourceViewer.setSelectedRange(newOffset, 0);
            sourceViewer.revealRange(newOffset, 0);
            // sourceViewer.setTextColor(Display.getCurrent().getSystemColor(SWT.COLOR_RED), newOffset, 10, false);
            sourceViewer.getTextWidget().setSelection(newOffset, newOffset+newLength);
        }
    }