Search in sources :

Example 1 with ClientTagInstance

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

the class Page method removeTagInstances.

public void removeTagInstances(Set<TagDefinition> tagDefinitions) {
    // page needs rebuild
    pageDiv = null;
    Set<String> tagDefUUIds = new HashSet<String>();
    for (TagDefinition td : tagDefinitions) {
        tagDefUUIds.add(td.getUuid());
    }
    Iterator<Map.Entry<String, ClientTagInstance>> iterator = relativeTagInstances.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, ClientTagInstance> entry = iterator.next();
        if (tagDefUUIds.contains(entry.getValue().getTagDefinitionID())) {
            iterator.remove();
            removeRelativeTagInstanceFromLine(entry.getKey());
        }
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with ClientTagInstance

use of de.catma.ui.client.ui.tagger.shared.ClientTagInstance 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 3 with ClientTagInstance

use of de.catma.ui.client.ui.tagger.shared.ClientTagInstance 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)

Example 4 with ClientTagInstance

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

the class Line method makeLineFromLineNode.

private void makeLineFromLineNode() {
    lineId = lineElement.getId();
    Map<String, ClientTagInstance> absoluteTagIntancesByID = new HashMap<String, ClientTagInstance>();
    Element lineBodyElement = lineElement.getFirstChildElement();
    for (int layerIdx = 0; layerIdx < lineBodyElement.getChildCount(); layerIdx++) {
        Node layerNode = lineBodyElement.getChild(layerIdx);
        if (Element.is(layerNode)) {
            Element layerElement = Element.as(layerNode);
            if (layerElement.hasClassName("tagger-display-layer")) {
                handleDisplayLayer(layerElement);
            } else if (layerElement.hasClassName("annotation-layer")) {
                handleAnnotationLayer(layerElement, absoluteTagIntancesByID);
            } else if (layerElement.hasClassName("highlight-layer")) {
                handleHighlightLayer(layerElement);
            }
        }
    }
    for (ClientTagInstance tagInstance : absoluteTagIntancesByID.values()) {
        tagInstanceTextRanges.addAll(tagInstance.getRanges());
    }
    this.absoluteTagIntances = new HashSet<>(absoluteTagIntancesByID.values());
}
Also used : ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) HashMap(java.util.HashMap) Element(com.google.gwt.dom.client.Element) Node(com.google.gwt.dom.client.Node)

Example 5 with ClientTagInstance

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

the class TaggerEditor method createAndAddTagIntance.

public void createAndAddTagIntance(ClientTagDefinition tagDefinition) {
    String tagInstanceId = IDGenerator.generate();
    List<TextRange> ranges = new ArrayList<>();
    for (Line line : lineIdToLineMap.values()) {
        if (line.hasSelectedTextRanges()) {
            ranges.addAll(line.getSelectedTextRanges());
            line.addTagInstance(new ClientTagInstance(tagDefinition.getId(), tagInstanceId, tagDefinition.getColor(), new ArrayList<>(line.getSelectedTextRanges())));
        }
    }
    if (!ranges.isEmpty()) {
        ClientTagInstance ti = new ClientTagInstance(tagDefinition.getId(), tagInstanceId, tagDefinition.getColor(), ranges);
        taggerEditorListener.annotationChanged(TaggerEditorEventType.ADD, ti);
    }
}
Also used : ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) ArrayList(java.util.ArrayList) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange)

Aggregations

ClientTagInstance (de.catma.ui.client.ui.tagger.shared.ClientTagInstance)15 TextRange (de.catma.ui.client.ui.tagger.shared.TextRange)10 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)5 TagDefinition (de.catma.tag.TagDefinition)4 TagReference (de.catma.document.annotation.TagReference)3 HashMap (java.util.HashMap)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 Element (com.google.gwt.dom.client.Element)2 JSONArray (com.google.gwt.json.client.JSONArray)2 JSONObject (com.google.gwt.json.client.JSONObject)2 Range (de.catma.document.Range)2 Annotation (de.catma.document.annotation.Annotation)2 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)2 Property (de.catma.tag.Property)2 TagInstance (de.catma.tag.TagInstance)2 TagLibrary (de.catma.tag.TagLibrary)2 AnnotationLayerBuilder (de.catma.ui.client.ui.tagger.shared.AnnotationLayerBuilder)2 EditAnnotationPropertiesDialog (de.catma.ui.module.annotate.annotationpanel.EditAnnotationPropertiesDialog)2