X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdCanvas.java;h=5ce36cb108d045f85461d3af816b491823b753ba;hb=ad48d68e5790a0fa55e947b9ab9bb4eb5ca716ca;hp=a7a4e34d47a8aa4e09ab55f2254d4dc56971326e;hpb=be32c14cd8e48fe0a207cd7030cb9cd46f894678;p=jalview.git diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index a7a4e34..5ce36cb 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -21,6 +21,8 @@ package jalview.gui; import jalview.datamodel.SequenceI; +import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; import java.awt.Color; @@ -30,6 +32,7 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import java.beans.PropertyChangeEvent; import java.util.List; import javax.swing.JPanel; @@ -40,7 +43,7 @@ import javax.swing.JPanel; * @author $author$ * @version $Revision$ */ -public class IdCanvas extends JPanel +public class IdCanvas extends JPanel implements ViewportListenerI { protected AlignViewport av; @@ -79,6 +82,7 @@ public class IdCanvas extends JPanel setLayout(new BorderLayout()); this.av = av; PaintRefresher.Register(this, av.getSequenceSetId()); + av.getRanges().addPropertyChangeListener(this); } /** @@ -86,6 +90,8 @@ public class IdCanvas extends JPanel * * @param gg * DOCUMENT ME! + * @param hiddenRows + * true - check and display hidden row marker if need be * @param s * DOCUMENT ME! * @param i @@ -95,8 +101,8 @@ public class IdCanvas extends JPanel * @param ypos * DOCUMENT ME! */ - public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty, - int ypos) + public void drawIdString(Graphics2D gg, boolean hiddenRows, SequenceI s, + int i, int starty, int ypos) { int xPos = 0; int panelWidth = getWidth(); @@ -134,7 +140,7 @@ public class IdCanvas extends JPanel gg.drawString(s.getDisplayId(av.getShowJVSuffix()), xPos, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5)); - if (av.hasHiddenRows() && av.getShowHiddenMarkers()) + if (hiddenRows) { drawMarker(i, starty, ypos); } @@ -156,33 +162,35 @@ public class IdCanvas extends JPanel return; } + ViewportRanges ranges = av.getRanges(); + gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.getCharHeight()); - int ss = av.startSeq; - int es = av.endSeq; + int ss = ranges.getStartSeq(); + int es = ranges.getEndSeq(); int transY = 0; if (vertical > 0) // scroll down { ss = es - vertical; - if (ss < av.startSeq) + if (ss < ranges.getStartSeq()) { // ie scrolling too fast, more than a page at a time - ss = av.startSeq; + ss = ranges.getStartSeq(); } else { - transY = imgHeight - (vertical * av.getCharHeight()); + transY = imgHeight - ((vertical + 1) * av.getCharHeight()); } } - else if (vertical < 0) + else if (vertical < 0) // scroll up { es = ss - vertical; - if (es > av.endSeq) + if (es > ranges.getEndSeq()) { - es = av.endSeq; + es = ranges.getEndSeq(); } } @@ -202,6 +210,7 @@ public class IdCanvas extends JPanel * @param g * DOCUMENT ME! */ + @Override public void paintComponent(Graphics g) { g.setColor(Color.white); @@ -237,7 +246,7 @@ public class IdCanvas extends JPanel gg.setColor(Color.white); gg.fillRect(0, 0, getWidth(), imgHeight); - drawIds(av.getStartSeq(), av.endSeq); + drawIds(av.getRanges().getStartSeq(), av.getRanges().getEndSeq()); g.drawImage(image, 0, 0, this); } @@ -274,6 +283,9 @@ public class IdCanvas extends JPanel Color currentColor = Color.white; Color currentTextColor = Color.black; + final boolean doHiddenCheck = av.isDisplayReferenceSeq() + || av.hasHiddenRows(), hiddenRows = av.hasHiddenRows(); + if (av.getWrapAlignment()) { int maxwidth = av.getAlignment().getWidth(); @@ -281,7 +293,8 @@ public class IdCanvas extends JPanel if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int annotationHeight = 0; @@ -308,16 +321,17 @@ public class IdCanvas extends JPanel int cHeight = alheight * av.getCharHeight() + hgap + annotationHeight; - int rowSize = av.getEndRes() - av.getStartRes(); + int rowSize = av.getRanges().getEndRes() + - av.getRanges().getStartRes(); // Draw the rest of the panels - for (int ypos = hgap, row = av.startRes; (ypos <= getHeight()) + for (int ypos = hgap, row = av.getRanges().getStartRes(); (ypos <= getHeight()) && (row < maxwidth); ypos += cHeight, row += rowSize) { for (int i = starty; i < alheight; i++) { SequenceI s = av.getAlignment().getSequenceAt(i); - if (av.isDisplayReferenceSeq() || av.hasHiddenRows()) + if (doHiddenCheck) { setHiddenFont(s); } @@ -326,7 +340,7 @@ public class IdCanvas extends JPanel gg.setFont(getIdfont()); } - drawIdString(gg, s, i, 0, ypos); + drawIdString(gg, hiddenRows, s, i, 0, ypos); } if (labels != null && av.isShowAnnotation()) @@ -348,7 +362,7 @@ public class IdCanvas extends JPanel SequenceI sequence; // Now draw the id strings - for (int i = starty; i < endy; i++) + for (int i = starty; i <= endy; i++) { sequence = av.getAlignment().getSequenceAt(i); @@ -357,7 +371,7 @@ public class IdCanvas extends JPanel continue; } - if (av.isDisplayReferenceSeq() || av.hasHiddenRows()) + if (doHiddenCheck) { setHiddenFont(sequence); } @@ -399,7 +413,7 @@ public class IdCanvas extends JPanel (((i - starty) * av.getCharHeight()) + av.getCharHeight()) - (av.getCharHeight() / 5)); - if (av.hasHiddenRows() && av.getShowHiddenMarkers()) + if (hiddenRows) { drawMarker(i, starty, 0); } @@ -447,11 +461,9 @@ public class IdCanvas extends JPanel if (below) { gg.fillPolygon( - new int[] - { getWidth() - av.getCharHeight(), - getWidth() - av.getCharHeight(), - getWidth() }, new int[] - { + new int[] { getWidth() - av.getCharHeight(), + getWidth() - av.getCharHeight(), getWidth() }, + new int[] { (i - starty) * av.getCharHeight() + yoffset, (i - starty) * av.getCharHeight() + yoffset + av.getCharHeight() / 4, @@ -460,11 +472,9 @@ public class IdCanvas extends JPanel if (above) { gg.fillPolygon( - new int[] - { getWidth() - av.getCharHeight(), - getWidth() - av.getCharHeight(), - getWidth() }, new int[] - { + new int[] { getWidth() - av.getCharHeight(), + getWidth() - av.getCharHeight(), getWidth() }, + new int[] { (i - starty + 1) * av.getCharHeight() + yoffset, (i - starty + 1) * av.getCharHeight() + yoffset - av.getCharHeight() / 4, @@ -478,7 +488,7 @@ public class IdCanvas extends JPanel Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont() .getSize()); - if (av.isHiddenRepSequence(seq)) + if (av.isReferenceSeq(seq) || av.isHiddenRepSequence(seq)) { gg.setFont(bold); } @@ -509,4 +519,15 @@ public class IdCanvas extends JPanel { this.idfont = idfont; } + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + // Respond to viewport range changes (e.g. alignment panel was scrolled) + if (evt.getPropertyName().equals("startseq") + || evt.getPropertyName().equals("endseq")) + { + fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); + } + } }