⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timeorderimpl.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *     * @return DOCUMENT ME!     */    public long proposeTimeFor(TimeSlot theSlot) {        if (theSlot.isTimeAligned()) {            return theSlot.getTime();        } else {            // find nearest aligned neighbours            TimeSlot lastAlignedSlot = null;            long segmentBegin = 0;            long segmentEnd = 0;            boolean slotFound = false;            int numOfUnalignedSlots = 0;            int slotCount = 0;            Iterator slotIter = orderedTimeSlotList.iterator();            while (slotIter.hasNext()) {                TimeSlot sl = (TimeSlot) slotIter.next();                if (sl.isTimeAligned()) {                    lastAlignedSlot = sl;                    if (slotFound) {                        segmentEnd = lastAlignedSlot.getTime();                        break;                    } else {                        numOfUnalignedSlots = 0; // reset                    }                } else { // unaligned                    numOfUnalignedSlots += 1;                }                if (sl == theSlot) {                    if (lastAlignedSlot != null) {                        segmentBegin = lastAlignedSlot.getTime();                    }                    slotFound = true;                    slotCount = numOfUnalignedSlots;                }            }            long deltaT = (segmentEnd - segmentBegin) / (numOfUnalignedSlots +                1);            return segmentBegin + (slotCount * deltaT);        }    }    /**     * DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public Enumeration elements() {        return orderedTimeSlotList.elements();    }    /**     * DOCUMENT ME!     *     * @param theSlot DOCUMENT ME!     * @param newTime DOCUMENT ME!     */    public void modifyTimeSlot(TimeSlot theSlot, long newTime) {        // find theSlot        int currentIndex = orderedTimeSlotList.indexOf(theSlot);        int newIndex = -1;        // if newTime > theSlot time, check if to be moved right        if (!theSlot.isTimeAligned() || (newTime > theSlot.getTime())) {            for (int i = currentIndex + 1; i < orderedTimeSlotList.size();                    i++) {                TimeSlot ts = (TimeSlot) (orderedTimeSlotList.elementAt(i));                if (ts.isTimeAligned() && (ts.getTime() <= newTime)) {                    newIndex = i;                } else if (ts.getTime() >= newTime) {                    break;                }            }        }        // if newTime < theSlot time, check if to be moved left        if ((newIndex == -1) && // not repositioned yet                (!theSlot.isTimeAligned() || (newTime < theSlot.getTime()))) {            for (int i = currentIndex - 1; i >= 0; i--) {                TimeSlot ts = (TimeSlot) (orderedTimeSlotList.elementAt(i));                if (ts.isTimeAligned() && (ts.getTime() >= newTime)) {                    newIndex = i;                } else if ((ts.getTime() <= newTime) && ts.isTimeAligned()) {                    break;                }            }        }        theSlot.updateTime(newTime); // don't call setTime !!!        if ((newIndex >= 0) && (currentIndex >= 0)) {            orderedTimeSlotList.removeElementAt(currentIndex);            if (newIndex < currentIndex) {                orderedTimeSlotList.insertElementAt(theSlot, newIndex);            } else {                orderedTimeSlotList.insertElementAt(theSlot, newIndex /* -1 */);            }            reindex();        }    }    /**     * Shift all times of all aligned timeslots later than fromTimeSlot. Used     * for 'shift mode'.     *     * @param fromTimeSlot DOCUMENT ME!     * @param shift DOCUMENT ME!     */    /*      public void shift(long fromTime, long shift, Vector fixedSlots) {            Vector slotsToShift = new Vector();            Enumeration enum = elements();    //        System.out.println("\nbefore:");    //        printTimeOrder();            while (enum.hasMoreElements()) {                TimeSlot ts = (TimeSlot) enum.nextElement();                if (ts.isTimeAligned() && ts.getTime() >= fromTime && !fixedSlots.contains(ts)) {                    slotsToShift.add(ts);                }            }            for (int i = 0; i < slotsToShift.size(); i++) {                TimeSlot slot = (TimeSlot) slotsToShift.elementAt(i);                slot.setTime(slot.getTime() + shift);            }    //        System.out.println("\nafter:");    //        printTimeOrder();        } */    /**     * Shift all times of all aligned timeslots later than fromTime. Used     * for 'shift mode'.<br>     * jan 05, HS: at edit time the order is not always predictable;     * especially slots that should not be shifted (from the source annotation     * or child annotations from the source annotation) may be positioned     * 'to the right' of fromTime.     *     * @param fromTime only slots with time values greater than this value will be changed     * @param shift the amount of ms to add to the time value     * @param lastFixedSlot the last slot that should not be changed     * (the end time slot of a source annotation)     * @param otherFixedSlots optional other slots that should not be changed     */    public void shift(long fromTime, long shift, TimeSlot lastFixedSlot,        Vector otherFixedSlots) {        if (shift < 0) { // maintain simple implementation of shift for operation from undo            Enumeration en = elements();            while (en.hasMoreElements()) {                TimeSlot ts = (TimeSlot) en.nextElement();                if (ts.isTimeAligned() && (ts.getTime() >= fromTime) &&                        (ts != lastFixedSlot)) {                    ts.updateTime(ts.getTime() + shift);                }            }            return;        }        // the lastFixedSlot might or might not be in the otherFixedSlots vector,        // remove it first         if ((otherFixedSlots != null) &&                otherFixedSlots.contains(lastFixedSlot)) {            otherFixedSlots.remove(lastFixedSlot);        }        // Algorithm:        // - iterate over timeslots        // - from first time slot later than fromTime, remember all slots in slotsToShift        // - until fixedSlot, remember slots that have to be relocated to after fixedSlot        // - remember first slot after fixedSlot, to insert before, especially if it is unaligned         // - shift all slot that are to be shifted        // - reorder all slots that are to be reordered        Vector slotsToShift = new Vector();        Vector slotsToReorder = new Vector();        Enumeration enum1 = elements();        //		  System.out.println("\nbefore:");        //		  printTimeOrder();        boolean startAdding = false;        boolean pastFixedSlot = false;        TimeSlot beforeSlot = null; // remember next slot from fixedSlot        while (enum1.hasMoreElements()) {            TimeSlot ts = (TimeSlot) enum1.nextElement();            if ((otherFixedSlots != null) && otherFixedSlots.contains(ts)) {                continue; // skip this one            }            if (ts.isTimeAligned() && (ts.getTime() >= fromTime)) {                startAdding = true;            }            if (startAdding) {                if (ts != lastFixedSlot) {                    slotsToShift.add(ts);                } else {                    pastFixedSlot = true;                }                if (!pastFixedSlot) {                    slotsToReorder.add(ts);                } else if ((beforeSlot == null) && (ts != lastFixedSlot)) {                    beforeSlot = ts;                }            }        }        TimeSlot afterSlot = lastFixedSlot;        // first shift all times        for (int k = 0; k < slotsToShift.size(); k++) {            TimeSlot slot = (TimeSlot) slotsToShift.elementAt(k);            if (slot.isTimeAligned()) {                slot.updateTime(slot.getTime() + shift);            }        }        // then correct order        for (int i = 0; i < slotsToReorder.size(); i++) {            TimeSlot slot = (TimeSlot) slotsToReorder.elementAt(i);            removeTimeSlot(slot);            insertTimeSlot(slot, afterSlot, beforeSlot);            afterSlot = slot;        }        //		  System.out.println("\nafter:");        //		  printTimeOrder();    }    /**     * Shifts all aligned timeslots with the specified amount of ms.<br>     * When an attempt is made to shift slots such that one or more slots     * would have a negative time value an exception is thrown.     * Slots will never implicitely be deleted.     *     * @param shiftValue the number of ms to add to the time value of aligned timeslots,     *    can be less than zero     * @throws IllegalArgumentException when the shift value is such that any aligned     *    slot would get a negative time value     */    public void shiftAll(long shiftValue) throws IllegalArgumentException {        long firstAlignedTime = 0L;        TimeSlot slot;        Iterator tsIter = orderedTimeSlotList.iterator();        while (tsIter.hasNext()) {            slot = (TimeSlot) tsIter.next();            if (slot.isTimeAligned()) {                firstAlignedTime = slot.getTime();                break;            }        }        if ((shiftValue < 0) && (-shiftValue > firstAlignedTime)) {            throw new IllegalArgumentException(                "The shift value should be greater than: " + firstAlignedTime +                " otherwise slots would get a negative time value.");        }        // no exception, so shift        tsIter = orderedTimeSlotList.iterator();        while (tsIter.hasNext()) {            slot = (TimeSlot) tsIter.next();            if (slot.isTimeAligned()) {                slot.updateTime(slot.getTime() + shiftValue);            }        }    }    /**     * Add a list of TimeSlots in one operation. <br>     * <b>Note: </b> it is assumed that the TimeSlots in the list are ordered!     * They are appended to any existing TimeSlots, without performing any checks.     * This method is intended to be used at loading time, i.e. where an .eaf (or other     * source file) is transformed into a Transcription object.     *      * @param slots a collection of ordered Time Slots     */    public void insertOrderedSlots(List slots) {        if (slots == null) {            return;        }        orderedTimeSlotList.addAll(slots);        reindex();    }}

⌨️ 快捷键说明

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