X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fworkers%2FColumnCounterSetWorker.java;h=6c5707de49350783762586db4085bbf6973f863a;hb=refs%2Fheads%2Fbug%2FJAL-2491;hp=cf6a229ba91c677fb60277ef0cc62f06f05ec29e;hpb=d0b6486ecb5c6572b823f9fd8676a603a4d493e9;p=jalview.git diff --git a/src/jalview/workers/ColumnCounterSetWorker.java b/src/jalview/workers/ColumnCounterSetWorker.java index cf6a229..6c5707d 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 @@ -140,6 +146,12 @@ class ColumnCounterSetWorker extends AlignCalcWorker { max[crow] = 0; } + + int[] minC = counter.getMinColour(); + int[] maxC = counter.getMaxColour(); + Color minColour = new Color(minC[0], minC[1], minC[2]); + Color maxColour = new Color(maxC[0], maxC[1], maxC[2]); + for (int col = 0; col < width; col++) { int[] count = counts[col]; @@ -164,6 +176,9 @@ 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]; @@ -175,8 +190,8 @@ class ColumnCounterSetWorker extends AlignCalcWorker int count = counts[i][anrow]; if (count > 0) { - Color color = ColorUtils.getGraduatedColour(count, 0, Color.cyan, - max[anrow], Color.blue); + Color color = ColorUtils.getGraduatedColour(count, 0, minColour, + max[anrow], maxColour); String str = String.valueOf(count); anns[i] = new Annotation(str, str, '0', count, color); } @@ -185,11 +200,14 @@ class ColumnCounterSetWorker extends AlignCalcWorker /* * construct or update the annotation */ - AlignmentAnnotation ann = alignViewport.getAlignment() - .findOrCreateAnnotation(counter.getNames()[anrow], - counter.getDescriptions()[anrow], false, null, - null); - ann.description = counter.getDescriptions()[anrow]; + String description = counter.getDescriptions()[anrow]; + 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; @@ -201,6 +219,7 @@ class ColumnCounterSetWorker extends AlignCalcWorker ourAnnots.add(ann); } } + return annotationAdded; } /**