package jalview.gui;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.HiddenColumns;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.renderer.ScaleRenderer;
import jalview.renderer.ScaleRenderer.ScaleMark;
+import jalview.viewmodel.ViewportListenerI;
import jalview.viewmodel.ViewportRanges;
import java.awt.BasicStroke;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.image.BufferedImage;
+import java.beans.PropertyChangeEvent;
import java.util.List;
import javax.swing.JComponent;
* @author $author$
* @version $Revision$
*/
-public class SeqCanvas extends JComponent
+public class SeqCanvas extends JComponent implements ViewportListenerI
{
final FeatureRenderer fr;
setLayout(new BorderLayout());
PaintRefresher.Register(this, av.getSequenceSetId());
setBackground(Color.white);
+
+ av.getRanges().addPropertyChangeListener(this);
}
public SequenceRenderer getSequenceRenderer()
{
g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2));
}
- g.drawLine((mpos * charWidth) + (charWidth / 2), (ypos + 2)
- - (charHeight / 2), (mpos * charWidth) + (charWidth / 2),
- ypos - 2);
+ g.drawLine((mpos * charWidth) + (charWidth / 2),
+ (ypos + 2) - (charHeight / 2),
+ (mpos * charWidth) + (charWidth / 2), ypos - 2);
}
}
}
if (av.hasHiddenColumns())
{
- startx = av.getColumnSelection().adjustForHiddenColumns(startx);
- endx = av.getColumnSelection().adjustForHiddenColumns(endx);
+ startx = av.getAlignment().getHiddenColumns()
+ .adjustForHiddenColumns(startx);
+ endx = av.getAlignment().getHiddenColumns()
+ .adjustForHiddenColumns(endx);
}
int maxwidth = av.getAlignment().getWidth();
if (av.hasHiddenColumns())
{
- maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+ maxwidth = av.getAlignment().getHiddenColumns()
+ .findColumnPosition(maxwidth) - 1;
}
// WEST SCALE
{
int x = LABEL_WEST - fm.stringWidth(String.valueOf(value))
- charWidth / 2;
- g.drawString(value + "", x, (ypos + (i * charHeight))
- - (charHeight / 5));
+ g.drawString(value + "", x,
+ (ypos + (i * charHeight)) - (charHeight / 5));
}
}
}
if (av.hasHiddenColumns())
{
- endx = av.getColumnSelection().adjustForHiddenColumns(endx);
+ endx = av.getAlignment().getHiddenColumns()
+ .adjustForHiddenColumns(endx);
}
SequenceI seq;
if (value != -1)
{
- g.drawString(String.valueOf(value), 0, (ypos + (i * charHeight))
- - (charHeight / 5));
+ g.drawString(String.valueOf(value), 0,
+ (ypos + (i * charHeight)) - (charHeight / 5));
}
}
}
fastpainting = true;
fastPaint = true;
updateViewport();
- gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth,
- imgHeight, -horizontal * charWidth, -vertical * charHeight);
ViewportRanges ranges = av.getRanges();
int sr = ranges.getStartRes();
int transX = 0;
int transY = 0;
+ gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth,
+ imgHeight, -horizontal * charWidth, -vertical * charHeight);
+
if (horizontal > 0) // scrollbar pulled right, image to the left
{
- er++;
transX = (er - sr - horizontal) * charWidth;
sr = er - horizontal;
}
else if (horizontal < 0)
{
- er = sr - horizontal - 1;
+ er = sr - horizontal;
}
else if (vertical > 0) // scroll down
{
// img and call later.
super.paintComponent(g);
- if (lcimg != null
- && (fastPaint
- || (getVisibleRect().width != g.getClipBounds().width) || (getVisibleRect().height != g
- .getClipBounds().height)))
+ if (lcimg != null && (fastPaint
+ || (getVisibleRect().width != g.getClipBounds().width)
+ || (getVisibleRect().height != g.getClipBounds().height)))
{
g.drawImage(lcimg, 0, 0, this);
fastPaint = false;
FontMetrics fm = getFontMetrics(av.getFont());
+ LABEL_EAST = 0;
+ LABEL_WEST = 0;
+
if (av.getScaleRightWrapped())
{
LABEL_EAST = fm.stringWidth(getMask());
av.setWrappedWidth(cWidth);
- av.getRanges().setEndRes(av.getRanges().getStartRes() + cWidth);
+ av.getRanges().setViewportStartAndWidth(startRes, cWidth);
int endx;
int ypos = hgap;
- int maxwidth = av.getAlignment().getWidth() - 1;
+ int maxwidth = av.getAlignment().getWidth();
if (av.hasHiddenColumns())
{
- maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+ maxwidth = av.getAlignment().getHiddenColumns()
+ .findColumnPosition(maxwidth);
}
while ((ypos <= canvasHeight) && (startRes < maxwidth))
{
g.setColor(Color.blue);
int res;
- for (int i = 0; i < av.getColumnSelection().getHiddenColumns()
- .size(); i++)
+ HiddenColumns hidden = av.getAlignment().getHiddenColumns();
+ List<Integer> positions = hidden.findHiddenRegionPositions();
+ for (int pos : positions)
{
- res = av.getColumnSelection().findHiddenRegionPosition(i)
- - startRes;
+ res = pos - startRes;
if (res < 0 || res > endx - startRes)
{
}
gg.fillPolygon(
- new int[] { res * charWidth - charHeight / 4,
+ new int[]
+ { res * charWidth - charHeight / 4,
res * charWidth + charHeight / 4, res * charWidth },
- new int[] { ypos - (charHeight / 2),
- ypos - (charHeight / 2), ypos - (charHeight / 2) + 8 },
+ new int[]
+ { ypos - (charHeight / 2), ypos - (charHeight / 2),
+ ypos - (charHeight / 2) + 8 },
3);
}
annotations = new AnnotationPanel(av);
}
- annotations.renderer.drawComponent(annotations, av, g, -1,
- startRes, endx + 1);
+ annotations.renderer.drawComponent(annotations, av, g, -1, startRes,
+ endx + 1);
g.translate(0, -cHeight - ypos - 3);
}
g.setClip(clip);
* @param offset
* DOCUMENT ME!
*/
- public void drawPanel(Graphics g1, int startRes, int endRes,
- int startSeq, int endSeq, int offset)
+ public void drawPanel(Graphics g1, int startRes, int endRes, int startSeq,
+ int endSeq, int offset)
{
updateViewport();
if (!av.hasHiddenColumns())
}
else
{
- List<int[]> regions = av.getColumnSelection().getHiddenColumns();
-
int screenY = 0;
int blockStart = startRes;
int blockEnd = endRes;
- for (int[] region : regions)
+ for (int[] region : av.getAlignment().getHiddenColumns()
+ .getHiddenColumnsCopy())
{
int hideStart = region[0];
int hideEnd = region[1];
if (av.isShowSequenceFeatures())
{
- fr.drawSequence(g, nextSeq, startRes, endRes, offset
- + ((i - startSeq) * charHeight), false);
+ fr.drawSequence(g, nextSeq, startRes, endRes,
+ offset + ((i - startSeq) * charHeight), false);
}
// / Highlight search Results once all sequences have been drawn
for (int r = 0; r < visibleResults.length; r += 2)
{
sr.drawHighlightedText(nextSeq, visibleResults[r],
- visibleResults[r + 1], (visibleResults[r] - startRes)
- * charWidth, offset
- + ((i - startSeq) * charHeight));
+ visibleResults[r + 1],
+ (visibleResults[r] - startRes) * charWidth,
+ offset + ((i - startSeq) * charHeight));
}
}
}
{
sx = (group.getStartRes() - startRes) * charWidth;
sy = offset + ((i - startSeq) * charHeight);
- ex = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth) - 1;
+ ex = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth)
+ - 1;
if (sx + ex < 0 || sx > visWidth)
{
}
if ((sx <= (endRes - startRes) * charWidth)
- && group.getSequences(null).contains(
- av.getAlignment().getSequenceAt(i)))
+ && group.getSequences(null)
+ .contains(av.getAlignment().getSequenceAt(i)))
{
- if ((bottom == -1)
- && !group.getSequences(null).contains(
- av.getAlignment().getSequenceAt(i + 1)))
+ if ((bottom == -1) && !group.getSequences(null)
+ .contains(av.getAlignment().getSequenceAt(i + 1)))
{
bottom = sy + charHeight;
}
if (!inGroup)
{
- if (((top == -1) && (i == 0))
- || !group.getSequences(null).contains(
- av.getAlignment().getSequenceAt(i - 1)))
+ if (((top == -1) && (i == 0)) || !group.getSequences(null)
+ .contains(av.getAlignment().getSequenceAt(i - 1)))
{
top = sy;
}
if (group == av.getSelectionGroup())
{
g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f },
- 0f));
+ BasicStroke.JOIN_ROUND, 3f, new float[]
+ { 5f, 3f }, 0f));
g.setColor(Color.RED);
}
else
repaint();
}
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ String eventName = evt.getPropertyName();
+
+ if (av.getWrapAlignment())
+ {
+ if (eventName.equals(ViewportRanges.STARTRES))
+ {
+ repaint();
+ }
+ }
+ else
+ {
+ int scrollX = 0;
+ if (eventName.equals(ViewportRanges.STARTRES))
+ {
+ // Make sure we're not trying to draw a panel
+ // larger than the visible window
+ ViewportRanges vpRanges = av.getRanges();
+ scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
+ int range = vpRanges.getEndRes() - vpRanges.getStartRes();
+ if (scrollX > range)
+ {
+ scrollX = range;
+ }
+ else if (scrollX < -range)
+ {
+ scrollX = -range;
+ }
+ }
+
+ // Both scrolling and resizing change viewport ranges: scrolling changes
+ // both start and end points, but resize only changes end values.
+ // Here we only want to fastpaint on a scroll, with resize using a normal
+ // paint, so scroll events are identified as changes to the horizontal or
+ // vertical start value.
+ if (eventName.equals(ViewportRanges.STARTRES))
+ {
+ // scroll - startres and endres both change
+ fastPaint(scrollX, 0);
+ }
+ else if (eventName.equals(ViewportRanges.STARTSEQ))
+ {
+ // scroll
+ fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
+ }
+ }
+ }
}