📄 mergestep2.java
字号:
} } /** * Notification that this step will become the active step, moving down. * * @see mpi.eudico.client.tool.viewer.enhanced.multistep.Step#enterStepBackward() */ public void enterStepBackward() { } /** * Notification that this step will no longer be the active step, moving * up. * * @see mpi.eudico.client.tool.viewer.enhanced.multistep.Step#leaveStepForward() */ public boolean leaveStepForward() { return true; } /** * @see mpi.eudico.client.tool.viewer.enhanced.multistep.Step#leaveStepBackward() */ public boolean leaveStepBackward() { multiPane.setButtonEnabled(MultiStepPane.FINISH_BUTTON, false); return true; } /** * Store selected tiers, check the overwrite checkbox, create a command, * register as listener and activate the progress ui. * * @return false; a new thread is started, the ui waits for its completion * * @see mpi.eudico.client.tool.viewer.enhanced.multistep.Step#doFinish() */ public boolean doFinish() { multiPane.setButtonEnabled(MultiStepPane.ALL_BUTTONS, false); setProgressUI(); boolean overwrite = overwriteCB.isSelected(); ArrayList tiersToAdd = new ArrayList(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) secTree.getModel() .getRoot(); DefaultMutableTreeNode node = null; SelectableObject so = null; Enumeration en = root.preorderEnumeration(); en.nextElement(); while (en.hasMoreElements()) { node = (DefaultMutableTreeNode) en.nextElement(); so = (SelectableObject) node.getUserObject(); if (so.isSelected()) { tiersToAdd.add(so.getValue()); } } // com = new MergeTranscriptionsCommand("MergeTranscriptions"); ((MergeTranscriptionsCommand) com).addProgressListener(this); // receiver is destination transcrption Object[] args = new Object[] { secTrans, destFileName, tiersToAdd, new Boolean(overwrite) }; com.execute(destTrans, args); // new Thread is started, return false return false; } /** * @see mpi.eudico.client.annotator.util.ProgressListener#progressUpdated(java.lang.Object, * int, java.lang.String) */ public void progressUpdated(Object source, int percent, String message) { if (progressPanel.isVisible()) { progressLabel.setText(message); if (percent < 0) { percent = 0; } else if (percent > 100) { percent = 100; } progressBar.setValue(percent); } } /** * @see mpi.eudico.client.annotator.util.ProgressListener#progressCompleted(java.lang.Object, * java.lang.String) */ public void progressCompleted(Object source, String message) { if (progressPanel.isVisible()) { progressLabel.setText(message); progressBar.setValue(100); if (com != null) { // merge process complete Object standalone = multiPane.getStepProperty("Standalone"); int option = JOptionPane.showOptionDialog(this, (message + "\nOpen new transcription in ELAN?"), null, JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { ElanLocale.getString("Button.Yes"), ElanLocale.getString("Button.No") }, ElanLocale.getString("Button.Yes")); if (option == JOptionPane.YES_OPTION) { //could open from transcription, but use the file to be sure... //new ElanFrame2(destFileName); FrameManager.getInstance().createFrame(destFileName); // check if we are standalone if (standalone != null) { // no need to check the actual value of standalone multiPane.putStepProperty("CanQuit", Boolean.FALSE); } multiPane.close(); } else { if (standalone == null) { multiPane.close(); } else { // ask wether more merging should be done. multiPane.previousStep(); } } } } } /** * @see mpi.eudico.client.annotator.util.ProgressListener#progressInterrupted(java.lang.Object, * java.lang.String) */ public void progressInterrupted(Object source, String message) { if (progressPanel.isVisible()) { progressLabel.setText(message); if (com != null) { showWarningDialog("An error occured: " + message); multiPane.close(); } } } /** * Shows a warning/error dialog with the specified message string. * * @param message the message to display */ private void showWarningDialog(String message) { JOptionPane.showMessageDialog(this, message, ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); } /** * Copies all parts of a Transcription to a new transcription. * * @param inTrans the source transcription * * @return a copy of the transcription */ private TranscriptionImpl copyTranscription(TranscriptionImpl inTrans) { TranscriptionImpl destTr = new TranscriptionImpl(); destTr.setNotifying(false); if (inTrans == null) { return destTr; } TranscriptionCopier copier = new TranscriptionCopier(); copier.copyTranscription(inTrans, destTr); return destTr; } /** * Checks whether tiers should be selected or deselected based on * dependencies and available tiers in the destination after a change in * the selected state of a tier. * * @param node the node containing the selected tier */ private void checkSelection(DefaultMutableTreeNode node) { if (node == null) { return; } Object obj = node.getUserObject(); if (!(obj instanceof SelectableObject)) { return; } boolean selected = ((SelectableObject) obj).isSelected(); String tierName = ((SelectableObject) obj).toString(); DefaultMutableTreeNode nextNode = null; SelectableObject so = null; String nextName = null; TierImpl t1; TierImpl t2 = null; if (!selected) { // check selected children Enumeration en = node.breadthFirstEnumeration(); en.nextElement(); while (en.hasMoreElements()) { nextNode = (DefaultMutableTreeNode) en.nextElement(); so = (SelectableObject) nextNode.getUserObject(); if (so.isSelected()) { nextName = (String) so.getValue(); t1 = (TierImpl) secTrans.getTierWithId(nextName); t2 = (TierImpl) destTrans.getTierWithId(nextName); if (t2 == null) { if ((destTrans.getTierWithId(t1.getParentTier().getName()) == null) || !lingTypeCompatible( (TierImpl) destTrans.getTierWithId( t1.getParentTier().getName()), (TierImpl) t1.getParentTier())) { so.setSelected(false); } } else if (!lingTypeCompatible(t1, t2)) { so.setSelected(false); } } } } else { // selected if (node.getLevel() > 1) { // check this node and if necessary its ancestors nextNode = node; while (!nextNode.isRoot()) { so = (SelectableObject) nextNode.getUserObject(); tierName = (String) so.getValue(); t1 = (TierImpl) secTrans.getTierWithId(tierName); t2 = (TierImpl) destTrans.getTierWithId(tierName); if ((t2 != null)) { if (lingTypeCompatible(t1, t2)) { break; // don't need to change anything } else { so.setSelected(false); break; } } else { so.setSelected(true); } nextNode = (DefaultMutableTreeNode) nextNode.getParent(); } } } secTree.repaint(); } /** * Check whether the LinguisticTypes of the tiers have the same stereotype. * This is a loose check, other attributes could also be checked; name, cv * etc. * * @param t the first tier for the comparison * @param t2 the second tier * * @return true if the Linguistic Type of the tiers have the same stereotype */ private boolean lingTypeCompatible(TierImpl t, TierImpl t2) { // check linguistic type LinguisticType lt = t.getLinguisticType(); LinguisticType lt2 = t2.getLinguisticType(); // losely check the linguistic types if ( /*lt.getLinguisticTypeName().equals(lt2.getLinguisticTypeName()) &&*/ lt.hasConstraints() == lt2.hasConstraints()) { if (lt.getConstraints() != null) { if (lt.getConstraints().getStereoType() == lt2.getConstraints() .getStereoType()) { return true; } else { // LOG.warning("Incompatible tier types in source and destination: " + t.getName()); return false; } } else { // both toplevel tiers return true; } } return false; } /** * Listen for a change in the selected state of a tier tree node. */ class TreeMouseListener extends MouseAdapter { /** * The mouse clicked event. * * @param me the mouse event */ public void mouseClicked(MouseEvent me) { int selRow = secTree.getRowForLocation(me.getX(), me.getY()); TreePath path = secTree.getPathForLocation(me.getX(), me.getY()); if (selRow != -1) { checkSelection((DefaultMutableTreeNode) path.getLastPathComponent()); } } } /** * The loading of the transcription is done in a separate thread. * * @author Han Sloetjes * @version 1.0 */ class LoadThread extends Thread { private boolean loadFirst = true; private boolean loadSec = true; /** * Creates a new LoadThread instance */ LoadThread() { } /** * Creates a new LoadThread instance * * @param loadFirst if true the first source should be loaded/copied * @param loadSec if true the second source should be loaded */ LoadThread(boolean loadFirst, boolean loadSec) { this.loadFirst = loadFirst; this.loadSec = loadSec; } /** * The run method; loads and updates the progress ui. */ public void run() { try { progressUpdated(this, 5, "Loading first transcription..."); if (loadFirst) { if (firstSource instanceof String) { firstTrans = new TranscriptionImpl((String) firstSource); destTrans = firstTrans; } else { firstTrans = (TranscriptionImpl) firstSource; destTrans = copyTranscription(firstTrans); } } progressUpdated(this, 40, "Loading second transcription..."); if (loadSec) { secTrans = new TranscriptionImpl(secondSource); } progressUpdated(this, 80, "Fetching tiers..."); // init two tier trees progressCompleted(this, ""); setTierTreeUI(); multiPane.setButtonEnabled(MultiStepPane.PREVIOUS_BUTTON, true); multiPane.setButtonEnabled(MultiStepPane.CANCEL_BUTTON, true); multiPane.setButtonEnabled(MultiStepPane.FINISH_BUTTON, true); fillTrees(); } catch (Exception ex) { progressInterrupted(this, "An error occurred: " + ex.getMessage()); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -