selection, boolean forGUI)
{
- 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 rowSize = av.getEndRes() - av.getStartRes();
+ int charHeight = alignViewport.getCharHeight();
+ g.fillRect(0, (i - startSeq) * charHeight, getWidth(), charHeight);
- // Draw the rest of the panels
- for (int ypos = hgap, row = av.startRes; (ypos <= getHeight())
- && (row < maxwidth); ypos += cHeight, row += rowSize)
- {
- for (int i = starty; i < alheight; i++)
- {
- SequenceI s = av.getAlignment().getSequenceAt(i);
- if (av.hasHiddenRows())
- {
- setHiddenFont(s);
- }
- else
- {
- gg.setFont(idfont);
- }
+ g.setColor(currentTextColor);
- drawIdString(gg, s, i, 0, ypos);
- }
+ String string = sequence
+ .getDisplayId(alignViewport.getShowJVSuffix());
- if (labels != null && av.showAnnotation)
- {
- gg.translate(0, ypos + (alheight * av.charHeight));
- labels.drawComponent(gg, getWidth());
- gg.translate(0, -ypos - (alheight * av.charHeight));
- }
+ if (alignViewport.isRightAlignIds())
+ {
+ xPos = panelWidth - fm.stringWidth(string) - 4;
}
- }
- 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;
+ g.drawString(string, xPos,
+ (((i - startSeq) * charHeight) + charHeight)
+ - (charHeight / 5));
- SequenceI sequence;
- // Now draw the id strings
- for (int i = starty; i < endy; i++)
+ if (hasHiddenRows && av.getShowHiddenMarkers())
{
- sequence = av.getAlignment().getSequenceAt(i);
+ drawMarker(g, alignViewport, i, startSeq, 0);
+ }
+ }
+ }
- if (sequence == null)
- {
- continue;
- }
+ /**
+ * 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)
+ {
+ drawIdsWrapped(g, alignViewport, startSeq, pageHeight, -1, true);
+ }
- if (av.hasHiddenRows())
- {
- setHiddenFont(sequence);
- }
+ /**
+ * render sequence IDs and annotation labels when wrapped - without GUI junk
+ * @param g
+ * @param av2
+ * @param i
+ * @param totalHeight
+ */
+ public void drawIdsWrappedNoGUI(Graphics2D g, AlignViewport av2, int i,
+ int totalHeight)
+ {
+ drawIdsWrapped(g, av2, totalHeight, totalHeight, i,false);
+ }
- // 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))
- {
- currentColor = Color.lightGray;
- currentTextColor = Color.black;
- }
- else
- {
- currentColor = av.getSequenceColour(sequence);
- currentTextColor = Color.black;
- }
+ void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport,
+ int startSeq, int pageHeight, int idWidth, boolean forGUI)
+ {
+ int alignmentWidth = alignViewport.getAlignment().getWidth();
+ final int alheight = alignViewport.getAlignment().getHeight();
- gg.setColor(currentColor);
+ /*
+ * assumption: SeqCanvas.calculateWrappedGeometry has been called
+ */
+ SeqCanvas seqCanvas = alignViewport.getAlignPanel()
+ .getSeqPanel().seqCanvas;
- gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
- av.charHeight);
+ final int charHeight = alignViewport.getCharHeight();
- gg.setColor(currentTextColor);
+ AnnotationLabels labels = null;
+ if (alignViewport.isShowAnnotation())
+ {
+ labels = new AnnotationLabels(alignViewport);
+ }
- String string = sequence.getDisplayId(av.getShowJVSuffix());
+ ViewportRanges ranges = alignViewport.getRanges();
- if (av.rightAlignIds)
+ int rowSize = ranges.getViewportWidth();
+
+ /*
+ * 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())
{
- xPos = panelWidth - fm.stringWidth(string) - 4;
+ g.setFont(getHiddenFont(s, alignViewport));
}
-
- gg.drawString(string, xPos,
- (((i - starty) * av.charHeight) + av.charHeight)
- - (av.charHeight / 5));
-
- if (av.hasHiddenRows() && av.showHiddenMarkers)
+ else
{
- drawMarker(i, starty, 0);
+ g.setFont(getIdfont());
}
+ drawIdString(g, hasHiddenRows, s, i, 0, ypos);
+ }
+ if (labels != null && alignViewport.isShowAnnotation())
+ {
+ int getWidth = getWidth();
+ int thisIdWidth = getWidth;
+ g.translate(0, ypos + (alheight * charHeight));
+ if (!manuallyAdjusted())
+ {
+ int getAnnotationsIdWidth = labels.drawLabels(g, false, -1, false,forGUI,
+ null);
+ thisIdWidth = idWidth < 0 ? getAnnotationsIdWidth : idWidth;
+ if (thisIdWidth > getWidth)
+ {
+ this.setPreferredSize(
+ new Dimension(thisIdWidth, this.getHeight()));
+ this.repaint();
+ alignViewport.setIdWidth(thisIdWidth);
+ }
+ }
+ labels.drawComponent(g, false, thisIdWidth, forGUI);
+ 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++)
{
@@ -430,49 +515,55 @@ 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();
}
/**
@@ -486,4 +577,60 @@ 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();
+ if (propertyName.equals(ViewportRanges.STARTSEQ)
+ || (av.getWrapAlignment()
+ && propertyName.equals(ViewportRanges.STARTRES)))
+ {
+ fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
+ }
+ else if (propertyName.equals(ViewportRanges.STARTRESANDSEQ))
+ {
+ fastPaint(((int[]) evt.getNewValue())[1]
+ - ((int[]) evt.getOldValue())[1]);
+ }
+ else if (propertyName.equals(ViewportRanges.MOVE_VIEWPORT))
+ {
+ repaint();
+ }
+ }
+
+ private boolean manuallyAdjusted = false;
+
+ public boolean manuallyAdjusted()
+ {
+ return manuallyAdjusted;
+ }
+
+ public void setManuallyAdjusted(boolean b)
+ {
+ manuallyAdjusted = b;
+ }
+
}