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

📄 tstrackmanager.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     TSTrackManager.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.timeseries;import mpi.eudico.client.annotator.commands.ELANCommandFactory;import mpi.eudico.client.annotator.timeseries.config.TSSourceConfiguration;import mpi.eudico.client.annotator.timeseries.config.TSTrackConfiguration;import mpi.eudico.client.annotator.timeseries.io.TSConfigurationEncoder;import mpi.eudico.client.annotator.timeseries.spi.TSServiceProvider;import mpi.eudico.client.annotator.timeseries.spi.TSServiceRegistry;import mpi.eudico.client.annotator.viewer.TimeSeriesViewer;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.LinkedFileDescriptor;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import java.awt.Component;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.Set;import java.util.Vector;/** * Manages time series tracks, their sources and configurations  and one or * more TimeSeriesViewers. * * @author Han Sloetjes */public class TSTrackManager implements TimeSeriesChangeListener {    private TranscriptionImpl transcription;    /** stores all defined tracks, from all source files */    private ArrayList tracks;    // sourcename - configuration mappings    private HashMap trackSourceConfigs;    private ArrayList listeners;    private TSConfigurationEncoder encoder;    private TSViewerPlayer syncPlayer;    /**     * Creates a new TSTrackManager instance     *     * @param transcription the transcription, the document identifier     */    public TSTrackManager(Transcription transcription) {        this.transcription = (TranscriptionImpl) transcription;        tracks = new ArrayList();        trackSourceConfigs = new HashMap();        encoder = new TSConfigurationEncoder();        //encoder.encodeAndSave((TranscriptionImpl) transcription);    }    /**     * Returns the list of all tracks from all sources that have been     * associated with the document.     *     * @return the tracks that have been added to the manager     */    public ArrayList getRegisteredTracks() {        return tracks;    }    /**     * Returns the track with the specified name, if defined.     *     * @param name the name of the track     *     * @return the track or null     */    public AbstractTSTrack getTrack(String name) {        if (name == null) {            return null;        }        AbstractTSTrack tr;        for (int i = 0; i < tracks.size(); i++) {            tr = (AbstractTSTrack) tracks.get(i);            if (tr.getName().equals(name)) {                return tr;            }        }        return null;    }    /**     * Returns a key set of the source configurations that have been added to     * the manager.     *     * @return the set of source configuration keys     */    public Set getConfigKeySet() {        return trackSourceConfigs.keySet();    }    /**     * Returns the source url's of the currently managed sources.     *     * @return a String array of source url's     */    public String[] getCurrentSourceNames() {        try {            return (String[]) getConfigKeySet().toArray(new String[] {  });        } catch (Exception ex) {            return new String[0];        }    }    /**     * Sets the offset of the specified time series source. All tracks configured from that     * source receive the same offset.     *     * @param source the source identifier (source url)     * @param offset the new offset for the ts source     */    public void setOffset(String source, int offset) {        if (source == null) {            return;        }        TSSourceConfiguration configuration = (TSSourceConfiguration) trackSourceConfigs.get(source);        if (configuration != null) {            configuration.setTimeOrigin(offset);            // update the transcription            Vector lfds = transcription.getLinkedFileDescriptors();            for (int j = 0; j < lfds.size(); j++) {                LinkedFileDescriptor lfd = (LinkedFileDescriptor) lfds.get(j);                if (lfd.linkURL.equals(source)) {                    lfd.timeOrigin = offset;                    transcription.setChanged();                    break;                }            }            Iterator keyIt = configuration.objectKeySet().iterator();            while (keyIt.hasNext()) {                Object key = keyIt.next();                Object o = configuration.getObject(key);                if (o instanceof AbstractTSTrack) {                    ((AbstractTSTrack) o).setTimeOffset(offset);                } else if (o instanceof TSTrackConfiguration) { // default                    TSTrackConfiguration tstc = (TSTrackConfiguration) o;                    Object tr = tstc.getObject(tstc.getTrackName());                    if (tr instanceof AbstractTSTrack) {                        ((AbstractTSTrack) tr).setTimeOffset(offset); // default situation                    } else {                        Iterator objIt = tstc.objectKeySet().iterator();                        while (objIt.hasNext()) {                            Object ke = objIt.next();                            Object oo = tstc.getObject(ke);                            if (oo instanceof AbstractTSTrack) {                                ((AbstractTSTrack) oo).setTimeOffset(offset);                            }                        }                    }                }            }            notifyListeners(new TimeSeriesChangeEvent(configuration,                    TimeSeriesChangeEvent.CHANGE,                    TimeSeriesChangeEvent.TS_SOURCE));            encoder.encodeAndSave((TranscriptionImpl) transcription,                trackSourceConfigs.values());        }    }    /**     * Returns the time offset (origin) of the specified source     *     * @param source the source url string (id)     *     * @return the offset of the specified timeseries source and thus the offset     * of all tracks originating from that source     */    public int getOffset(String source) {        if (source == null) {            return 0;        }        TSSourceConfiguration configuration = (TSSourceConfiguration) trackSourceConfigs.get(source);        if (configuration != null) {            return configuration.getTimeOrigin();        }        return 0;    }    /**     * If there is a configurable track source show the configuration dialog.     * If there are more than one sources show a selection dialog with the     * sources. Otherwise just show a message dialog that there is nothing to     * configure.     *     * @param parent the parent component     */    public void configureTracks(Component parent) {        TSServiceRegistry registry = TSServiceRegistry.getInstance();        TSServiceProvider provider;        ArrayList configurables = new ArrayList(3);        Iterator confIt = getConfigKeySet().iterator();        TSSourceConfiguration config;        while (confIt.hasNext()) {            config = (TSSourceConfiguration) trackSourceConfigs.get(confIt.next());            if (config.getProviderClassName() != null) {                provider = registry.getProviderByClassName(config.getProviderClassName());            } else {                provider = registry.getProviderForFile(config.getSource());            }            if (provider != null) {                if (provider.isConfigurable()) {                    configurables.add(config);                }            }        }        TSConfigurationUI cui = new TSConfigurationUI();        switch (configurables.size()) {        case 0:            // show message            cui.showNoConfigMessage(parent);            break;        case 1:            // show config for the one            cui.showConfigDialog(parent,                (TSSourceConfiguration) configurables.get(0), this);            break;        default:            // show selection option pane            TSSourceConfiguration cfg = cui.selectConfigurableSource(parent,                    configurables);            if (cfg != null) {                cui.showConfigDialog(parent, cfg, this);            }            break;        }    }    /**     * Informs the track manager about the creation of a new track from the     * specified source file. The track(configuration) might or might not have     * been added to the source configuration.  In the latter case it is added     * to the source config here.  The track is added to the list of     * registered tracks and listeners are notified.     *     * @param sourceConfig the configuration of the source file     * @param trackConfig the configuration of the track     */    public void addTrack(TSSourceConfiguration sourceConfig,        TSTrackConfiguration trackConfig) {        if ((sourceConfig == null) || (trackConfig == null)) {            return;        }        // check if the track has been added to the source configuration        if (sourceConfig.getObject(trackConfig.getTrackName()) == null) {            sourceConfig.putObject(trackConfig.getTrackName(), trackConfig);        }        Object tr = trackConfig.getObject(trackConfig.getTrackName());        if (tr instanceof TimeSeriesTrack) {            tracks.add(tr); // default situation        } else {            Iterator objIt = trackConfig.objectKeySet().iterator();            while (objIt.hasNext()) {                Object key = objIt.next();                Object oo = trackConfig.getObject(key);                if (oo instanceof TimeSeriesTrack) {                    tracks.add(oo);                }            }        }        notifyListeners(new TimeSeriesChangeEvent(trackConfig,                TimeSeriesChangeEvent.ADD, TimeSeriesChangeEvent.TRACK));    }    /**     * Informs the track manager about the deletion of a track from the     * specified source file. The track(configuration) might or might not have     * been removed from the source configuration.  In the latter case it is     * removed from the source config here.  The track is removed from the     * list of registered tracks and listeners are notified.     *     * @param sourceConfig the configuration of the source file     * @param trackConfig the configuration of the track     */    public void removeTrack(TSSourceConfiguration sourceConfig,        TSTrackConfiguration trackConfig) {        if ((sourceConfig == null) || (trackConfig == null)) {            return;        }        // check if the track has been removed from the source configuration        if (sourceConfig.getObject(trackConfig.getTrackName()) != null) {            sourceConfig.removeObject(trackConfig.getTrackName());        }        Object tr = trackConfig.getObject(trackConfig.getTrackName());        if (tr instanceof TimeSeriesTrack) {            tracks.remove(tr); // default situation        } else {            Iterator objIt = trackConfig.objectKeySet().iterator();            while (objIt.hasNext()) {                Object key = objIt.next();                Object oo = trackConfig.getObject(key);                if (oo instanceof TimeSeriesTrack) {                    tracks.remove(oo);                }            }        }        notifyListeners(new TimeSeriesChangeEvent(trackConfig,                TimeSeriesChangeEvent.DELETE, TimeSeriesChangeEvent.TRACK));    }    /**     * Removes a track from the list of registered tracks.

⌨️ 快捷键说明

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