📄 alignableannotation.java
字号:
beginTime.setTime(parentBegin); } if (beginTime.getTime() > parentEnd) { beginTime.setTime(parentEnd); } } if (endTime.isTimeAligned()) { if (endTime.getTime() > parentEnd) { endTime.setTime(parentEnd); } if (endTime.getTime() < parentBegin) { endTime.setTime(parentBegin); } } // HB, 10 apr 03, adjust to parent time alignment changes if ((beginTime.isTimeAligned()) && (endTime.isTimeAligned()) && (beginTime.getTime() >= endTime.getTime())) { ((AlignableAnnotation) e.getSource()).removeParentAnnotationListener(this); markDeleted(true); } } } } /** * Checks if this AlignableAnnotation has a parent Annotation on basis of * the assumption that Constraints are always met (e.g. if the annotation * is part of a time subdivision of some other annotation, it is assumed * that this annotation exists. * * @return DOCUMENT ME! */ public boolean hasParentAnnotation() { boolean hasParent = false; LinguisticType lt = ((TierImpl) getTier()).getLinguisticType(); if (lt != null) { Constraint c = lt.getConstraints(); if (c != null) { if ((c.getStereoType() == Constraint.TIME_SUBDIVISION) || (c.getStereoType() == Constraint.INCLUDED_IN)) { hasParent = true; } } } return hasParent; } /** * Parent-child relationship for AlignableAnnotations is defined by 1. * sharing of TimeSlots between annotations. 2. parent-child relationship * between their tiers This method determines the parent annotation on * basis of this. Return null if no parent. * * @return DOCUMENT ME! */ /* public Annotation getParentAnnotation() { AlignableAnnotation parent = null; TierImpl parentTier = (TierImpl) ((TierImpl) getTier()).getParentTier(); if (parentTier != null) { // TimeOrder to = ((TranscriptionImpl)(((TierImpl) getTier()).getParent())).getTimeOrder(); TreeSet connectedAnnots = new TreeSet(); TreeSet connectedTimeSlots = new TreeSet(); ((TranscriptionImpl) (parentTier.getParent())).getConnectedAnnots(connectedAnnots, connectedTimeSlots, getBegin()); Iterator annIter = parentTier.getAnnotations(null).iterator(); // make copy of TreeSet. For some reason I don't understand the treeset sometimes // incorrectly returns false when 'contains' is called. Vector connectedAnnotVector = new Vector(connectedAnnots); while (annIter.hasNext()) { AlignableAnnotation a = (AlignableAnnotation) annIter.next(); if (connectedAnnotVector.contains(a)) { TreeSet subtreeAnnots = new TreeSet(); ((TranscriptionImpl) (parentTier.getParent())).getConnectedSubtree(subtreeAnnots, a.getBegin(), a.getEnd()); Vector subtreeVector = new Vector(subtreeAnnots); if (subtreeVector.contains(this)) { parent = a; break; } } } } return parent; } */ /** * Parent-child relationship for AlignableAnnotations is defined by 1. * sharing of TimeSlots between annotations. 2. parent-child relationship * between their tiers This method determines the parent annotation on * basis of this. Return null if no parent. * * @return DOCUMENT ME! */ public Annotation getParentAnnotation() { AlignableAnnotation parent = null; TierImpl parentTier = (TierImpl) ((TierImpl) getTier()).getParentTier(); if (parentTier != null) { if (((TierImpl) getTier()).getLinguisticType().getConstraints() .getStereoType() == Constraint.TIME_SUBDIVISION) { TimeSlot chainBegin = ((TierImpl) this.getTier()).getBeginSlotOfChain(getBegin(), false); Vector candidates = parentTier.getAnnotationsUsingTimeSlot(chainBegin); for (int i = 0; i < candidates.size(); i++) { AlignableAnnotation a = (AlignableAnnotation) candidates.elementAt(i); if (a.getBegin() == chainBegin) { parent = a; break; } } } else if (((TierImpl) getTier()).getLinguisticType() .getConstraints().getStereoType() == Constraint.INCLUDED_IN) { parent = (AlignableAnnotation) parentTier.getAnnotationAtTime(getBegin() .getTime()); } } return parent; } /** * Checks whether this annotation is an ancestor annotation of the specified annotation. * @param aa the annotation * @return true if this annotation is an ancestor of aa, false otherwise */ public boolean isAncestorOf(AlignableAnnotation aa) { if (aa == null) { return false; } if (getParentListeners().contains(aa)) { return true; } else { ArrayList pl = getParentListeners(); AlignableAnnotation chan; for (int i = 0; i < pl.size(); i++) { if (pl.get(i) instanceof AlignableAnnotation) { chan = (AlignableAnnotation) pl.get(i); if (chan.isAncestorOf(aa)) { return true; } } } } return false; } /** * When updateTimeInterval() has been called notifyParentListeners (and * thus parentAnnotationChanged()) takes care of marking annotations for * deletion that have a begin- and end-timeslot that are time aligned. * (Partially) unaligned annotations are not marked for deletion; this is * therefore done here. * * @since jan 2005 */ private void cleanUpUnalignedChildAnnotations() { ArrayList l = this.getParentListeners(); ArrayList yetToBeDeleted = new ArrayList(); for (int i = 0; i < l.size(); i++) { Annotation a = (Annotation) l.get(i); if (a instanceof AlignableAnnotation) { AlignableAnnotation aa = (AlignableAnnotation) a; if (!aa.getBegin().isTimeAligned() || !aa.getEnd().isTimeAligned()) { if (aa.calculateBeginTime() == aa.calculateEndTime()) { // do not call markDeleted here, because that would change the // array of parent listeners and influence the operation yetToBeDeleted.add(aa); } } } } for (int j = 0; j < yetToBeDeleted.size(); j++) { ((AlignableAnnotation) yetToBeDeleted.get(j)).markDeleted(true); } } /** * When an annotation has been moved beyond another annotation on the same * tier the annotations treeset has to be resorted (also on depending * tiers). Unaligned TimeSlots have not been repositioned, this is done * here also. * * @param oldConnectedTimeSlots */ private void resortAnnotationsAndSlots(TreeSet oldConnectedTimeSlots) { ((TierImpl) this.getTier()).resortAnnotations(); // unaligned TimeSlots are not automatically repositioned, do it here // undesirable, temporary solution TimeOrderImpl timeOrder = (TimeOrderImpl) ((TranscriptionImpl) (((TierImpl) getTier()).getParent())).getTimeOrder(); // use the previously collected timeslots Vector slots = new Vector(oldConnectedTimeSlots); Enumeration elements; for (int i = slots.size() - 1; i >= 0; i--) { TimeSlot sl = (TimeSlot) slots.get(i); elements = timeOrder.elements(); boolean stillPresent = false; while (elements.hasMoreElements()) { if (elements.nextElement() == sl) { stillPresent = true; break; } } // remove slots that have been pruned from the TimeOrder if (!stillPresent) { slots.remove(i); } } if (!slots.contains(getBegin())) { slots.add(0, getBegin()); } if (!slots.contains(getEnd())) { slots.add(getEnd()); } // reposition the unaligned time slots for (int i = 0; i < (slots.size() - 2); i++) { TimeSlot t1 = (TimeSlot) slots.get(i); TimeSlot t2 = (TimeSlot) slots.get(i + 1); TimeSlot t3 = (TimeSlot) slots.get(i + 2); if (!t2.isTimeAligned()) { int index1 = t1.getIndex(); int index2 = t2.getIndex(); int index3 = t3.getIndex(); //System.out.println("t1: " + index1 + " t2:" + index2 + " t3: " + index3); if (index2 < index1) { timeOrder.removeTimeSlot(t2); if (index2 > index3) { timeOrder.insertTimeSlot(t2, t1, null); } else { timeOrder.insertTimeSlot(t2, t1, t3); } } else if (index2 > index1) { timeOrder.removeTimeSlot(t2); timeOrder.insertTimeSlot(t2, t1, null); } else if (index2 > index3) { timeOrder.removeTimeSlot(t2); if (index2 > index1) { timeOrder.insertTimeSlot(t2, t1, null); } else { timeOrder.insertTimeSlot(t2, t1, t3); } } } } Vector depTiers = ((TierImpl) this.getTier()).getDependentTiers(); for (int i = 0; i < depTiers.size(); i++) { ((TierImpl) depTiers.get(i)).resortAnnotations(); } } /** * Checks the consistency of the annotation ordering of the specified tiers * and it's depending tiers. * * @param fromTier the 'root' tier of the tiers to check * * @return true if all annotations on all relevant tiers are ordered * correctly, false otherwise */ private boolean checkAnnotationOrderConsistency(TierImpl fromTier) { boolean consistent = fromTier.checkAnnotationOrderConsistency(); if (!consistent) { return consistent; } else { Vector depTiers = fromTier.getDependentTiers(); for (int i = 0; i < depTiers.size(); i++) { consistent = ((TierImpl) depTiers.get(i)).checkAnnotationOrderConsistency(); if (!consistent) { return consistent; } } } // if we get here all relevant tiers are consistent return consistent; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -