📄 exportshoebox.java
字号:
/* * File: ExportShoebox.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.export;import mpi.eudico.client.annotator.Constants;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.Preferences;import mpi.eudico.client.annotator.gui.ShoeboxMarkerDialog;import mpi.eudico.client.annotator.util.ElanFileFilter;import mpi.eudico.client.annotator.util.FileExtension;import mpi.eudico.client.util.CheckBoxTableCellRenderer;import mpi.eudico.server.corpora.clom.TranscriptionStore;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import mpi.eudico.server.corpora.clomimpl.dobes.ACM24TranscriptionStore;import mpi.eudico.server.corpora.clomimpl.shoebox.MarkerRecord;import mpi.eudico.server.corpora.clomimpl.shoebox.ShoeboxTypFile;import mpi.eudico.server.corpora.clomimpl.shoebox.ToolboxEncoderInfo;import mpi.eudico.server.corpora.clomimpl.shoebox.interlinear.Interlinearizer;import mpi.eudico.server.corpora.clomimpl.type.Constraint;import java.awt.Dimension;import java.awt.Frame;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowEvent;import java.io.BufferedWriter;import java.io.File;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.util.Collections;import java.util.Comparator;import java.util.Iterator;import java.util.List;import java.util.Vector;import javax.swing.ButtonGroup;import javax.swing.DefaultCellEditor;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JTextField;import javax.swing.border.TitledBorder;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;/** * An export dialog for exporting tiers to a Shoebox/Toolbox file. * * @author Han Sloetjes */public class ExportShoebox extends AbstractTierExportDialog implements ActionListener, ItemListener, ListSelectionListener { private JButton downButton; private JButton fieldSpecButton; private JButton typButton; private JButton upButton; private JCheckBox allUnicodeCB; private JCheckBox correctTimesCB; private JCheckBox generateMarkersCB; private JCheckBox wrapLinesCB; /** ui elements */ private JLabel charPerLineLabel; private JLabel dbTypeLabel; private JLabel tierNamesLabel; private JLabel timeFormatLabel; private JLabel typeLabel; private JPanel markerPanel; private JRadioButton hhMMSSMSFormatRB; private JRadioButton specRB; private JRadioButton ssMSFormatRB; private JRadioButton tierNamesRB; private JRadioButton typeRB; private JTextField dbTypField; private JTextField numCharTF; private JTextField typField; // some strings // not visible in the table header /** default line width */ private final int NUM_CHARS = 80; private List markers; // fields for the encoder private String databaseType; private String exportFileName; /** * Constructor. * * @param parent parent frame * @param modal the modal/blocking attribute * @param transcription the transcription to export from */ public ExportShoebox(Frame parent, boolean modal, TranscriptionImpl transcription) { super(parent, modal, transcription, null); makeLayout(); extractTiers(); postInit(); typField.requestFocus(); } /** * * * @param tier DOCUMENT ME! * * @return DOCUMENT ME! */ public Vector getTierTree(TierImpl tier) { Vector tierTree = new Vector(); Vector tierTrees = new Vector(); Vector children = tier.getChildTiers(); tierTree.add(tier); for (int j = 0; j < children.size(); j++) { TierImpl child = (TierImpl) children.elementAt(j); tierTrees.add(getTierTree(child)); } Collections.sort(tierTrees, new VectorComparator()); for (int j = 0; j < tierTrees.size(); j++) { tierTree.addAll((Vector) tierTrees.elementAt(j)); } return tierTree; } /** * The action performed event handling. * * @param ae the action event */ public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); if (source == upButton) { moveUp(); } else if (source == downButton) { moveDown(); } else if (source == typButton) { chooseTyp(); typeRB.setSelected(true); } else if (source == fieldSpecButton) { specifyFieldSpecs(); specRB.setSelected(true); } else { super.actionPerformed(ae); } } /** * The item state changed handling. * * @param ie the ItemEvent */ public void itemStateChanged(ItemEvent ie) { if (ie.getSource() == wrapLinesCB) { if (wrapLinesCB.isSelected()) { setDefaultNumOfChars(); numCharTF.requestFocus(); } else { numCharTF.setEnabled(false); numCharTF.setBackground(Constants.DEFAULTBACKGROUNDCOLOR); } } else if (ie.getSource() == typeRB) { setEnabledAutoGenerate(false); setEnabledAllUnicode(true); } else if (ie.getSource() == specRB) { setEnabledAutoGenerate(false); setEnabledAllUnicode(false); } else if (ie.getSource() == tierNamesRB) { setEnabledAutoGenerate(true); setEnabledAllUnicode(false); } } /** * Updates the checked state of the export checkboxes. * * @param lse the list selection event */ public void valueChanged(ListSelectionEvent lse) { if ((model != null) && lse.getValueIsAdjusting()) { int b = lse.getFirstIndex(); int e = lse.getLastIndex(); int col = model.findColumn(EXPORT_COLUMN); for (int i = b; i <= e; i++) { if (tierTable.isRowSelected(i)) { model.setValueAt(Boolean.TRUE, i, col); } } } } /** * Extract candidate tiers for export. */ protected void extractTiers() { if (model != null) { for (int i = model.getRowCount() - 1; i >= 0; i--) { model.removeRow(i); } if (transcription != null) { //Vector v = getHierarchicallySortedTiers(transcription); Vector v = transcription.getTiers(); TierImpl t; for (int i = 0; i < v.size(); i++) { t = (TierImpl) v.get(i); // add all model.addRow(new Object[] { Boolean.TRUE, t.getName() }); } } if (model.getRowCount() > 1) { upButton.setEnabled(true); downButton.setEnabled(true); } else { upButton.setEnabled(false); downButton.setEnabled(false); } } else { upButton.setEnabled(false); downButton.setEnabled(false); } } /** * Initializes UI elements. */ protected void makeLayout() { super.makeLayout(); charPerLineLabel = new JLabel(); wrapLinesCB = new JCheckBox(); wrapLinesCB.setSelected(true); numCharTF = new JTextField(4); timeFormatLabel = new JLabel(); ssMSFormatRB = new JRadioButton(); hhMMSSMSFormatRB = new JRadioButton(); correctTimesCB = new JCheckBox(); upButton = new JButton(); downButton = new JButton(); typField = new JTextField("", 23); typButton = new JButton("..."); typeLabel = new JLabel(); allUnicodeCB = new JCheckBox(); fieldSpecButton = new JButton(); dbTypeLabel = new JLabel(); dbTypField = new JTextField("", 14); ButtonGroup buttonGroup = new ButtonGroup(); typeRB = new JRadioButton(); typeRB.setSelected(true); typeRB.addItemListener(this); specRB = new JRadioButton(); specRB.addItemListener(this); tierNamesRB = new JRadioButton(); tierNamesRB.addItemListener(this); buttonGroup.add(typeRB); buttonGroup.add(specRB); buttonGroup.add(tierNamesRB); tierNamesLabel = new JLabel(); generateMarkersCB = new JCheckBox(); try { ImageIcon upIcon = new ImageIcon(this.getClass().getResource("/toolbarButtonGraphics/navigation/Up16.gif")); ImageIcon downIcon = new ImageIcon(this.getClass().getResource("/toolbarButtonGraphics/navigation/Down16.gif")); upButton.setIcon(upIcon); downButton.setIcon(downIcon); } catch (Exception ex) { upButton.setText("Up"); downButton.setText("Down"); } model.setColumnIdentifiers(new String[] { EXPORT_COLUMN, TIER_NAME_COLUMN }); tierTable.getColumn(EXPORT_COLUMN).setCellEditor(new DefaultCellEditor( new JCheckBox())); tierTable.getColumn(EXPORT_COLUMN).setCellRenderer(new CheckBoxTableCellRenderer()); tierTable.getColumn(EXPORT_COLUMN).setMaxWidth(30); tierTable.setShowVerticalLines(false); tierTable.setTableHeader(null); tierTable.getSelectionModel().addListSelectionListener(this); GridBagConstraints gridBagConstraints; upButton.addActionListener(this); downButton.addActionListener(this); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; tierSelectionPanel.add(upButton, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; tierSelectionPanel.add(downButton, gridBagConstraints); optionsPanel.setLayout(new GridBagLayout()); wrapLinesCB.addItemListener(this); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.anchor = GridBagConstraints.WEST;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -