📄 mediafilespanel.java
字号:
/* * File: MediaFilesPanel.java * Project: MPI Linguistic Application * Date: 02 May 2007 * * Copyright (C) 2001-2007 Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package mpi.eudico.client.annotator.linkedmedia;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.Preferences;import mpi.eudico.client.annotator.commands.Command;import mpi.eudico.client.annotator.commands.ELANCommandFactory;import mpi.eudico.client.annotator.util.ElanFileFilter;import mpi.eudico.client.annotator.util.FileUtility;import mpi.eudico.client.util.CheckBoxTableCellRenderer;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.MediaDescriptor;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Font;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.util.ArrayList;import java.util.List;import java.util.Vector;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.ListSelectionModel;import javax.swing.SwingConstants;import javax.swing.border.TitledBorder;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.event.TableModelEvent;import javax.swing.event.TableModelListener;import javax.swing.filechooser.FileFilter;import javax.swing.table.TableModel;/** * @author Han Sloetjes */public class MediaFilesPanel extends JPanel implements ActionListener, ListSelectionListener, TableModelListener { /** Holds value of property DOCUMENT ME! */ private static final String NO_SOURCE = "-"; // ui stuff private JScrollPane mediaScrollPane; private JTable mediaTable; private JPanel linkInfoPanel; private JLabel linkInfoLabel; private JButton addRemoteMB; private JButton addMB; private JButton removeMB; private JButton updateMB; private JButton masterMB; private JButton extractMB; private JButton moveUpButton; private JButton moveDownButton; private JPanel moveButtonPanel; private JPanel mediaButtonPanel; private TranscriptionImpl transcription; private Vector currentMDCopy; /** * Creates a modal new LinkedFilesDialog. * * @param transcription the transcription */ public MediaFilesPanel(Transcription transcription) { this.transcription = (TranscriptionImpl) transcription; if (transcription != null) { Vector orgMD = transcription.getMediaDescriptors(); currentMDCopy = new Vector(orgMD.size()); MediaDescriptor md; MediaDescriptor cloneMD; for (int i = 0; i < orgMD.size(); i++) { md = (MediaDescriptor) orgMD.get(i); cloneMD = (MediaDescriptor) md.clone(); if (cloneMD != null) { currentMDCopy.add(cloneMD); } } } initComponents(); } /** * This method is called from within the constructor to initialize the * dialog. */ private void initComponents() { GridBagConstraints gridBagConstraints; ImageIcon upIcon = new ImageIcon(this.getClass().getResource("/toolbarButtonGraphics/navigation/Up16.gif")); ImageIcon downIcon = new ImageIcon(this.getClass().getResource("/toolbarButtonGraphics/navigation/Down16.gif")); ImageIcon tickIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/Tick16.gif")); ImageIcon untickIcon = new ImageIcon(this.getClass().getResource("/mpi/eudico/client/annotator/resources/Untick16.gif")); CheckBoxTableCellRenderer cbRenderer = new CheckBoxTableCellRenderer(); cbRenderer.setIcon(untickIcon); cbRenderer.setSelectedIcon(tickIcon); cbRenderer.setHorizontalAlignment(SwingConstants.CENTER); mediaScrollPane = new JScrollPane(); mediaTable = new JTable(); linkInfoPanel = new JPanel(); linkInfoLabel = new JLabel(); mediaButtonPanel = new JPanel(); addRemoteMB = new JButton(); addMB = new JButton(); removeMB = new JButton(); updateMB = new JButton(); masterMB = new JButton(); extractMB = new JButton(); moveUpButton = new JButton(); moveDownButton = new JButton(); setLayout(new GridBagLayout()); Insets insets = new Insets(2, 6, 2, 6); mediaScrollPane.setMinimumSize(new Dimension(100, 100)); mediaScrollPane.setPreferredSize(new Dimension(550, 100)); MediaDescriptorTableModel model = new MediaDescriptorTableModel(currentMDCopy); mediaTable.setModel(model); mediaTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); mediaTable.getSelectionModel().addListSelectionListener(this); mediaTable.getModel().addTableModelListener(this); for (int i = 0; i < mediaTable.getColumnCount(); i++) { if (mediaTable.getModel().getColumnClass(i) != String.class) { mediaTable.getColumn(mediaTable.getModel().getColumnName(i)) .setPreferredWidth(35); } if (mediaTable.getModel().getColumnClass(i) == Boolean.class) { mediaTable.getColumn(mediaTable.getModel().getColumnName(i)) .setCellRenderer(cbRenderer); } } mediaScrollPane.setViewportView(mediaTable); mediaScrollPane.getViewport().setBackground(mediaTable.getBackground()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = insets; add(mediaScrollPane, gridBagConstraints); linkInfoPanel.setLayout(new BorderLayout()); linkInfoLabel.setFont(linkInfoLabel.getFont().deriveFont(Font.PLAIN, 10)); fillInfoPanel(-1); linkInfoPanel.add(linkInfoLabel, BorderLayout.WEST); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = insets; add(linkInfoPanel, gridBagConstraints); mediaButtonPanel.setLayout(new GridLayout(2, 4, 6, 2)); addRemoteMB.addActionListener(this); mediaButtonPanel.add(addRemoteMB); addMB.addActionListener(this); mediaButtonPanel.add(addMB); removeMB.setEnabled(false); removeMB.addActionListener(this); mediaButtonPanel.add(removeMB); updateMB.setEnabled(false); updateMB.addActionListener(this); mediaButtonPanel.add(updateMB); mediaButtonPanel.add(new JLabel()); masterMB.setEnabled(false); masterMB.addActionListener(this); mediaButtonPanel.add(masterMB); extractMB.setEnabled(false); extractMB.addActionListener(this); mediaButtonPanel.add(extractMB); moveButtonPanel = new JPanel(); moveButtonPanel.setLayout(new GridLayout(1, 2, 6, 2)); moveUpButton.setIcon(upIcon); moveUpButton.setEnabled(false); moveUpButton.addActionListener(this); moveButtonPanel.add(moveUpButton); moveDownButton.setIcon(downIcon); moveDownButton.setEnabled(false); moveDownButton.addActionListener(this); moveButtonPanel.add(moveDownButton); mediaButtonPanel.add(moveButtonPanel); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = GridBagConstraints.NORTHEAST; gridBagConstraints.insets = insets; add(mediaButtonPanel, gridBagConstraints); updateLocale(); } /** * Applies localized strings to the ui elements. */ private void updateLocale() { linkInfoPanel.setBorder(new TitledBorder(ElanLocale.getString( "LinkedFilesDialog.Label.LinkInfo"))); addRemoteMB.setText(ElanLocale.getString( "Frame.ElanFrame.NewDialog.RemoteMedia")); addMB.setText(ElanLocale.getString("LinkedFilesDialog.Button.Add")); removeMB.setText(ElanLocale.getString("LinkedFilesDialog.Button.Remove")); updateMB.setText(ElanLocale.getString("LinkedFilesDialog.Button.Update")); masterMB.setText(ElanLocale.getString( "LinkedFilesDialog.Button.MasterMedia")); extractMB.setText(ElanLocale.getString( "LinkedFilesDialog.Button.Extracted")); moveUpButton.setToolTipText(ElanLocale.getString( "LinkedFilesDialog.Button.Up")); moveDownButton.setToolTipText(ElanLocale.getString( "LinkedFilesDialog.Button.Down")); } /** * Checks whether changes have been made to the set of linked media files * and, if any, creates a command that replaces the media descriptors. * The dialog is then closed. */ void applyChanges() { boolean anyChange = hasChanged(); // warn if a video and an extracted audio have a different // offset checkUnequalOffsets(); if (anyChange) { Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.CHANGE_LINKED_FILES); c.execute(transcription, new Object[] { currentMDCopy, Boolean.TRUE }); } } /** * Checks whether anything has changed in the linked mediafiles setup. * * @return whether anything has been changed in the linked mediafiles setup */ boolean hasChanged() { boolean anyChange = false; Vector orgMD = transcription.getMediaDescriptors(); MediaDescriptor olddesc; MediaDescriptor newdesc; // first compare the size of the vectors if (orgMD.size() != currentMDCopy.size()) { anyChange = true; } // if the size is the same check if all elements are the same if (!anyChange) {outerloop: for (int i = 0; i < orgMD.size(); i++) { olddesc = (MediaDescriptor) orgMD.get(i); for (int j = 0; j < currentMDCopy.size(); j++) { newdesc = (MediaDescriptor) currentMDCopy.get(j); if ((olddesc != null) && olddesc.equals(newdesc)) { // check on change in master media and let the order be important //if ((i == 0 && j > 0) || (i > 0 && j == 0)) { master change if (i != j) { anyChange = true; break outerloop; } continue outerloop; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -