📄 editcvdialog.java
字号:
private File getImportFile() { // setup a file chooser String dir = (String) Preferences.get("LastUsedEAFDir", null); if (dir == null) { dir = (new File(transcription.getName())).getParent(); if (dir == null) { dir = System.getProperty("user.dir"); } } JFileChooser chooser = new JFileChooser(dir); chooser.setDialogTitle(ElanLocale.getString("Button.Import")); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); chooser.addChoosableFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.EAF_TYPE)); chooser.setFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.TEMPLATE_TYPE)); JTextArea textAr = new JTextArea(ElanLocale.getString( "EditCVDialog.Message.Browse")); textAr.setBackground(chooser.getBackground()); textAr.setWrapStyleWord(true); textAr.setLineWrap(true); textAr.setEditable(false); textAr.setPreferredSize(new Dimension(160, 100)); textAr.setMargin(new Insets(5, 5, 5, 5)); chooser.setAccessory(textAr); int option = chooser.showOpenDialog(this); if (option == JFileChooser.CANCEL_OPTION) { return null; } else if (option == JFileChooser.APPROVE_OPTION) { File impFile = chooser.getSelectedFile(); String filePath = impFile.getAbsolutePath(); if (!impFile.exists() || impFile.isDirectory()) { StringBuffer strMessage = new StringBuffer(ElanLocale.getString( "Menu.Dialog.Message1")); strMessage.append(impFile.getName()); strMessage.append(ElanLocale.getString("Menu.Dialog.Message2")); String strError = ElanLocale.getString("Message.Error"); JOptionPane.showMessageDialog(this, strMessage, strError, JOptionPane.ERROR_MESSAGE); return null; } if (!filePath.toLowerCase().endsWith(".etf") && !filePath.toLowerCase().endsWith(".eaf")) { StringBuffer strMessage = new StringBuffer(ElanLocale.getString( "Menu.Dialog.Message1")); strMessage.append(impFile.getName()); strMessage.append(ElanLocale.getString("Menu.Dialog.Message3")); String strError = ElanLocale.getString("Message.Error"); JOptionPane.showMessageDialog(this, strMessage, strError, JOptionPane.ERROR_MESSAGE); return null; } Preferences.set("LastUsedEAFDir", impFile.getParent(), null); return impFile; } return null; } /** * Adds an existing, imported CV, probably already containing entries to * the Transcription. * * @param conVoc the CV to add * * @see #importCV() */ private void addCV(ControlledVocabulary conVoc) { if (conVoc == null) { return; } //create a new CV and add it to the Transcription Command com = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.ADD_CV); Object[] args = new Object[1]; args[0] = conVoc; com.execute(transcription, args); //reextractCVs() is done somewhere else } /** * Imports a or several CV's from a template file, selected by the user. * When there are CV's with the same identifier as existing CV's the user * is prompted to either replace an existing CV or rename the imported CV * or just skip the CV. */ private void importCV() { File importFile = getImportFile(); if (importFile == null) { return; } // use an eaf skeleton parser, can handle etf as well as eaf EAFSkeletonParser skelParser = null; try { skelParser = new EAFSkeletonParser(importFile.getAbsolutePath()); skelParser.parse(); } catch (ParseException pe) { showWarningDialog(ElanLocale.getString( "EditCVDialog.Message.ReadError") + importFile.getAbsolutePath()); LOG.warning("Could not parse the file: " + pe.getMessage()); return; } ArrayList allCVs = skelParser.getControlledVocabularies(); if (allCVs.size() == 0) { showWarningDialog(ElanLocale.getString( "EditCVDialog.Message.NoCVFound")); return; } ControlledVocabulary cv = null; //now add them to the transcription, ensuring that all CV-names are unique for (int i = 0; i < allCVs.size(); i++) { cv = (ControlledVocabulary) allCVs.get(i); if (transcription.getControlledVocabulary(cv.getName()) != null) { // cv with that name already exists: prompt user: // replace, rename, merge or skip int option = showCVQuestionDialog(cv.getName()); if (option == REPLACE) { replaceCV(cv); } else if (option == RENAME) { String newName; while (true) { newName = showAskNameDialog(cv.getName()); if (transcription.getControlledVocabulary(newName) != null) { showWarningDialog(ElanLocale.getString( "EditCVDialog.Message.CVExists")); continue; } break; } if ((newName == null) || (newName.length() == 0)) { continue; //means skipping } cv.setName(newName); addCV(cv); } else if (option == MERGE) { mergeCVs(cv); } // else continue... } else { // the transcription does not contain a cv with the same name, add it addCV(cv); } } updateComboBox(); } /** * Deletes an existing CV with the name of the specified CV and adds the * specified CV. The user is not promted or warned. * * @param conVoc the new ControlledVocabulary */ private void replaceCV(ControlledVocabulary conVoc) { String name = conVoc.getName(); ControlledVocabulary oldCv = transcription.getControlledVocabulary(name); if (oldCv != null) { Command com = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.REPLACE_CV); com.execute(transcription, new Object[] { oldCv, conVoc }); } } /** * Merges two CV's with the same name; entries present in the second cv that are not in the first cv * are added to the first cv. * * @param conVoc the second cv */ private void mergeCVs(ControlledVocabulary conVoc) { String name = conVoc.getName(); ControlledVocabulary oldCv = transcription.getControlledVocabulary(name); if (oldCv != null) { Command com = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.MERGE_CVS); com.execute(transcription, new Object[] { oldCv, conVoc }); } } /** * Prompts the user to enter a new name for a CV. * * @param name the old name * * @return the new name, or null when the user has cancelled the dialog */ private String showAskNameDialog(String name) { String message = ElanLocale.getString("EditCVDialog.Message.NewName") + "\n\n- " + name; String newName = JOptionPane.showInputDialog(this, message, ElanLocale.getString("EditCVDialog.Message.Rename"), JOptionPane.QUESTION_MESSAGE); return newName; } /** * Ask the user to skip, replace existing cv or rename importing cv. * * @param cvName name of the cv * * @return 0 means skip, 1 means replace and 2 means rename */ private int showCVQuestionDialog(String cvName) { String[] options = new String[4]; options[0] = ElanLocale.getString("EditCVDialog.Message.Skip"); options[1] = ElanLocale.getString("EditCVDialog.Message.Replace"); options[2] = ElanLocale.getString("EditCVDialog.Message.Rename"); options[3] = ElanLocale.getString("EditCVDialog.Message.Merge"); String message = ElanLocale.getString("EditCVDialog.Message.CVExists") + "\n\n- " + cvName + "\n"; JOptionPane pane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options); pane.createDialog(this, "").show(); Object selValue = pane.getValue(); for (int i = 0; i < options.length; i++) { if (selValue == options[i]) { return i; } } return SKIP; } /** * Add the Escape and Ctrl-W close actions. */ protected void addCloseActions() { EscCloseAction escAction = new EscCloseAction(this); CtrlWCloseAction wAction = new CtrlWCloseAction(this); InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = getRootPane().getActionMap(); if (inputMap instanceof ComponentInputMap && (actionMap != null)) { String esc = "esc"; inputMap.put((KeyStroke) escAction.getValue(Action.ACCELERATOR_KEY), esc); actionMap.put(esc, escAction); String wcl = "cw"; inputMap.put((KeyStroke) wAction.getValue(Action.ACCELERATOR_KEY), wcl); actionMap.put(wcl, wAction); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -