⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seclinkedfilespanel.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     SecLinkedFilesPanel.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.FileExtension;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.LinkedFileDescriptor;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.table.TableModel;/** * A panel for adding and removing of secondary linked files, * additional files not containing a primary source of annotation. * * @author Han Sloetjes */public class SecLinkedFilesPanel extends JPanel implements ActionListener,    ListSelectionListener, TableModelListener {    private TranscriptionImpl transcription;    /** empty value string */    private final String NO_SOURCE = "-";    // ui stuff    private JScrollPane linkScrollPane;    private JTable linkTable;    private JPanel linkInfoPanel;    private JLabel linkInfoLabel;    private JButton addMB;    private JButton removeMB;    private JButton updateMB;    private JButton associateJB;    private JPanel linkButtonPanel;    // data    private Vector descCopy;    /**     * Creates a new SecLinkedFilesPanel instance     *     * @param trans DOCUMENT ME!     */    public SecLinkedFilesPanel(Transcription trans) {        this.transcription = (TranscriptionImpl) trans;        if (transcription != null) {            Vector orgLFD = transcription.getLinkedFileDescriptors();            descCopy = new Vector(orgLFD.size());            LinkedFileDescriptor lfd;            LinkedFileDescriptor cloneLFD;            for (int i = 0; i < orgLFD.size(); i++) {                lfd = (LinkedFileDescriptor) orgLFD.get(i);                cloneLFD = (LinkedFileDescriptor) lfd.clone();                if (cloneLFD != null) {                    descCopy.add(cloneLFD);                }            }        }        initComponents();    }    /**     * This method is called from within the constructor to initialize the     * dialog.     */    private void initComponents() {        GridBagConstraints gridBagConstraints;        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);        linkScrollPane = new JScrollPane();        linkTable = new JTable();        linkInfoPanel = new JPanel();        linkInfoLabel = new JLabel();        linkButtonPanel = new JPanel();        addMB = new JButton();        removeMB = new JButton();        updateMB = new JButton();        associateJB = new JButton();        setLayout(new GridBagLayout());        Insets insets = new Insets(2, 6, 2, 6);        linkScrollPane.setMinimumSize(new Dimension(100, 100));        linkScrollPane.setPreferredSize(new Dimension(550, 100));        LFDescriptorTableModel model = new LFDescriptorTableModel(descCopy);        linkTable.setModel(model);        linkTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        linkTable.getSelectionModel().addListSelectionListener(this);        linkTable.getModel().addTableModelListener(this);        for (int i = 0; i < linkTable.getColumnCount(); i++) {            if (linkTable.getModel().getColumnClass(i) != String.class) {                linkTable.getColumn(linkTable.getModel().getColumnName(i))                         .setPreferredWidth(35);            }            if (linkTable.getModel().getColumnClass(i) == Boolean.class) {                linkTable.getColumn(linkTable.getModel().getColumnName(i))                         .setCellRenderer(cbRenderer);            }        }        linkScrollPane.setViewportView(linkTable);        linkScrollPane.getViewport().setBackground(linkTable.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(linkScrollPane, gridBagConstraints);        linkInfoPanel.setLayout(new BorderLayout());        linkInfoLabel.setFont(linkInfoLabel.getFont().deriveFont(Font.PLAIN, 10));        fillInfoPanel(0);        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);        linkButtonPanel.setLayout(new GridLayout(2, 2, 6, 2));        addMB.addActionListener(this);        linkButtonPanel.add(addMB);        removeMB.setEnabled(false);        removeMB.addActionListener(this);        linkButtonPanel.add(removeMB);        associateJB.setEnabled(false);        associateJB.addActionListener(this);        linkButtonPanel.add(associateJB);        updateMB.setEnabled(false);        updateMB.addActionListener(this);        linkButtonPanel.add(updateMB);        gridBagConstraints = new GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 2;        gridBagConstraints.anchor = GridBagConstraints.NORTHEAST;        gridBagConstraints.insets = insets;        add(linkButtonPanel, gridBagConstraints);        updateLocale();    }    /**     * Applies localized strings to the ui elements.     */    private void updateLocale() {        linkInfoPanel.setBorder(new TitledBorder(ElanLocale.getString(                    "LinkedFilesDialog.Label.LinkInfo")));        addMB.setText(ElanLocale.getString("LinkedFilesDialog.Button.Add"));        removeMB.setText(ElanLocale.getString("LinkedFilesDialog.Button.Remove"));        updateMB.setText(ElanLocale.getString("LinkedFilesDialog.Button.Update"));        associateJB.setText(ElanLocale.getString(                "LinkedFilesDialog.Button.AssociatedWith"));    }    /**     * 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() {        if (hasChanged()) {            Command c = ELANCommandFactory.createCommand(transcription,                    ELANCommandFactory.CHANGE_LINKED_FILES);            c.execute(transcription, new Object[] { descCopy, Boolean.FALSE });        }    }    /**     * Checks whether anything has changed in the linked files setup.     *     * @return whether anything has been changed in the linked files setup     */    boolean hasChanged() {        boolean anyChange = false;        Vector orgMD = transcription.getLinkedFileDescriptors();        LinkedFileDescriptor olddesc;        LinkedFileDescriptor newdesc;        // first compare the size of the vectors        if (orgMD.size() != descCopy.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 = (LinkedFileDescriptor) orgMD.get(i);                for (int j = 0; j < descCopy.size(); j++) {                    newdesc = (LinkedFileDescriptor) descCopy.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;                    }                }                // if we come here something has changed                anyChange = true;                break outerloop;            }        }        return anyChange;    }    /**     * Prompts the user to select a file and creates a descriptor for the file.     */    private void addDescriptor() {        String file = chooseFile();        if (file == null) {            return;        }        LinkedFileDescriptor lfd = LinkedFileDescriptorUtil.createLFDescriptor(file);        for (int i = 0; i < descCopy.size(); i++) {            LinkedFileDescriptor otherLFD = (LinkedFileDescriptor) descCopy.get(i);            if (otherLFD.linkURL.equals(lfd.linkURL)) {                showWarningDialog(ElanLocale.getString(                        "LinkedFilesDialog.Message.AlreadyLinked"));                return;            }        }        descCopy.add(lfd);        // the table model has a reference to the same vector of link descriptors        ((LFDescriptorTableModel) linkTable.getModel()).rowDataChanged();        linkTable.getSelectionModel().setLeadSelectionIndex(descCopy.size() -

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -