Search in sources :

Example 1 with AnnotationLayerBuilder

use of de.catma.ui.client.ui.tagger.shared.AnnotationLayerBuilder in project catma by forTEXT.

the class Line method toHTML.

public Element toHTML() {
    List<TextRange> rangeParts = new ArrayList<>();
    rangeParts.add(new TextRange(this.textRange));
    Set<TextRange> tagInstanceAndHighlightedTextRanges = new HashSet<>(textRangesByRelativeTagInstanceID.values());
    tagInstanceAndHighlightedTextRanges.addAll(highlightedTextRanges);
    for (TextRange currentTextRange : tagInstanceAndHighlightedTextRanges) {
        for (TextRange rangePart : new TreeSet<TextRange>(rangeParts)) {
            if (rangePart.hasOverlappingRange(currentTextRange)) {
                rangeParts.remove(rangePart);
                rangeParts.add(rangePart.getOverlappingRange(currentTextRange));
                for (TextRange disjointRange : rangePart.getDisjointRanges(currentTextRange)) {
                    if (rangePart.hasOverlappingRange(disjointRange)) {
                        rangeParts.add(disjointRange);
                    } else {
                        currentTextRange = disjointRange;
                    }
                }
            }
        }
    }
    Collections.sort(rangeParts);
    // 
    // for (TextRange rangePart : rangeParts) {
    // System.out.println(rangePart);
    // }
    // 
    // $NON-NLS-1$
    Element table = new Element("table");
    // $NON-NLS-1$ //$NON-NLS-2$
    table.addAttribute(new Attribute("class", "taggerline-table"));
    // $NON-NLS-1$ //$NON-NLS-2$
    table.addAttribute(new Attribute("id", "LINE." + String.valueOf(lineId)));
    // $NON-NLS-1$
    Element tbody = new Element("tbody");
    table.appendChild(tbody);
    // display layer
    // $NON-NLS-1$
    Element contentDisplayLayer = new Element("tr");
    // $NON-NLS-1$ //$NON-NLS-2$
    contentDisplayLayer.addAttribute(new Attribute("class", "tagger-display-layer"));
    // $NON-NLS-1$ //$NON-NLS-2$
    contentDisplayLayer.addAttribute(new Attribute("id", textRange.getStartPos() + "." + textRange.getEndPos()));
    tbody.appendChild(contentDisplayLayer);
    // $NON-NLS-1$
    Element visibleContentLayerContent = new Element("td");
    contentDisplayLayer.appendChild(visibleContentLayerContent);
    visibleContentLayerContent.addAttribute(// $NON-NLS-1$
    new Attribute("colspan", String.valueOf(rangeParts.size())));
    visibleContentLayerContent.appendChild(getPresentationContent());
    // highlight layer
    if (!highlightedTextRanges.isEmpty()) {
        // $NON-NLS-1$
        Element highlightLayer = new Element("tr");
        // $NON-NLS-1$ //$NON-NLS-2$
        highlightLayer.addAttribute(new Attribute("class", "highlight-layer"));
        // $NON-NLS-1$ //$NON-NLS-2$
        highlightLayer.addAttribute(new Attribute("unselectable", "on"));
        tbody.appendChild(highlightLayer);
        for (TextRange rangePart : rangeParts) {
            // $NON-NLS-1$
            Element highlightLayerContent = new Element("td");
            highlightLayer.appendChild(highlightLayerContent);
            highlightLayerContent.appendChild(TextRange.NBSP);
            highlightLayerContent.addAttribute(new Attribute(// $NON-NLS-1$
            "id", // $NON-NLS-1$ //$NON-NLS-2$
            "h." + rangePart.getStartPos() + "." + rangePart.getEndPos()));
            if (rangePartIsHighlighted(rangePart)) {
                highlightLayerContent.addAttribute(// $NON-NLS-1$ //$NON-NLS-2$
                new Attribute("class", "highlighted-content"));
            } else {
                highlightLayerContent.addAttribute(// $NON-NLS-1$ //$NON-NLS-2$
                new Attribute("class", "empty-highlight-layer"));
            }
        }
    }
    // comment layer
    // Element commentLayer = new Element("tr"); //$NON-NLS-1$
    // commentLayer.addAttribute(new Attribute("class", "comment-layer")); //$NON-NLS-1$ //$NON-NLS-2$
    // commentLayer.addAttribute(new Attribute("unselectable", "on")); //$NON-NLS-1$ //$NON-NLS-2$
    // tbody.appendChild(commentLayer);
    // 
    // Element commentContent = new Element("td"); //$NON-NLS-1$
    // commentLayer.appendChild(commentContent);
    // commentContent.addAttribute(
    // new Attribute("class", "empty-comment-layer")); //$NON-NLS-1$ //$NON-NLS-2$
    // 
    // commentContent.addAttribute(
    // new Attribute("class", "comment-anchor")); //$NON-NLS-1$ //$NON-NLS-2$
    // 
    // Element commentContainer = new Element("div");
    // commentContent.appendChild(commentContainer);
    // commentContainer.addAttribute(
    // new Attribute("class", "comment-container")); //$NON-NLS-1$ //$NON-NLS-2$
    // annotation layers
    AnnotationLayerBuilder annotationLayerBuilder = new AnnotationLayerBuilder(relativeTagInstanceByID.values(), rangeParts);
    Table<Integer, TextRange, ClientTagInstance> layerTable = annotationLayerBuilder.getLayerTable();
    int rowCount = layerTable.rowKeySet().size();
    for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
        // $NON-NLS-1$
        Element annotationLayer = new Element("tr");
        // $NON-NLS-1$ //$NON-NLS-2$
        annotationLayer.addAttribute(new Attribute("class", "annotation-layer"));
        // $NON-NLS-1$ //$NON-NLS-2$
        annotationLayer.addAttribute(new Attribute("unselectable", "on"));
        tbody.appendChild(annotationLayer);
        for (TextRange rangePart : rangeParts) {
            // $NON-NLS-1$
            Element annotationLayerContent = new Element("td");
            annotationLayer.appendChild(annotationLayerContent);
            annotationLayerContent.appendChild(TextRange.NBSP);
            ClientTagInstance relativeTagInstance = layerTable.get(rowIdx, rangePart);
            if (relativeTagInstance != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                annotationLayerContent.addAttribute(new Attribute("class", "unselected-tag-instance"));
                annotationLayerContent.addAttribute(new Attribute(// $NON-NLS-1$
                "id", relativeTagInstance.getInstanceID() + // $NON-NLS-1$
                "." + rangePart.getStartPos() + // $NON-NLS-1$
                "." + rangePart.getEndPos()));
                annotationLayerContent.addAttribute(new Attribute(// $NON-NLS-1$
                "style", // $NON-NLS-1$
                "background:#" + relativeTagInstance.getColor() + ";color:#" + // $NON-NLS-1$
                relativeTagInstance.getColor()));
            } else {
                annotationLayerContent.addAttribute(// $NON-NLS-1$ //$NON-NLS-2$
                new Attribute("class", "empty-annotation-layer"));
            }
        }
    }
    // segmentation layer
    // $NON-NLS-1$
    Element segmentationLayer = new Element("tr");
    // $NON-NLS-1$ //$NON-NLS-2$
    segmentationLayer.addAttribute(new Attribute("class", "segmentation-layer"));
    // $NON-NLS-1$ //$NON-NLS-2$
    segmentationLayer.addAttribute(new Attribute("unselectable", "on"));
    tbody.appendChild(segmentationLayer);
    String lastPresentationContent = null;
    for (TextRange rangePart : rangeParts) {
        // $NON-NLS-1$
        Element segmentationLayerContent = new Element("td");
        segmentationLayer.appendChild(segmentationLayerContent);
        String presentationContent = getPresentationContent(rangePart);
        if (rightToLeftWriting && (lastPresentationContent != null) && !lastPresentationContent.endsWith(TextRange.NBSP)) {
            segmentationLayerContent.appendChild(presentationContent + TextRange.ZWJ);
        } else {
            segmentationLayerContent.appendChild(presentationContent);
        }
        lastPresentationContent = presentationContent;
    }
    return table;
}
Also used : AnnotationLayerBuilder(de.catma.ui.client.ui.tagger.shared.AnnotationLayerBuilder) Attribute(nu.xom.Attribute) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) Element(nu.xom.Element) ArrayList(java.util.ArrayList) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet)

Example 2 with AnnotationLayerBuilder

use of de.catma.ui.client.ui.tagger.shared.AnnotationLayerBuilder in project catma by forTEXT.

the class Line method createLineElement.

private Element createLineElement() {
    List<TextRange> rangeParts = new ArrayList<>();
    rangeParts.add(new TextRange(this.textRange));
    Set<TextRange> segmentTextRanges = new HashSet<>(tagInstanceTextRanges);
    segmentTextRanges.addAll(highlightedTextRanges);
    segmentTextRanges.addAll(selectedTextRanges);
    for (TextRange currentTextRange : segmentTextRanges) {
        for (TextRange rangePart : new TreeSet<TextRange>(rangeParts)) {
            if (rangePart.hasOverlappingRange(currentTextRange)) {
                rangeParts.remove(rangePart);
                rangeParts.add(rangePart.getOverlappingRange(currentTextRange));
                for (TextRange disjointRange : rangePart.getDisjointRanges(currentTextRange)) {
                    if (rangePart.hasOverlappingRange(disjointRange)) {
                        rangeParts.add(disjointRange);
                    } else {
                        currentTextRange = disjointRange;
                    }
                }
            }
        }
    }
    Collections.sort(rangeParts);
    Element table = DOM.createTable();
    table.setAttribute("class", "taggerline-table");
    table.setAttribute("id", lineId);
    Element tbody = DOM.createTBody();
    table.appendChild(tbody);
    // display layer
    Element contentDisplayLayer = DOM.createTR();
    contentDisplayLayer.setAttribute("class", "tagger-display-layer");
    contentDisplayLayer.setAttribute("id", textRange.getStartPos() + "." + textRange.getEndPos());
    tbody.appendChild(contentDisplayLayer);
    Element visibleContentLayerContent = DOM.createTD();
    contentDisplayLayer.appendChild(visibleContentLayerContent);
    visibleContentLayerContent.setAttribute("colspan", String.valueOf(rangeParts.size()));
    visibleContentLayerContent.setInnerText(getPresentationContent());
    if (!selectedTextRanges.isEmpty()) {
        Element selectionLayer = DOM.createTR();
        selectionLayer.setAttribute("class", "selection-layer");
        selectionLayer.setAttribute("unselectable", "on");
        tbody.appendChild(selectionLayer);
        for (TextRange rangePart : rangeParts) {
            Element selectionLayerContent = DOM.createTD();
            selectionLayer.appendChild(selectionLayerContent);
            selectionLayerContent.setInnerText(TextRange.NBSP);
            selectionLayerContent.setAttribute("id", "s" + rangePart.getStartPos() + "." + rangePart.getEndPos());
            if (rangePartIsSelected(rangePart)) {
                selectionLayerContent.setAttribute("class", "selected-content");
            } else {
                selectionLayerContent.setAttribute("class", "empty-selection-layer");
            }
        }
    }
    if (!highlightedTextRanges.isEmpty()) {
        Element highlightLayer = DOM.createTR();
        highlightLayer.setAttribute("class", "highlight-layer");
        highlightLayer.setAttribute("unselectable", "on");
        tbody.appendChild(highlightLayer);
        for (TextRange rangePart : rangeParts) {
            Element highlightLayerContent = DOM.createTD();
            highlightLayer.appendChild(highlightLayerContent);
            highlightLayerContent.setInnerText(TextRange.NBSP);
            highlightLayerContent.setAttribute("id", "h." + rangePart.getStartPos() + "." + rangePart.getEndPos());
            if (rangePartIsHighlighted(rangePart)) {
                highlightLayerContent.setAttribute("class", "highlighted-content");
            } else {
                highlightLayerContent.setAttribute("class", "empty-highlight-layer");
            }
        }
    }
    // annotation layers
    AnnotationLayerBuilder annotationLayerBuilder = new AnnotationLayerBuilder(absoluteTagIntances, rangeParts);
    Table<Integer, TextRange, ClientTagInstance> annotationLayerTable = annotationLayerBuilder.getLayerTable();
    int rowCount = annotationLayerTable.rowKeySet().size();
    for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
        Element annotationLayer = DOM.createTR();
        annotationLayer.setAttribute("class", "annotation-layer");
        annotationLayer.setAttribute("unselectable", "on");
        tbody.appendChild(annotationLayer);
        for (TextRange rangePart : rangeParts) {
            Element annotationLayerContent = DOM.createTD();
            annotationLayer.appendChild(annotationLayerContent);
            annotationLayerContent.setInnerText(TextRange.NBSP);
            ClientTagInstance relativeTagInstance = annotationLayerTable.get(rowIdx, rangePart);
            if (relativeTagInstance != null) {
                annotationLayerContent.setAttribute("class", "unselected-tag-instance");
                annotationLayerContent.setAttribute("id", relativeTagInstance.getInstanceID() + "." + rangePart.getStartPos() + "." + rangePart.getEndPos());
                annotationLayerContent.setAttribute("style", "background:#" + relativeTagInstance.getColor() + ";color:#" + relativeTagInstance.getColor());
            } else {
                annotationLayerContent.setAttribute("class", "empty-annotation-layer");
            }
        }
    }
    // segmentation layer
    Element segmentationLayer = DOM.createTR();
    segmentationLayer.setAttribute("class", "segmentation-layer");
    segmentationLayer.setAttribute("unselectable", "on");
    tbody.appendChild(segmentationLayer);
    boolean isRtl = isRtlWriting();
    String lastPresentationContent = null;
    for (TextRange rangePart : rangeParts) {
        Element segmentationLayerContent = DOM.createTD();
        segmentationLayer.appendChild(segmentationLayerContent);
        String presentationContent = getPresentationContent(rangePart);
        if (isRtl && (lastPresentationContent != null) && !lastPresentationContent.endsWith(TextRange.NBSP)) {
            segmentationLayerContent.setInnerText(presentationContent + TextRange.ZWJ);
        } else {
            segmentationLayerContent.setInnerText(presentationContent);
        }
        lastPresentationContent = presentationContent;
    }
    return table;
}
Also used : AnnotationLayerBuilder(de.catma.ui.client.ui.tagger.shared.AnnotationLayerBuilder) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) Element(com.google.gwt.dom.client.Element) ArrayList(java.util.ArrayList) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet)

Aggregations

AnnotationLayerBuilder (de.catma.ui.client.ui.tagger.shared.AnnotationLayerBuilder)2 ClientTagInstance (de.catma.ui.client.ui.tagger.shared.ClientTagInstance)2 TextRange (de.catma.ui.client.ui.tagger.shared.TextRange)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TreeSet (java.util.TreeSet)2 Element (com.google.gwt.dom.client.Element)1 Attribute (nu.xom.Attribute)1 Element (nu.xom.Element)1