📄 tierimpl.java
字号:
if (t != null) { if (t.isAfter(theTag)) { // go back until immediately before theTag while (mt.hasPrevious()) { t = (Tag) mt.previous(); if (!t.isAfter(theTag)) { t = (Tag) mt.next(); break; } } } else { // before or simultaneous: go forward until right after, then go back one while (mt.hasNext()) { t = (Tag) mt.next(); if (t.isAfter(theTag)) { if (mt.hasPrevious()) { t = (Tag) mt.previous(); } break; } } } } } } // SharedDataObject interface method(s), via Transcription interface // DataTreeNode interface methods /** * Returns the parent object in the hierarchy of Corpus data objects. * * @return the parent DataTreeNode */ public DataTreeNode getParent() { return parent; } /** * Removes a child in the Corpus data hierarchy by deleting the reference * to the child. The garbage collector will then do the actual deletion. * Children for GestureTiers are Tags. Removing Tags is not yet * implemented, therefore removeChild does nothing yet. * * @param theChild the child to be deleted */ public void removeChild(DataTreeNode theChild) { } // Unreferenced interface method public void unreferenced() { // transcription should store the only reference to tier, so // removing this reference results in deletion by GC getParent().removeChild(this); } // HB, 17-oct-01, migrated methods from DobesTier to here public void setName(String theName) { sharedInfo.setTierName(theName); modified(ACMEditEvent.CHANGE_TIER, null); } /** * Adds an Annotation to the Tier. Where the Annotation is inserted is determined by * the Annotation's compareTo method. The 'compareTo' method uses the TimeOrder that is * associated with this Tier's Transcription to find the correct ordering. * Therefore the Annotation has to be added to the TimeOrder first. * * <p>MK:02/06/18<br> A single tier may contain either Alignable- or RefAnnotations. * This property of a tier is set by its LinguisticType. * This method should throw an Exception if one trys to add a RefAnnotation * to a tier that must only contain AlignableAnnotation. * Currently, this is not the case. * </p> */ public void addAnnotation(Annotation theAnnotation) { // if theAnnotation has TimeSlots, they are supposed to be inserted in TimeOrder. // Since annotations is a TreeSet, ordering will be on basis of Annotation.compareTo annotations.add(theAnnotation); // annotation time segments may now overlap. Since DobesTier (in this version) does // not allow overlapping annotations, this should be corrected. In a more generic // Tier case this call should be preceded by a querying the Tier if it allows overlapping. if (theAnnotation instanceof AlignableAnnotation) { // assume all Tier's annots are alignable AlignableAnnotation a = (AlignableAnnotation) theAnnotation; if ((((TranscriptionImpl) parent).getTimeChangePropagationMode() == Transcription.BULLDOZER) && (this.getParentTier() == null)) { // only for root annotations correctOverlapsByPushing(a, a.getBegin().getTime(), a.getBegin().getTime()); } else if ((((TranscriptionImpl) parent).getTimeChangePropagationMode() == Transcription.SHIFT) && (this.getParentTier() == null)) { Vector fixedSlots = new Vector(); fixedSlots.add(a.getBegin()); ((TranscriptionImpl) parent).correctOverlapsByShifting(a, fixedSlots, a.getBegin().getTime(), a.getBegin().getTime()); correctTimeOverlaps(a); } else { correctTimeOverlaps(a); if ((linguisticType.getConstraints() != null) && (linguisticType.getConstraints().getStereoType() == Constraint.TIME_SUBDIVISION)) { correctDependingOverlaps(a); } } } } /** * DOCUMENT ME! * * @param theAnnotation DOCUMENT ME! */ public void insertAnnotation(Annotation theAnnotation) { // if theAnnotation has TimeSlots, they are supposed to be inserted in TimeOrder. // Since annotations is a TreeSet, ordering will be on basis of Annotation.compareTo annotations.add(theAnnotation); } /** * Checks whether the order of the annotations in the TreeSet is still * correct. When one annotation has been moved beyond another (by updating * its begin and end times) the order of the annotations is incorrect and * has to be corrected. * * @see AlignableAnnotation.updateTimeInterval(long, long) * @see #resortAnnotations() * * @return true if all annotations are in the correct position, false otherwise */ public boolean checkAnnotationOrderConsistency() { Vector v = new Vector(annotations); Annotation a1; Annotation a2; for (int i = 0; i < (v.size() - 1); i++) { a1 = (Annotation) v.get(i); a2 = (Annotation) v.get(i + 1); if (a1.compareTo(a2) == 1) { return false; } } return true; } /** * When an annotation has been moved beyond another annotation on the same * tier their order in the TreeSet is incorrect and has to be changed. * Since a TreeSet uses compareTo() to find and remove an object, removing * a single object can fail when the ordering is inconsistent. * That is why in that case all annotations are removed from the TreeSet * and added again.<br> * Call checkAnnotationOrderConsistency() before calling this method.<br> * This method has package access, so can not be called from client code. * * @see #checkAnnotationOrderConsistency() * @see AlignableAnnotation.updateTimeInterval(long, long) */ void resortAnnotations() { Vector v = new Vector(annotations); annotations.clear(); annotations.addAll(v); } /** * DOCUMENT ME! * * @param beforeAnn DOCUMENT ME! * * @return DOCUMENT ME! */ public Annotation createAnnotationBefore(Annotation beforeAnn) { Annotation a = null; Constraint c = linguisticType.getConstraints(); if ((c != null) && (c.supportsInsertion())) { a = c.insertBefore(beforeAnn, this); modified(ACMEditEvent.ADD_ANNOTATION_BEFORE, a); } return a; } /** * DOCUMENT ME! * * @param afterAnn DOCUMENT ME! * * @return DOCUMENT ME! */ public Annotation createAnnotationAfter(Annotation afterAnn) { Annotation a = null; Constraint c = linguisticType.getConstraints(); if ((c != null) && (c.supportsInsertion())) { a = c.insertAfter(afterAnn, this); modified(ACMEditEvent.ADD_ANNOTATION_AFTER, a); } return a; } /** * DOCUMENT ME! * * @param theAnnotation DOCUMENT ME! */ public void removeAnnotation(Annotation theAnnotation) { //boolean removed = annotations.remove(theAnnotation); theAnnotation.markDeleted(true); // HB, 4-7-02: outcommented, seems unnecessary since markDeleted // already propagates deletion to ParentAnnotationListeners. // ((AbstractAnnotation) theAnnotation).notifyListeners(); ((TranscriptionImpl) parent).pruneAnnotations(this); // prunes all tiers that might have been changed } /** * DOCUMENT ME! */ public void removeAllAnnotations() { Iterator annIter = annotations.iterator(); while (annIter.hasNext()) { Annotation annot = (Annotation) annIter.next(); annot.markDeleted(true); // HB, 16 jul 02: outcommented, since markDeleted propagates deletion // to ParentAnnotationListeners. // ((AbstractAnnotation) annot).notifyListeners(ACMEditEvent.REMOVE_ANNOTATION, null); } ((TranscriptionImpl) parent).pruneAnnotations(this); // prunes all tiers that might have been changed } /** * <p>MK:02/05/06<br> * Unclear how this method relates to getTags() * DobesTier.getTags() returns the annotation member, * not the tagList member. * This is probably due to the shift from tag to annotation. * </p> * @return Vector of Annotation Objects. * */ public Vector getAnnotations() { if ((annotations.size() == 0) && (parent != null)) { ((TranscriptionImpl) parent).loadAnnotations(); } Vector annVector = new Vector(annotations); //Collections.sort(annVector); return annVector; } /** * Returns the annotation with the corresponding id; * null if no annotation has a corresponding id; * @param id * @return */ public Annotation getAnnotation(String id) { if (id == null) { return null; } Vector annVector = getAnnotations(); for (int i = 0; i < annVector.size(); i++) { if (id.equals(((Annotation) annVector.get(i)).getId())) { return (Annotation) annVector.get(i); } } return null; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public int getNumberOfAnnotations() { // necessary, because getAnnotations.size() would invoke loadAnnotations in case of 0 // MK:02/05/06 The test on (== 0) seems silly to me anyhow and should be replaced. return annotations.size(); } /** * DOCUMENT ME! * * @param theAnnotation DOCUMENT ME! * * @return DOCUMENT ME! */ public Annotation getAnnotationBefore(Annotation theAnnotation) { Annotation previousAnnotation = null; Annotation currentAnnotation = null; Iterator iter = annotations.iterator(); while (iter.hasNext()) { previousAnnotation = currentAnnotation; currentAnnotation = (Annotation) iter.next(); if (currentAnnotation.equals(theAnnotation)) { break; } } return previousAnnotation; } /** * DOCUMENT ME! * * @param time DOCUMENT ME! * * @return DOCUMENT ME! */ public Annotation getAnnotationBefore(long time) { Annotation previousAnnotation = null; Annotation currentAnnotation = null; Annotation foundAnnotation = null; Iterator iter = annotations.iterator(); while (iter.hasNext()) { previousAnnotation = currentAnnotation; currentAnnotation = (Annotation) iter.next(); if (currentAnnotation.getEndTimeBoundary() > time) { foundAnnotation = previousAnnotation; break; } } if (foundAnnotation != null) { return foundAnnotation;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -