* @param vertical
* shift up or down in repaint
*/
- public void fastPaint(int horizontal, int vertical, boolean isresize)
+ public void fastPaint(int horizontal, int vertical)
{
if (fastpainting || gg == null)
{
int transX = 0;
int transY = 0;
- if (isresize)
- {
- imgWidth = getWidth();
- imgHeight = getHeight();
-
- imgWidth -= (imgWidth % charWidth);
- imgHeight -= (imgHeight % charHeight);
+ gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth,
+ imgHeight, -horizontal * charWidth, -vertical * charHeight);
- if ((imgWidth > 0) && (imgHeight > 0))
- {
- BufferedImage newimg = new BufferedImage(imgWidth, imgHeight,
- BufferedImage.TYPE_INT_ARGB);
-
- gg = (Graphics2D) newimg.getGraphics();
- gg.setFont(av.getFont());
- gg.drawImage(img, null, 0, 0);
- img = newimg;
-
- if (horizontal != 0)
- {
- transX = (er - horizontal - sr) * charWidth;
- sr = er - horizontal - sr;
- }
- else if (vertical != 0)
- {
- transY = imgHeight - ((vertical + 1) * charHeight);
- ss = es - vertical - ss;
- }
- }
+ if (horizontal > 0) // scrollbar pulled right, image to the left
+ {
+ transX = (er - sr - horizontal) * charWidth;
+ sr = er - horizontal;
}
- else
+ else if (horizontal < 0)
{
- gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth,
- imgHeight, -horizontal * charWidth, -vertical * charHeight);
+ er = sr - horizontal;
+ }
+ else if (vertical > 0) // scroll down
+ {
+ ss = es - vertical;
- if (horizontal > 0) // scrollbar pulled right, image to the left
- {
- transX = (er - sr - horizontal) * charWidth;
- sr = er - horizontal;
+ if (ss < ranges.getStartSeq())
+ { // ie scrolling too fast, more than a page at a time
+ ss = ranges.getStartSeq();
}
- else if (horizontal < 0)
+ else
{
- er = sr - horizontal;
+ transY = imgHeight - ((vertical + 1) * charHeight);
}
- else if (vertical > 0) // scroll down
- {
- ss = es - vertical;
+ }
+ else if (vertical < 0)
+ {
+ es = ss - vertical;
- if (ss < ranges.getStartSeq())
- { // ie scrolling too fast, more than a page at a time
- ss = ranges.getStartSeq();
- }
- else
- {
- transY = imgHeight - ((vertical + 1) * charHeight);
- }
- }
- else if (vertical < 0)
+ if (es > ranges.getEndSeq())
{
- es = ss - vertical;
-
- if (es > ranges.getEndSeq())
- {
- es = ranges.getEndSeq();
- }
+ es = ranges.getEndSeq();
}
}
@Override
public void propertyChange(PropertyChangeEvent evt)
{
+ String eventName = evt.getPropertyName();
+
if (!av.getWrapAlignment())
{
- if (evt.getPropertyName().equals("startres"))
+ int scrollX = 0;
+ if (eventName.equals(ViewportRanges.STARTRES))
{
- // scroll - startres and endres both change
-
// Make sure we're not trying to draw a panel
// larger than the visible window
ViewportRanges vpRanges = av.getRanges();
- int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
- if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes())
+ scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
+ int range = vpRanges.getEndRes() - vpRanges.getStartRes();
+ if (scrollX > range)
{
- scrollX = vpRanges.getEndRes() - vpRanges.getStartRes();
+ scrollX = range;
}
- else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes())
+ else if (scrollX < -range)
{
- scrollX = vpRanges.getStartRes() - vpRanges.getEndRes();
+ scrollX = -range;
}
- fastPaint(scrollX, 0, false);
}
- else if (evt.getPropertyName().equals("endres"))
+
+ // 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))
{
- // resize - only endres changes
- int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
- fastPaint(scrollX, 0, true);
+ // scroll - startres and endres both change
+ fastPaint(scrollX, 0);
}
- else if (evt.getPropertyName().equals("startseq"))
+ else if (eventName.equals(ViewportRanges.STARTSEQ))
{
// scroll
- fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue(), false);
- }
- else if (evt.getPropertyName().equals("endseq"))
- {
- // resize
- fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue(),
- true);
+ fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
}
}
}