public void showAnnotations()

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


    public void showAnnotations (List<AnnotationObject> annotationList, boolean refreshView) {
        
        long start = System.currentTimeMillis();
        
        // Create list of visible and overlapped annotations
        List<StyleRange> styleRangeList = new ArrayList<StyleRange>(); // List of StyleRanges to be shown
        List<AnnotationObject> visibleAnnotationList = new ArrayList<AnnotationObject>();
        List<AnnotationObject> overlapList = new ArrayList<AnnotationObject>();
        
        int lastOffset = 0; // for checking overlapped annotation
        for (AnnotationObject annot: annotationList) {
            if (annot.show) {                
                if (lastOffset > annot.begin) {
                    // Overlapped Annotation
                    overlapList.add(annot);
                    continue;
                }
                lastOffset = annot.end;
                visibleAnnotationList.add(annot);

                // Get color from Type instead of using the one set with the annotation
                TypeStyle style = typeSystemStyle.getTypeStyle(annot.getTypeName());
                // Create new StyleRange
                styleRangeList.add(new StyleRange(annot.begin, annot.end - annot.begin, 
                        style.getForeground(), style.getBackground()));
            }
        }
        if (debug_show_performance)
            Trace.trace("Perf for visibleAnnotationList-1 " + visibleAnnotationList.size()
                + " annotations : " + (System.currentTimeMillis()-start));
        
        // Check validity of StyleRange
//        lastOffset = 0;
//        for (int i = 0; i < visibleAnnotationList.size(); i ++) {
//            annot = (AnnotationObject) visibleAnnotationList.get(i);
//            if (lastOffset > annot.begin) {
//                Trace.trace("Range error by annotation " + annot.getTypeName() 
//                      + " lastOffset=" + lastOffset  + " begin=" + annot.begin + " end=" + annot.end);    
//            }
//            lastOffset = annot.end;
//        }
        
        if (refreshView) {
            // long startTime = System.currentTimeMillis();
            
//            AnnotationScanner sc = AnnotationScanner.getInstance();
//            sc.setAnnotations(visibleAnnotationList);
            // sourceViewer.setDocument(document, model);
            updateAnnotationMarkersInModel(visibleAnnotationList, true);
            textPresentation.clear();
            if (styleRangeList.size() > 0) {
                textPresentation.replaceStyleRanges((StyleRange[]) styleRangeList
                        .toArray(new StyleRange[styleRangeList.size()]));  
                
                // Is there any "overlapped" range ?
                if (overlapList.size() > 0) {
                    // Create StyleRange of "overlapped" ranges 
                    List<StyleRange> extraStyleRangeList = new ArrayList<StyleRange>();
                    for (AnnotationObject annot: overlapList) {
                        // Get color from Type instead of using the one set with the annotation
                        TypeStyle style = typeSystemStyle.getTypeStyle(annot.getTypeName());
                        extraStyleRangeList.add(new StyleRange(annot.begin, annot.end - annot.begin, 
                                style.getForeground(), style.getBackground()));                        
                    }
                    
                    // Merge StyleRanges
                    textPresentation.mergeStyleRanges((StyleRange[]) extraStyleRangeList
                            .toArray(new StyleRange[extraStyleRangeList.size()]));  
                    updateAnnotationMarkersInModel(overlapList, false); // Don't delete OLD annotations
                }
                
                // Painter Support
                addAnnotationTypesAndColorsToPainter ();
            }
            // Save "Top" position of StyledText
            int top = ((SourceViewer) sourceViewer).getTextWidget().getTopPixel();
            
            sourceViewer.getTextWidget().setRedraw(false);            
            sourceViewer.setDocument(documentObject, model); // required, otherwise no redraw 
            sourceViewer.changeTextPresentation(textPresentation, false);
            
            // Restore "Top" position of StyledText
            ((SourceViewer) sourceViewer).getTextWidget().setTopPixel(top);
            sourceViewer.getTextWidget().setRedraw(true);
            
            if (debug_show_performance)
                Trace.trace("Perf showAnnotationsForView for " + annotationList.size()
                   + " annotations : " + (System.currentTimeMillis()-start));
        }
    } // showAnnotations