📄 mergetranscriptions.java
字号:
/* * File: MergeTranscriptions.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.imports;import mpi.eudico.client.annotator.Constants;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.Preferences;import mpi.eudico.client.annotator.gui.ClosableDialog;import mpi.eudico.client.annotator.util.ElanFileFilter;import mpi.eudico.client.annotator.util.FileExtension;import mpi.eudico.client.annotator.util.ProgressListener;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import java.awt.BorderLayout;import java.awt.Dimension;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.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.File;import java.io.IOException;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JProgressBar;import javax.swing.JTextField;import javax.swing.SwingConstants;import javax.swing.WindowConstants;import javax.swing.border.TitledBorder;import javax.swing.filechooser.FileFilter;/** * A dialog that offers the opportunity to merge two existing transcriptions/ * transcription files (.eaf) to a new, destination transcription file. Can be * created from within ELAN or can be run as a separate application. * * @author Han Sloetjes */public class MergeTranscriptions extends ClosableDialog implements ActionListener, ProgressListener { private static boolean exitOnClose = false; private TranscriptionImpl transcription; private JButton browseSource1; private JButton browseSource2; private JButton browseDest; private JLabel select1Label; private JLabel select2Label; private JLabel selectDestLabel; private JTextField source1Field; private JTextField source2Field; private JTextField destField; private JLabel titleLabel; private JPanel titlePanel; private JPanel transPanel; private JPanel progressPanel; private JLabel progressLabel; private JProgressBar progressBar; private JPanel buttonPanel; private JButton startButton; private JButton closeButton; /** * Creates a new MergeTranscriptions instance.<br> * * @param transcription the first source transcription, or null */ public MergeTranscriptions(Transcription transcription) { //super(ELANCommandFactory.getRootFrame(transcription), true); super(new JFrame(), true); this.transcription = (TranscriptionImpl) transcription; initComponents(); postInit(); } /** * Initializes UI elements. */ protected void initComponents() { GridBagConstraints gridBagConstraints; titlePanel = new JPanel(); titleLabel = new JLabel(); transPanel = new JPanel(); browseSource1 = new JButton(); browseSource2 = new JButton(); browseDest = new JButton(); source1Field = new JTextField(); source2Field = new JTextField(); destField = new JTextField(); select1Label = new JLabel(); select2Label = new JLabel(); selectDestLabel = new JLabel(); buttonPanel = new JPanel(); startButton = new JButton(); closeButton = new JButton(); progressPanel = new JPanel(); progressLabel = new JLabel(); progressBar = new JProgressBar(); getContentPane().setLayout(new GridBagLayout()); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { closeDialog(evt); } }); Insets insets = new Insets(2, 6, 2, 6); titlePanel.setLayout(new BorderLayout(0, 4)); titleLabel.setFont(titleLabel.getFont().deriveFont((float) 16)); titleLabel.setHorizontalAlignment(SwingConstants.CENTER); JPanel titleLabelPanel = new JPanel(); titleLabelPanel.add(titleLabel); titlePanel.add(titleLabelPanel, BorderLayout.NORTH); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.NORTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = insets; getContentPane().add(titlePanel, gridBagConstraints); transPanel.setLayout(new GridBagLayout()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = insets; transPanel.add(select1Label, gridBagConstraints); if (transcription != null) { source1Field.setEnabled(false); source1Field.setText(transcription.getFullPath()); } gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = insets; transPanel.add(source1Field, gridBagConstraints); if (transcription != null) { browseSource1.setEnabled(false); } else { browseSource1.addActionListener(this); } gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.NONE; gridBagConstraints.anchor = GridBagConstraints.EAST; gridBagConstraints.insets = insets; transPanel.add(browseSource1, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = insets; transPanel.add(select2Label, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = insets; transPanel.add(source2Field, gridBagConstraints); browseSource2.addActionListener(this); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = GridBagConstraints.NONE; gridBagConstraints.anchor = GridBagConstraints.EAST; gridBagConstraints.insets = insets; transPanel.add(browseSource2, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = insets; transPanel.add(selectDestLabel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = insets; transPanel.add(destField, gridBagConstraints); browseDest.addActionListener(this); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = GridBagConstraints.NONE; gridBagConstraints.anchor = GridBagConstraints.EAST; gridBagConstraints.insets = insets; transPanel.add(browseDest, gridBagConstraints); JPanel filler = new JPanel(); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTH; gridBagConstraints.insets = insets; gridBagConstraints.weighty = 1.0; transPanel.add(filler, gridBagConstraints); progressPanel.setLayout(new GridBagLayout()); progressPanel.setPreferredSize(new Dimension(50, 80)); progressLabel.setFont(Constants.SMALLFONT); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; progressPanel.add(progressLabel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; progressPanel.add(progressBar, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 7; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; transPanel.add(progressPanel, gridBagConstraints); progressPanel.setVisible(false); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = insets; getContentPane().add(transPanel, gridBagConstraints); buttonPanel.setLayout(new GridLayout(1, 2, 6, 0)); startButton.addActionListener(this); buttonPanel.add(startButton); closeButton.addActionListener(this); buttonPanel.add(closeButton); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.insets = insets; getContentPane().add(buttonPanel, gridBagConstraints); updateLocale(); } /** * Enable/disable ui elements. * * @param enable true to enable all buttons etc., false to disable */ private void activateUI(boolean enable) { startButton.setEnabled(enable); closeButton.setEnabled(enable); if (transcription == null) { browseSource1.setEnabled(enable); source1Field.setEnabled(enable); } browseSource2.setEnabled(enable); browseDest.setEnabled(enable); source2Field.setEnabled(enable); destField.setEnabled(enable); } /** * Applies localized strings to the ui elements. */ protected void updateLocale() { setTitle(ElanLocale.getString("MergeTranscriptionDialog.Title")); transPanel.setBorder(new TitledBorder(ElanLocale.getString( "MergeTranscriptionDialog.Title"))); titleLabel.setText(ElanLocale.getString( "MergeTranscriptionDialog.Title")); select1Label.setText(ElanLocale.getString( "MergeTranscriptionDialog.Label.Source1")); select2Label.setText(ElanLocale.getString(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -