Search in sources :

Example 1 with TextRange

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

the class Page method addHighlight.

/**
 * @param highlightedAbsoluteRange
 * @return the ID of the first affected {@link Line}
 */
public int addHighlight(Range highlightedAbsoluteRange) {
    pageDiv = null;
    Line firstLine = null;
    TextRange highlightedRelativeRange = getRelativeRangeFor(highlightedAbsoluteRange);
    for (Line line : lines) {
        TextRange overlappingRange = line.getOverlappingRange(highlightedRelativeRange);
        if (overlappingRange != null) {
            line.addHighlight(overlappingRange);
            firstLine = (firstLine == null) ? line : firstLine;
        }
    }
    if (firstLine != null) {
        return firstLine.getLineId();
    }
    return -1;
}
Also used : TextRange(de.catma.ui.client.ui.tagger.shared.TextRange)

Example 2 with TextRange

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

the class Page method buildLines.

private void buildLines() {
    this.lines = new ArrayList<>();
    Matcher matcher = Pattern.compile(Pager.LINE_CONTENT_PATTERN).matcher(text);
    Line currentLine = new Line(rightToLeftWriting);
    int lineLength = 0;
    int lineId = 0;
    int pageOffset = 0;
    while (matcher.find()) {
        if (lineLength + matcher.group().length() > approxMaxLineLength) {
            int lineStart = pageOffset;
            int lineEnd = pageOffset + lineLength;
            currentLine.setLineId(lineId++);
            currentLine.setTextRange(new TextRange(lineStart, lineEnd));
            lines.add(currentLine);
            pageOffset += lineEnd - lineStart;
            currentLine = new Line(rightToLeftWriting);
            lineLength = 0;
        }
        if (matcher.group(Pager.WORDCHARACTER_GROUP) != null) {
            currentLine.addCharacterContent(matcher.group(Pager.WORDCHARACTER_GROUP));
        }
        if ((matcher.group(Pager.WHITESPACE_GROUP) != null) && (!matcher.group(Pager.WHITESPACE_GROUP).isEmpty())) {
            currentLine.addWhitespaceContent(matcher.group(Pager.WHITESPACE_GROUP));
        }
        if (matcher.group(Pager.LINE_SEPARATOR_GROUP) != null) {
            lineLength += matcher.group(Pager.LINE_SEPARATOR_GROUP).length();
            currentLine.addLineSeparatorContent(matcher.group(Pager.LINE_SEPARATOR_GROUP));
            int lineStart = pageOffset;
            int lineEnd = pageOffset + lineLength;
            currentLine.setLineId(lineId++);
            currentLine.setTextRange(new TextRange(lineStart, lineEnd));
            lines.add(currentLine);
            pageOffset += lineEnd - lineStart;
            currentLine = new Line(rightToLeftWriting);
            lineLength = 0;
        } else {
            lineLength += matcher.group().length();
        }
    }
    if (lineLength != 0) {
        int lineStart = pageOffset;
        int lineEnd = pageOffset + lineLength;
        currentLine.setLineId(lineId++);
        currentLine.setTextRange(new TextRange(lineStart, lineEnd));
        lines.add(currentLine);
    }
    lineCount = lineId;
}
Also used : Matcher(java.util.regex.Matcher) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange)

Example 3 with TextRange

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

the class CharacterContent method getPresentationContent.

@Override
public String getPresentationContent(TextRange rangePart) {
    TextRange overlappingRange = this.textRange.getOverlappingRange(rangePart);
    int start = overlappingRange.getStartPos() - this.textRange.getStartPos();
    int end = start + overlappingRange.size();
    return content.substring(start, end);
}
Also used : TextRange(de.catma.ui.client.ui.tagger.shared.TextRange)

Example 4 with TextRange

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

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

the class Line method getTagInstanceIDs.

public List<String> getTagInstanceIDs(String instancePartID) {
    TextRange range = ClientTagInstance.getTextRangeFromPartId(instancePartID);
    ArrayList<String> result = new ArrayList<String>();
    for (Map.Entry<String, Collection<TextRange>> entry : textRangesByRelativeTagInstanceID.asMap().entrySet()) {
        if (range.isCoveredBy(entry.getValue())) {
            result.add(entry.getKey());
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TextRange (de.catma.ui.client.ui.tagger.shared.TextRange)27 ArrayList (java.util.ArrayList)11 ClientTagInstance (de.catma.ui.client.ui.tagger.shared.ClientTagInstance)10 ClientComment (de.catma.ui.client.ui.tagger.shared.ClientComment)6 HashSet (java.util.HashSet)5 Element (com.google.gwt.dom.client.Element)4 JSONObject (com.google.gwt.json.client.JSONObject)4 Comment (de.catma.document.comment.Comment)4 Node (com.google.gwt.dom.client.Node)3 JSONArray (com.google.gwt.json.client.JSONArray)3 TagDefinition (de.catma.tag.TagDefinition)3 URISyntaxException (java.net.URISyntaxException)3 List (java.util.List)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Subscribe (com.google.common.eventbus.Subscribe)2 JSONString (com.google.gwt.json.client.JSONString)2 ValueOutOfBoundsException (com.vaadin.ui.Slider.ValueOutOfBoundsException)2