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

📄 extracttrackdatacommand.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     ExtractTrackDataCommand.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.eudico.client.annotator.commands;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.timeseries.AbstractTSTrack;import mpi.eudico.client.annotator.util.AnnotationDataRecord;import mpi.eudico.client.annotator.util.ClientLogger;import mpi.eudico.client.annotator.util.ProgressListener;import mpi.eudico.server.corpora.clomimpl.abstr.AlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.RefAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import java.awt.Cursor;import java.text.DecimalFormat;import java.text.DecimalFormatSymbols;import java.util.ArrayList;import java.util.Locale;/** * A Command that extracts maximum, minimum or average from a timeseries track, * based on intervals/annotations on one tier and stores the information  in * annotations on a dependent tier. * * @author Han Sloetjes * @version 1.0 */public class ExtractTrackDataCommand implements UndoableCommand, ClientLogger {    private String commandName;    private ArrayList listeners;    private TranscriptionImpl transcription;    private String sourceTierName;    private String destTierName;    private ArrayList newAnnos;    private ArrayList changedAnnos;    /**     * Creates a new ExtractTrackDataCommand instance     *     * @param commandName the name     */    public ExtractTrackDataCommand(String commandName) {        this.commandName = commandName;    }    /**     * The undo action; newly created annotations are deleted, changed     * annotations are restored to their old state.     */    public void undo() {        if (transcription != null) {            TierImpl tier = (TierImpl) transcription.getTierWithId(destTierName);            if (tier == null) {                LOG.severe("Tier " + destTierName + " does no longer exist");                return;            }            setWaitCursor(true);            RefAnnotation ref;            AnnotationDataRecord record;            if (newAnnos != null) {                for (int i = 0; i < newAnnos.size(); i++) {                    record = (AnnotationDataRecord) newAnnos.get(i);                    ref = (RefAnnotation) tier.getAnnotationAtTime(record.getBeginTime());                    if (ref != null) {                        tier.removeAnnotation(ref);                    } else {                        LOG.warning("Could not delete annotation: " +                            record.getValue() + "bt: " + record.getBeginTime());                    }                }            }            ValueRecord valRec;            if (changedAnnos != null) {                for (int i = 0; i < changedAnnos.size(); i++) {                    valRec = (ValueRecord) changedAnnos.get(i);                    ref = (RefAnnotation) tier.getAnnotationAtTime(valRec.beginTime);                    if (ref != null) {                        ref.setValue(valRec.oldValue);                    } else {                        LOG.warning("Could not find annotation: " +                            valRec.oldValue + "bt: " + valRec.beginTime);                    }                }            }            setWaitCursor(false);        }    }    /**     * The redo action.     */    public void redo() {        if (transcription != null) {            TierImpl tier = (TierImpl) transcription.getTierWithId(destTierName);            if (tier == null) {                LOG.severe("Tier " + destTierName + " does no longer exist");                return;            }            setWaitCursor(true);            RefAnnotation ref;            AnnotationDataRecord record;            long mid;            if (newAnnos != null) {                for (int i = 0; i < newAnnos.size(); i++) {                    record = (AnnotationDataRecord) newAnnos.get(i);                    ref = (RefAnnotation) tier.getAnnotationAtTime(record.getBeginTime());                    if (ref == null) {                        mid = (long) ((record.getBeginTime() +                            record.getEndTime()) / 2);                        ref = (RefAnnotation) tier.createAnnotation(mid, mid);                        if (ref != null) {                            ref.setValue(record.getValue());                        } else {                            LOG.warning(                                "Could not create a reference annotation at time: " +                                mid);                        }                    } else {                        LOG.warning("Annotation was not deleted in undo: " +                            record.getValue() + "bt: " + record.getBeginTime());                    }                }            }            ValueRecord valRec;            if (changedAnnos != null) {                for (int i = 0; i < changedAnnos.size(); i++) {                    valRec = (ValueRecord) changedAnnos.get(i);                    ref = (RefAnnotation) tier.getAnnotationAtTime(valRec.beginTime);                    if (ref != null) {                        ref.setValue(valRec.newValue);                    } else {                        LOG.warning("Could not find annotation: " +                            valRec.newValue + "bt: " + valRec.beginTime);                    }                }            }            setWaitCursor(false);        }    }    /**     * Extracts values from a time series track based on intervals of     * annotations on one tier and stores the values in annotations on a     * dependent tier. <b>Note: </b>it is assumed the types and order of the     * arguments are correct.     *     * @param receiver the transcription     * @param arguments the arguments: <ul><li>arg[0] the source tier     *        (String)</li> <li>arg[1] the destination tier (String)</li>     *        <li>arg[2] the track to extract the data from     *        (AbstractTSTrack/Object)</li> <li>arg[3] what to extract     *        maximum, minimum, average (String)</li> <li>arg[4] whether or     *        not to overwrite existing annotation values (Boolean)</li> </ul>     */    public void execute(Object receiver, Object[] arguments) {        transcription = (TranscriptionImpl) receiver;        sourceTierName = (String) arguments[0];        destTierName = (String) arguments[1];        AbstractTSTrack track = (AbstractTSTrack) arguments[2];        String method = (String) arguments[3];        boolean overwrite = ((Boolean) arguments[4]).booleanValue();        TierImpl sourceTier = (TierImpl) transcription.getTierWithId(sourceTierName);        if (sourceTier == null) {            progressInterrupt(ElanLocale.getString(                    "TimeSeriesViewer.Extract.NotFound") + " " +                sourceTierName);            return;        }        TierImpl destTier = (TierImpl) transcription.getTierWithId(destTierName);        if (destTier == null) {            progressInterrupt(ElanLocale.getString(                    "TimeSeriesViewer.Extract.NotFound") + " " + destTierName);            return;        }        // ?? test sourceTier.isAlignable, sourceTier is ancestorof destTier,         // destTier is symbolicassociation ??        if (track == null) {            progressInterrupt(ElanLocale.getString(                    "TimeSeriesViewer.Extract.NotFound") + " " + "track");            return;        }        if (method == null) {            progressInterrupt(ElanLocale.getString(                    "TimeSeriesViewer.Extract.NoMethod"));            return;        }        newAnnos = new ArrayList();        changedAnnos = new ArrayList();        ExtractThread thread = new ExtractThread(sourceTier, destTier, track,                method, overwrite);        try {            thread.start();        } catch (Exception e) {            LOG.warning("Error in extraction progress: " + e.getMessage());            progressInterrupt("Extraction progress interrupted");            transcription.setNotifying(true);        }    }    /**     * Returns the name of the command.     *     * @return the command name

⌨️ 快捷键说明

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