From bd56b8fb21d730b15bb759c529990d244cafbe37 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 28 Apr 2006 13:38:39 +0000 Subject: [PATCH] validCharWidth moved to viewport --- src/jalview/gui/AlignViewport.java | 2 ++ src/jalview/gui/AnnotationPanel.java | 8 +++----- src/jalview/gui/FeatureRenderer.java | 2 +- src/jalview/gui/SeqPanel.java | 3 +++ src/jalview/gui/SequenceRenderer.java | 33 +++++++++++++++++---------------- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 5b5b1f3..d4ba5ea 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -61,6 +61,7 @@ public class AlignViewport SequenceGroup selectionGroup; int charHeight; int charWidth; + boolean validCharWidth; int wrappedWidth; Font font; AlignmentI alignment; @@ -624,6 +625,7 @@ public class AlignViewport java.awt.FontMetrics fm = c.getFontMetrics(font); setCharHeight(fm.getHeight()); setCharWidth(fm.charWidth('M')); + validCharWidth = true; } /** diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 232a60c..f9ed690 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -51,7 +51,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, BufferedImage image; Graphics2D gg; FontMetrics fm; - boolean validCharWidth; int imgWidth = 0; boolean fastPaint = false; @@ -643,7 +642,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, if (fm == null) fm = g.getFontMetrics(); - validCharWidth = fm.charWidth('M') <= av.charWidth; g.setColor(Color.white); g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight()); @@ -654,8 +652,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.black); - if(validCharWidth) - g.drawString("Alignment has no annotations", 20, 15); + if(av.validCharWidth) + g.drawString("Alignment has no annotations", 20, 15); return; } @@ -753,7 +751,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - if (validCharWidth && validRes && + if (av.validCharWidth && validRes && (row.annotations[column].displayCharacter.length() > 0)) { diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index 6fbdee8..fdbd7eb 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -319,7 +319,7 @@ public class FeatureRenderer g.fillRect( (i - start) * av.charWidth, y1, av.charWidth,av.charHeight); - if(offscreenRender) + if(offscreenRender || !av.validCharWidth) continue; g.setColor(Color.white); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 9d2e84c..48651f9 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -635,6 +635,9 @@ public class SeqPanel extends JPanel implements MouseListener, ap.repaint(); } + FontMetrics fm = getFontMetrics(av.getFont()); + av.validCharWidth = fm.charWidth('M') <= av.charWidth; + lastMousePress = evt.getPoint(); return; diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 6350fba..02ea4b5 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -41,7 +41,6 @@ public class SequenceRenderer Graphics graphics; boolean monospacedFont; boolean forOverview = false; - boolean validCharWidth = true; /** * Creates a new SequenceRenderer object. @@ -63,8 +62,6 @@ public class SequenceRenderer graphics = g; fm = g.getFontMetrics(); monospacedFont = fm.getStringBounds("M",g).getWidth()==fm.getStringBounds("|",g).getWidth(); - validCharWidth = fm.charWidth('M') <= av.charWidth; - this.renderGaps = renderGaps; } @@ -132,7 +129,7 @@ public class SequenceRenderer drawBoxes(seq, start, end, y1); - if (validCharWidth) + if (av.validCharWidth) drawText(seq, start, end, y1); } @@ -344,17 +341,20 @@ public class SequenceRenderer char s = '~'; // Need to find the sequence position here. - for (int i = start; i <= end; i++) + if(av.validCharWidth) { + for (int i = start; i <= end; i++) + { if (i < seq.getLength()) { - s = seq.getSequence().charAt(i); + s = seq.getSequence().charAt(i); } charOffset = (av.charWidth - fm.charWidth(s)) / 2; graphics.drawString(String.valueOf(s), - charOffset + x1 + (av.charWidth * (i - start)), - (y1 + av.charHeight) - pady); + charOffset + x1 + (av.charWidth * (i - start)), + (y1 + av.charHeight) - pady); + } } } @@ -364,17 +364,18 @@ public class SequenceRenderer int charOffset = 0; graphics.setColor(Color.black); graphics.fillRect(x1, y1, av.charWidth, av.charHeight); - graphics.setColor(Color.white); - graphics.setColor(Color.white); - - char s = seq.getCharAt(res); + if(av.validCharWidth) + { + graphics.setColor(Color.white); - charOffset = (av.charWidth - fm.charWidth(s)) / 2; - graphics.drawString(String.valueOf(s), - charOffset + x1, - (y1 + av.charHeight) - pady); + char s = seq.getCharAt(res); + charOffset = (av.charWidth - fm.charWidth(s)) / 2; + graphics.drawString(String.valueOf(s), + charOffset + x1, + (y1 + av.charHeight) - pady); + } } } -- 1.7.10.2