X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAnnotationPanel.java;h=bcc2866b8aeda417dce20b472237a18c53fb2262;hb=cc6f7ebe59c148e62cd9f1947d9ba30638db2980;hp=ad4aeb80703f34c597cc168b60fb80ad719ea21a;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index ad4aeb8..bcc2866 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) { @@ -99,7 +108,7 @@ public class AnnotationPanel aa[i].height += 16; } - if (aa[i].isGraph) + if (aa[i].graph>0) { aa[i].height += GRAPH_HEIGHT; } @@ -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) @@ -249,247 +264,421 @@ public class AnnotationPanel repaint(); } + /** + * DOCUMENT ME! + * + * @param g DOCUMENT ME! + * @param startRes DOCUMENT ME! + * @param endRes DOCUMENT ME! + */ 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++) + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + + 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; + + boolean [] graphGroupDrawn = new boolean[aa.length]; + + + //\u03B2 \u03B1 + for (int i = 0; i < aa.length; i++) { - if (row.annotations.length <= j || row.annotations[j] == null) - { - validRes = false; - } - else - { - validRes = true; - } + AlignmentAnnotation row = aa[i]; - x = (j - startRes) * av.charWidth; + if (!row.visible) + { + continue; + } - if (activeRow == i) - { - g.setColor(Color.red); - if (activeRes != null) + if (row.graph>0) { - for (int n = 0; n < activeRes.size(); n++) - { - int v = Integer.parseInt(activeRes.elementAt(n).toString()); - if (v == j) + if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] ) + continue; + + // 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; + } + + x = (j - startRes) * av.charWidth; + + if (activeRow == i) + { + g.setColor(Color.red); + + if (activeRes != null) + { + for (int n = 0; n < activeRes.size(); n++) + { + int v = Integer.parseInt(activeRes.elementAt(n).toString()); + + if (v == j) + { + g.fillRect((j - startRes) * av.charWidth, y, + av.charWidth, row.height); + } + } + } + } + + 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.graph>0) + { + 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) + { + 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; + + + 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; + } + } } - } - if (row.hasIcons) - { - if (!validRes || row.annotations[j].secondaryStructure != lastSS[i]) + x += av.charWidth; + + if (row.hasIcons) { - switch (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; + 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; + g.setColor(SHEET_COLOUR); + + if (row.annotations.length > endRes + && row.annotations[endRes].secondaryStructure != 'E') + { + 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); + } + else + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i], 7); + + break; + case 'C': - break; + 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; - } - } + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); - if (validRes && row.isGraph) - { - g.setColor(new Color(0, 0, 180)); - int height = (int) ( (row.annotations[j].value / row.graphMax) * - GRAPH_HEIGHT); + break; + } + } - if (row.windowLength > 1) + if (row.graph>0) { - int total = 0; - for (int i2 = j - (row.windowLength / 2); - i2 < j + (row.windowLength / 2); i2++) - { - if (i2 < 0 || i2 >= av.alignment.getWidth()) + if(row.graph == AlignmentAnnotation.LINE_GRAPH ) { - continue; + if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup]) + { + float groupmax=-999999, groupmin=9999999; + for(int gg=0; gggroupmax) + groupmax = aa[gg].graphMax; + if(aa[gg].graphMin0 && row.hasText) + { + y += av.charHeight; } - g.setColor(row.annotations[j].colour); - g.fillRect(x, y - height, av.charWidth, height); - } + if (row.graph==0) + { + y += aa[i].height; + } } + } + + public void drawLineGraph(Graphics g, AlignmentAnnotation aa, + int sRes, int eRes, + int y, + float min, float max, + int graphHeight) + { + if(sRes>aa.annotations.length) + return; - x += av.charWidth; + int x = 0; - 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; + //Adjustment for fastpaint to left + if(eResaa.annotations.length) + return; + + int x=0, y1, y2; + + float range = max - min; + + if(aa.graphLines!=null) + { + for(int l=0; l0) + g.fillRect(x, y2, av.charWidth, y1-y2 ); + else + g.fillRect(x, y1, av.charWidth, y2-y1 ); + + x += av.charWidth; } + } // 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; + } } - } }