📄 edittypedialog2.java
字号:
"EditTypeDialog.CurrentTypes"))); timeAlignableLabel.setText(ElanLocale.getString( "EditTypeDialog.Label.TimeAlignable")); graphicReferencesLabel.setText(ElanLocale.getString( "EditTypeDialog.Label.Graphics")); constraintsLabel.setText(ElanLocale.getString( "EditTypeDialog.Label.Stereotype")); cvLabel.setText(ElanLocale.getString("EditTypeDialog.Label.CV")); cancelButton.setText(ElanLocale.getString("Button.Close")); importSourceLabel.setText("<html>" + ElanLocale.getString("EditTypeDialog.Label.ImportSource") + "</html>"); importSourceButton.setText(ElanLocale.getString("Button.Browse")); } /** * Updates texts and enables/disables components for the current edit * mode. */ private void updateForMode() { switch (mode) { case ADD: setTitle(ElanLocale.getString("EditTypeDialog.Title.Add")); currentTypesLabel.setText(""); currentTypesComboBox.setEnabled(false); typeTextField.setEnabled(true); typeTextField.setEditable(true); typeTextField.setText(""); constraintsComboBox.setEnabled(true); constraintsComboBox.setSelectedItem(none); timeAlignableCheckbox.setSelected(true); graphicReferencesCheckbox.setSelected(false); cvComboBox.setEnabled(true); cvComboBox.setSelectedItem(none); changeButton.setText(ElanLocale.getString("Button.Add")); changeButton.setEnabled(true); break; case CHANGE: setTitle(ElanLocale.getString("EditTypeDialog.Title.Change")); currentTypesLabel.setText(ElanLocale.getString( "EditTypeDialog.ChangeType")); changeButton.setText(ElanLocale.getString("Button.Change")); currentTypesComboBox.setEnabled(true); typeTextField.setEnabled(true); typeTextField.setEditable(true); constraintsComboBox.setEnabled(true); cvComboBox.setEnabled(true); if (currentTypesComboBox.getModel().getSize() > 0) { updateUIForType((String) currentTypesComboBox.getItemAt(0)); currentTypesComboBox.addItemListener(this); } else { changeButton.setEnabled(false); } //oldConstraint = (String)constraints.getSelectedItem(); break; case DELETE: setTitle(ElanLocale.getString("EditTypeDialog.Title.Delete")); currentTypesLabel.setText(ElanLocale.getString( "EditTypeDialog.DeleteType")); changeButton.setText(ElanLocale.getString("Button.Delete")); currentTypesComboBox.setEnabled(true); typeTextField.setEnabled(false); typeTextField.setEditable(false); constraintsComboBox.setEnabled(false); cvComboBox.setEnabled(false); if (currentTypesComboBox.getModel().getSize() > 0) { updateUIForType((String) currentTypesComboBox.getItemAt(0)); currentTypesComboBox.addItemListener(this); //typeTextField.setText((String)currentTypes.getItemAt(0)); } else { changeButton.setEnabled(false); } typeTextField.setEditable(false); constraintsComboBox.setEnabled(false); cvComboBox.setEnabled(false); graphicReferencesCheckbox.setEnabled(false); break; case IMPORT: setTitle(ElanLocale.getString("EditTypeDialog.Title.Import")); changeButton.setText(ElanLocale.getString("Button.Import")); break; } titleLabel.setText(getTitle()); } /** * Extract the linguistic types already present in the transcription. */ private void extractCurrentTypes() { currentTypesComboBox.removeItemListener(this); currentTypesComboBox.removeAllItems(); types = transcription.getLinguisticTypes(); if (types == null) { types = new Vector(); return; } LinguisticType lt = null; Iterator tIter = types.iterator(); while (tIter.hasNext()) { lt = (LinguisticType) tIter.next(); currentTypesComboBox.addItem(lt.getLinguisticTypeName()); } currentTypesComboBox.addItemListener(this); } /** * Again axtract the types from the transcription after an add, change or * delete operation. */ private void reextractTypes() { extractCurrentTypes(); if (currentTypesComboBox.getItemCount() > 0) { currentTypesComboBox.setSelectedIndex(0); String name = (String) currentTypesComboBox.getSelectedItem(); if (name != null) { updateUIForType(name); } } else { typeTextField.setText(""); } if (mode == ADD) { typeTextField.setText(""); } if (model != null) { typeTable.getSelectionModel().removeListSelectionListener(this); model.removeAllRows(); Iterator typeIt = types.iterator(); LinguisticType lt; while (typeIt.hasNext()) { lt = (LinguisticType) typeIt.next(); model.addRow(lt); } typeTable.getSelectionModel().addListSelectionListener(this); } } /** * Fills the cv combo box with the Controlled Vocabularies present in the * Transcription. */ private void extractControlledVocabularies() { Vector cv = ((TranscriptionImpl) transcription).getControlledVocabularies(); cvComboBox.addItem(none); for (int i = 0; i < cv.size(); i++) { cvComboBox.addItem(((ControlledVocabulary) cv.get(i)).getName()); } } /** * Initialize UI elements with the attributes from the first element in the * types list. * * @param typeName the name of the LinguisticType */ private void updateUIForType(String typeName) { if (typeName != null) { typeTextField.setText(typeName); Iterator typeIt = types.iterator(); LinguisticType lt; while (typeIt.hasNext()) { lt = (LinguisticType) typeIt.next(); if ((lt != null) && lt.getLinguisticTypeName().equals(typeName)) { if (currentTypesComboBox.getSelectedItem() != typeName) { currentTypesComboBox.setSelectedItem(typeName); } constraintsComboBox.removeItemListener(this); Constraint oldC = lt.getConstraints(); if (oldC != null) { String stereoType = Constraint.stereoTypes[oldC.getStereoType()]; oldConstraint = stereoType; constraintsComboBox.setSelectedItem(stereoType); } else { oldConstraint = none; constraintsComboBox.setSelectedItem(none); } timeAlignableCheckbox.setSelected(lt.isTimeAlignable()); graphicReferencesCheckbox.setSelected(lt.hasGraphicReferences()); if (lt.isUsingControlledVocabulary()) { String cvName = lt.getControlledVocabylaryName(); cvComboBox.getModel().setSelectedItem(cvName); } else { cvComboBox.getModel().setSelectedItem(none); } if (mode == CHANGE) { Vector tiers = transcription.getTiersWithLinguisticType(typeName); if (tiers.size() > 0) { constraintsComboBox.setEnabled(false); } else { constraintsComboBox.setEnabled(true); } if (lt.isTimeAlignable()) { graphicReferencesCheckbox.setEnabled(true); } else { graphicReferencesCheckbox.setEnabled(false); } } constraintsComboBox.addItemListener(this); // update table if (model != null) { typeTable.getSelectionModel() .removeListSelectionListener(this); int col = model.findColumn(LinguisticTypeTableModel.NAME); for (int i = 0; i < model.getRowCount(); i++) { if (typeName.equals(model.getValueAt(i, col))) { typeTable.getSelectionModel() .setLeadSelectionIndex(i); typeTable.scrollRectToVisible(typeTable.getCellRect( i, col, true)); break; } } typeTable.getSelectionModel().addListSelectionListener(this); } break; } } } else { oldConstraint = none; constraintsComboBox.setSelectedItem(none); cvComboBox.getModel().setSelectedItem(none); timeAlignableCheckbox.setSelected(true); graphicReferencesCheckbox.setSelected(false); } } /** * Utility method for creating a Constraint for a given name. * * @param name the name of the constraint * * @return a Constraint or <code>null</code> */ private Constraint getConstraintForName(String name) { Constraint c = null; if (name.equals(Constraint.stereoTypes[Constraint.TIME_SUBDIVISION])) { c = new TimeSubdivision(); } else if (name.equals( Constraint.stereoTypes[Constraint.SYMBOLIC_SUBDIVISION])) { c = new SymbolicSubdivision(); } else if (name.equals( Constraint.stereoTypes[Constraint.SYMBOLIC_ASSOCIATION])) { c = new SymbolicAssociation(); } else if (name.equals(Constraint.stereoTypes[Constraint.INCLUDED_IN])) { c = new IncludedIn(); } return c; } /** * Shows a warning message when the document needs to be reopened to view * graphic annotations. * * @param type the modified linguistic type */ private void checkGraphics(LinguisticType type) { Vector tiersOfType = transcription.getTiersWithLinguisticType(type.getLinguisticTypeName()); boolean alreadyThere = false; Vector allTiers = transcription.getTiers(); Iterator tierIt = allTiers.iterator(); TierImpl tier; LinguisticType otherType; while (tierIt.hasNext()) { tier = (TierImpl) tierIt.next(); otherType = tier.getLinguisticType(); if ((otherType != type) && otherType.hasGraphicReferences()) { alreadyThere = true; break; } } if (!alreadyThere && (tiersOfType.size() > 0)) { JOptionPane.showMessageDialog(this, ElanLocale.getString("EditTierDialog.Message.Graphics"), ElanLocale.getString("Message.Warning"), JOptionPane.WARNING_MESSAGE); } } private void doAdd(String name) { // check existence LinguisticType lt = null; Iterator tIter = types.iterator(); while (tIter.hasNext()) { lt = (LinguisticType) tIter.next(); if (lt.getLinguisticTypeName().equals(name)) { String errorMessage = ElanLocale.getString( "EditTypeDialog.Message.Exists"); typeTextField.requestFocus(); JOptionPane.showMessageDialog(this, errorMessage, ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); return; } } //create new type String cons = (String) constraintsComboBox.getSelectedItem(); Constraint c = getConstraintForName(cons); boolean alignable = timeAlignableCheckbox.isSelected(); boolean graphicsRef = graphicReferencesCheckbox.isSelected(); String cvName = (String) cvComboBox.getSelectedItem(); if (cvName.equals(none)) { cvName = null; } //create and execute a command Command com = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.ADD_TYPE); Object[] args = new Object[5]; args[0] = name; args[1] = c; args[2] = cvName; args[3] = new Boolean(alignable); args[4] = new Boolean(graphicsRef); com.execute(transcription, args); reextractTypes(); //dispose(); } private void doChange(String name) { String oldName = (String) currentTypesComboBox.getSelectedItem(); LinguisticType lt = null; LinguisticType iterType = null; Iterator tIter = types.iterator(); while (tIter.hasNext()) { iterType = (LinguisticType) tIter.next(); if (iterType.getLinguisticTypeName().equals(oldName)) { lt = iterType; } if (iterType.getLinguisticTypeName().equals(name) && (iterType != lt)) { // name already exists String errorMessage = ElanLocale.getString( "EditTypeDialog.Message.Exists"); typeTextField.requestFocus(); JOptionPane.showMessageDialog(this, errorMessage, ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); return; } } if (lt == null) { // something is wrong
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -