📄 elanframe2.java
字号:
JOptionPane.showMessageDialog(this, strMessage, strError, JOptionPane.ERROR_MESSAGE); return; } //open the eaf and get the Transcription from it try { // When config files are possible check if eaf or configuration file // String path = chooser.getSelectedFile().getAbsolutePath(); //String path = fullPath; String path = fileTemp.getAbsolutePath(); // replace all backslashes by forward slashes path = path.replace('\\', '/'); //long before = System.currentTimeMillis(); Transcription transcription = new TranscriptionImpl(new File(path).getAbsolutePath()); //long after = System.currentTimeMillis(); //System.out.println("open eaf took " + (after - before) + " ms"); transcription.setUnchanged(); if (mediaFiles != null) { //Vector descriptors = createMediaDescriptors(mediaFiles); Vector descriptors = MediaDescriptorUtil.createMediaDescriptors(mediaFiles); // improve this; check and compare with the medianames from the eaf transcription.setMediaDescriptors(descriptors); transcription.setChanged(); } int lastSlash = path.lastIndexOf('/'); String eafPath = path.substring(0, lastSlash); boolean validMedia = checkMedia(transcription, eafPath); if (!validMedia) { // ask if incomplete media session is ok, if not return int answer = JOptionPane.showConfirmDialog(this, ElanLocale.getString( "Frame.ElanFrame.IncompleteMediaQuestion"), ElanLocale.getString( "Frame.ElanFrame.IncompleteMediaAvailable"), JOptionPane.YES_NO_OPTION); if (answer != JOptionPane.YES_OPTION) { return; } } if (transcriptionForThisFrame != null) { // create a new ElanFrame for the Transcription //new ElanFrame2(transcription); FrameManager.getInstance().createFrame(transcription); } else { transcriptionForThisFrame = transcription; //new InitThread(transcriptionForThisFrame.getName()).start(); initElan(); FrameManager.getInstance().updateFrameTitle(this, transcription.getFullPath()); } } catch (Exception e) { e.printStackTrace(); } } /** * DOCUMENT ME! * * @param fullPath DOCUMENT ME! */ public void openEAF(String fullPath) { openEAF(fullPath, null); } /** * Sets the transcription (document) for this frame. Only effective if this * frame is an empty frame, if there already is an transcription this * method simply returns. * * @param transcription the transcription object */ void setTranscription(Transcription transcription) { if ((transcriptionForThisFrame != null) || !(transcription instanceof TranscriptionImpl)) { return; } transcriptionForThisFrame = transcription; initElan(); } /** * Returns the viewermanager for this frame * * @return DOCUMENT ME! */ public ViewerManager2 getViewerManager() { return viewerManager; } /** * Check for existence of media files and fix URLs if needed and possible. * The directory from which the .eaf file came is used as an alternative * location for the media file if the absolute path does not exist. When * the file is not found the user is prompted with a file chooser to * locate the file. * * @param transcription * @param eafPath DOCUMENT ME! * * @return boolean that flags if the media descriptors are valid */ public boolean checkMedia(Transcription transcription, String eafPath) { boolean validMedia = true; File currentDirectory = null; try { Vector mediaDescriptors = transcription.getMediaDescriptors(); for (int i = 0; i < mediaDescriptors.size(); i++) { MediaDescriptor md = (MediaDescriptor) mediaDescriptors.elementAt(i); // remove the file: part of the URL, leading slashes are no problem int colonPos = md.mediaURL.indexOf(':'); // wwj: if the url begins with rtsp, bypass the file checking if (colonPos > 0) { String urlhead = md.mediaURL.substring(0, colonPos); if (urlhead.trim().equalsIgnoreCase("rtsp")) { continue; } } String fileName = md.mediaURL.substring(colonPos + 1); // replace all back slashes by forward slashes fileName = fileName.replace('\\', '/'); File file = new File(fileName); if (!file.exists()) { // look for the file in the local directory int lastSlashPos = fileName.lastIndexOf('/'); String localFileName = fileName.substring(lastSlashPos + 1); file = new File(eafPath + "/" + localFileName); if (file.exists()) { // adjust urls adjustMediaDescriptors(mediaDescriptors, i, file.getAbsolutePath()); transcription.setChanged(); continue; } // look in a relative path ../Media file = new File(eafPath + "/../Media/" + localFileName); if (file.exists()) { // adjust urls adjustMediaDescriptors(mediaDescriptors, i, file.getAbsolutePath()); transcription.setChanged(); continue; } // look in a relative path ../media file = new File(eafPath + "/../media/" + localFileName); if (file.exists()) { // adjust urls adjustMediaDescriptors(mediaDescriptors, i, file.getAbsolutePath()); transcription.setChanged(); continue; } // no fallback worked, prompt the user to locate the file JFileChooser chooser = new JFileChooser(); if (md.mimeType.equals(MediaDescriptor.WAV_MIME_TYPE)) { chooser.setFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.WAV_TYPE)); } else if (md.mimeType.equals(MediaDescriptor.MPG_MIME_TYPE)) { chooser.setFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.MPEG_TYPE)); } else { FileFilter mediaFilter = ElanFileFilter.createFileFilter(ElanFileFilter.MEDIA_TYPE); chooser.addChoosableFileFilter(mediaFilter); chooser.addChoosableFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.MP4_TYPE)); chooser.addChoosableFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.QT_TYPE)); chooser.setFileFilter(mediaFilter); } chooser.setDialogTitle(ElanLocale.getString( "Frame.ElanFrame.LocateMedia") + ": " + localFileName); boolean found = false; while (!found) { if (currentDirectory != null) { chooser.setCurrentDirectory(currentDirectory); } chooser.setSelectedFile(new File(file.getName())); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { currentDirectory = chooser.getCurrentDirectory(); //String name = chooser.getSelectedFile().getName(); //if (name.equals(localFileName)) { if (!chooser.getSelectedFile().exists()) { JOptionPane.showMessageDialog(null, ElanLocale.getString( "Frame.ElanFrame.LocateMedia"), ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); found = false; continue; } // adjust urls adjustMediaDescriptors(mediaDescriptors, i, chooser.getSelectedFile().getAbsolutePath()); transcription.setChanged(); found = true; /*} else { // we do not allow another media file name than the original JOptionPane.showMessageDialog(null, ElanLocale.getString( "Frame.ElanFrame.MediaFileRenamed"), ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); } */ } else { // the user did choose cancel and thereby gave up locating the file md.isValid = false; validMedia = false; break; } } } } } catch (Exception e) { e.printStackTrace(); } return validMedia; } /** * Replace the current path in a media descriptor and all the media * descriptors that are derived from it * * @param mediaDescriptors * @param index position in the Vector of descriptors of the descriptor * which media URL must be changed * @param newPath the new file path that must become the new media URL */ private void adjustMediaDescriptors(Vector mediaDescriptors, int index, String newPath) { // remember the old URL String oldURL = ((MediaDescriptor) mediaDescriptors.elementAt(index)).mediaURL; //String newURL = pathToURLString(newPath); String newURL = FileUtility.pathToURLString(newPath); String newExt = null; if (newURL.indexOf('.') > -1) { newExt = newURL.substring(newURL.lastIndexOf('.') + 1); } // replace the old URL and mime type ((MediaDescriptor) mediaDescriptors.elementAt(index)).mediaURL = newURL; ((MediaDescriptor) mediaDescriptors.elementAt(index)).mimeType = MediaDescriptorUtil.mimeTypeForExtension(newExt); // replace the extracted from URL's for (int i = 0; i < mediaDescriptors.size(); i++) { String extractedFrom = ((MediaDescriptor) mediaDescriptors.elementAt(i)).extractedFrom; if (oldURL.equals(extractedFrom)) { ((MediaDescriptor) mediaDescriptors.elementAt(i)).extractedFrom = newURL; } } } /** * Init Elan for a Transcription mediaDecriptors should be contained in * Transcription Is this the place to create all the viewers, must there * be getters for these viewers who needs to know about them? */ private void initElan() { setTitle("Initializing...."); viewerManager = new ViewerManager2(transcriptionForThisFrame);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -