From 575c5d6f1be723ddde8df56d3393450e826116bd Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 28 Apr 2006 12:34:06 +0000 Subject: [PATCH] Helix glyphs fixed --- src/jalview/gui/AnnotationPanel.java | 100 +++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 1b4a230..3b0127d 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -51,6 +51,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, BufferedImage image; Graphics2D gg; FontMetrics fm; + boolean validCharWidth; int imgWidth = 0; boolean fastPaint = false; @@ -635,6 +636,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void drawComponent(Graphics g, int startRes, int endRes) { + validCharWidth = fm.charWidth('M') <= av.charWidth; + g.setFont(av.getFont()); if (fm == null) @@ -644,12 +647,13 @@ public class AnnotationPanel extends JPanel implements MouseListener, g.setColor(Color.white); g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight()); - if ((av.alignment.getAlignmentAnnotation() == null) || + if ( (av.alignment.getAlignmentAnnotation() == null) || (av.alignment.getAlignmentAnnotation().length < 1)) { g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.black); + if(validCharWidth) g.drawString("Alignment has no annotations", 20, 15); return; @@ -705,20 +709,17 @@ public class AnnotationPanel extends JPanel implements MouseListener, } int column = startRes; - int yPos = startRes; - while (yPos < endRes) + while (column < endRes) { if (av.hasHiddenColumns) { - column = av.getColumnSelection().adjustForHiddenColumns(yPos); + column = av.getColumnSelection().adjustForHiddenColumns(column); if (column > row.annotations.length-1) { break; } } - else - column = yPos; if ((row.annotations.length <= column) || (row.annotations[column] == null)) @@ -730,7 +731,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, validRes = true; } - x = (yPos - startRes) * av.charWidth; + x = (column - startRes) * av.charWidth; if (activeRow == i) { @@ -751,7 +752,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - if (validRes && + if (validCharWidth && validRes && (row.annotations[column].displayCharacter.length() > 0)) { @@ -765,10 +766,13 @@ public class AnnotationPanel extends JPanel implements MouseListener, g.drawString(row.annotations[column].displayCharacter, x+charOffset, y + iconOffset + 3); } - else if (((row.annotations[column - 1] == null) - || - (!row.annotations[column].displayCharacter.equals( - row.annotations[column - 1].displayCharacter)))) + else if ( + row.annotations[column - 1] == null + ||(!row.annotations[column].displayCharacter.equals( + row.annotations[column - 1].displayCharacter) + || + (row.annotations[column].displayCharacter.length() <2 && + row.annotations[column].secondaryStructure==' '))) { g.drawString(row.annotations[column].displayCharacter, x+charOffset, y + iconOffset + 3); @@ -784,9 +788,25 @@ public class AnnotationPanel extends JPanel implements MouseListener, { case 'H': g.setColor(HELIX_COLOUR); - g.fillRoundRect(lastSSX, y + 4 + iconOffset, - x - lastSSX, 7, 8, 8); + int sCol = (lastSSX / av.charWidth) + startRes; + int x1 = lastSSX; + int x2 = x; + + if(row.annotations[sCol-1]==null || + row.annotations[sCol-1].secondaryStructure!='H') + { + g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ; + x1 += av.charWidth/2; + } + + if(row.annotations[column]==null || + row.annotations[column].secondaryStructure!='H') + { + g.fillArc(x-av.charWidth, y+4+iconOffset, av.charWidth, 8, 270,180); + x2 -= av.charWidth/2; + } + g.fillRect(x1, y+4+iconOffset, x2-x1, 8); break; case 'E': @@ -824,7 +844,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - yPos++; + column++; } x += av.charWidth; @@ -834,9 +854,27 @@ public class AnnotationPanel extends JPanel implements MouseListener, switch (lastSS) { case 'H': - g.setColor(HELIX_COLOUR); - g.fillRoundRect(lastSSX, y + 4 + iconOffset, - x - lastSSX, 7, 8, 8); + g.setColor(HELIX_COLOUR); + + int sCol = (lastSSX / av.charWidth) + startRes; + int x1 = lastSSX; + int x2 = x; + + if(row.annotations[sCol-1]==null || + row.annotations[sCol-1].secondaryStructure!='H') + { + g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ; + x1 += av.charWidth/2; + } + + if(row.annotations[column]==null || + row.annotations[column].secondaryStructure!='H') + { + g.fillArc(x-av.charWidth, y+4+iconOffset, av.charWidth, 8, 270,180); + x2 -= av.charWidth/2; + } + + g.fillRect(x1, y+4+iconOffset, x2-x1, 8); break; @@ -961,27 +999,23 @@ public class AnnotationPanel extends JPanel implements MouseListener, eRes = Math.min(eRes, aa.annotations.length); int column = sRes; - int yPos = sRes; int aaMax = aa.annotations.length-1; - while( yPos < eRes ) + while( column < eRes ) { if(av.hasHiddenColumns) { - column = av.getColumnSelection().adjustForHiddenColumns(yPos); + column = av.getColumnSelection().adjustForHiddenColumns(column); if(column > aaMax) { break; } } - else - column = yPos; - - yPos ++; if(aa.annotations[column]==null || aa.annotations[column-1]==null) { x+=av.charWidth; + column ++; continue; } @@ -990,6 +1024,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, y2 = y - (int) (((aa.annotations[column].value-min) / range) * graphHeight); g.drawLine(x-av.charWidth/2, y1, x+av.charWidth/2, y2); x += av.charWidth; + + column++; + } if(aa.threshold!=null) { @@ -1031,31 +1068,26 @@ public class AnnotationPanel extends JPanel implements MouseListener, int column = sRes; - int yPos = sRes; int aaMax = aa.annotations.length-1; - while( yPos < eRes ) + while( column < eRes ) { if(av.hasHiddenColumns) { - column = av.getColumnSelection().adjustForHiddenColumns(yPos); + column = av.getColumnSelection().adjustForHiddenColumns(column); if(column > aaMax) { break; } } - else - column = yPos; - - yPos ++; if (aa.annotations[column] == null) { x += av.charWidth; + column ++; continue; } - g.setColor(aa.annotations[column].colour); y1 = y - (int) (((aa.annotations[column].value-min) / (range)) * aa.graphHeight); @@ -1065,6 +1097,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, g.fillRect(x, y1, av.charWidth, y2-y1 ); x += av.charWidth; + column ++; + } if(aa.threshold!=null) { -- 1.7.10.2