📄 seclinkedfilespanel.java
字号:
1); } /** * Removes the selected linkdescriptor from the list/table. It thereby is * also removed from the vector of copied descriptors. Other descriptors * may have to be changed or removed, e.g. when there is an linkdescriptor with an * associated with field pointing to the removed descriptor. */ private void removeDescriptor() { int row = linkTable.getSelectedRow(); if (row >= 0) { // the row number is the same as the position of the LinkedFileDescriptor LinkedFileDescriptor lfd = (LinkedFileDescriptor) descCopy.get(row); descCopy.remove(row); for (int i = descCopy.size() - 1; i >= 0; i--) { LinkedFileDescriptor desc = (LinkedFileDescriptor) descCopy.get(i); if (lfd.linkURL.equals(desc.associatedWith)) { desc.associatedWith = null; //descCopy.remove(i); } } // the table model has a reference to the same vector of link descriptors ((LFDescriptorTableModel) linkTable.getModel()).rowDataChanged(); } } /** * Presents a selection box with possible files/descriptors to associate this * file/descriptor with. */ private void setAssociatedWith() { int row = linkTable.getSelectedRow(); if (row >= 0) { LinkedFileDescriptor updateLFD = (LinkedFileDescriptor) descCopy.get(row); String ref = selectAssociation(updateLFD); if (ref != null) { if (ref == NO_SOURCE) { updateLFD.associatedWith = null; } else { updateLFD.associatedWith = ref; } } ((LFDescriptorTableModel) linkTable.getModel()).rowDataChanged(); linkTable.getSelectionModel().setLeadSelectionIndex(row); } } /** * Updates an existing descriptor e.g. when a file has been renamed or moved. * Descriptors associated with this file will be updated as well. Time offset * can be maintained if the user chooses so. */ private void updateDescriptor() { int row = linkTable.getSelectedRow(); if (row >= 0) { LinkedFileDescriptor updateLFD = (LinkedFileDescriptor) descCopy.get(row); String file = chooseFile(); if (file == null) { return; } LinkedFileDescriptor lfd = LinkedFileDescriptorUtil.createLFDescriptor(file); // it should not be exactly the same file if (lfd.linkURL.equals(updateLFD.linkURL)) { showWarningDialog(ElanLocale.getString( "LinkedFilesDialog.Message.SameFile")); return; } // should the updated file be of the same mime-type? for (int i = 0; i < descCopy.size(); i++) { if (i == row) { continue; } LinkedFileDescriptor otherLFD = (LinkedFileDescriptor) descCopy.get(i); // check whether the file was already linked if (otherLFD.linkURL.equals(lfd.linkURL)) { showWarningDialog(ElanLocale.getString( "LinkedFilesDialog.Message.AlreadyLinked")); return; } // update descriptors that were associated with this one ? if (updateLFD.linkURL.equals(otherLFD.associatedWith)) { otherLFD.associatedWith = lfd.linkURL; } if (updateLFD.associatedWith.equals(otherLFD.linkURL)) { lfd.associatedWith = otherLFD.linkURL; } } if (updateLFD.timeOrigin != 0) { // prompt user whether or not to maintain the offset if (showOptionDialog(ElanLocale.getString( "LinkedFilesDialog.Question.UpdateKeepOffset"))) { lfd.timeOrigin = updateLFD.timeOrigin; } } // finally replace the descriptor descCopy.remove(row); descCopy.add(row, lfd); // the table model has a reference to the same vector of media descriptors ((LFDescriptorTableModel) linkTable.getModel()).rowDataChanged(); linkTable.getSelectionModel().setLeadSelectionIndex(row); } } /** * Enables/disables buttons after a change in table data or table * selection. */ private void updateUIComponents() { int row = linkTable.getSelectedRow(); if ((row >= 0) && (row < descCopy.size())) { removeMB.setEnabled(true); updateMB.setEnabled(true); associateJB.setEnabled(true); } else { removeMB.setEnabled(false); updateMB.setEnabled(false); associateJB.setEnabled(false); } fillInfoPanel(row); } /** * Sets the contents of the media file info panel. A JLabel with html * formatting is used for the info strings, which are a kind of key-value * pairs. * * @param row the source Descriptor for the info, when null empty * value strings are used */ private void fillInfoPanel(int row) { TableModel model = linkTable.getModel(); Object linkedObj = model.getValueAt(row, 5); boolean isLinked = (linkedObj instanceof Boolean) ? ((Boolean) linkedObj).booleanValue() : false; linkInfoLabel.setText("<html><table>" + "<tr><td>" + model.getColumnName(0) + "</td><td>" + ((model.getValueAt(row, 0) != null) ? model.getValueAt(row, 0) : "") + "</td></tr>" + "<tr><td>" + model.getColumnName(1) + "</td><td>" + ((model.getValueAt(row, 1) != null) ? model.getValueAt(row, 1) : "") + "</td></tr>" + "<tr><td>" + model.getColumnName(2) + "</td><td>" + ((model.getValueAt(row, 2) != null) ? model.getValueAt(row, 2) : "") + "</td></tr>" + "<tr><td>" + model.getColumnName(3) + "</td><td>" + ((model.getValueAt(row, 3) != null) ? model.getValueAt(row, 3) : "") + "</td></tr>" + "<tr><td>" + model.getColumnName(4) + "</td><td>" + ((model.getValueAt(row, 4) != null) ? model.getValueAt(row, 4) : "") + "</td></tr>" + "<tr><td>" + model.getColumnName(5) + "</td><td>" + ((model.getValueAt(row, 5) != null) ? (isLinked ? ElanLocale.getString("LinkedFilesDialog.Label.StatusLinked") : ElanLocale.getString("LinkedFilesDialog.Label.StatusMissing")) : "") + "</td></tr>" + "</table></html>"); } /** * Shows a FileChhoser for a mediafile. * * @param mediaType DOCUMENT ME! * * @return the full path to a mediafile as a String, or null */ private String chooseFile() { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(ElanLocale.getString("Button.Select")); chooser.setApproveButtonText(ElanLocale.getString( "LinkedFilesDialog.SelectMediaDialog.Approve")); String dir = (String) Preferences.get("LinkedFileDir", null); if (dir == null) { // user.dir is probably a better choice than home.dir? dir = System.getProperty("user.dir"); } chooser.setCurrentDirectory(new File(dir)); int option = chooser.showOpenDialog(this); if (option == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); if ((selected != null) && selected.exists()) { String selectedFilePath = selected.getAbsolutePath(); String mediaDir = selected.getParent(); Preferences.set("LinkedFileDir", mediaDir, null); return selectedFilePath; } } return null; } /** * Shows a warning/error dialog with the specified message string. * * @param message the message to display */ private void showWarningDialog(String message) { JOptionPane.showMessageDialog(this, message, ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); } /** * Shows a yes-no option dialog with the specified question. * * @param question the question * * @return true if the user's answer is confirmative, false otherwise */ private boolean showOptionDialog(String question) { int option = JOptionPane.showOptionDialog(this, question, ElanLocale.getString("LinkedFilesDialog.Title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { ElanLocale.getString("Button.Yes"), ElanLocale.getString("Button.No") }, ElanLocale.getString("Button.Yes")); return (option == JOptionPane.YES_OPTION); } /** * Presents a dialog with a list of all media files and other linked files, * except for the file represented by the specified descriptor. * * @param descriptor the file that should be associated with another file * @return the selcted url or null (dialog cancelled) */ private String selectAssociation(LinkedFileDescriptor descriptor) { if (descriptor == null) { return null; } String ref = null; List candidates = new ArrayList(); candidates.add(NO_SOURCE); Vector mediaDesc = transcription.getMediaDescriptors(); MediaDescriptor md; for (int i = 0; i < mediaDesc.size(); i++) { md = (MediaDescriptor) mediaDesc.get(i); candidates.add(md.mediaURL); } LinkedFileDescriptor lfd; for (int i = 0; i < descCopy.size(); i++) { lfd = (LinkedFileDescriptor) descCopy.get(i); if (lfd != descriptor) { candidates.add(lfd.linkURL); } } ref = (String) JOptionPane.showInputDialog(this, ElanLocale.getString( "LinkedFilesDialog.Question.SelectAssocaition"), ElanLocale.getString("LinkedFilesDialog.Title"), JOptionPane.QUESTION_MESSAGE, null, candidates.toArray(), NO_SOURCE); return ref; } /** * The action performed method. * * @param actionEvent the event */ public void actionPerformed(ActionEvent actionEvent) { Object source = actionEvent.getSource(); if (source == addMB) { addDescriptor(); } else if (source == removeMB) { removeDescriptor(); } else if (source == updateMB) { updateDescriptor(); } else if (source == associateJB) { setAssociatedWith(); } } /** * Updates some buttons after a change in the selected row. * * @param lse the event * * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) */ public void valueChanged(ListSelectionEvent lse) { if (!lse.getValueIsAdjusting()) { updateUIComponents(); } } /** * Updates some buttons after a change in the table model. * * @param tme the event * * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) */ public void tableChanged(TableModelEvent tme) { //updateUIComponents(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -