📄 edittierdialog2.java
字号:
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.insets = insets; gbc.weightx = 1.0; importPanel.add(importSourceTF, gbc); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.insets = insets; importPanel.add(importSourceButton, gbc); 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(mode, editPanel); } else { tabPane.setComponentAt(0, editPanel); } tabPane.setSelectedIndex(mode); tabPane.addChangeListener(this); // buttons buttonPanel = new JPanel(new GridLayout(1, 2, 6, 2)); changeButton = new JButton(); changeButton.addActionListener(this); cancelButton = new JButton(); cancelButton.addActionListener(this); buttonPanel.add(changeButton); buttonPanel.add(cancelButton); gbc = new GridBagConstraints(); gbc.gridy = 3; gbc.anchor = GridBagConstraints.SOUTH; gbc.insets = insets; getContentPane().add(buttonPanel, gbc); } /** * Pack, size and set location. */ private void postInit() { pack(); int w = 550; int h = 400; setSize((getSize().width < w) ? w : getSize().width, (getSize().height < h) ? h : getSize().height); setLocationRelativeTo(getParent()); //setResizable(false); } /** * Applies localized strings to the ui elements. */ private void updateLocale() { tablePanel.setBorder(new TitledBorder(ElanLocale.getString( "EditTierDialog.Label.CurrentTiers"))); tierNameLabel.setText(ElanLocale.getString( "EditTierDialog.Label.TierName")); participantLabel.setText(ElanLocale.getString( "EditTierDialog.Label.Participant")); annotatorLabel.setText(ElanLocale.getString( "EditTierDialog.Label.Annotator")); lingTypeLabel.setText(ElanLocale.getString( "EditTierDialog.Label.LinguisticType")); parentLabel.setText(ElanLocale.getString("EditTierDialog.Label.Parent")); languageLabel.setText(ElanLocale.getString( "EditTierDialog.Label.Language")); cancelButton.setText(ElanLocale.getString("Button.Close")); importSourceLabel.setText("<html>" + ElanLocale.getString("EditTierDialog.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("EditTierDialog.Title.Add")); selectTierLabel.setText(""); currentTiersComboBox.setEnabled(false); //currentTiersComboBox.setVisible(false); changeButton.setText(ElanLocale.getString("Button.Add")); parentComboBox.setEnabled(true); tierNameTextField.setEditable(true); participantTextField.setEditable(true); annotatorTextField.setEditable(true); lingTypeComboBox.setEnabled(true); languageComboBox.setEnabled(true); tierNameTextField.setText(""); participantTextField.setText(""); annotatorTextField.setText(""); break; case CHANGE: setTitle(ElanLocale.getString("EditTierDialog.Title.Change")); selectTierLabel.setText(ElanLocale.getString( "EditTierDialog.Label.ChangeTier")); selectTierLabel.setVisible(true); currentTiersComboBox.setEnabled(true); currentTiersComboBox.setVisible(true); currentTiersComboBox.requestFocus(); changeButton.setText(ElanLocale.getString("Button.Change")); parentComboBox.setEnabled(false); tierNameTextField.setEditable(true); participantTextField.setEditable(true); annotatorTextField.setEditable(true); lingTypeComboBox.setEnabled(true); languageComboBox.setEnabled(true); break; case DELETE: setTitle(ElanLocale.getString("EditTierDialog.Title.Delete")); selectTierLabel.setText(ElanLocale.getString( "EditTierDialog.Label.DeleteTier")); changeButton.setText(ElanLocale.getString("Button.Delete")); tierNameTextField.setEditable(false); participantTextField.setEditable(false); annotatorTextField.setEditable(false); parentComboBox.setEnabled(false); lingTypeComboBox.setEnabled(false); languageComboBox.setEnabled(false); selectTierLabel.setVisible(true); currentTiersComboBox.setEnabled(true); currentTiersComboBox.setVisible(true); currentTiersComboBox.requestFocus(); break; case IMPORT: setTitle(ElanLocale.getString("EditTierDialog.Title.Import")); changeButton.setText(ElanLocale.getString("Button.Import")); changeButton.requestFocus(); break; } titleLabel.setText(getTitle()); } /** * Fill the tiers combobox with the currently present tiers. */ private void extractCurrentTiers() { currentTiersComboBox.removeItemListener(this); currentTiersComboBox.removeAllItems(); tiers = transcription.getTiers(); if (tiers == null) { tiers = new Vector(); return; } Iterator tierIt = tiers.iterator(); while (tierIt.hasNext()) { TierImpl t = (TierImpl) tierIt.next(); currentTiersComboBox.addItem(t.getName()); } if (currentTiersComboBox.getItemCount() > 0) { currentTiersComboBox.setSelectedIndex(0); tier = (TierImpl) tiers.get(0); } currentTiersComboBox.addItemListener(this); } /** * Again extract the tiers from the transcription after an add, change or * delete operation. */ private void reextractTiers() { extractCurrentTiers(); if (currentTiersComboBox.getItemCount() > 0) { currentTiersComboBox.setSelectedIndex(0); } else { tierNameTextField.setText(""); participantTextField.setText(""); annotatorTextField.setText(""); } if (mode == ADD) { tierNameTextField.setText(""); participantTextField.setText(""); annotatorTextField.setText(""); } if (model != null) { tierTable.getSelectionModel().removeListSelectionListener(this); model.removeAllRows(); Iterator tierIt = tiers.iterator(); while (tierIt.hasNext()) { TierImpl t = (TierImpl) tierIt.next(); model.addRow(t); } tierTable.getSelectionModel().addListSelectionListener(this); } } /** * Empties and refills the Linguistic Type menu with types that are not * excluded by the current parent tier choice. */ private void fillLingTypeMenu() { lingTypeComboBox.removeItemListener(this); lingTypeComboBox.removeAllItems(); // Aug 2006: in Change mode only add Ling. Types: // - with the same stereotype as the current stereotype if there are already annotations on the tier // - else if there are dependent tiers and the current tier is time alignable check if any of the // dependent tiers is time-alignable: if so only add time-alignable types else allow all (if there is a parent tier) // - if there are no dependent tiers allow all (if there is a parent tier) int curStereoType = -1; boolean onlySameStereo = false; boolean onlyTimeAlignable = false; boolean excludeTimeAlignable = false; if (mode == CHANGE) { if (tier.getNumberOfAnnotations() > 0) { onlySameStereo = true; } if (tier.getLinguisticType().getConstraints() != null) { curStereoType = tier.getLinguisticType().getConstraints() .getStereoType(); } if (!onlySameStereo && (curStereoType >= 0)) { if (tier.getDependentTiers().size() > 0) { // if there is at least one time alignable child only add time alignable TierImpl ch; for (int i = 0; i < tier.getDependentTiers().size(); i++) { ch = (TierImpl) tier.getDependentTiers().get(i); if (ch.isTimeAlignable()) { onlyTimeAlignable = true; break; } } } } } TierImpl parentTier = (TierImpl) (transcription.getTierWithId((String) parentComboBox.getSelectedItem())); Constraint parentConstraint = null; if (parentTier != null) { parentConstraint = parentTier.getLinguisticType().getConstraints(); if (parentConstraint != null) { if ((parentConstraint.getStereoType() == Constraint.SYMBOLIC_SUBDIVISION) || (parentConstraint.getStereoType() == Constraint.SYMBOLIC_ASSOCIATION)) { excludeTimeAlignable = true; } } } Enumeration e = transcription.getLinguisticTypes().elements(); while (e.hasMoreElements()) { LinguisticType lt = (LinguisticType) e.nextElement(); String ltName = lt.getLinguisticTypeName(); if (parentTier == null) { // only unconstrained types if (lt.getConstraints() != null) { continue; } } if (excludeTimeAlignable && (lt.getConstraints() != null) && ((lt.getConstraints().getStereoType() == Constraint.TIME_SUBDIVISION) || (lt.getConstraints().getStereoType() == Constraint.INCLUDED_IN))) { continue; } if (parentTier != null) { // only constrained types if (lt.getConstraints() == null) { continue; } } // special cases change mode if (onlySameStereo) { if ((lt.getConstraints() != null) && (lt.getConstraints().getStereoType() != curStereoType)) { continue; } } if (onlyTimeAlignable && (lt.getConstraints() != null) && ((lt.getConstraints().getStereoType() != Constraint.TIME_SUBDIVISION) && (lt.getConstraints().getStereoType() != Constraint.INCLUDED_IN))) { continue; } lingTypeComboBox.addItem(ltName); } // set selected the current type of the selected tier String tierName = (String) currentTiersComboBox.getSelectedItem(); if (tierName != null) { TierImpl t2 = (TierImpl) transcription.getTierWithId(tierName); if (t2 != null) { LinguisticType type = t2.getLinguisticType(); if (type != null) { lingTypeComboBox.setSelectedItem(type.getLinguisticTypeName()); } } } lingTypeComboBox.addItemListener(this); if (lingTypeComboBox.getModel().getSize() <= 0) { changeButton.setEnabled(false); } else { changeButton.setEnabled(true); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -