X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAnnotationPanel.java;h=a1597f8320f13dd1d98ac14c893a6796bc383359;hb=436a05e4d6015e30a04bb0234cebd07210137df8;hp=ad4aeb80703f34c597cc168b60fb80ad719ea21a;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index ad4aeb8..a1597f8 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -69,15 +69,24 @@ public class AnnotationPanel // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this ); } + + public AnnotationPanel(AlignViewport av) + { + this.av = av; + } + + public void adjustmentValueChanged(AdjustmentEvent evt) { ap.alabels.setScrollOffset( -evt.getValue()); } - public void adjustPanelHeight() + public int adjustPanelHeight() { // setHeight of panels AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + + int height = 0; if (aa != null) { @@ -117,12 +126,14 @@ public class AnnotationPanel } this.setSize(getSize().width, height); - ap.annotationScroller.setSize(getSize().width, height); + if(ap!=null) + ap.annotationScroller.setSize(getSize().width, height); -// ap.annotationSpaceFillerHolder.setSize(d.width,annotationPanel.getSize().height); repaint(); + return height; + } public void addEditableColumn(int i) @@ -130,6 +141,9 @@ public class AnnotationPanel if (activeRow == -1) { AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if(aa ==null) + return; + for (int j = 0; j < aa.length; j++) { if (aa[j].editable) @@ -192,6 +206,8 @@ public class AnnotationPanel public void paint(Graphics g) { + g.setColor(Color.white); + g.fillRect(0,0, getSize().width, getSize().height); imgWidth = (av.endRes - av.startRes + 1) * av.charWidth; if (image == null || imgWidth != image.getWidth(this)) @@ -212,7 +228,6 @@ public class AnnotationPanel drawComponent(gg, av.startRes, av.endRes + 1); g.drawImage(image, 0, 0, this); - } public void fastPaint(int horizontal) @@ -251,245 +266,253 @@ public class AnnotationPanel public void drawComponent(Graphics g, int startRes, int endRes) { - g.setColor(Color.white); - g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height); - if (av.alignment.getAlignmentAnnotation() == null || - av.alignment.getAlignmentAnnotation().length < 1) - { - g.setColor(Color.white); - g.fillRect(0, 0, getSize().width, getSize().height); - g.setColor(Color.black); - g.drawString("Alignment has no annotations", 20, 15); - return; - } + g.setFont(av.getFont()); - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if (fm == null) + fm = g.getFontMetrics(); - int j, x = 0, y = 0; - char[] lastSS = new char[aa.length]; - int[] lastSSX = new int[aa.length]; - int iconOffset = av.charHeight / 2; - boolean validRes = false; - //\u03B2 \u03B1 - for (int i = 0; i < aa.length; i++) - { - AlignmentAnnotation row = aa[i]; - if (!row.visible) - { - continue; - } + g.setColor(Color.white); + g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height); - if (row.isGraph) - { - // this is so that we draw the characters below the graph - y += row.height; - if (row.hasText) - { - y -= av.charHeight; - } - } - if (row.hasText) - { - iconOffset = av.charHeight / 2; - } - else + if ((av.alignment.getAlignmentAnnotation() == null) || + (av.alignment.getAlignmentAnnotation().length < 1)) { - iconOffset = 0; + g.setColor(Color.white); + g.fillRect(0, 0, getSize().width, getSize().height); + g.setColor(Color.black); + g.drawString("Alignment has no annotations", 20, 15); + + return; } - for (j = startRes; j < endRes; j++) - { - if (row.annotations.length <= j || row.annotations[j] == null) - { - validRes = false; - } - else - { - validRes = true; - } + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - x = (j - startRes) * av.charWidth; + int j; + int x = 0; + int y = 0; + char[] lastSS = new char[aa.length]; + int[] lastSSX = new int[aa.length]; + int iconOffset = av.charHeight / 2; + boolean validRes = false; - if (activeRow == i) - { + //\u03B2 \u03B1 + for (int i = 0; i < aa.length; i++) + { + AlignmentAnnotation row = aa[i]; + + if (!row.visible) + { + continue; + } - g.setColor(Color.red); - if (activeRes != null) + if (row.isGraph) { - for (int n = 0; n < activeRes.size(); n++) - { - int v = Integer.parseInt(activeRes.elementAt(n).toString()); - if (v == j) + // this is so that we draw the characters below the graph + y += row.height; + + if (row.hasText) { - g.fillRect( (j - startRes) * av.charWidth, y, av.charWidth, - row.height); + y -= av.charHeight; } - } } - } - if (validRes && row.annotations[j].displayCharacter.length() > 0) - { - int charOffset = (av.charWidth - - fm.charWidth(row.annotations[j].displayCharacter. - charAt(0))) / 2; - g.setColor(row.annotations[j].colour); - if (j == 0) + if (row.hasText) { - if (row.annotations[0].secondaryStructure == 'H' - || row.annotations[0].secondaryStructure == 'E') - { - g.drawString(row.annotations[j].displayCharacter, x, - y + iconOffset + 2); - } + iconOffset = av.charHeight / 2; } - else if ( (row.annotations[j].secondaryStructure == 'H' - || row.annotations[j].secondaryStructure == 'E') && - (row.annotations[j - 1] == null || - row.annotations[j].secondaryStructure != - row.annotations[j - 1].secondaryStructure)) + else { - - g.drawString(row.annotations[j].displayCharacter, x + charOffset, - y + iconOffset + 2); + iconOffset = 0; } - if (!row.hasIcons) + for (j = startRes; j < endRes; j++) { - g.drawString(row.annotations[j].displayCharacter, x + charOffset, - y + iconOffset + 2); - } - } + if ((row.annotations.length <= j) || + (row.annotations[j] == null)) + { + validRes = false; + } + else + { + validRes = true; + } - if (row.hasIcons) - { - if (!validRes || row.annotations[j].secondaryStructure != lastSS[i]) - { - switch (lastSS[i]) - { - case 'H': - g.setColor(HELIX_COLOUR); - g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i], - 7, 8, 8); - break; - case 'E': - g.setColor(SHEET_COLOUR); - g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4, - 7); - g.fillPolygon(new int[] - {x - 4, x - 4, x} - , new int[] - {y + iconOffset, y + 14 + iconOffset, - y + 8 + iconOffset}, 3); - break; - case 'C': - break; - default: - g.setColor(Color.gray); - g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); - break; - } - - if (validRes) - { - lastSS[i] = row.annotations[j].secondaryStructure; - } - else - { - lastSS[i] = ' '; - } - lastSSX[i] = x; - } - } + x = (j - startRes) * av.charWidth; - if (validRes && row.isGraph) - { - g.setColor(new Color(0, 0, 180)); - int height = (int) ( (row.annotations[j].value / row.graphMax) * - GRAPH_HEIGHT); - if (row.windowLength > 1) - { - int total = 0; - for (int i2 = j - (row.windowLength / 2); - i2 < j + (row.windowLength / 2); i2++) - { - if (i2 < 0 || i2 >= av.alignment.getWidth()) + if (validRes && + (row.annotations[j].displayCharacter.length() > 0)) + { + + int charOffset = (av.charWidth - + fm.charWidth(row.annotations[j].displayCharacter.charAt( + 0))) / 2; + g.setColor(row.annotations[j].colour); + + if (j == 0 || row.isGraph) + { + g.drawString(row.annotations[j].displayCharacter, x+charOffset, + y + iconOffset + 3); + } + else if (((row.annotations[j - 1] == null) || + (row.annotations[j].displayCharacter != row.annotations[j - + 1].displayCharacter))) + { + g.drawString(row.annotations[j].displayCharacter, x+charOffset, + y + iconOffset + 3); + } + } + + if (row.hasIcons) { - continue; + if (!validRes || + (row.annotations[j].secondaryStructure != lastSS[i])) + { + switch (lastSS[i]) + { + case 'H': + g.setColor(HELIX_COLOUR); + g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i], 7, 8, 8); + + break; + + case 'E': + g.setColor(SHEET_COLOUR); + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i] - 4, 7); + g.fillPolygon(new int[] { x - 4, x - 4, x }, + new int[] + { + y + iconOffset, y + 14 + iconOffset, + y + 8 + iconOffset + }, 3); + + break; + + case 'C': + break; + + default: + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y + 6 + iconOffset, + x - lastSSX[i], 2); + + break; + } + + if (validRes) + { + lastSS[i] = row.annotations[j].secondaryStructure; + } + else + { + lastSS[i] = ' '; + } + + lastSSX[i] = x; + } } - total += row.annotations[i2].value; - } + if (validRes && row.isGraph) + { + g.setColor(new Color(0, 0, 180)); + + int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); + + if (row.windowLength > 1) + { + int total = 0; + + for (int i2 = j - (row.windowLength / 2); + i2 < (j + (row.windowLength / 2)); i2++) + { + if ((i2 < 0) || (i2 >= av.alignment.getWidth())) + { + continue; + } - total /= row.windowLength; - height = (int) ( (total / row.graphMax) * GRAPH_HEIGHT); + total += row.annotations[i2].value; + } + total /= row.windowLength; + height = (int) ((total / row.graphMax) * GRAPH_HEIGHT); + } + + g.setColor(row.annotations[j].colour); + g.fillRect(x, y - height, av.charWidth, height); + } } - g.setColor(row.annotations[j].colour); - g.fillRect(x, y - height, av.charWidth, height); - } - } + x += av.charWidth; - x += av.charWidth; + if (row.hasIcons) + { + switch (lastSS[i]) + { + case 'H': + g.setColor(HELIX_COLOUR); + g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i], 7, 8, 8); - if (row.hasIcons) - { - switch (lastSS[i]) - { - case 'H': - g.setColor(HELIX_COLOUR); - g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i], 7, - 8, 8); - break; - case 'E': - g.setColor(SHEET_COLOUR); - g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4, 7); - g.fillPolygon(new int[] - {x - 4, x - 4, x} - , new int[] - {y + iconOffset, y + 14 + iconOffset, - y + 7 + iconOffset} - , 3); - break; - case 'C': - break; - default: - g.setColor(Color.gray); - g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); - break; + break; - } - } + case 'E': + g.setColor(SHEET_COLOUR); + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i] - 4, 7); + g.fillPolygon(new int[] { x - 4, x - 4, x }, + new int[] + { + y + iconOffset, y + 14 + iconOffset, + y + 7 + iconOffset + }, 3); + + break; - if (row.isGraph && row.hasText) - { - y += av.charHeight; - } - if (!row.isGraph) - { - y += aa[i].height; - } - } + case 'C': + break; + + default: + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); + + break; + } + } + + if (row.isGraph && row.hasText) + { + y += av.charHeight; + } + + if (!row.isGraph) + { + y += aa[i].height; + } + } } // used by overview window - public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y) + public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes) { - g.setColor(Color.white); - g.fillRect(0, 0, width, y); - g.setColor(new Color(0, 0, 180)); - int x = 0; - for (int j = 0; j < aa.annotations.length; j++) - { + g.setColor(Color.white); + g.fillRect(0, 0, width, y); g.setColor(new Color(0, 0, 180)); - int height = (int) ( (aa.annotations[j].value / aa.graphMax) * - GRAPH_HEIGHT); - g.fillRect(x, y - height, av.charWidth, height); - x += av.charWidth; + + int x = 0, height; + + for (int j = sRes; j < eRes; j++) + { + g.setColor(new Color(0, 0, 180)); + + height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); + if(height>y) + height = y; + g.fillRect(x, y - height, av.charWidth, height); + x += av.charWidth; + } } - } }