📄 edittierdialog2.java
字号:
/** * Fills the parent tier combobox with the potential parent tiers for the * specified tier. */ private void fillParentComboBox() { parentComboBox.removeItemListener(this); parentComboBox.removeAllItems(); parentComboBox.addItem(none); if ((tier != null) && (mode != ADD)) { Vector candidateParents = transcription.getCandidateParentTiers(tier); Iterator pIter = candidateParents.iterator(); while (pIter.hasNext()) { parentComboBox.addItem(((Tier) pIter.next()).getName()); } if (tier.hasParentTier()) { parentComboBox.setSelectedItem(tier.getParentTier().getName()); } } else if (mode == ADD) { Iterator tierIt = tiers.iterator(); while (tierIt.hasNext()) { TierImpl t = (TierImpl) tierIt.next(); parentComboBox.addItem(t.getName()); } parentComboBox.setSelectedItem(none); } parentComboBox.addItemListener(this); } /** * Gets the Locale of the currently selected tier and tries to set this * Locale as the selected item in the language combo box.<br> * If the tier has a Locale that is not in the list, add it to the list. */ private void updateLanguageComboBox() { languageComboBox.removeAllItems(); if (langs != null) { for (int i = 0; i < langs.length; i++) { if ((i == 0) && (langs[i] == Locale.getDefault())) { languageComboBox.addItem(langs[i].getDisplayName() + " (System default)"); } else { languageComboBox.addItem(langs[i].getDisplayName()); } } } if (tier != null) { Locale l = tier.getDefaultLocale(); if (l != null) { /* List al = Arrays.asList(langs); if (!al.contains(l)) { languageComboBox.addItem(l.getDisplayName()); } */ languageComboBox.setSelectedItem(l.getDisplayName()); } else { languageComboBox.setSelectedIndex(0); } } } /** * Updates ui elements for a certain selected tier, e.g. after committing a * change to the set of tiers. * * @param name the name of the selected tier */ private void updateUIForTier(String name) { if (name != null) { tier = (TierImpl) transcription.getTierWithId(name); if (tier != null) { if (currentTiersComboBox.getSelectedItem() != tier.getName()) { currentTiersComboBox.setSelectedItem(name); } oldParentTier = (TierImpl) tier.getParentTier(); if (oldParentTier != null) { oldParentTierName = tier.getParentTier().getName(); } else { oldParentTierName = none; } oldLingType = tier.getLinguisticType(); oldLocale = tier.getDefaultLocale(); oldTierName = tier.getName(); oldParticipant = tier.getParticipant(); oldAnnotator = tier.getAnnotator(); if (mode != ADD) { tierNameTextField.setText(oldTierName); participantTextField.setText(oldParticipant); annotatorTextField.setText(oldAnnotator); if (mode == CHANGE) { if (tier.getNumberOfAnnotations() == 0) { parentComboBox.setEnabled(true); } } } } fillParentComboBox(); fillLingTypeMenu(); updateLanguageComboBox(); // update table if (model != null) { tierTable.getSelectionModel().removeListSelectionListener(this); int col = model.findColumn(TierTableModel.NAME); for (int i = 0; i < model.getRowCount(); i++) { if (name.equals(model.getValueAt(i, col))) { tierTable.getSelectionModel().setLeadSelectionIndex(i); break; } } tierTable.getSelectionModel().addListSelectionListener(this); } } else { fillParentComboBox(); fillLingTypeMenu(); } } /** * Adds a new tier to the transcription. * * @param tierName the name of the new tier * @param parentTier the parent tier, can be null * @param lingType the Linguistic Type name * @param participant the participant value for the tier * @param annotator the annotator of the tier * @param locale the default language for the tier */ private void doAdd(String tierName, Tier parentTier, String lingType, String participant, String annotator, Locale locale) { Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.ADD_TIER); Object receiver = transcription; Object[] args = new Object[6]; args[0] = tierName; args[1] = parentTier; args[2] = lingType; args[3] = participant; args[4] = annotator; args[5] = locale; c.execute(receiver, args); // update the dialog ui reextractTiers(); updateUIForTier(null); // warn if this is the first tier with a linguistic type // allowing graphic refs. TierImpl tt = (TierImpl) transcription.getTierWithId(tierName); if ((tt != null) && tt.getLinguisticType().hasGraphicReferences()) { checkGraphics(tt); } } /** * Changes properties of a tier. * * @param tierName new name of the tier * @param parentTier the parent tier * @param lingType the linguistic type * @param participant the participant * @param annotator the annotator of the tier * @param locale the locale */ private void doChange(String tierName, Tier parentTier, String lingType, String participant, String annotator, Locale locale) { // double check on parent and type if (tier.getNumberOfAnnotations() > 0) { if (((parentTier != null) && (oldParentTier == null)) || ((parentTier == null) && (oldParentTier != null)) || (parentTier != oldParentTier)) { parentTier = oldParentTier; } if (getStereoTypeForTypeName(lingType) != getStereoTypeForType( oldLingType)) { lingType = oldLingType.getLinguisticTypeName(); } } // check whether something has changed if (!tierName.equals(oldTierName) || ((parentTier != null) && (oldParentTier != null) && (parentTier != oldParentTier)) || !lingType.equals(oldLingType.getLinguisticTypeName()) || !participant.equals(oldParticipant) || !annotator.equals(oldAnnotator) || ((locale != null) && (locale != oldLocale))) { Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.CHANGE_TIER); Object receiver = tier; Object[] args = new Object[6]; args[0] = tierName; args[1] = parentTier; args[2] = lingType; args[3] = participant; args[4] = annotator; args[5] = locale; c.execute(receiver, args); // notify if this is the first tier allowing graphic references if (tier.getLinguisticType().hasGraphicReferences() && !lingType.equals(oldLingType.getLinguisticTypeName())) { checkGraphics(tier); } if (singleEditMode) { // dispose dispose(); } else { // update the dialog ui reextractTiers(); } } else { //System.out.println("no change"); } } /** * Actually deletes the tier. */ private void doDelete() { if (tier != null) { Vector depTiers = tier.getDependentTiers(); StringBuffer mesBuf = new StringBuffer(); mesBuf.append(ElanLocale.getString( "EditTierDialog.Message.ConfirmDelete")); mesBuf.append(" "); mesBuf.append(oldTierName); mesBuf.append(" ?\n"); if ((depTiers != null) && (depTiers.size() > 0)) { mesBuf.append(ElanLocale.getString( "EditTierDialog.Message.AlsoDeleted")); Iterator depIt = depTiers.iterator(); while (depIt.hasNext()) { Tier t = (Tier) depIt.next(); mesBuf.append("\n- "); mesBuf.append(t.getName()); } } int option = JOptionPane.showConfirmDialog(this, mesBuf.toString(), ElanLocale.getString("Message.Warning"), JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { Object[] args = new Object[] { tier }; Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.DELETE_TIER); c.execute(transcription, args); if (singleEditMode) { // dispose dispose(); } else { // update the dialog ui reextractTiers(); } } } } /** * Imports tiers (without annotations) from an eaf or etf. */ private void doImport() { String fileName = importSourceTF.getText(); if (!isValidFile(fileName)) { JOptionPane.showMessageDialog(this, ElanLocale.getString("EditTierDialog.Message.SelectValid"), ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); return; } Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.IMPORT_TIERS); c.execute(transcription, new Object[] { fileName }); reextractTiers(); updateUIForTier(null); } /** * Prompts the user to browse to an eaf or etf file, checks a little and * updates the ui. */ private void promptForImportFile() { 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( "EditTierDialog.Title.Select")); File eafFile = null; FileFilter filter = ElanFileFilter.createFileFilter(ElanFileFilter.EAF_TYPE); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter(filter); chooser.addChoosableFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.TEMPLATE_TYPE)); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File curDir = chooser.getCurrentDirectory(); if (curDir != null) { Preferences.set("LastUsedEAFDir", curDir.getAbsolutePath(), null); } eafFile = chooser.getSelectedFile();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -