📄 mergestep1.java
字号:
} /** * Prompts the user to browse to a valid .eaf file. * * @return a String representation of a file */ private String getOpenFileName() { String eafDir = (String) Preferences.get("LastUsedEAFDir", null); if (eafDir == null) { eafDir = System.getProperty("user.dir"); } JFileChooser chooser = new JFileChooser(); // the file chooser is not really part of the localisation chooser.setApproveButtonText("Select"); chooser.setCurrentDirectory(new File(eafDir)); chooser.setDialogTitle(ElanLocale.getString( "MergeTranscriptionDialog.SelectEAF")); File eafFile = null; FileFilter filter = ElanFileFilter.createFileFilter(ElanFileFilter.EAF_TYPE); chooser.setFileFilter(filter); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File curDir = chooser.getCurrentDirectory(); if (curDir != null) { Preferences.set("LastUsedEAFDir", curDir.getAbsolutePath(), null); } eafFile = chooser.getSelectedFile(); if (eafFile != null) { String name = eafFile.getAbsolutePath(); if (isExistingEAF(name)) { return name; } else { return null; } } else { return null; } } else { // dialog canceled return null; } } /** * Prompts the user to provide a filepath for a new .eaf file. * * @return a String representation of a file */ private String getSaveFileName() { String eafDir = (String) Preferences.get("LastUsedEAFDir", null); if (eafDir == null) { eafDir = System.getProperty("user.dir"); } JFileChooser chooser = new JFileChooser(); // the file chooser is not really part of the localisation chooser.setApproveButtonText("Save"); chooser.setCurrentDirectory(new File(eafDir)); chooser.setDialogTitle(ElanLocale.getString( "MergeTranscriptionDialog.SelectEAF")); File eafFile = null; FileFilter filter = ElanFileFilter.createFileFilter(ElanFileFilter.EAF_TYPE); chooser.setFileFilter(filter); if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File curDir = chooser.getCurrentDirectory(); if (curDir != null) { Preferences.set("LastUsedEAFDir", curDir.getAbsolutePath(), null); } eafFile = chooser.getSelectedFile(); if (eafFile != null) { String name = eafFile.getAbsolutePath(); if (!validEAFName(name)) { name += ("." + FileExtension.EAF_EXT[0]); } File f = new File(name); if (f.exists()) { if (JOptionPane.showConfirmDialog(null, (name + "\n" + ElanLocale.getString( "MergeTranscriptionDialog.Warning.DestinationExists")), ElanLocale.getString("Message.Warning"), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { return null; } return name; } return name; } else { return null; } } else { // dialog canceled return null; } } /** * Checks if a filename points to an exisitng .eaf file. * * @param fileName a String representation of a file * * @return true if the file exists and is an .eaf, false otherwise */ private boolean isExistingEAF(String fileName) { if (fileName == null) { return false; } File f = new File(fileName); if (!f.exists()) { return false; } return validEAFName(fileName); } /** * Checks the extension of the filename. * * @param name the filename * * @return true if it ends with .eaf (case insensitive) */ private boolean validEAFName(String name) { if (name == null) { return false; } String lowerPathName = name.toLowerCase(); String[] exts = FileExtension.EAF_EXT; boolean validExt = false; for (int i = 0; i < exts.length; i++) { if (lowerPathName.endsWith("." + exts[i])) { validExt = true; break; } } return validExt; } /** * If there are valid sources and a valid destination the next button can * be enabled, after storing the file paths to the properties map. */ private void checkCondition() { if (src1Ready && src2Ready && destReady) { if (source1Field.getText().equals(source2Field.getText())) { JOptionPane.showMessageDialog(this, ElanLocale.getString( "MergeTranscriptionDialog.Warning.SameSources"), ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); multiPane.setButtonEnabled(MultiStepPane.NEXT_BUTTON, false); return; } if (source1Field.getText().equals(destField.getText()) || source2Field.getText().equals(destField.getText())) { JOptionPane.showMessageDialog(this, ElanLocale.getString( "MergeTranscriptionDialog.Warning.DestinationIsSource"), ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); multiPane.setButtonEnabled(MultiStepPane.NEXT_BUTTON, false); return; } multiPane.setButtonEnabled(MultiStepPane.NEXT_BUTTON, true); } else { multiPane.setButtonEnabled(MultiStepPane.NEXT_BUTTON, false); } } /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { if (e.getSource() == browseSource1) { String name = getOpenFileName(); if (name != null) { source1Field.setText(name); src1Ready = true; } else { if (isExistingEAF(source1Field.getText())) { src1Ready = true; } else { src1Ready = false; } } } else if (e.getSource() == browseSource2) { String name = getOpenFileName(); if (name != null) { source2Field.setText(name); src2Ready = true; } else { if (isExistingEAF(source2Field.getText())) { src2Ready = true; } else { src2Ready = false; } } } else { String name = getSaveFileName(); if (name != null) { destField.setText(name); destReady = true; } else { if ((destField.getText() != null) && (destField.getText().length() > 4)) { destReady = true; } else { destReady = false; } } } checkCondition(); } /** * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) */ public void itemStateChanged(ItemEvent e) { // only one possible source if (e.getStateChange() == ItemEvent.SELECTED) { browseSource1.setEnabled(false); source1Field.setText(curTranscription.getFullPath()); src1Ready = true; } else { browseSource1.setEnabled(true); source1Field.setText(""); src1Ready = false; } checkCondition(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -