selection)
{
- if (av.seqNameItalics)
+ Font font = alignViewport.getFont();
+ if (alignViewport.isSeqNameItalics())
{
- idfont = new Font(av.getFont().getName(), Font.ITALIC, av.getFont()
- .getSize());
+ setIdfont(new Font(font.getName(), Font.ITALIC,
+ font.getSize()));
}
else
{
- idfont = av.getFont();
+ setIdfont(font);
}
- gg.setFont(idfont);
- fm = gg.getFontMetrics();
+ g.setFont(getIdfont());
+ FontMetrics fm = g.getFontMetrics();
- if (av.antiAlias)
+ if (alignViewport.antiAlias)
{
- gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
Color currentColor = Color.white;
Color currentTextColor = Color.black;
- if (av.getWrapAlignment())
+ boolean hasHiddenRows = alignViewport.hasHiddenRows();
+
+ if (alignViewport.getWrapAlignment())
{
- int maxwidth = av.getAlignment().getWidth();
- int alheight = av.getAlignment().getHeight();
+ drawIdsWrapped(g, alignViewport, startSeq, getHeight());
+ return;
+ }
- if (av.hasHiddenColumns())
- {
- maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
- }
+ // Now draw the id strings
+ int panelWidth = getWidth();
+ int xPos = 0;
- int annotationHeight = 0;
+ // Now draw the id strings
+ for (int i = startSeq; i <= endSeq; i++)
+ {
+ SequenceI sequence = alignViewport.getAlignment().getSequenceAt(i);
- if (av.showAnnotation)
+ if (sequence == null)
{
- if (ap == null)
- {
- ap = new AnnotationPanel(av);
- }
+ continue;
+ }
- annotationHeight = ap.adjustPanelHeight();
- if (labels == null)
- {
- labels = new AnnotationLabels(av);
- }
+ if (hasHiddenRows || alignViewport.isDisplayReferenceSeq())
+ {
+ g.setFont(getHiddenFont(sequence, alignViewport));
+ fm = g.getFontMetrics();
}
- int hgap = av.charHeight;
- if (av.scaleAboveWrapped)
+ // Selected sequence colours
+ if (selection != null && selection.contains(sequence))
+ {
+ currentColor = Color.black;
+ currentTextColor = Color.white;
+ }
+ else if ((alignViewport.getSelectionGroup() != null) && alignViewport
+ .getSelectionGroup().getSequences(null).contains(sequence))
+ {
+ currentColor = Color.lightGray;
+ currentTextColor = Color.black;
+ }
+ else
{
- hgap += av.charHeight;
+ currentColor = alignViewport.getSequenceColour(sequence);
+ currentTextColor = Color.black;
}
- int cHeight = alheight * av.charHeight + hgap + annotationHeight;
+ g.setColor(currentColor);
+
+ int charHeight = alignViewport.getCharHeight();
+ g.fillRect(0, (i - startSeq) * charHeight,
+ getWidth(), charHeight);
+
+ g.setColor(currentTextColor);
- int rowSize = av.getEndRes() - av.getStartRes();
+ String string = sequence
+ .getDisplayId(alignViewport.getShowJVSuffix());
- // Draw the rest of the panels
- for (int ypos = hgap, row = av.startRes; (ypos <= getHeight())
- && (row < maxwidth); ypos += cHeight, row += rowSize)
+ if (alignViewport.isRightAlignIds())
{
- for (int i = starty; i < alheight; i++)
- {
- SequenceI s = av.getAlignment().getSequenceAt(i);
- if (av.hasHiddenRows())
- {
- setHiddenFont(s);
- }
- else
- {
- gg.setFont(idfont);
- }
-
- drawIdString(gg, s, i, 0, ypos);
- }
+ xPos = panelWidth - fm.stringWidth(string) - 4;
+ }
- if (labels != null && av.showAnnotation)
- {
- gg.translate(0, ypos + (alheight * av.charHeight));
- labels.drawComponent(gg, getWidth());
- gg.translate(0, -ypos - (alheight * av.charHeight));
- }
+ g.drawString(string, xPos, (((i - startSeq) * charHeight) + charHeight)
+ - (charHeight / 5));
+
+ if (hasHiddenRows && av.getShowHiddenMarkers())
+ {
+ drawMarker(g, alignViewport, i, startSeq, 0);
}
}
- else
- {
- // No need to hang on to labels if we're not wrapped
- labels = null;
-
- // Now draw the id strings
- int panelWidth = getWidth();
- int xPos = 0;
+ }
- SequenceI sequence;
- // Now draw the id strings
- for (int i = starty; i < endy; i++)
+ /**
+ * Draws sequence ids, and annotation labels if annotations are shown, in
+ * wrapped mode
+ *
+ * @param g
+ * @param alignViewport
+ * @param startSeq
+ */
+ void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport,
+ int startSeq, int pageHeight)
+ {
+ int alignmentWidth = alignViewport.getAlignment().getWidth();
+ final int alheight = alignViewport.getAlignment().getHeight();
+
+
+ /* (former)
+ * assumption: SeqCanvas.calculateWrappedGeometry has been called
+ *
+ * was based on the fact that SeqCanvas was added as a child prior to IdCanvas,
+ * and children are processed in order of addition.
+ *
+ * It's probably fine. But...
+ *
+ */
+ SeqCanvas seqCanvas = alignViewport.getAlignPanel()
+ .getSeqPanel().seqCanvas;
+ // ...better: let's call it now
+ seqCanvas.calculateWrappedGeometry();
+
+ final int charHeight = alignViewport.getCharHeight();
+
+ AnnotationLabels labels = null;
+ if (alignViewport.isShowAnnotation())
+ {
+ // BH when was ap == null?
+ if (ap == null)
{
- sequence = av.getAlignment().getSequenceAt(i);
+ ap = new AnnotationPanel(alignViewport);
+ }
+ labels = new AnnotationLabels(alignViewport);
+ }
- if (sequence == null)
- {
- continue;
- }
+ ViewportRanges ranges = alignViewport.getRanges();
- if (av.hasHiddenRows())
- {
- setHiddenFont(sequence);
- }
+ int rowSize = ranges.getViewportWidth();
- // Selected sequence colours
- if ((searchResults != null) && searchResults.contains(sequence))
- {
- currentColor = Color.black;
- currentTextColor = Color.white;
- }
- else if ((av.getSelectionGroup() != null)
- && av.getSelectionGroup().getSequences(null)
- .contains(sequence))
+ /*
+ * draw repeating sequence ids until out of sequence data or
+ * out of visible space, whichever comes first
+ */
+ boolean hasHiddenRows = alignViewport.hasHiddenRows();
+ int ypos = seqCanvas.wrappedSpaceAboveAlignment;
+ int rowStartRes = ranges.getStartRes();
+ while ((ypos <= pageHeight) && (rowStartRes < alignmentWidth))
+ {
+ for (int i = startSeq; i < alheight; i++)
+ {
+ SequenceI s = alignViewport.getAlignment().getSequenceAt(i);
+ if (hasHiddenRows || alignViewport.isDisplayReferenceSeq())
{
- currentColor = Color.lightGray;
- currentTextColor = Color.black;
+ g.setFont(getHiddenFont(s, alignViewport));
}
else
{
- currentColor = av.getSequenceColour(sequence);
- currentTextColor = Color.black;
- }
-
- gg.setColor(currentColor);
-
- gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
- av.charHeight);
-
- gg.setColor(currentTextColor);
-
- String string = sequence.getDisplayId(av.getShowJVSuffix());
-
- if (av.rightAlignIds)
- {
- xPos = panelWidth - fm.stringWidth(string) - 4;
- }
-
- gg.drawString(string, xPos,
- (((i - starty) * av.charHeight) + av.charHeight)
- - (av.charHeight / 5));
-
- if (av.hasHiddenRows() && av.showHiddenMarkers)
- {
- drawMarker(i, starty, 0);
+ g.setFont(getIdfont());
}
+ drawIdString(g, hasHiddenRows, s, i, 0, ypos);
+ }
+ if (labels != null && alignViewport.isShowAnnotation())
+ {
+ g.translate(0, ypos + (alheight * charHeight));
+ labels.drawComponent(g, getWidth());
+ g.translate(0, -ypos - (alheight * charHeight));
}
+ ypos += seqCanvas.wrappedRepeatHeightPx;
+ rowStartRes += rowSize;
}
}
- void drawMarker(int i, int starty, int yoffset)
+ /**
+ * Draws a marker (a blue right-pointing triangle) between sequences to
+ * indicate hidden sequences.
+ *
+ * @param g
+ * @param alignViewport
+ * @param seqIndex
+ * @param starty
+ * @param yoffset
+ */
+ void drawMarker(Graphics2D g, AlignViewport alignViewport, int seqIndex, int starty, int yoffset)
{
-
- SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
+ SequenceI[] hseqs = alignViewport.getAlignment()
+ .getHiddenSequences().hiddenSequences;
// Use this method here instead of calling hiddenSeq adjust
// 3 times.
int hSize = hseqs.length;
- int hiddenIndex = i;
- int lastIndex = i - 1;
- int nextIndex = i + 1;
+ int hiddenIndex = seqIndex;
+ int lastIndex = seqIndex - 1;
+ int nextIndex = seqIndex + 1;
for (int j = 0; j < hSize; j++)
{
@@ -431,49 +499,56 @@ public class IdCanvas extends JPanel
}
}
+ /*
+ * are we below or above the hidden sequences?
+ */
boolean below = (hiddenIndex > lastIndex + 1);
boolean above = (nextIndex > hiddenIndex + 1);
- gg.setColor(Color.blue);
+ g.setColor(Color.blue);
+ int charHeight = av.getCharHeight();
+
+ /*
+ * vertices of the triangle, below or above hidden seqs
+ */
+ int[] xPoints = new int[]
+ { getWidth() - charHeight,
+ getWidth() - charHeight, getWidth() };
+ int yShift = seqIndex - starty;
+
if (below)
{
- gg.fillPolygon(
- new int[]
- { getWidth() - av.charHeight, getWidth() - av.charHeight,
- getWidth() }, new int[]
- {
- (i - starty) * av.charHeight + yoffset,
- (i - starty) * av.charHeight + yoffset + av.charHeight
- / 4, (i - starty) * av.charHeight + yoffset }, 3);
+ int[] yPoints = new int[] { yShift * charHeight + yoffset,
+ yShift * charHeight + yoffset + charHeight / 4,
+ yShift * charHeight + yoffset };
+ g.fillPolygon(xPoints, yPoints, 3);
}
if (above)
{
- gg.fillPolygon(
- new int[]
- { getWidth() - av.charHeight, getWidth() - av.charHeight,
- getWidth() }, new int[]
- {
- (i - starty + 1) * av.charHeight + yoffset,
- (i - starty + 1) * av.charHeight + yoffset
- - av.charHeight / 4,
- (i - starty + 1) * av.charHeight + yoffset }, 3);
-
+ yShift++;
+ int[] yPoints = new int[] { yShift * charHeight + yoffset,
+ yShift * charHeight + yoffset - charHeight / 4,
+ yShift * charHeight + yoffset };
+ g.fillPolygon(xPoints, yPoints, 3);
}
}
- void setHiddenFont(SequenceI seq)
+ /**
+ * Answers the standard sequence id font, or a bold font if the sequence is
+ * set as reference or a hidden group representative
+ *
+ * @param seq
+ * @param alignViewport
+ * @return
+ */
+ private Font getHiddenFont(SequenceI seq, AlignViewport alignViewport)
{
- Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
- .getSize());
-
- if (av.isHiddenRepSequence(seq))
- {
- gg.setFont(bold);
- }
- else
+ if (av.isReferenceSeq(seq) || av.isHiddenRepSequence(seq))
{
- gg.setFont(idfont);
+ return new Font(av.getFont().getName(), Font.BOLD,
+ av.getFont().getSize());
}
+ return getIdfont();
}
/**
@@ -487,4 +562,61 @@ public class IdCanvas extends JPanel
searchResults = list;
repaint();
}
+
+ public Font getIdfont()
+ {
+ return idfont;
+ }
+
+ public void setIdfont(Font idfont)
+ {
+ this.idfont = idfont;
+ }
+
+ /**
+ * Respond to viewport range changes (e.g. alignment panel was scrolled). 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.
+ *
+ * In unwrapped mode, only responds to a vertical scroll, as horizontal scroll
+ * leaves sequence ids unchanged. In wrapped mode, only vertical scroll is
+ * provided, but it generates a change of "startres" which does require an
+ * update here.
+ */
+ @Override
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ String propertyName = evt.getPropertyName();
+ switch (propertyName)
+ {
+ case ViewportRanges.STARTSEQ:
+ fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
+ break;
+ case ViewportRanges.STARTRES:
+ if (av.getWrapAlignment())
+ {
+ fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
+ }
+ break;
+ case ViewportRanges.STARTRESANDSEQ:
+ fastPaint(((int[]) evt.getNewValue())[1]
+ - ((int[]) evt.getOldValue())[1]);
+ break;
+ case ViewportRanges.MOVE_VIEWPORT:
+ repaint();
+ break;
+ default:
+ }
+ }
+
+ /**
+ * Clears the flag that allows a 'fast paint' on the next repaint, so
+ * requiring a full repaint
+ */
+ public void setNoFastPaint()
+ {
+ allowFastPaint = false;
+ }
}