📄 segmentationdialog.java
字号:
gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = GridBagConstraints.NORTH; gridBagConstraints.insets = insets; tierPreviewPanel.add(controlPanel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTH; gridBagConstraints.insets = insets; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; getContentPane().add(tierPreviewPanel, gridBagConstraints); buttonPanel.setLayout(new GridLayout(1, 2, 6, 0)); applyButton.addActionListener(this); buttonPanel.add(applyButton); closeButton.addActionListener(this); buttonPanel.add(closeButton); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.insets = insets; getContentPane().add(buttonPanel, gridBagConstraints); } /** * Pack, size and set location. */ private void postInit() { pack(); Rectangle dialogBounds = (Rectangle) Preferences.get("SegmentationDialogBounds", null); if (dialogBounds != null) { setBounds(dialogBounds); } else { int w = 550; int h = 380; setSize((getSize().width < w) ? w : getSize().width, (getSize().height < h) ? h : getSize().height); setLocationRelativeTo(getParent()); } setResizable(true); // add actions with accelerator keys and without a menu item to the input // and action map InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = getRootPane().getActionMap(); if (inputMap instanceof ComponentInputMap && (actionMap != null)) { Action[] invActions = new Action[] { ELANCommandFactory.getCommandAction(transcription, ELANCommandFactory.PLAY_PAUSE), ELANCommandFactory.getCommandAction(transcription, ELANCommandFactory.GO_TO_BEGIN), ELANCommandFactory.getCommandAction(transcription, ELANCommandFactory.GO_TO_END), ELANCommandFactory.getCommandAction(transcription, ELANCommandFactory.PREVIOUS_SCROLLVIEW), ELANCommandFactory.getCommandAction(transcription, ELANCommandFactory.NEXT_SCROLLVIEW), ELANCommandFactory.getCommandAction(transcription, ELANCommandFactory.SECOND_LEFT), ELANCommandFactory.getCommandAction(transcription, ELANCommandFactory.SECOND_RIGHT), new SegmentAction() }; for (int i = 0; i < invActions.length; i++) { inputMap.put((KeyStroke) invActions[i].getValue( Action.ACCELERATOR_KEY), invActions[i].getValue(Action.DEFAULT)); actionMap.put(invActions[i].getValue(Action.DEFAULT), invActions[i]); } } if (transcription != null) { ELANCommandFactory.getViewerManager(transcription).connectListener(this); ELANCommandFactory.getViewerManager(transcription).connectListener(previewer); } } /** * Applies localized strings to the ui elements. */ private void updateLocale() { setTitle(ElanLocale.getString("SegmentationDialog.Title")); titleLabel.setText(ElanLocale.getString("SegmentationDialog.Title")); keyLabel.setText(ElanLocale.getString("SegmentationDialog.Label.Key") + " " + ELANCommandFactory.convertAccKey(KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0))); tierSelectionPanel.setBorder(new TitledBorder(ElanLocale.getString( "SegmentationDialog.Title"))); tierPreviewPanel.setBorder(new TitledBorder(ElanLocale.getString( "SegmentationDialog.Preview"))); tierLabel.setText(ElanLocale.getString("SegmentationDialog.Label.Tier")); oneClickRB.setText(ElanLocale.getString( "SegmentationDialog.Mode.SingleStroke")); twoClicksRB.setText(ElanLocale.getString( "SegmentationDialog.Mode.DoubleStroke")); applyButton.setText(ElanLocale.getString("Button.Apply")); closeButton.setText(ElanLocale.getString("Button.Cancel")); } /** * Closes the dialog * * @param evt the window closing event */ private void closeDialog(WindowEvent evt) { if (transcription != null) { ELANCommandFactory.getViewerManager(transcription) .disconnectListener(this); ELANCommandFactory.getViewerManager(transcription).destroyViewer(previewer); } savePreferences(); setVisible(false); dispose(); } /** * Save preferences. */ private void savePreferences() { Preferences.set("SegmentationDialogBounds", getBounds(), null); } /** * The button actions. * * @param ae the action event */ public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); if (source == applyButton) { Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.ADD_SEGMENTATION); c.execute(transcription, new Object[] { curTier, timeSegments }); closeDialog(null); } else if (source == closeButton) { closeDialog(null); } else if (source == oneClickRB) { if (mode == TWO_TIMES_SEGMENTATION) { timeCount = 0; lastSegmentTime = -1; } } else if (source == twoClicksRB) { if (mode == ONE_TIME_SEGMENTTATION) { timeCount = 0; lastSegmentTime = -1; } } } /** * Selection of a different tier. * * @param ie the item event */ public void itemStateChanged(ItemEvent ie) { if (ie.getStateChange() == ItemEvent.SELECTED) { String newSel = (String) tierComboBox.getSelectedItem(); if (newSel.equals(curTier)) { return; } if ((player != null) && player.isPlaying()) { player.stop(); } if (timeSegments.size() > 0) { if (showConfirmDialog(ElanLocale.getString( "SegmentationDialog.Message.Apply"))) { Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.ADD_SEGMENTATION); c.execute(transcription, new Object[] { curTier, timeSegments }); } timeSegments = new ArrayList(); timeCount = 0; lastSegmentTime = -1; } curTier = newSel; if (!curTier.equals(EMPTY)) { previewer.setTier(transcription.getTierWithId(curTier)); } } } /** * Handles controller (i.e. player) updates. * * @param event the controller event */ public void controllerUpdate(ControllerEvent event) { if (event instanceof StartEvent) { tierComboBox.setEnabled(false); if (twoClicksRB.isSelected()) { mode = TWO_TIMES_SEGMENTATION; } else { mode = ONE_TIME_SEGMENTTATION; } twoClicksRB.setEnabled(false); oneClickRB.setEnabled(false); } else if (event instanceof StopEvent) { tierComboBox.setEnabled(true); twoClicksRB.setEnabled(true); oneClickRB.setEnabled(true); } } /** * Add the begin or end boundary of an annotation. */ public void addSegmentTime() { if (player == null) { return; } long cur = player.getMediaTime(); if (mode == TWO_TIMES_SEGMENTATION) { if (cur != lastSegmentTime) { timeCount++; if ((timeCount % 2) != 0) { lastSegmentTime = cur; } else { TimeInterval ti = new TimeInterval(lastSegmentTime, cur); if (ti.getDuration() > 0) { timeSegments.add(ti); previewer.addSegment(ti); } lastSegmentTime = cur; } } } else { if (lastSegmentTime == -1) { timeCount++; lastSegmentTime = cur; } else { if (cur != lastSegmentTime) { timeCount++; TimeInterval ti = new TimeInterval(lastSegmentTime, cur); if (ti.getDuration() > 0) { timeSegments.add(ti); previewer.addSegment(ti); } lastSegmentTime = cur; } } } } /** * Shows a confirm (yes/no) dialog with the specified message string. * * @param message the messsage to display * * @return true if the user clicked OK, false otherwise */ private boolean showConfirmDialog(String message) { int confirm = JOptionPane.showConfirmDialog(this, message, ElanLocale.getString("Message.Warning"), JOptionPane.YES_NO_OPTION); return confirm == JOptionPane.YES_OPTION; } /** * An action class to handle the enter-key-typed event. * * @author Han Sloetjes */ class SegmentAction extends AbstractAction { /** * Constructor, sets the accelerator key to the VK_ENTER key. */ public SegmentAction() { putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); putValue(Action.DEFAULT, "Segment"); } /** * Forwards the action to the enclosing class. * * @param e the action event */ public void actionPerformed(ActionEvent e) { SegmentationDialog.this.addSegmentTime(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -