📄 extracttrackdatacommand.java
字号:
*/ public String getName() { return commandName; } /** * Adds a ProgressListener to the list of ProgressListeners. * * @param pl the new ProgressListener */ public synchronized void addProgressListener(ProgressListener pl) { if (listeners == null) { listeners = new ArrayList(2); } listeners.add(pl); } /** * Removes the specified ProgressListener from the list of listeners. * * @param pl the ProgressListener to remove */ public synchronized void removeProgressListener(ProgressListener pl) { if ((pl != null) && (listeners != null)) { listeners.remove(pl); } } /** * Notifies any listeners of a progress update. * * @param percent the new progress percentage, [0 - 100] * @param message a descriptive message */ private void progressUpdate(int percent, String message) { if (listeners != null) { for (int i = 0; i < listeners.size(); i++) { ((ProgressListener) listeners.get(i)).progressUpdated(this, percent, message); } } } /** * Notifies any listeners that the process has completed. * * @param message a descriptive message */ private void progressComplete(String message) { if (listeners != null) { for (int i = 0; i < listeners.size(); i++) { ((ProgressListener) listeners.get(i)).progressCompleted(this, message); } } } /** * Notifies any listeners that the process has been interrupted. * * @param message a descriptive message */ private void progressInterrupt(String message) { if (listeners != null) { for (int i = 0; i < listeners.size(); i++) { ((ProgressListener) listeners.get(i)).progressInterrupted(this, message); } } } /** * Changes the cursor to either a 'busy' cursor or the default cursor. * * @param showWaitCursor when <code>true</code> show the 'busy' cursor */ private void setWaitCursor(boolean showWaitCursor) { if (showWaitCursor) { ELANCommandFactory.getRootFrame(transcription).getRootPane() .setCursor(Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR)); } else { ELANCommandFactory.getRootFrame(transcription).getRootPane() .setCursor(Cursor.getDefaultCursor()); } } /** * Class for minimal storage of a time value and an old and new textual * value. * * @author Han Sloetjes, MPI */ private class ValueRecord { /** begin time */ public final long beginTime; /** the old value */ public final String oldValue; /** the new value */ public final String newValue; /** * Creates a new ValueRecord instance * * @param beginTime begin time * @param oldValue the old value * @param newValue the new value */ ValueRecord(long beginTime, String oldValue, String newValue) { this.beginTime = beginTime; this.oldValue = oldValue; this.newValue = newValue; } } /** * The actual extraction is executed in a separate thread; a listener with * a user interface will be able to update itself (progress bar) * * @author Han Sloetjes, MPI */ private class ExtractThread extends Thread { /** the source tier */ private TierImpl sourceTier; /** the destination tier */ private TierImpl destTier; /** the track */ private AbstractTSTrack track; /** id for the calculation method; min, max or ave */ private String method; /** the overwrite flag */ private boolean overwrite = false; /** Holds value of property DOCUMENT ME! */ private final char[] modes = new char[] { '<', '>', '=' }; private char mode = modes[0]; /** * Creates a new ExtractThread instance * * @param sourceTier the source tier * @param destTier the destination tier * @param track the time series track * @param method the calculation method * @param overwrite overwrite flag */ ExtractThread(TierImpl sourceTier, TierImpl destTier, AbstractTSTrack track, String method, boolean overwrite) { super(ExtractThread.class.getName()); this.sourceTier = sourceTier; this.destTier = destTier; this.track = track; this.method = method; if ("max".equalsIgnoreCase(method)) { mode = modes[1]; } else if ("ave".equalsIgnoreCase(method)) { mode = modes[2]; } this.overwrite = overwrite; } /** * The actual work * * @see Runnable#run() */ public void run() { transcription.setNotifying(false); ArrayList annos = new ArrayList(sourceTier.getAnnotations()); float perAnn = 100f / Math.max(annos.size(), 1); DecimalFormat format = new DecimalFormat("#0.####", new DecimalFormatSymbols(Locale.US)); AlignableAnnotation aa; RefAnnotation ref; long begin; long end; float value = 0f; for (int i = 0; i < annos.size(); i++) { aa = (AlignableAnnotation) annos.get(i); begin = aa.getBeginTimeBoundary(); end = aa.getEndTimeBoundary(); try { switch (mode) { case '<': value = track.getMinimum(begin, end); break; case '>': value = track.getMaximum(begin, end); break; case '=': value = track.getAverage(begin, end); } } catch (Exception ex) { transcription.setNotifying(true); LOG.warning("Exception occured during calculation: " + ex.getMessage()); progressInterrupt("Exception occured during calculation: " + ex.getMessage()); return; } ref = (RefAnnotation) destTier.getAnnotationAtTime(begin); String valString; if (ref == null) { long mid = (long) ((begin + end) / 2); ref = (RefAnnotation) destTier.createAnnotation(mid, mid); if (ref != null) { //ref.setValue(String.valueOf(value)); ref.setValue(format.format(value)); // store for undo newAnnos.add(new AnnotationDataRecord(ref)); } else { LOG.warning( "Could not create a reference annotation at time: " + mid); } } else if (overwrite) { // store for undo // valString = String.valueOf(value); valString = format.format(value); changedAnnos.add(new ValueRecord(begin, ref.getValue(), valString)); ref.setValue(valString); } progressUpdate((int) ((i + 1) * perAnn), null); } transcription.setNotifying(true); progressComplete("Operation complete..."); } /** * Interrupts the current merging process. */ public void interrupt() { progressInterrupt("Operation interrupted..."); super.interrupt(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -