📄 exportselectionaseaf.java
字号:
/* * File: ExportSelectionAsEAF.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.export;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.Preferences;import mpi.eudico.client.annotator.commands.ELANCommandFactory;import mpi.eudico.client.annotator.util.AnnotationRecreator;import mpi.eudico.client.annotator.util.ClientLogger;import mpi.eudico.client.annotator.util.ElanFileFilter;import mpi.eudico.client.annotator.util.FileExtension;import mpi.eudico.client.util.TierTree;import mpi.eudico.server.corpora.clom.TranscriptionStore;import mpi.eudico.server.corpora.clomimpl.abstr.AlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.LinkedFileDescriptor;import mpi.eudico.server.corpora.clomimpl.abstr.MediaDescriptor;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import mpi.eudico.server.corpora.clomimpl.dobes.ACM24TranscriptionStore;import mpi.eudico.server.corpora.clomimpl.type.Constraint;import mpi.eudico.server.corpora.clomimpl.type.IncludedIn;import mpi.eudico.server.corpora.clomimpl.type.LinguisticType;import mpi.eudico.server.corpora.clomimpl.type.SymbolicAssociation;import mpi.eudico.server.corpora.clomimpl.type.SymbolicSubdivision;import mpi.eudico.server.corpora.clomimpl.type.TimeSubdivision;import mpi.util.CVEntry;import mpi.util.ControlledVocabulary;import java.io.File;import java.util.Enumeration;import java.util.Vector;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import javax.swing.ProgressMonitor;import javax.swing.filechooser.FileFilter;import javax.swing.tree.DefaultMutableTreeNode;/** * Creates a new transcription document with the annotations that are found * within a selected time interval in the source document.<br> * First all MediaDescriptors, Controlled Vocabularies, Linguistic Types and * Tiers are copied to a new Transcription. Next all annotations that overlap * the selected time interval are copied. The copied annotations are forced * into the interval (i.e. if the begintime is smaller than the interval * begin time, the annotation's begin time is updated to the interval begin * time. Same if the annotation's end time is greater than the interval end * time. <br> * Finally all annotations are shifted in time by a value of -(selection begin * time), making the original selection begin time the time origin (point 0) * of the new transcription. * * @author Han Sloetjes * @version 1.0 Oct 2005 */public class ExportSelectionAsEAF implements ClientLogger { private TranscriptionImpl transcription; private TranscriptionImpl nextTrans; private String path; private long beginTime; private long endTime; private ProgressMonitor monitor; /** * Creates a new ExportSelectionAsEAF instance * * @param transcription the source transcription * @param beginTime interval begin time * @param endTime interval end time */ public ExportSelectionAsEAF(TranscriptionImpl transcription, long beginTime, long endTime) { this.transcription = transcription; this.beginTime = beginTime; this.endTime = endTime; if (transcription != null) { startExport(); } } /** * Prompts for a file name, creates a progress monitor and spawns a new * thread for the actual work. */ private void startExport() { // get a file path to save to path = promptForFileName(); if (path == null) { return; } nextTrans = new TranscriptionImpl(); monitor = new ProgressMonitor(null, ElanLocale.getString("SaveDialog.Message.Title"), "", 0, 100); monitor.setMillisToDecideToPopup(10); monitor.setMillisToPopup(10); new Thread() { public void run() { try { Thread.sleep(50); } catch (Exception e) { e.printStackTrace(); } ExportSelectionAsEAF.this.startCopy(); } }.start(); //copy(transcription, nextTrans, beginTime, endTime); } /** * Starts the copy process. */ private void startCopy() { if ((transcription == null) || (nextTrans == null)) { progressUpdate(null, 100); return; } progressUpdate(null, 10); copy(transcription, nextTrans, beginTime, endTime); progressUpdate(null, 100); } /** * Copies MediaDescriptors, Controlled Vocabularies, Linguistic Types, * Tiers and the relevant Annotations to the new Transcription. The * annotations are forced into the selection interval. Finally the * annotations are shifted with a value of -begin and the transcription is * written to file. This method could be split into separate parts for * copying each group of objects, when there is a need for this. Maybe in * its own helper class. * * @param sourceTrans the source transcription * @param copyTrans the copy transcription * @param begin the selection begin time * @param end the selection end time */ private void copy(TranscriptionImpl sourceTrans, TranscriptionImpl copyTrans, long begin, long end) { copyTrans.setNotifying(false); // copy/clone media descriptors Vector mds = sourceTrans.getMediaDescriptors(); Vector cmds = new Vector(mds.size()); MediaDescriptor md; for (int i = 0; i < mds.size(); i++) { md = (MediaDescriptor) mds.get(i); cmds.add((MediaDescriptor) md.clone()); } copyTrans.setMediaDescriptors(cmds); // copy/clone linked files descriptors Vector lfds = sourceTrans.getLinkedFileDescriptors(); Vector clfds = new Vector(lfds.size()); LinkedFileDescriptor lfd; for (int i = 0; i < lfds.size(); i++) { lfd = (LinkedFileDescriptor) lfds.get(i); clfds.add((LinkedFileDescriptor) lfd.clone()); } copyTrans.setLinkedFileDescriptors(clfds); progressUpdate(null, 20); if (isCancelled()) { return; } // cv's Vector cvs = sourceTrans.getControlledVocabularies(); Vector cvc = new Vector(cvs.size()); ControlledVocabulary cv1; ControlledVocabulary cv2; CVEntry[] entries; CVEntry ent1; CVEntry ent2; for (int i = 0; i < cvs.size(); i++) { cv1 = (ControlledVocabulary) cvs.get(i); cv2 = new ControlledVocabulary(cv1.getName(), cv1.getDescription()); entries = cv1.getEntries(); for (int j = 0; j < entries.length; j++) { ent1 = entries[j]; ent2 = new CVEntry(ent1.getValue(), ent1.getDescription()); cv2.addEntry(ent2); } cvc.add(cv2); } copyTrans.setControlledVocabularies(cvc); progressUpdate(null, 30); if (isCancelled()) { return; } // linguistic types Vector types = sourceTrans.getLinguisticTypes(); Vector typc = new Vector(types.size()); LinguisticType lt1; LinguisticType lt2; Constraint con1; Constraint con2 = null; for (int i = 0; i < types.size(); i++) { lt1 = (LinguisticType) types.get(i); lt2 = new LinguisticType(lt1.getLinguisticTypeName()); lt2.setTimeAlignable(lt1.isTimeAlignable()); lt2.setGraphicReferences(lt1.hasGraphicReferences()); lt2.setControlledVocabularyName(lt1.getControlledVocabylaryName()); con1 = lt1.getConstraints(); if (con1 != null) { switch (con1.getStereoType()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -