tierimpl.java

来自「编辑视频文件」· Java 代码 · 共 1,749 行 · 第 1/5 页

JAVA
1,749
字号
            }        }    }    /**     * Special case for Included_In annotations.     * @param aa the annotation to force within the interval of fixedAnnotation     * @param fixedAnnotation the leading annotation     */    private void forceAnnotationInInterval(AlignableAnnotation aa,        AlignableAnnotation fixedAnnotation) {        TimeSlot begin = aa.getBegin();        TimeSlot end = aa.getEnd();        Constraint cc = ((TierImpl) aa.getTier()).getLinguisticType()                         .getConstraints();        if ((cc != null) && (cc.getStereoType() == Constraint.INCLUDED_IN)) {            if ((begin.getTime() >= fixedAnnotation.getBeginTimeBoundary()) &&                    (end.getTime() <= fixedAnnotation.getEndTimeBoundary())) {                return;            } else if ((begin.getTime() < fixedAnnotation.getBeginTimeBoundary()) &&                    (end.getTime() > fixedAnnotation.getBeginTimeBoundary())) {                begin.setTime(fixedAnnotation.getBeginTimeBoundary());                if (end.getTime() > fixedAnnotation.getEndTimeBoundary()) {                    end.setTime(fixedAnnotation.getEndTimeBoundary());                }                // update existing Time_Subdivision and Included_In child tiers                 forceChildAnnotationsOfAlignable(aa);            } else if ((end.getTime() > fixedAnnotation.getEndTimeBoundary()) &&                    (begin.getTime() < fixedAnnotation.getEndTimeBoundary())) {                end.setTime(fixedAnnotation.getEndTimeBoundary());                if (begin.getTime() < fixedAnnotation.getBeginTimeBoundary()) {                    begin.setTime(fixedAnnotation.getBeginTimeBoundary());                }                // update existing Time_Subdivision and Included_In child tiers                forceChildAnnotationsOfAlignable(aa);            } else {                // delete                end.setTime(begin.getTime());                //aa.markDeleted(true);            }        }    }    /**     * Special treatment for Time Subdivision child annotations.     * @param aa the child annotation     * @param graphEndpoints he graph endpoints     * @param fixedAnnotation the ancestor in which interval the children should be forced     */    private void forceTSInsideFixedInterval(AlignableAnnotation aa,        TimeSlot[] graphEndpoints, AlignableAnnotation fixedAnnotation) {        Constraint cc = ((TierImpl) aa.getTier()).getLinguisticType()                         .getConstraints();        if ((cc == null) ||                (cc.getStereoType() != Constraint.TIME_SUBDIVISION)) {            return;        }        if (!aa.getBegin().isTimeAligned() || !aa.getEnd().isTimeAligned()) {            return;        }        TimeSlot begin = aa.getBegin();        TimeSlot end = aa.getEnd();        if ((begin.getTime() < end.getTime()) &&                (end.getTime() < fixedAnnotation.getBegin().getTime()) &&                (begin != fixedAnnotation.getBegin()) &&                (begin != graphEndpoints[0])) {            begin.setTime(fixedAnnotation.getBegin().getTime());        } else if ((begin.getTime() < end.getTime()) &&                (begin.getTime() > fixedAnnotation.getEnd().getTime()) &&                (end != fixedAnnotation.getEnd()) &&                (end != graphEndpoints[1])) {            end.setTime(fixedAnnotation.getEnd().getTime());        }    }    /**     * Propagate changes in existing Incuded_In annotations or toplevel annotations to     * child annotations (parent listeners).     * Special case because Included In annotations are not part of the time slot based annotation chain.     * This should be done recursively.     *     * @param aa the time alignable annotation that has been changed     */    private void forceChildAnnotationsOfAlignable(AlignableAnnotation aa) {        Constraint cc = ((TierImpl) aa.getTier()).getLinguisticType()                         .getConstraints();        if (cc == null) {            //return;        } else if ((cc.getStereoType() != Constraint.INCLUDED_IN) &&                (cc.getStereoType() != Constraint.TIME_SUBDIVISION)) {            return;        }        ArrayList chan = aa.getParentListeners();        Object next;        AlignableAnnotation ann;        Constraint sc = null;        HashMap tsChildren = null;        for (int i = 0; i < chan.size(); i++) {            next = chan.get(i);            if (!(next instanceof AlignableAnnotation)) {                continue;            }            ann = (AlignableAnnotation) next;            sc = ((TierImpl) ann.getTier()).getLinguisticType().getConstraints();            if (sc.getStereoType() == Constraint.INCLUDED_IN) {                forceAnnotationInInterval(ann, aa);                if (ann.getBegin().getTime() == ann.getEnd().getTime()) {                    ann.markDeleted(true);                }            } else if (sc.getStereoType() == Constraint.TIME_SUBDIVISION) {                if (tsChildren == null) {                    tsChildren = new HashMap(3);                }                if (tsChildren.containsKey(ann.getTier())) {                    ((ArrayList) tsChildren.get(ann.getTier())).add(ann);                } else {                    ArrayList al = new ArrayList(5);                    al.add(ann);                    tsChildren.put(ann.getTier(), al);                }            }        }        if (tsChildren != null) {            Iterator keyIt = tsChildren.keySet().iterator();            Object key;            while (keyIt.hasNext()) {                key = keyIt.next();                updateTSChildren(aa, (TierImpl) key,                    (ArrayList) tsChildren.get(key));            }        }    }    /**     * Adjusts time of Time_Subdivision children of Included_In or toplevel annotations. This should be done recursively.     * @param parent the parent annotation, should be an Included_In annotation or toplevel annotation     * @param tier the tier the child annotations are part of, should be a Time_Subdivision tier     * @param tsAnnos the child annotations     */    private void updateTSChildren(AlignableAnnotation parAnn, TierImpl tier,        ArrayList tsAnnos) {        if ((tier.getLinguisticType().getConstraints() == null) ||                (tier.getLinguisticType().getConstraints().getStereoType() != Constraint.TIME_SUBDIVISION)) {            return;        }        Collections.sort(tsAnnos);        AlignableAnnotation ann;        boolean shouldPropagate = false;        for (int i = 0; i < tsAnnos.size(); i++) {            ann = (AlignableAnnotation) tsAnnos.get(i);            shouldPropagate = false;            if (ann.getBegin() == parAnn.getBegin()) {                // the first child                if (ann.getEnd().isTimeAligned() &&                        (ann.getEnd().getTime() < parAnn.getBegin().getTime())) {                    ann.markDeleted(true); // or set Begin = End                } else {                    shouldPropagate = true;                }            } else {                if (!ann.getBegin().isTimeAligned() &&                        parAnn.getBegin().isAfter(ann.getEnd())) {                    ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(ann.getBegin());                    ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(ann.getBegin(),                        parAnn.getBegin(), null);                    shouldPropagate = true;                }                if ((ann.getEnd().isTimeAligned() &&                        (parAnn.getBegin().getTime() >= ann.getEnd().getTime())) ||                        (ann.getBegin().isTimeAligned() &&                        (parAnn.getEnd().getTime() <= ann.getBegin().getTime()))) {                    ann.markDeleted(true);                }                if (ann.getBegin().isTimeAligned() &&                        (parAnn.getBegin().getTime() >= ann.getBegin().getTime()) &&                        (ann.getBegin() != parAnn.getBegin())) {                    ann.setBegin(parAnn.getBegin());                    if (!ann.getEnd().isTimeAligned() &&                            ann.getBegin().isAfter(ann.getEnd())) {                        ((TranscriptionImpl) parent).getTimeOrder()                         .removeTimeSlot(ann.getEnd());                        ((TranscriptionImpl) parent).getTimeOrder()                         .insertTimeSlot(ann.getEnd(), ann.getBegin(),                            parAnn.getEnd());                    }                    shouldPropagate = true;                }                if (ann.getEnd().isTimeAligned() &&                        (parAnn.getEnd().getTime() <= ann.getEnd().getTime()) &&                        (ann.getEnd() != parAnn.getEnd())) {                    ann.setEnd(parAnn.getEnd());                    shouldPropagate = true;                }                if (!ann.getEnd().isTimeAligned() &&                        ann.getEnd().isAfter(parAnn.getEnd())) {                    ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(ann.getEnd());                    ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(ann.getEnd(),                        ann.getBegin(), parAnn.getEnd());                    shouldPropagate = true;                }                if (!ann.getBegin().isTimeAligned() &&                        !ann.getEnd().isTimeAligned() &&                        ann.getBegin().isAfter(ann.getEnd())) {                    ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(ann.getEnd());                    ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(ann.getEnd(),                        ann.getBegin(), parAnn.getEnd());                    shouldPropagate = true;                }            }            if (shouldPropagate) {                forceChildAnnotationsOfAlignable(ann);            }        }    }    /**     * Only makes changes to annotations on this tier.     * @param graphEndpoints     * @param fixedSlot1     * @param fixedSlot2     */    private void forceAnnotChainOutOfFixedInterval(TimeSlot[] graphEndpoints,        TimeSlot fixedSlot1, TimeSlot fixedSlot2) {        TimeSlot annBegin = graphEndpoints[0];        TimeSlot annEnd = graphEndpoints[0];        Vector annotsForTS = null;        AlignableAnnotation currentAnn = null;        boolean passedFixedSlot1 = false;        boolean passedFixedSlot2 = false;        if ((annBegin == fixedSlot1) ||                (annBegin.getTime() >= fixedSlot1.getTime())) {            passedFixedSlot1 = true;        }        while (annEnd != null) {            annotsForTS = this.getAnnotsBeginningAtTimeSlot(annBegin);            if ((annotsForTS != null) && (annotsForTS.size() > 0)) {                currentAnn = (AlignableAnnotation) annotsForTS.firstElement();                annEnd = currentAnn.getEnd();                if (passedFixedSlot1 && !passedFixedSlot2) {                    if ((annEnd != fixedSlot2) && annEnd.isTimeAligned() &&                            (annEnd.getTime() > fixedSlot1.getTime())) {                        annEnd.setTime(fixedSlot1.getTime());                    }                }                if (passedFixedSlot2 && annEnd.isTimeAligned() &&                        (annEnd.getTime() < fixedSlot2.getTime())) {                    annEnd.setTime(fixedSlot2.getTime());                }                if (annEnd.getTime() >= fixedSlot1.getTime() /*|| annEnd == fixedSlot1*/) {                    passedFixedSlot1 = true;                }                if (annEnd == fixedSlot2) {                    passedFixedSlot2 = true;                }                annBegin = annEnd;                if (annEnd == graphEndpoints[1]) {                    break;                }            } else {                annEnd = null;            }        }    }    /**     * Propagate changes in annotations on this tier to dependent tiers. Relies on NoTimeGapWithinParent's     * detachAnnotation() method to restore the chain.     * @param aa the parent annotation     * @param graphEndpoints the endpoints of the graph     * @param fixedSlot1 fixed begin slot     * @param fixedSlot2 fixed end slot     * @param left if true force to the left     */    private void forceChildChainOutOfInterval(AlignableAnnotation aa,        TimeSlot[] graphEndpoints, TimeSlot fixedSlot1, TimeSlot fixedSlot2,        boolean left) {        Vector ct = this.getDependentTiers();        TierImpl t;        for (int i = 0; i < ct.size(); i++) {            t = (TierImpl) ct.get(i);            if (t.getLinguisticType().getConstraints().getStereoType() == Constraint.TIME_SUBDIVISION) {                if (left) {                    t.forceAnnotChainOutOfFixedInterval(new TimeSlot[] {                            aa.getBegin(), aa.getEnd()                        }, fixedSlot1, fixedSlot2);                    continue;                }                TimeSlot annBegin = aa.getBegin();                TimeSlot annEnd = aa.getBegin();                Vector annotsForTS = null;                AlignableAnnotation currentAnn = null;                boolean passedFixedSlot1 = false;                boolean passedFixedSlot2 = false;                if ((annBegin == fixedSlot1) ||                        (annBegin.getTime() >= fixedSlot1.getTime())) {                    passedFixedSlot1 = true;                }                if ((annBegin == fixedSlot2) ||                        (annBegi

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?