import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
+import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
* <li>scrolling by trackpad, middle mouse button, or other device</li>
* <li>by moving the box in the Overview window</li>
* <li>programmatically to make a highlighted position visible</li>
+ * <li>pasting a block of sequences</li>
* </ul>
*
* @param horizontal
*/
public void fastPaint(int horizontal, int vertical)
{
- if (fastpainting || img == null)
+ // System.err.println("<<SeqCanvas fastPaint " + fastpainting + " "
+ // + horizontal + " " + vertical);
+ // effectively:
+ // if (horizontal != 0 && vertical != 0)
+ // throw new InvalidArgumentException();
+ if (fastpainting || img == null)
{
return;
}
{
int charHeight = av.getCharHeight();
int charWidth = av.getCharWidth();
-
+
ViewportRanges ranges = av.getRanges();
int startRes = ranges.getStartRes();
int endRes = ranges.getEndRes();
int endSeq = ranges.getEndSeq();
int transX = 0;
int transY = 0;
-
- Graphics gg = img.getGraphics();
- gg.copyArea(horizontal * charWidth, vertical * charHeight,
- img.getWidth(), img.getHeight(), -horizontal * charWidth,
- -vertical * charHeight);
if (horizontal > 0) // scrollbar pulled right, image to the left
{
}
}
+
+ // System.err.println(">>> FastPaint to " + transX + " " + transY + " "
+ // + horizontal + " " + vertical + " " + startRes + " " + endRes
+ // + " " + startSeq + " " + endSeq);
+
+ Graphics gg = img.getGraphics();
+ gg.copyArea(horizontal * charWidth, vertical * charHeight,
+ img.getWidth(), img.getHeight(), -horizontal * charWidth,
+ -vertical * charHeight);
+
+ /** @j2sNative xxi = this.img */
+
gg.translate(transX, transY);
drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
gg.translate(-transX, -transY);
gg.dispose();
-
+
// Call repaint on alignment panel so that repaints from other alignment
// panel components can be aggregated. Otherwise performance of the
// overview window and others may be adversely affected.
@Override
public void paintComponent(Graphics g)
{
- //super.paintComponent(g); // BH 2019
-
int charHeight = av.getCharHeight();
int charWidth = av.getCharWidth();
- ViewportRanges ranges = av.getRanges();
-
int width = getWidth();
int height = getHeight();
width -= (width % charWidth);
height -= (height % charHeight);
- if ((img != null) && (fastPaint
- || (getVisibleRect().width != g.getClipBounds().width)
- || (getVisibleRect().height != g.getClipBounds().height)))
+ // BH 2019 can't possibly fastPaint if width and height are 0
+ if (width == 0 || height == 0)
{
- g.drawImage(img, 0, 0, this);
-
- drawSelectionGroup((Graphics2D) g, ranges.getStartRes(),
- ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq());
+ return;
+ }
+ ViewportRanges ranges = av.getRanges();
+ int startRes = ranges.getStartRes();
+ int startSeq = ranges.getStartSeq();
+ int endRes = ranges.getEndRes();
+ int endSeq = ranges.getEndSeq();
+
+ // System.err.println(">>SeqCanvas paintComponent " + fastPaint + "\n"
+ // + getVisibleRect() + "\n" + g.getClipBounds());
+ // System.err.println(">>>>>>>>>>>>>>>>SeqCanvas paintComponent "
+ // + startRes + " " + endRes + " " + startSeq + " " + endSeq);
+ Rectangle vis, clip;
+ if (img != null
+ && (fastPaint
+ || (vis = getVisibleRect()).width != (clip = g
+ .getClipBounds()).width
+ || vis.height != clip.height))
+ {
+ g.drawImage(img, 0, 0, this);
+ // System.err.println(">>>>>>>>>>>>>>>>SeqCanvas paintComponent FAST");
+ drawSelectionGroup((Graphics2D) g, startRes, endRes, startSeq,
+ endSeq);
fastPaint = false;
}
- else if (width > 0 && height > 0)
+ else
{
+
/*
- * img is a cached version of the last view we drew, if any
- * if we have no img or the size has changed, make a new one
+ * img is a cached version of the last view we drew.
+ * If we have no img or the size has changed, make a new one
*/
if (img == null || width != img.getWidth()
|| height != img.getHeight())
if (av.getWrapAlignment())
{
- drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes());
+ drawWrappedPanel(gg, width, height, ranges.getStartRes());
}
else
{
- drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(),
- ranges.getStartSeq(), ranges.getEndSeq(), 0);
+ drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
}
- drawSelectionGroup(gg, ranges.getStartRes(),
- ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq());
+ drawSelectionGroup(gg, startRes, endRes, startSeq, endSeq);
g.drawImage(img, 0, 0, this);
gg.dispose();
if (av.cursorMode)
{
- drawCursor(g, ranges.getStartRes(), ranges.getEndRes(),
- ranges.getStartSeq(), ranges.getEndSeq());
+ drawCursor(g, startRes, endRes, startSeq, endSeq);
}
}
public void propertyChange(PropertyChangeEvent evt)
{
String eventName = evt.getPropertyName();
-
+ // System.err.println(">>SeqCanvas propertyChange " + eventName);
if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED))
{
fastPaint = true;
else if (eventName.equals(ViewportRanges.MOVE_VIEWPORT))
{
fastPaint = false;
+ // System.err.println("!!!! fastPaint false from MOVE_VIEWPORT");
repaint();
return;
}
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))
+ // 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))
+ {
+ if (av.getWrapAlignment())
{
- if (av.getWrapAlignment())
- {
- fastPaintWrapped(scrollX);
- }
- else
- {
- fastPaint(scrollX, 0);
- }
+ fastPaintWrapped(scrollX);
+ }
+ else
+ {
+ fastPaint(scrollX, 0);
}
- else if (eventName.equals(ViewportRanges.STARTSEQ))
+ }
+ else if (eventName.equals(ViewportRanges.STARTSEQ))
+ {
+ // scroll
+ fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
+ }
+ else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
+ {
+ if (av.getWrapAlignment())
{
- // scroll
- fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
+ fastPaintWrapped(scrollX);
}
- else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
+ else
{
- if (av.getWrapAlignment())
- {
- fastPaintWrapped(scrollX);
- }
- else
- {
- fastPaint(scrollX, 0);
- }
+ fastPaint(scrollX, 0);
+ }
}
else if (eventName.equals(ViewportRanges.STARTSEQ))
{
fastPaint = true;
fastpainting = true;
- System.out
- .println("fastpaintwrapped fastpainting true; fastPaint="
- + fastPaint);
try
{