📄 edittypedialog2.java
字号:
String errorMessage = ElanLocale.getString( "EditTypeDialog.Message.UnknownError"); JOptionPane.showMessageDialog(this, errorMessage, ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); //dispose(); return; } String oldCV = null; if (lt.isUsingControlledVocabulary()) { oldCV = lt.getControlledVocabylaryName(); } boolean oldGraphicsRef = lt.hasGraphicReferences(); String cons = (String) constraintsComboBox.getSelectedItem(); Constraint c = getConstraintForName(cons); String cvName = (String) cvComboBox.getSelectedItem(); if (cvName.equals(none)) { cvName = null; } boolean alignable = timeAlignableCheckbox.isSelected(); boolean graphicsRef = graphicReferencesCheckbox.isSelected(); // if nothing has changed do nothing if (name.equals(oldName) && (((c == null) && (lt.getConstraints() == null)) || (c == lt.getConstraints())) && (((oldCV == null) && (cvName == null)) || ((oldCV != null) && oldCV.equals(cvName))) && (lt.isTimeAlignable() == alignable) && (oldGraphicsRef == graphicsRef)) { return; } // warn if graphic references allowed has been deselected... if (oldGraphicsRef && !graphicsRef) { String warning = ElanLocale.getString( "EditTypeDialog.Message.GraphicsLost") + "\n" + ElanLocale.getString("EditTypeDialog.Message.Confirm"); int option = JOptionPane.showConfirmDialog(this, warning, ElanLocale.getString("Message.Warning"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (option != JOptionPane.YES_OPTION) { return; } } if (graphicsRef) { // check whether there are tiers using this type and // whether these are the first tiers allowing graphic refs checkGraphics(lt); } //create and execute a command Object[] args = new Object[6]; args[0] = name; args[1] = c; args[2] = cvName; args[3] = new Boolean(alignable); args[4] = new Boolean(graphicsRef); args[5] = lt; Command com = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.CHANGE_TYPE); com.execute(transcription, args); reextractTypes(); //dispose(); } private void doDelete() { String oldName = (String) currentTypesComboBox.getSelectedItem(); LinguisticType lt = null; Iterator tIter = types.iterator(); while (tIter.hasNext()) { lt = (LinguisticType) tIter.next(); if (lt.getLinguisticTypeName().equals(oldName)) { break; } } if (lt == null) { // something is wrong String errorMessage = ElanLocale.getString( "EditTypeDialog.Message.UnknownError"); JOptionPane.showMessageDialog(this, errorMessage, ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); //dispose(); return; } else { //warn Vector clientTiers = transcription.getTiersWithLinguisticType(oldName); if (clientTiers.size() > 0) { StringBuffer errorBuffer = new StringBuffer(ElanLocale.getString( "EditTypeDialog.Message.TypeInUse")); errorBuffer.append(":\n"); Iterator clIter = clientTiers.iterator(); while (clIter.hasNext()) { errorBuffer.append("- "); errorBuffer.append(((Tier) clIter.next()).getName()); errorBuffer.append("\n"); } errorBuffer.append(ElanLocale.getString( "EditTypeDialog.Message.Reassign")); JOptionPane.showMessageDialog(this, errorBuffer.toString(), ElanLocale.getString("Message.Warning"), JOptionPane.ERROR_MESSAGE); return; } } //create and execute a command Command com = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.DELETE_TYPE); com.execute(transcription, new Object[] { lt }); reextractTypes(); //dispose(); } /** * Imports tiers (without annotations) from an eaf or etf. */ private void doImport() { String fileName = importSourceTF.getText(); if (!isValidFile(fileName)) { // reuse message from import tiers... JOptionPane.showMessageDialog(this, ElanLocale.getString("EditTierDialog.Message.SelectValid"), ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); return; } Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.IMPORT_TYPES); c.execute(transcription, new Object[] { fileName }); reextractTypes(); updateUIForType(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(); 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; } /** * DOCUMENT ME! * * @param event DOCUMENT ME! */ public void actionPerformed(ActionEvent event) { if (event.getSource() == changeButton) { if (mode == DELETE) { doDelete(); } else if (mode == IMPORT) { doImport(); } else { String typeName = typeTextField.getText(); typeName.replace('\n', ' '); typeName.trim(); if (typeName.length() == 0) { String errorMessage = ElanLocale.getString( "EditTypeDialog.Message.TypeName"); typeTextField.requestFocus(); JOptionPane.showMessageDialog(this, errorMessage, ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); return; } else { switch (mode) { case ADD: doAdd(typeName); break; case CHANGE: doChange(typeName); break; default: return; } } } } else if (event.getSource() == importSourceButton) { promptForImportFile(); } else { dispose(); } } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void itemStateChanged(ItemEvent e) { if ((e.getSource() == currentTypesComboBox) && (e.getStateChange() == ItemEvent.SELECTED)) { String name = (String) currentTypesComboBox.getSelectedItem(); if (name != null) { updateUIForType(name); } } else if ((e.getSource() == constraintsComboBox) && (e.getStateChange() == ItemEvent.SELECTED)) { String constraint = (String) constraintsComboBox.getSelectedItem(); if ((constraint == "Symbolic Subdivision") || (constraint == "Symbolic Association")) { timeAlignableCheckbox.setSelected(false); graphicReferencesCheckbox.setSelected(false); // ?? graphicReferencesCheckbox.setEnabled(false); } else { timeAlignableCheckbox.setSelected(true); graphicReferencesCheckbox.setEnabled(true); } //if ((e.getSource() == constraints) && (oldType != null)) { // warn if tiers use the type if ((mode == CHANGE) && (oldConstraint != constraint)) { String typeName = (String) currentTypesComboBox.getSelectedItem(); Vector tiers = transcription.getTiersWithLinguisticType(typeName); if (tiers.size() > 0) { StringBuffer mesBuf = new StringBuffer(ElanLocale.getString( "EditTypeDialog.Message.TypeInUse")); mesBuf.append("\n"); mesBuf.append(ElanLocale.getString( "EditTypeDialog.Message.Corrupt")); JOptionPane.showMessageDialog(null, mesBuf.toString(), ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); /* // HB, 9 may 03, restore old stereotype Constraint oldC = oldType.getConstraints(); String oldStereoType = none; if (oldC != null) { oldStereoType = Constraint.stereoTypes[oldC.getStereoType()]; } constraints.setSelectedItem(oldStereoType); */ updateUIForType(typeName); } } } } /** * 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 (currentTypesComboBox.getItemCount() > 0) { String name = (String) currentTypesComboBox.getSelectedItem(); updateUIForType(name); } } } /** * Update the ui after selection of a type in the table. * * @param e the list selection event */ public void valueChanged(ListSelectionEvent e) { if (mode == ADD) { return; } int row = typeTable.getSelectedRow(); if (row > -1) { int column = model.findColumn(LinguisticTypeTableModel.NAME); updateUIForType((String) model.getValueAt(row, column)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -