X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationPanel.java;h=8f72f71c336a6959e3f8862a3db2e6c12754e9ab;hb=848bef9fdc243cfab564acb0b82fc7ee3bcffe9f;hp=15bc284e428c62ad508cf4c6b17117dd6caae1e0;hpb=09bcf67a11fad002fc7c18aca46bf3672bb9f3ec;p=jalview.git diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 15bc284..8f72f71 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -76,6 +76,12 @@ public class AnnotationPanel extends JPanel implements MouseListener, ap.annotationScroller.getVerticalScrollBar().addAdjustmentListener(this); } + public AnnotationPanel(AlignViewport av) + { + this.av = av; + } + + /** * DOCUMENT ME! * @@ -89,7 +95,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, /** * DOCUMENT ME! */ - public void adjustPanelHeight() + public int adjustPanelHeight() { // setHeight of panels image = null; @@ -117,7 +123,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, aa[i].height += 16; } - if (aa[i].isGraph) + if (aa[i].graph>0) { aa[i].height += GRAPH_HEIGHT; } @@ -136,6 +142,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, } this.setPreferredSize(new Dimension(1, height)); + + return height; } /** @@ -606,10 +614,13 @@ public class AnnotationPanel extends JPanel implements MouseListener, * @param startRes DOCUMENT ME! * @param endRes DOCUMENT ME! */ - public void drawComponent(Graphics2D g, int startRes, int endRes) + public void drawComponent(Graphics g, int startRes, int endRes) { - if(fm==null) - fm = g.getFontMetrics(); + g.setFont(av.getFont()); + + if (fm == null) + fm = g.getFontMetrics(); + g.setColor(Color.white); g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight()); @@ -646,7 +657,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, } - if (row.isGraph) + if (row.graph>0) { // this is so that we draw the characters below the graph y += row.height; @@ -708,7 +719,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, 0))) / 2; g.setColor(row.annotations[j].colour); - if (j == 0 || row.isGraph) + if (j == 0 || row.graph>0) { g.drawString(row.annotations[j].displayCharacter, x+charOffset, y + iconOffset + 3); @@ -773,33 +784,19 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - if (validRes && row.isGraph) + if (validRes && row.graph>0) { - g.setColor(new Color(0, 0, 180)); + ///g.setColor(new Color(0, 0, 180)); - int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); + if(row.graph== AlignmentAnnotation.LINE_GRAPH ) + drawLineGraph(g, row, j, j+1, x, y); + else if(row.graph == AlignmentAnnotation.BAR_GRAPH ) + drawBarGraph(g, row, j, j+1, x, y); - if (row.windowLength > 1) - { - int total = 0; + //int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); - for (int i2 = j - (row.windowLength / 2); - i2 < (j + (row.windowLength / 2)); i2++) - { - if ((i2 < 0) || (i2 >= av.alignment.getWidth())) - { - continue; - } - - 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); } } @@ -840,38 +837,73 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - if (row.isGraph && row.hasText) + if (row.graph>0 && row.hasText) { y += av.charHeight; } - if (!row.isGraph) + if (row.graph==0) { y += aa[i].height; } } } - // used by overview window - public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes) + public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes, int eRes, int x, int y) { - g.setColor(Color.white); - g.fillRect(0, 0, width, y); - g.setColor(new Color(0, 0, 180)); + g.setColor(new Color(0, 0, 0)); + if(sRes==0) + sRes++; + int y1=y, y2=y; + for (int j = sRes; j < eRes; j++) + { + if(aa.annotations[j-1]!=null) + y1 = y - (int) ((aa.annotations[j-1].value / aa.graphMax) * GRAPH_HEIGHT); - int x = 0, height; + if(aa.annotations[j]!=null) + y2 = y - (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); - for (int j = sRes; j < eRes; j++) - { - g.setColor(new Color(0, 0, 180)); + g.drawLine(x-av.charWidth/2, y1, x+av.charWidth/2, y2); - height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); - if(height>y) - height = y; + x += av.charWidth; + } + } - g.fillRect(x, y - height, av.charWidth, height); - x += av.charWidth; + public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes, int eRes, int x, int y) + { + g.setColor(new Color(0, 0, 180)); + int j, height=0; + for (j = sRes; j < eRes; j++) + { + g.setColor(aa.annotations[j].colour); + height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); + + g.fillRect(x, y - height, av.charWidth, height); + x += av.charWidth; } } + + // used by overview window + 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, height; + + for (int j = sRes; j < eRes; j++) + { + g.setColor(new Color(0, 0, 180)); + + height = (int) ((aa.annotations[j].value / aa.graphMax) * y); + if(height>y) + height = y; + + g.fillRect(x, y - height, av.charWidth, height); + x += av.charWidth; + } + } + }