📄 exportselectionaseaf.java
字号:
case Constraint.TIME_SUBDIVISION: con2 = new TimeSubdivision(); break; case Constraint.SYMBOLIC_SUBDIVISION: con2 = new SymbolicSubdivision(); break; case Constraint.SYMBOLIC_ASSOCIATION: con2 = new SymbolicAssociation(); break; case Constraint.INCLUDED_IN: con2 = new IncludedIn(); } lt2.addConstraint(con2); } typc.add(lt2); } copyTrans.setLinguisticTypes(typc); progressUpdate(null, 35); if (isCancelled()) { return; } TierTree tree = new TierTree(sourceTrans); DefaultMutableTreeNode root = tree.getTree(); DefaultMutableTreeNode node; TierImpl t1; TierImpl t2; TierImpl copyTier; String name; String parentName; Enumeration en = root.breadthFirstEnumeration(); en.nextElement(); while (en.hasMoreElements()) { copyTier = null; // reset node = (DefaultMutableTreeNode) en.nextElement(); name = (String) node.getUserObject(); t1 = (TierImpl) sourceTrans.getTierWithId(name); if (t1 != null) { lt1 = t1.getLinguisticType(); lt2 = copyTrans.getLinguisticTypeByName(lt1.getLinguisticTypeName()); if (lt2 != null) { if (t1.hasParentTier()) { parentName = t1.getParentTier().getName(); t2 = (TierImpl) copyTrans.getTierWithId(parentName); if (t2 != null) { copyTier = new TierImpl(t2, name, t1.getParticipant(), copyTrans, lt2); copyTier.setDefaultLocale(t1.getDefaultLocale()); copyTier.setAnnotator(t1.getAnnotator()); } else { LOG.warning("The parent tier: " + parentName + " for tier: " + name + " was not found in the destination transcription"); } } else { copyTier = new TierImpl(name, t1.getParticipant(), copyTrans, lt2); copyTier.setDefaultLocale(t1.getDefaultLocale()); copyTier.setAnnotator(t1.getAnnotator()); } } else { LOG.warning("Could not add tier: " + name + " because the Linguistic Type was not found in the destination transcription."); } } if (copyTier != null) { copyTrans.addTier(copyTier); } } progressUpdate(null, 40); if (isCancelled()) { return; } // copy annotations within the interval, loop over toplevel tiers Vector srcAnnos; AlignableAnnotation ann; AlignableAnnotation copyAnn; DefaultMutableTreeNode record; float incr = (float) (80 - 40) / Math.max(root.getChildCount(), 1); // prevent division by 0 for (int i = 0; i < root.getChildCount(); i++) { node = (DefaultMutableTreeNode) root.getChildAt(i); name = (String) node.getUserObject(); t1 = (TierImpl) sourceTrans.getTierWithId(name); srcAnnos = t1.getAnnotations(); for (int j = 0; j < srcAnnos.size(); j++) { ann = (AlignableAnnotation) srcAnnos.get(j); if (ann.getEndTimeBoundary() <= begin) { continue; } if (ann.getBeginTimeBoundary() >= end) { break; } record = AnnotationRecreator.createTreeForAnnotation(ann); copyAnn = (AlignableAnnotation) AnnotationRecreator.createAnnotationFromTree(copyTrans, record); // force in interval if (copyAnn.getBeginTimeBoundary() < begin) { copyAnn.updateTimeInterval(begin, copyAnn.getEndTimeBoundary()); } if (copyAnn.getEndTimeBoundary() > end) { copyAnn.updateTimeInterval(copyAnn.getBeginTimeBoundary(), end); } } progressUpdate(null, 40 + (int) (i * incr)); if (isCancelled()) { return; } } progressUpdate(null, 80); if (isCancelled()) { return; } copyTrans.shiftAllAnnotations(-begin); ACM24TranscriptionStore store = new ACM24TranscriptionStore(); store.storeTranscription(copyTrans, null, new Vector(), path, TranscriptionStore.EAF); LOG.info("Selection saved as new .eaf"); } /** * Prompt for a filename and location. * * @return a path as a string */ private String promptForFileName() { String exportDir = (String) Preferences.get("LastUsedEAFDir", null); if (exportDir == null) { exportDir = System.getProperty("user.dir"); } JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(exportDir)); chooser.setDialogTitle(ElanLocale.getString("SaveDialog.Title")); File exportFile = null; FileFilter filter = ElanFileFilter.createFileFilter(ElanFileFilter.EAF_TYPE); chooser.setFileFilter(filter); if (chooser.showSaveDialog(ELANCommandFactory.getRootFrame( transcription)) == JFileChooser.APPROVE_OPTION) { File curDir = chooser.getCurrentDirectory(); if (curDir != null) { Preferences.set("LastUsedEAFDir", curDir.getAbsolutePath(), null); } exportFile = chooser.getSelectedFile(); if (exportFile != null) { String name = exportFile.getAbsolutePath(); String lowerPathName = name.toLowerCase(); String[] exts = FileExtension.EAF_EXT; boolean validExt = false; for (int i = 0; i < exts.length; i++) { if (lowerPathName.endsWith("." + exts[i])) { validExt = true; break; } } if (!validExt) { name += ("." + exts[0]); exportFile = new File(name); } if (exportFile.exists()) { int answer = JOptionPane.showConfirmDialog(null, ElanLocale.getString("Message.Overwrite"), ElanLocale.getString("SaveDialog.Message.Title"), JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.NO_OPTION) { return promptForFileName(); } else { return name; } } else { return name; } } else { return null; } } else { // save dialog canceled return null; } } private void progressUpdate(String note, int progress) { if (monitor != null) { if (note != null) { monitor.setNote(note); } monitor.setProgress(progress); } } /** * Checks whether the operation has been canceled via the progress monitor. * * @return true if the cancel button of the monitor has been clicked, false otherwise */ private boolean isCancelled() { if (monitor != null) { return monitor.isCanceled(); } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -