📄 mediafilespanel.java
字号:
// if we come here something has changed anyChange = true; break outerloop; } } return anyChange; } /** * Creates an input pane for the url of a rtsp media stream. * The syntax of the returned address is roughly checked and a MediaDescriptor is created. */ private void addRemoteMedia() { String url = chooseRemoteFile(); if (url == null) { return; } else { MediaDescriptor md = MediaDescriptorUtil.createMediaDescriptor(url); addMediaDescriptor(md); } } /** * Adds a MediaDescriptor to the list of descriptors. - prompts the user to * locate the media file - performs some checking on type and validity of * the new media (e.g. it is not allowed to have more than one audio * file) - adds the mediadescriptor to the table model (i.e. to the vector * of copied descriptors) */ private void addMediaDescriptor() { String file = chooseMediaFile(ElanFileFilter.MEDIA_TYPE); if (file == null) { return; } MediaDescriptor md = MediaDescriptorUtil.createMediaDescriptor(file); addMediaDescriptor(md); } /** * Adds a MediaDescriptor to the list of descriptors. Performs some checking on type and validity * of the new media, adds the mediadescriptor to the table model (i.e. to the vector * of copied descriptors). * @param md the media descriptor */ private void addMediaDescriptor(MediaDescriptor md) { if (md == null) { return; } int row = mediaTable.getSelectedRow(); for (int i = 0; i < currentMDCopy.size(); i++) { MediaDescriptor otherMD = (MediaDescriptor) currentMDCopy.get(i); if (otherMD.mediaURL.equals(md.mediaURL)) { showWarningDialog(ElanLocale.getString( "LinkedFilesDialog.Message.AlreadyLinked")); return; } // should this automatic detection of extracted_from remain?? if (md.mimeType.equals(MediaDescriptor.WAV_MIME_TYPE) && MediaDescriptorUtil.isVideoType(otherMD)) { if (FileUtility.sameNameIgnoreExtension(md.mediaURL, otherMD.mediaURL)) { md.extractedFrom = otherMD.mediaURL; } } if (otherMD.mimeType.equals(MediaDescriptor.WAV_MIME_TYPE) && MediaDescriptorUtil.isVideoType(md)) { if (FileUtility.sameNameIgnoreExtension(md.mediaURL, otherMD.mediaURL)) { otherMD.extractedFrom = md.mediaURL; } } } currentMDCopy.add(md); // the table model has a reference to the same vector of media descriptors ((MediaDescriptorTableModel) mediaTable.getModel()).rowDataChanged(); if (row >= 0) { mediaTable.getSelectionModel().setLeadSelectionIndex(currentMDCopy.size() - 1); } } /** * Removes the selected mediadescriptor from the list/table. It thereby is * also removed from the vector of copied descriptors. Other descriptors * may have to be changed, e.g. when ther is an mediadescriptor with an * extracted from field pointing to the removed descriptor. */ private void removeMediaDescriptor() { int row = mediaTable.getSelectedRow(); if (row >= 0) { // the row number is the same as the position of the MediaDescriptor // in the vector of descriptors. MediaDescriptor md = (MediaDescriptor) currentMDCopy.get(row); if (md.mimeType.equals(MediaDescriptor.MPG_MIME_TYPE)) { for (int i = 0; i < currentMDCopy.size(); i++) { if (i == row) { continue; } MediaDescriptor desc = (MediaDescriptor) currentMDCopy.get(i); if (desc.mimeType.equals(MediaDescriptor.WAV_MIME_TYPE) && (desc.extractedFrom != null) && desc.extractedFrom.equals(md.mediaURL)) { desc.extractedFrom = null; if (md.timeOrigin != 0) { if (showOptionDialog(ElanLocale.getString( "LinkedFilesDialog.Question.AudioKeepOffset"))) { desc.timeOrigin = md.timeOrigin; } } break; } } } currentMDCopy.remove(row); // the table model has a reference to the same vector of media descriptors ((MediaDescriptorTableModel) mediaTable.getModel()).rowDataChanged(); } } /** * Changes an existing media descriptor. A typical use would be to update * the location of a (missing) file. But it can also be used to replace * one file by another of the same type. - the user is prompted to locate * the new file - when the new file has another name than the old file and * the old file had a non-zero time offset the user is prompted whether * or not to keep the offset. Same for extracted from. - checks whether * other existing descriptors should be changed as well */ private void updateMediaDescriptor() { int row = mediaTable.getSelectedRow(); if (row >= 0) { MediaDescriptor updateMD = (MediaDescriptor) currentMDCopy.get(row); String file = null; if (updateMD.mimeType.equals(MediaDescriptor.MPG_MIME_TYPE)) { file = chooseMediaFile(ElanFileFilter.MPEG_TYPE); } else if (updateMD.mimeType.equals(MediaDescriptor.WAV_MIME_TYPE)) { file = chooseMediaFile(ElanFileFilter.WAV_TYPE); } else { file = chooseMediaFile(ElanFileFilter.MEDIA_TYPE); } if (file == null) { return; } MediaDescriptor md = MediaDescriptorUtil.createMediaDescriptor(file); // it should not be exactly the same file if (md.mediaURL.equals(updateMD.mediaURL)) { showWarningDialog(ElanLocale.getString( "LinkedFilesDialog.Message.SameFile")); return; } // should the updated file be of the same mime-type? for (int i = 0; i < currentMDCopy.size(); i++) { if (i == row) { continue; } MediaDescriptor otherMD = (MediaDescriptor) currentMDCopy.get(i); // check whether the file was already linked if (otherMD.mediaURL.equals(md.mediaURL)) { showWarningDialog(ElanLocale.getString( "LinkedFilesDialog.Message.AlreadyLinked")); return; } // if there is an audio descriptor that has been extracted from the descriptor // being updated, prompt the user whether the audio should now be considered // to be extracted from the new file if ((otherMD.extractedFrom != null) && otherMD.extractedFrom.equals(updateMD.mediaURL)) { if (md.mimeType.equals(MediaDescriptor.MPG_MIME_TYPE)) { if (showOptionDialog(ElanLocale.getString( "LinkedFilesDialog.Question.UpdateExtractedFrom"))) { otherMD.extractedFrom = md.mediaURL; } else { otherMD.extractedFrom = null; } } else { otherMD.extractedFrom = null; } } // should this automatic detection of extracted_from remain?? if (md.mimeType.equals(MediaDescriptor.WAV_MIME_TYPE) && otherMD.mimeType.equals(MediaDescriptor.MPG_MIME_TYPE)) { if (FileUtility.sameNameIgnoreExtension(md.mediaURL, otherMD.mediaURL)) { md.extractedFrom = otherMD.mediaURL; } } if (otherMD.mimeType.equals(MediaDescriptor.WAV_MIME_TYPE) && md.mimeType.equals(MediaDescriptor.MPG_MIME_TYPE)) { if (FileUtility.sameNameIgnoreExtension(md.mediaURL, otherMD.mediaURL)) { otherMD.extractedFrom = md.mediaURL; } } } if (updateMD.timeOrigin != 0) { // prompt user whether or not to maintain the offset if (showOptionDialog(ElanLocale.getString( "LinkedFilesDialog.Question.UpdateKeepOffset"))) { md.timeOrigin = updateMD.timeOrigin; } } // finally replace the descriptor currentMDCopy.remove(row); currentMDCopy.add(row, md); // the table model has a reference to the same vector of media descriptors ((MediaDescriptorTableModel) mediaTable.getModel()).rowDataChanged(); mediaTable.getSelectionModel().setLeadSelectionIndex(row); } } /** * Sets the selected media (descriptor) to be the master media. The master * media is always the first one in the list of media descriptors. */ private void setMasterMedia() { int row = mediaTable.getSelectedRow(); if (row > 0) { Object md = currentMDCopy.remove(row); currentMDCopy.add(0, md); // the table model has a reference to the same vector of media descriptors ((MediaDescriptorTableModel) mediaTable.getModel()).rowDataChanged(); mediaTable.getSelectionModel().setLeadSelectionIndex(0); } } /** * Changes the "extracted from" field of an audio file to a video file * selected by the user. */ private void setExtractedFrom() { int row = mediaTable.getSelectedRow(); if (row >= 0) { MediaDescriptor md = (MediaDescriptor) currentMDCopy.get(row); if (md.mimeType.equals(MediaDescriptor.WAV_MIME_TYPE)) { String source = showVideoSelectionDialog(md); if (source != null) { if (source == NO_SOURCE) { md.extractedFrom = null; } else { md.extractedFrom = source; } } // the table model has a reference to the same vector of media descriptors ((MediaDescriptorTableModel) mediaTable.getModel()).rowDataChanged(); mediaTable.getSelectionModel().setLeadSelectionIndex(row); } } } /** * Moves the selected media descriptor one position up in the list of * descriptors. */ private void moveUp() { int row = mediaTable.getSelectedRow(); if (row > 0) { Object md = currentMDCopy.remove(row); currentMDCopy.add(row - 1, md); // the table model has a reference to the same vector of media descriptors ((MediaDescriptorTableModel) mediaTable.getModel()).rowDataChanged(); mediaTable.getSelectionModel().setLeadSelectionIndex(row - 1); } } /** * Moves the selected media descriptor one position down in the list of * descriptors. */ private void moveDown() { int row = mediaTable.getSelectedRow(); if ((row >= 0) && (row < (currentMDCopy.size() - 1))) { Object md = currentMDCopy.remove(row); currentMDCopy.add(row + 1, md); // the table model has a reference to the same vector of media descriptors ((MediaDescriptorTableModel) mediaTable.getModel()).rowDataChanged(); mediaTable.getSelectionModel().setLeadSelectionIndex(row + 1); } } /** * Enables/disables buttons after a change in table data or table * selection. */ private void updateUIComponents() { int row = mediaTable.getSelectedRow(); if ((row >= 0) && (row < currentMDCopy.size())) { removeMB.setEnabled(true); updateMB.setEnabled(true); if (row == 0) { masterMB.setEnabled(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -