X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fworkers%2FColumnCounterSetWorker.java;h=2422748086a2ad248e453f5e07333137e3eaf012;hb=9cee9c3255a397e190ec7f12f86bab7a2f6bc45a;hp=e1cbd2a752cb603e5d24a5e72f4f082747f67ad6;hpb=e811386cfe6d7ab7d73db56a31ac83732e185861;p=jalview.git diff --git a/src/jalview/workers/ColumnCounterSetWorker.java b/src/jalview/workers/ColumnCounterSetWorker.java index e1cbd2a..2422748 100644 --- a/src/jalview/workers/ColumnCounterSetWorker.java +++ b/src/jalview/workers/ColumnCounterSetWorker.java @@ -69,6 +69,7 @@ class ColumnCounterSetWorker extends AlignCalcWorker @Override public void run() { + boolean annotationAdded = false; try { calcMan.notifyStart(this); @@ -93,7 +94,7 @@ class ColumnCounterSetWorker extends AlignCalcWorker { try { - computeAnnotations(); + annotationAdded = computeAnnotations(); } catch (IndexOutOfBoundsException x) { // probable race condition. just finish and return without any fuss. @@ -111,7 +112,10 @@ class ColumnCounterSetWorker extends AlignCalcWorker if (ap != null) { - ap.adjustAnnotationHeight(); + if (annotationAdded) + { + ap.adjustAnnotationHeight(); + } ap.paintAlignment(true); } @@ -120,8 +124,10 @@ class ColumnCounterSetWorker extends AlignCalcWorker /** * Scan each column of the alignment to calculate a count by feature type. Set * the count as the value of the alignment annotation for that feature type. + * + * @return */ - void computeAnnotations() + boolean computeAnnotations() { FeatureRenderer fr = new FeatureRenderer(alignViewport); // TODO use the commented out code once JAL-2075 is fixed @@ -170,43 +176,51 @@ class ColumnCounterSetWorker extends AlignCalcWorker max[crow] = Math.max(count[crow], max[crow]); } } + + boolean annotationAdded = false; + for (int anrow = 0; anrow < rows; anrow++) { Annotation[] anns = new Annotation[width]; + long rmax = 0; /* - * add non-zero counts as annotations + * add counts as annotations. zeros are needed since select-by-annotation ignores empty annotation positions */ for (int i = 0; i < counts.length; i++) { int count = counts[i][anrow]; - if (count > 0) - { - Color color = ColorUtils.getGraduatedColour(count, 0, minColour, - max[anrow], maxColour); - String str = String.valueOf(count); - anns[i] = new Annotation(str, str, '0', count, color); - } + + Color color = ColorUtils.getGraduatedColour(count, 0, minColour, + max[anrow], maxColour); + String str = String.valueOf(count); + anns[i] = new Annotation(str, str, '0', count, color); + rmax = Math.max(count, rmax); } /* * construct or update the annotation */ String description = counter.getDescriptions()[anrow]; - AlignmentAnnotation ann = alignViewport.getAlignment() - .findOrCreateAnnotation(counter.getNames()[anrow], - description, false, null, null); + if (!alignment.findAnnotation(description).iterator().hasNext()) + { + annotationAdded = true; + } + AlignmentAnnotation ann = alignment.findOrCreateAnnotation( + counter.getNames()[anrow], description, false, null, null); ann.description = description; ann.showAllColLabels = true; ann.scaleColLabel = true; ann.graph = AlignmentAnnotation.BAR_GRAPH; ann.annotations = anns; - setGraphMinMax(ann, anns); + ann.graphMin = 0f; // minimum always zero count + ann.graphMax = rmax; // maximum count from loop over feature columns ann.validateRangeAndDisplay(); if (!ourAnnots.contains(ann)) { ourAnnots.add(ann); } } + return annotationAdded; } /**