📄 mergestep2.java
字号:
/* * File: MergeStep2.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.ElanFrame2;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.FrameManager;import mpi.eudico.client.annotator.commands.Command;import mpi.eudico.client.annotator.commands.MergeTranscriptionsCommand;import mpi.eudico.client.annotator.gui.multistep.MultiStepPane;import mpi.eudico.client.annotator.gui.multistep.StepPane;import mpi.eudico.client.annotator.util.ProgressListener;import mpi.eudico.client.util.CheckboxTreeCellEditor;import mpi.eudico.client.util.CheckboxTreeCellRenderer;import mpi.eudico.client.util.SelectableObject;import mpi.eudico.client.util.TierTree;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import mpi.eudico.server.corpora.clomimpl.type.LinguisticType;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.ArrayList;import java.util.Enumeration;import javax.swing.JCheckBox;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JProgressBar;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTree;import javax.swing.border.EmptyBorder;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.DefaultTreeSelectionModel;import javax.swing.tree.TreePath;import javax.swing.tree.TreeSelectionModel;/** * Second step in the merge process; loading of first source (=dest * transcription) or copying of first transcription, loading of second * source, presentation of available tiers for selection, etc. */public class MergeStep2 extends StepPane implements ProgressListener { private TranscriptionImpl firstTrans; private TranscriptionImpl secTrans; private TranscriptionImpl destTrans; private Object firstSource; private String secondSource; private String destFileName; private Insets insets; private JPanel progressPanel; private JLabel progressLabel; private JProgressBar progressBar; private JPanel treePanel; private JTable firstTable; private JTable secTable; private JTree firstTree; private JTree secTree; private JScrollPane firstScroll; private JScrollPane secScroll; private JLabel firstLabel; private JLabel secLabel; private JCheckBox overwriteCB; // the Command private Command com; /** * Creates a new MergeStep2 instance. * * @param multiPane the enclosing MultiStepPane */ public MergeStep2(MultiStepPane multiPane) { super(multiPane); initComponents(); } /** * Initializes the components of the step ui. */ public void initComponents() { setLayout(new GridBagLayout()); setBorder(new EmptyBorder(12, 12, 12, 12)); insets = new Insets(4, 6, 4, 6); // progress panel progressPanel = new JPanel(new GridBagLayout()); progressLabel = new JLabel("Loading..."); progressBar = new JProgressBar(); progressPanel.setPreferredSize(new Dimension(50, 80)); progressLabel.setFont(Constants.SMALLFONT); GridBagConstraints 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); // tree panel treePanel = new JPanel(new GridBagLayout()); firstLabel = new JLabel(ElanLocale.getString( "MergeTranscriptionDialog.Label.TiersSource1")); secLabel = new JLabel(ElanLocale.getString( "MergeTranscriptionDialog.Label.SelectTiers")); overwriteCB = new JCheckBox(ElanLocale.getString( "MergeTranscriptionDialog.Label.Overwrite")); // try trees instead of tables gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; treePanel.add(firstLabel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; firstScroll = new JScrollPane(firstTable); treePanel.add(firstScroll, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; treePanel.add(secLabel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; secScroll = new JScrollPane(secTable); treePanel.add(secScroll, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; treePanel.add(overwriteCB, gridBagConstraints); } /** * Adds the progress bar ui to this pane. */ private void setProgressUI() { removeAll(); treePanel.setVisible(false); GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 1; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.CENTER; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(progressPanel, gridBagConstraints); progressPanel.setVisible(true); revalidate(); } /** * Adds the tier selection ui to this pane. */ private void setTierTreeUI() { removeAll(); progressPanel.setVisible(false); GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(treePanel, gridBagConstraints); treePanel.setVisible(true); revalidate(); } /** * Fills the tree overview of both transcriptions. * The second tree has checkboxes to represent the selected * state of each tier. */ private void fillTrees() { if (destTrans != null) { TierTree tree = new TierTree(destTrans); DefaultMutableTreeNode transNode = tree.getTree(); //transNode.setUserObject(ElanLocale.getString( // "MultiStep.Reparent.Transcription")); firstTree = new JTree(transNode); DefaultTreeSelectionModel model = new DefaultTreeSelectionModel(); model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); firstTree.setSelectionModel(model); firstTree.putClientProperty("JTree.lineStyle", "Angled"); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) firstTree.getCellRenderer(); renderer.setLeafIcon(null); renderer.setOpenIcon(null); renderer.setClosedIcon(null); renderer.setBackgroundNonSelectionColor(Constants.DEFAULTBACKGROUNDCOLOR); firstTree.setShowsRootHandles(true); firstTree.setRootVisible(false); firstTree.setBackground(Constants.DEFAULTBACKGROUNDCOLOR); firstScroll.setViewportView(firstTree); for (int i = 0; i < firstTree.getRowCount(); i++) { firstTree.expandRow(i); } } if (secTrans != null) { // tree TierTree tree = new TierTree(secTrans); DefaultMutableTreeNode transNode = tree.getTree(); // replace the UserObject Strings by SelectableObject's DefaultMutableTreeNode node = null; Enumeration en = transNode.breadthFirstEnumeration(); while (en.hasMoreElements()) { node = (DefaultMutableTreeNode) en.nextElement(); if (node != transNode) { node.setUserObject(new SelectableObject( node.getUserObject(), true)); } } secTree = new JTree(transNode); DefaultTreeSelectionModel model = new DefaultTreeSelectionModel(); model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); secTree.setSelectionModel(model); secTree.putClientProperty("JTree.lineStyle", "Angled"); CheckboxTreeCellRenderer render = new CheckboxTreeCellRenderer(); render.setBackgroundNonSelectionColor(Constants.DEFAULTBACKGROUNDCOLOR); CheckboxTreeCellEditor editor = new CheckboxTreeCellEditor(); editor.setBackground(Constants.DEFAULTBACKGROUNDCOLOR); secTree.setCellRenderer(render); secTree.setCellEditor(editor); secTree.setRootVisible(false); secTree.setShowsRootHandles(true); secTree.setBackground(Constants.DEFAULTBACKGROUNDCOLOR); secScroll.setViewportView(secTree); for (int i = 0; i < secTree.getRowCount(); i++) { secTree.expandRow(i); checkSelection((DefaultMutableTreeNode) secTree.getPathForRow(i) .getLastPathComponent()); } secTree.setEditable(true); secTree.addMouseListener(new TreeMouseListener()); } } /** * @see mpi.eudico.client.annotator.gui.multistep.Step#getStepTitle() */ public String getStepTitle() { return ElanLocale.getString("MergeTranscriptionDialog.Title"); } /** * @see mpi.eudico.client.tool.viewer.enhanced.multistep.Step#enterStepForward() */ public void enterStepForward() { if ((firstSource != null) && (secondSource != null) && (destFileName != null)) { // we have been here before: check if anything has been changed in step 1 multiPane.setButtonEnabled(MultiStepPane.NEXT_BUTTON, false); Object fs = multiPane.getStepProperty("Source1"); String ss = (String) multiPane.getStepProperty("Source2"); destFileName = (String) multiPane.getStepProperty("Destination"); boolean fsChanged = false; boolean ssChanged = false; if (fs instanceof String) { if (!firstSource.equals(fs)) { fsChanged = true; firstSource = (String) fs; } } else if (fs != firstSource) { fsChanged = true; firstSource = fs; } if (!secondSource.equals(ss)) { ssChanged = true; secondSource = (String) ss; } //System.out.println("First Source changed: " + fsChanged); //System.out.println("Second Source changed: " + ssChanged); if (fsChanged || ssChanged) { multiPane.setButtonEnabled(MultiStepPane.PREVIOUS_BUTTON, false); multiPane.setButtonEnabled(MultiStepPane.CANCEL_BUTTON, false); setProgressUI(); new LoadThread(fsChanged, ssChanged).start(); } else { multiPane.setButtonEnabled(MultiStepPane.FINISH_BUTTON, true); multiPane.setButtonEnabled(MultiStepPane.CANCEL_BUTTON, true); multiPane.setButtonEnabled(MultiStepPane.PREVIOUS_BUTTON, true); } } else { multiPane.setButtonEnabled(MultiStepPane.NEXT_BUTTON, false); setProgressUI(); // start loading, set progressbar visible firstSource = multiPane.getStepProperty("Source1"); secondSource = (String) multiPane.getStepProperty("Source2"); destFileName = (String) multiPane.getStepProperty("Destination"); multiPane.setButtonEnabled(MultiStepPane.PREVIOUS_BUTTON, false); multiPane.setButtonEnabled(MultiStepPane.CANCEL_BUTTON, false); new LoadThread().start();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -