X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationPanel.java;h=bc14d6637284dff184512cc7a445598730c71b3c;hb=18b27ea838aeaca9964a46c9b833a47fbb372d3b;hp=b8570a9740ceedbc7827dd1a506edbb5c1d4277e;hpb=9fff97021c2c637e426f6971d54dcf3fd4191985;p=jalview.git diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index b8570a9..bc14d66 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -92,6 +92,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, public void adjustPanelHeight() { // setHeight of panels + image = null; AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); int height = 0; @@ -147,6 +148,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, if (activeRow == -1) { AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if(aa==null) + return; for (int j = 0; j < aa.length; j++) { @@ -177,6 +180,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, if (activeRow == -1) { AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if(aa==null) + return; for (int j = 0; j < aa.length; j++) { @@ -332,7 +337,10 @@ public class AnnotationPanel extends JPanel implements MouseListener, for (int i = 0; i < aa.length; i++) { - height += aa[i].height; + if (aa[i].visible) + { + height += aa[i].height; + } if (evt.getY() < height) { @@ -519,29 +527,32 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void paintComponent(Graphics g) { - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); - if (fastPaint) - { - g.drawImage(image, 0, 0, this); - fastPaint = false; - - return; - } + if (fastPaint && image!=null) + { + g.drawImage(image, 0, 0, this); + fastPaint = false; + return; + } - imgWidth = (av.endRes - av.startRes + 1) * av.charWidth; + imgWidth = (av.endRes - av.startRes + 1) * av.charWidth; + if (image == null || imgWidth != image.getWidth()) + { image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(), - BufferedImage.TYPE_INT_RGB); + BufferedImage.TYPE_INT_RGB); gg = (Graphics2D) image.getGraphics(); gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + RenderingHints.VALUE_ANTIALIAS_ON); gg.setFont(av.getFont()); + fm = gg.getFontMetrics(); + } - drawComponent(gg, av.startRes, av.endRes + 1); - g.drawImage(image, 0, 0, this); + drawComponent(gg, av.startRes, av.endRes + 1); + g.drawImage(image, 0, 0, this); } /** @@ -583,7 +594,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, gg.translate(-transX, 0); fastPaint = true; + repaint(); + } /** @@ -595,9 +608,12 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void drawComponent(Graphics2D g, int startRes, int endRes) { - if(fm==null) + if (fm == null) fm = g.getFontMetrics(); + if(fm==null) + fm = g.getFontMetrics(); + g.setColor(Color.white); g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight()); @@ -632,6 +648,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, continue; } + if (row.isGraph) { // this is so that we draw the characters below the graph @@ -697,14 +714,14 @@ public class AnnotationPanel extends JPanel implements MouseListener, if (j == 0 || row.isGraph) { g.drawString(row.annotations[j].displayCharacter, x+charOffset, - y + iconOffset + 2); + 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 + 2); + y + iconOffset + 3); } } @@ -839,19 +856,23 @@ public class AnnotationPanel extends JPanel implements MouseListener, } // 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++) + int x = 0, height; + + for (int j = sRes; j < eRes; j++) { g.setColor(new Color(0, 0, 180)); - int height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); + 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; }