📄 linkedfiledescriptorutil.java
字号:
return; } Vector oldDescriptors = transcription.getLinkedFileDescriptors(); List removedSources = new ArrayList(4); List addedSources = new ArrayList(4); LinkedFileDescriptor lfd; LinkedFileDescriptor olfd;outerloop: for (int i = 0; i < oldDescriptors.size(); i++) { olfd = (LinkedFileDescriptor) oldDescriptors.get(i); if (descriptors.size() == 0) { removedSources.add(olfd); } else { for (int j = 0; j < descriptors.size(); j++) { lfd = (LinkedFileDescriptor) descriptors.get(j); if (lfd.linkURL.equals(olfd.linkURL)) { // check for changes?? continue outerloop; } if (j == (descriptors.size() - 1)) { removedSources.add(olfd); } } } }outerloop: for (int i = 0; i < descriptors.size(); i++) { lfd = (LinkedFileDescriptor) descriptors.get(i); if (oldDescriptors.size() == 0) { addedSources.add(lfd); } else { for (int j = 0; j < oldDescriptors.size(); j++) { olfd = (LinkedFileDescriptor) oldDescriptors.get(j); if (olfd.linkURL.equals(lfd.linkURL)) { // check for changes?? continue outerloop; } if (j == (oldDescriptors.size() - 1)) { addedSources.add(lfd); } } } } // if there is any time series source detected... TSTrackManager trackManager = ELANCommandFactory.getTrackManager(transcription); TSServiceRegistry registry = TSServiceRegistry.getInstance(); if (removedSources.size() > 0) { for (int i = 0; i < removedSources.size(); i++) { lfd = (LinkedFileDescriptor) removedSources.get(i); // check track manager if (trackManager != null) { trackManager.removeTrackSource(lfd.linkURL); } // check other ?? } } if (addedSources.size() > 0) { for (int i = 0; i < addedSources.size(); i++) { lfd = (LinkedFileDescriptor) addedSources.get(i); TSServiceProvider provider = registry.getProviderForFile(lfd.linkURL); if (provider != null) { if (trackManager == null) { trackManager = new TSTrackManager(transcription); ELANCommandFactory.addTrackManager(transcription, trackManager); // get viewer manager, create viewer TimeSeriesViewer tsViewer = ELANCommandFactory.getViewerManager(transcription) .createTimeSeriesViewer(); tsViewer.setTrackManager(trackManager); // get layout manager, add viewer ELANCommandFactory.getLayoutManager(transcription).add(tsViewer); } TSSourceConfiguration config = new TSSourceConfiguration(lfd.linkURL); config.setProviderClassName(provider.getClass().getName()); if (!provider.isConfigurable()) { provider.autoCreateTracks(config); } trackManager.addTrackSource(config); } } } // check if there are any sources left in the trackmanager? // Destroy time series viewer? transcription.setLinkedFileDescriptors(descriptors); transcription.setChanged(); } /** * Checks wether linked files can be found on the system: * first check the specified path/url then look in the same directory as the eaf. * * @param transcription the transcription holding the linkedfiles descriptors. * @return a map containing old url to new url mappings */ private static HashMap checkLinkedFiles(TranscriptionImpl transcription) { HashMap linkMap = new HashMap(2); if (transcription == null) { return linkMap; } Vector lfDescs = transcription.getLinkedFileDescriptors(); if ((lfDescs == null) || (lfDescs.size() == 0)) { return linkMap; } LinkedFileDescriptor lfd; String oldLinkURL; File currentDir = null; for (int i = 0; i < lfDescs.size(); i++) { lfd = (LinkedFileDescriptor) lfDescs.get(i); if (lfd.linkURL == null) { LOG.warning("Link url is null"); continue; } oldLinkURL = lfd.linkURL; // remove protocol int colonIndex = oldLinkURL.indexOf(':'); String path = null; if ((colonIndex > 0) && (colonIndex < (lfd.linkURL.length() - 1))) { path = lfd.linkURL.substring(colonIndex + 1); } else { path = lfd.linkURL; } path = path.replace('\\', '/'); File file = new File(path); if (file.exists()) { continue; } int lastSlash = path.lastIndexOf('/'); String linkName = path; if ((lastSlash >= 0) && (lastSlash < (path.length() - 1))) { linkName = path.substring(lastSlash + 1); } // get the dir of the transcription and look in the dir String linkDir = null; String eafFileName = transcription.getFullPath(); colonIndex = eafFileName.indexOf(':'); if (colonIndex > -1) { eafFileName = eafFileName.substring(colonIndex + 1); } File eafFile = new File(eafFileName); if (eafFile.exists() && (eafFile.getParentFile() != null)) { linkDir = eafFile.getParentFile().getAbsolutePath(); } File searchFile = null; if (linkDir != null) { searchFile = new File(linkDir + "/" + linkName); } else { searchFile = new File(linkName); } if (searchFile.exists()) { // update de url lfd.linkURL = FileUtility.pathToURLString(searchFile.getAbsolutePath()); LOG.info("Updating url from: " + oldLinkURL + " to: " + lfd.linkURL); transcription.setChanged(); linkMap.put(oldLinkURL, lfd.linkURL); } else { // prompt JFileChooser chooser = new JFileChooser(); if (lfd.mimeType.equals(LinkedFileDescriptor.XML_TYPE)) { chooser.setFileFilter(new ElanFileFilter( FileExtension.XML_EXT)); } else if (oldLinkURL.toLowerCase().endsWith(FileExtension.LOG_EXT[0])) { chooser.setFileFilter(new ElanFileFilter( FileExtension.LOG_EXT)); } else if (lfd.mimeType.equals(LinkedFileDescriptor.TEXT_TYPE)) { chooser.setFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.TEXT_TYPE)); } else if (lfd.mimeType.equals(LinkedFileDescriptor.SVG_TYPE)) { chooser.setFileFilter(new ElanFileFilter( FileExtension.SVG_EXT)); } chooser.setDialogTitle(ElanLocale.getString( "LinkedFilesDialog.Message.Locate") + ": " + linkName); chooser.setApproveButtonText(ElanLocale.getString( "Button.Select")); boolean found = false; while (!found) { if (currentDir != null) { chooser.setCurrentDirectory(currentDir); } else { chooser.setCurrentDirectory(searchFile.getParentFile()); } chooser.setSelectedFile(new File(linkName)); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { currentDir = chooser.getCurrentDirectory(); if ((chooser.getSelectedFile() != null) && !chooser.getSelectedFile().exists()) { JOptionPane.showMessageDialog(null, ElanLocale.getString( "LinkedFilesDialog.Message.Locate"), ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); found = false; continue; } String nextUrl = FileUtility.pathToURLString(chooser.getSelectedFile() .getAbsolutePath()); lfd.linkURL = nextUrl; LOG.info("Updating url from: " + oldLinkURL + " to: " + nextUrl); transcription.setChanged(); linkMap.put(oldLinkURL, nextUrl); found = true; } else { break; } } } } return linkMap; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -