📄 filtertiercommand.java
字号:
(destTier == null)) { LOG.severe( "Error in retrieving the transcription or one of the tiers."); return; } existAnnotations = new ArrayList(); newAnnotations = new ArrayList(); existChangedAnnotations = new ArrayList(); int curPropMode = 0; curPropMode = transcription.getTimeChangePropagationMode(); if (curPropMode != Transcription.NORMAL) { transcription.setTimeChangePropagationMode(Transcription.NORMAL); } // filter thread new FilterThread().start(); // restore the time propagation mode transcription.setTimeChangePropagationMode(curPropMode); } /** * Returns the name of the command. * * @return the name of the command */ public String getName() { return commandName; } /** * 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()); } } /** * Applies the specified filters to the source string.<br> * The output is created by extracting/removing the strings in the filters * from the source. * * @param source the source string * @param filters the filters * * @return a filtered string */ public String applyFilters(String source, String[] filters) { if ((filters == null) || (filters.length == 0) || (source == null) || (source.length() == 0)) { return source; } char[] resultchars = source.toCharArray(); // the filters loop for (int i = 0; i < filters.length; i++) { if ((filters[i] == null) || (filters[i].length() == 0) || (filters[i].length() > resultchars.length)) { continue; } char[] filter = filters[i].toCharArray(); int from = 0;searchloop: while (true) { if (from > (resultchars.length - filter.length)) { break searchloop; } for (; from <= (resultchars.length - filter.length); from++) { // check the first char if (resultchars[from] == filter[0]) { int count = 1; int start = from + count; int end = (from + filter.length) - 1; while (start <= end) { if (resultchars[start++] != filter[count++]) { from++; continue searchloop; } } // if we get here the filter is found StringBuffer buf = new StringBuffer(resultchars.length); buf.append(resultchars); buf.delete(from, end + 1); char[] ch = new char[buf.length()]; buf.getChars(0, buf.length(), ch, 0); resultchars = ch; continue searchloop; } } } // end of the current filter } // end of all filters if (resultchars.length == source.length()) { return source; } else { return String.valueOf(resultchars); } } /////////////////////////////////////////// // inner class: execution thread /////////////////////////////////////////// /** * Class that handles the filtering in a separate thread. * * @author Han Sloetjes */ private class FilterThread extends Thread { /** * Before using this inner class we must ensure none of the relevant * fields (transcription, sourcetier and destination tier) are null! */ FilterThread() { } /** * DOCUMENT ME! */ public void run() { final IndeterminateProgressMonitor monitor = new IndeterminateProgressMonitor(ELANCommandFactory.getRootFrame( transcription), true, ElanLocale.getString("FilterDialog.Message.Filtering"), true, ElanLocale.getString("Button.Cancel")); // if we are blocking (modal) call show from a separate thread new Thread(new Runnable() { public void run() { monitor.show(); } }).start(); /// Vector sourceAnnos = sourceTier.getAnnotations(); if (sourceAnnos.size() <= 0) { monitor.close(); return; } FilterTierCommand.this.transcription.setNotifying(false); //start iterating over source annotations Iterator annIt = sourceAnnos.iterator(); AbstractAnnotation srcAnn; String srcValue; Vector childrenOnDest; AbstractAnnotation childOnDest; while (annIt.hasNext()) { srcAnn = (AbstractAnnotation) annIt.next(); childrenOnDest = srcAnn.getChildrenOnTier(destTier); // should be only one annotation on a symbolic association tier if ((childrenOnDest.size() > 0) && !preserve) { // store old annotation childOnDest = (AbstractAnnotation) childrenOnDest.get(0); existAnnotations.add(new AnnotationDataRecord(childOnDest)); childOnDest.setValue(FilterTierCommand.this.applyFilters( srcAnn.getValue(), FilterTierCommand.this.filters)); // store the annotation with the new value for redo existChangedAnnotations.add(new AnnotationDataRecord( childOnDest)); } // if existing anns need to be preserved, do nothing if (childrenOnDest.size() == 0) { srcValue = srcAnn.getValue(); if (srcValue.length() == 0) { // if the source annotation is empty and the create destination // for empty source is selected create one empty annotation if (createEmpty) { long time = (long) (srcAnn.getBeginTimeBoundary() + srcAnn.getEndTimeBoundary()) / 2; Annotation ann = destTier.createAnnotation(time, time); if (ann != null) { newAnnotations.add(new AnnotationDataRecord(ann)); } else { LOG.warning( "Filter tier: could not create a new annotation for: " + srcValue + " " + srcAnn.getBeginTimeBoundary() + " - " + srcAnn.getEndTimeBoundary()); } } } else { long time = (long) (srcAnn.getBeginTimeBoundary() + srcAnn.getEndTimeBoundary()) / 2; Annotation ann = destTier.createAnnotation(time, time); if (ann != null) { // apply filters ann.setValue(FilterTierCommand.this.applyFilters( srcAnn.getValue(), FilterTierCommand.this.filters)); newAnnotations.add(new AnnotationDataRecord(ann)); } else { LOG.warning( "Filter tier: could not create a new annotation for: " + srcValue + " " + srcAnn.getBeginTimeBoundary() + " - " + srcAnn.getEndTimeBoundary()); } } } // after completion of a whole source annotation, check the cancelled value of the monitor if (monitor.isCancelled()) { //monitor.close(); //return; break; } } FilterTierCommand.this.transcription.setNotifying(true); /// monitor.close(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -