📄 edittierdialog2.java
字号:
if (eafFile != null) { String name = eafFile.getAbsolutePath(); if (isValidFile(name)) { importSourceTF.setText(name); } } } } /** * Checks if a filename points to an exisitng .eaf or .etf file. * * @param fileName a String representation of a file * * @return true if the file exists and is an .eaf or .rtf, false otherwise */ private boolean isValidFile(String fileName) { if (fileName == null) { return false; } File f = new File(fileName); if (!f.exists()) { return false; } String lowerPathName = fileName.toLowerCase(); String[] exts = FileExtension.EAF_EXT; for (int i = 0; i < exts.length; i++) { if (lowerPathName.endsWith("." + exts[i])) { return true; } } exts = FileExtension.TEMPLATE_EXT; for (int i = 0; i < exts.length; i++) { if (lowerPathName.endsWith("." + exts[i])) { return true; } } return false; } /** * Checks whether this is the first tier with a linguistic type that allows * graphic annotations. Shows a warning message if so. * * @param ti the changed or new tier */ private void checkGraphics(TierImpl ti) { int numGraphicTiers = 1; Vector tiers2 = transcription.getTiers(); Iterator tierIt = tiers2.iterator(); TierImpl t; while (tierIt.hasNext()) { t = (TierImpl) tierIt.next(); if ((t != ti) && t.getLinguisticType().hasGraphicReferences()) { numGraphicTiers++; } } if ((numGraphicTiers == 1) && ((transcription.getSVGFile() == null) || (transcription.getSVGFile().length() == 0))) { JOptionPane.showMessageDialog(this, ElanLocale.getString("EditTierDialog.Message.Graphics"), ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); } } /** * Returns the stereotype for a linguistic type. When the linguistic type * has no constraints -1 is returned. * * @param name type name * * @return the stereotype or -1 */ private int getStereoTypeForTypeName(String name) { LinguisticType type = null; Vector types = transcription.getLinguisticTypes(); LinguisticType tempType = null; for (int i = 0; i < types.size(); i++) { tempType = (LinguisticType) types.get(i); if (tempType.getLinguisticTypeName().equals(name)) { type = tempType; break; } } return getStereoTypeForType(type); } /** * Returns the stereotype for a linguistic type. When the linguistic type * has no constraints -1 is returned. * * @param type type * * @return the stereotype or -1 */ private int getStereoTypeForType(LinguisticType type) { if ((type == null) || (type.getConstraints() == null)) { return -1; } else { return type.getConstraints().getStereoType(); } } /* (non-Javadoc) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent event) { if (event.getSource() == changeButton) { if (mode == DELETE) { doDelete(); return; } else if (mode == IMPORT) { doImport(); return; } else { String tierName = tierNameTextField.getText(); tierName.replace('\n', ' '); tierName.trim(); if (tierName.length() == 0) { tierNameTextField.requestFocus(); JOptionPane.showMessageDialog(this, ElanLocale.getString("EditTierDialog.Message.TierName"), ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); return; } if (transcription.getTierWithId(tierName) != null) { if ((mode == ADD) || ((mode == CHANGE) && !tierName.equals(oldTierName))) { tierNameTextField.requestFocus(); JOptionPane.showMessageDialog(this, ElanLocale.getString( "EditTierDialog.Message.Exists"), ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); return; } } String participant = participantTextField.getText(); String annotator = annotatorTextField.getText(); String lingType = (String) lingTypeComboBox.getSelectedItem(); Tier parentTier = transcription.getTierWithId((String) parentComboBox.getSelectedItem()); String localeName = (String) languageComboBox.getSelectedItem(); Locale locale = null; if ((languageComboBox.getSelectedIndex() == 0) && (localeName.indexOf("(System default)") > -1)) { locale = Locale.getDefault(); } else { if (langs != null) { for (int i = 0; i < langs.length; i++) { if (langs[i].getDisplayName().equals(localeName)) { locale = langs[i]; break; } } } } if (locale == null) { locale = oldLocale; } switch (mode) { case ADD: doAdd(tierName, parentTier, lingType, participant, annotator, locale); break; case CHANGE: doChange(tierName, parentTier, lingType, participant, annotator, locale); break; } } //dispose(); } else if (event.getSource() == importSourceButton) { promptForImportFile(); } else { dispose(); } } /** * ComboBox selection changes. * * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) */ public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (e.getSource() == currentTiersComboBox) { String name = (String) currentTiersComboBox.getSelectedItem(); updateUIForTier(name); } else if ((e.getSource() == lingTypeComboBox) && (mode == CHANGE)) { if ((tier != null) && (tier.getNumberOfAnnotations() > 0)) { // warn if more than 0 annotations and stereotype is different String newTypeName = (String) e.getItem(); boolean stereoTypeChanged = false; int newStereoType = getStereoTypeForTypeName(newTypeName); int oldStereoType = getStereoTypeForType(oldLingType); if (newStereoType != oldStereoType) { stereoTypeChanged = true; } if (!oldLingType.getLinguisticTypeName().equals(newTypeName) && stereoTypeChanged) { StringBuffer buf = new StringBuffer(ElanLocale.getString( "EditTierDialog.Message.RecommendType")); buf.append("\n"); buf.append(ElanLocale.getString( "EditTierDialog.Message.Corrupt")); JOptionPane.showMessageDialog(this, buf.toString(), ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); // HS sep-04 prevent changing the lin. type when there are annotations lingTypeComboBox.setSelectedItem(oldLingType.getLinguisticTypeName()); } } } else if (e.getSource() == parentComboBox) { if ((mode == CHANGE) && (tier != null) && (tier.getNumberOfAnnotations() > 0)) { if (!(oldParentTierName.equals((String) e.getItem()))) { StringBuffer buf = new StringBuffer(ElanLocale.getString( "EditTierDialog.Message.RecommendParent")); buf.append("\n"); buf.append(ElanLocale.getString( "EditTierDialog.Message.Corrupt")); JOptionPane.showMessageDialog(this, buf.toString(), ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); // HS sep-04 prevent changing the parent when there are annotations parentComboBox.setSelectedItem(oldParentTierName); } } else { // suggest the participant name from the parent... String partiName = participantTextField.getText(); if ((partiName == null) || (partiName.trim().length() == 0)) { TierImpl parent = (TierImpl) transcription.getTierWithId((String) e.getItem()); if (parent != null) { participantTextField.setText(parent.getParticipant()); } } } fillLingTypeMenu(); } } } /** * Add the editpanel to the selected tab * * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) */ public void stateChanged(ChangeEvent e) { tabPane.removeChangeListener(this); mode = tabPane.getSelectedIndex(); tabPane.removeAll(); tabPane.addTab(ElanLocale.getString("Button.Add"), null); tabPane.addTab(ElanLocale.getString("Button.Change"), null); tabPane.addTab(ElanLocale.getString("Button.Delete"), null); tabPane.addTab(ElanLocale.getString("Button.Import"), importPanel); if (mode < IMPORT) { tabPane.setComponentAt(tabPane.getSelectedIndex(), editPanel); } else { tabPane.setComponentAt(1, editPanel); } tabPane.setSelectedIndex(mode); updateForMode(); //editPanel.revalidate(); tabPane.revalidate(); tabPane.addChangeListener(this); if ((mode == CHANGE) || (mode == DELETE)) { if (currentTiersComboBox.getItemCount() > 0) { String name = (String) currentTiersComboBox.getSelectedItem(); updateUIForTier(name); } } else if (mode == ADD) { if (parentComboBox.getItemCount() > 0) { parentComboBox.setSelectedIndex(0); } } } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void valueChanged(ListSelectionEvent e) { if (mode == ADD) { return; } int row = tierTable.getSelectedRow(); if (row > -1) { int column = model.findColumn(TierTableModel.NAME); updateUIForTier((String) model.getValueAt(row, column)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -