📄 mergetranscriptions.java
字号:
"MergeTranscriptionDialog.Label.Source2")); selectDestLabel.setText(ElanLocale.getString( "MergeTranscriptionDialog.Label.Destination")); browseSource1.setText(ElanLocale.getString("Button.Browse")); browseSource2.setText(ElanLocale.getString("Button.Browse")); browseDest.setText(ElanLocale.getString("Button.Browse")); startButton.setText(ElanLocale.getString( "MergeTranscriptionDialog.Button.Merge")); closeButton.setText(ElanLocale.getString("Button.Close")); } /** * Pack, size and set location. */ protected void postInit() { pack(); int w = 550; int h = 400; setSize((getSize().width < w) ? w : getSize().width, (getSize().height < h) ? h : getSize().height); setLocationRelativeTo(getParent()); setResizable(false); } /** * Closes the dialog * * @param evt the window closing event */ protected void closeDialog(WindowEvent evt) { setVisible(false); dispose(); if (exitOnClose) { System.exit(0); } } /** * Start the merging process. First some checks are performed on the * contents of the fields for the source and destination files, next a * TranscriptionMerger object is created, then we register as a * progresslistener so that a progressbar can visualize the progress of * the merging process, and finally the merging process is started. */ private void startMerge() { if (transcription == null) { // check first source if (!checkValidEAFFile(source1Field.getText())) { showWarningDialog(ElanLocale.getString( "MergeTranscriptionDialog.Warning.Source1")); return; } } if (!checkValidEAFFile(source2Field.getText())) { showWarningDialog(ElanLocale.getString( "MergeTranscriptionDialog.Warning.Source2")); return; } String dest = destField.getText(); if ((dest == null) || (dest.length() < 4)) { showWarningDialog(ElanLocale.getString( "MergeTranscriptionDialog.Warning.NoDestination")); return; } if (checkValidEAFFile(destField.getText())) { int answer = JOptionPane.showConfirmDialog(null, ElanLocale.getString( "MergeTranscriptionDialog.Warning.DestinationExists"), ElanLocale.getString("Message.Warning"), JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.NO_OPTION) { return; } } // start the merging process TranscriptionMerger merger = null; try { if (transcription != null) { merger = new TranscriptionMerger(transcription, source2Field.getText(), destField.getText()); } else { merger = new TranscriptionMerger(source1Field.getText(), source2Field.getText(), destField.getText()); } } catch (IOException ioe) { showWarningDialog(ioe.getMessage()); return; } catch (Exception e) { showWarningDialog(e.getMessage()); return; } if (merger != null) { activateUI(false); progressPanel.setVisible(true); merger.addProgressListener(this); merger.startMerge(); } } /** * Let the user browse to the first source eaf. */ private void browseFirstSource() { String name = promptForFileName(); if (name != null) { source1Field.setText(name); if (progressPanel.isVisible()) { progressLabel.setText(""); progressBar.setValue(0); } } } /** * Let the user browse to the second source eaf. */ private void browseSecondSource() { String name = promptForFileName(); if (name != null) { source2Field.setText(name); if (progressPanel.isVisible()) { progressLabel.setText(""); progressBar.setValue(0); } } } /** * Let the user browse to and/or typ the destination eaf. */ private void browseDestination() { String name = promptForFileName(); if (name != null) { destField.setText(name); if (progressPanel.isVisible()) { progressLabel.setText(""); progressBar.setValue(0); } } } /** * Prompts the user for a file name and location. * * @return a file path */ private String promptForFileName() { 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(null) == 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(); 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; } } if (!validExt) { name += ("." + exts[0]); eafFile = new File(name); } return name; } else { return null; } } else { // dialog canceled return null; } } /** * Checks whether the file exists and has the extension eaf. * * @param path the file path * * @return true if the file exists and is an eaf file, false otherwise */ private boolean checkValidEAFFile(String path) { if ((path == null) || (path.length() == 0)) { return false; } if (new File(path).exists()) { String lowerPathName = path.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; } } if (validExt) { return true; } } return false; } /** * The action performed event handling. * * @param ae the action event */ public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); if (source == startButton) { startMerge(); } else if (source == closeButton) { closeDialog(null); } else if (source == browseSource1) { browseFirstSource(); } else if (source == browseSource2) { browseSecondSource(); } else if (source == browseDest) { browseDestination(); } } /** * Creates the dialog as a standalone application. * * @param args not used */ public static void main(String[] args) { exitOnClose = true; new MergeTranscriptions(null).setVisible(true); } /** * Shows a warning/error dialog with the specified message string. * * @param message the message to display */ protected void showWarningDialog(String message) { JOptionPane.showMessageDialog(this, message, ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); } /** * Receives progress update notifications. * * @param source the source of the notification * @param percent the progress value. [0 - 100] * @param message a description of the progress */ 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); } if (percent >= 100) { activateUI(true); } } /** * Notification that the process has been completed. * * @param source the source of the notification * @param message a description of the progress */ public void progressCompleted(Object source, String message) { if (progressPanel.isVisible()) { progressLabel.setText(message); progressBar.setValue(100); } activateUI(true); } /** * Notification that the process has been interrupted. * * @param source the source of the notification * @param message a description of the progress */ public void progressInterrupted(Object source, String message) { if (progressPanel.isVisible()) { progressLabel.setText(message); } activateUI(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -