From: amwaterhouse Date: Thu, 8 Sep 2005 15:48:22 +0000 (+0000) Subject: Optimised for wide alignments X-Git-Tag: Release_2_05b~60 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1c37c329efcec099e7af2eb3db81fc7182e5a51d;p=jalview.git Optimised for wide alignments --- diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 2ddc5ff..3cd229d 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -120,11 +120,8 @@ public class OverviewPanel boxX = evt.getX(); boxY = evt.getY(); checkValid(); - if (!resizing) - { - ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()), + ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()), (int) (boxY / scaleh / av.getCharHeight())); - } } public void doMouseDragged(MouseEvent evt) @@ -132,11 +129,9 @@ public class OverviewPanel boxX = evt.getX(); boxY = evt.getY(); checkValid(); - if (!resizing) - { - ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()), + ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()), (int) (boxY / scaleh / av.getCharHeight())); - } + repaint(); ap.repaint(); } @@ -169,17 +164,25 @@ public class OverviewPanel */ public void updateOverviewImage() { - if (resizing) - { - resizeAgain = true; - return; - } + if (resizing) + { + resizeAgain = true; + return; + } - resizing = true; + resizing = true; - Thread thread = new Thread(this); - thread.start(); - repaint(); + if ( (getSize().width > 0) && (getSize().height > 0)) + { + width = getSize().width; + sequencesHeight = getSize().height - graphHeight; + } + setSize(new Dimension(width, sequencesHeight + graphHeight)); + setBoxPosition(); + + Thread thread = new Thread(this); + thread.start(); + repaint(); } // This is set true if the user resizes whilst @@ -320,27 +323,23 @@ public class OverviewPanel public void paint(Graphics g) { - if (resizing) + if (miniMe != null) + { + g.drawImage(miniMe, 0, 0, this); + } + else { g.setColor(Color.white); g.fillRect(0, 0, getSize().width, getSize().height); g.setColor(Color.black); - g.setFont(new Font("Verdana", Font.BOLD, 15)); g.drawString("Recalculating", 5, sequencesHeight / 2); - g.drawString("Overview.....", 5, sequencesHeight / 2 + 20); + g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20); } - else - { - if (miniMe != null) - { - g.drawImage(miniMe, 0, 0, this); - } - g.setColor(Color.red); - g.drawRect(boxX, boxY, boxWidth, boxHeight); - g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); - } + g.setColor(Color.red); + g.drawRect(boxX, boxY, boxWidth, boxHeight); + g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); } } diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 8ffad08..9e8f895 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -133,7 +133,7 @@ public class SeqCanvas public void fastPaint(int horizontal, int vertical) { - if (horizontal == 0 && vertical == 0 || gg == null) + if (gg == null) { return; } @@ -412,97 +412,139 @@ public class SeqCanvas { do { - int oldY = -1; - int i = 0; - boolean inGroup = false; - int top = -1, bottom = -1; - for (i = y1; i < y2; i++) - { - sx = (group.getStartRes() - startx) * av.charWidth; - sy = offset + (i-starty)*av.charHeight; - ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth - 1; + int oldY = -1; + int i = 0; + boolean inGroup = false; + int top = -1; + int bottom = -1; - if (sx < getSize().width - && ex > 0 - && group.sequences.contains(av.alignment.getSequenceAt(i))) + for (i = y1; i < y2; i++) { - if (bottom == -1 && (i == av.alignment.getHeight() - 1 || - !group.sequences.contains(av.alignment. - getSequenceAt(i + 1)))) - { - bottom = sy + av.charHeight; - } + sx = (group.getStartRes() - startx) * av.charWidth; + sy = offset + ((i - starty) * av.charHeight); + ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - + 1; - if (!inGroup) - { - if (top == -1 && i == 0 || - !group.sequences.contains(av.alignment.getSequenceAt(i - 1))) + if(sx+ex<0 || sx>imgWidth) { - top = sy; + continue; } - oldY = sy; - inGroup = true; - if (group == av.getSelectionGroup()) + if ( (sx <= (x2-x1)*av.charWidth) && + group.sequences.contains(av.alignment.getSequenceAt( + i))) { - g.setColor(new Color(255, 0, 0)); + if ((bottom == -1) && + !group.sequences.contains( + av.alignment.getSequenceAt(i + 1))) + { + bottom = sy + av.charHeight; + } + + if (!inGroup) + { + if (((top == -1) && (i == 0)) || + !group.sequences.contains( + av.alignment.getSequenceAt(i - 1))) + { + top = sy; + } + + oldY = sy; + inGroup = true; + + if (group == av.getSelectionGroup()) + { + g.setColor(Color.red); + } + else + { + g.setColor(group.getOutlineColour()); + } + } } else { - g.setColor(group.getOutlineColour()); + if (inGroup) + { + if (sx >= 0 && sx < imgWidth) + g.drawLine(sx, oldY, sx, sy); + + if (sx + ex < imgWidth) + g.drawLine(sx + ex, oldY, sx + ex, sy); + + if (sx < 0) + { + ex += sx; + sx = 0; + } + + if (sx + ex > imgWidth) + ex = imgWidth; + + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; + + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; + } + + if (bottom != -1) + { + g.drawLine(sx, bottom, sx + ex, bottom); + bottom = -1; + } + + inGroup = false; + } } - } } - else + + if (inGroup) { - if (inGroup) - { + sy = offset + ( (i - starty) * av.charHeight); + if (sx >= 0 && sx < imgWidth) g.drawLine(sx, oldY, sx, sy); + + if (sx + ex < imgWidth) g.drawLine(sx + ex, oldY, sx + ex, sy); - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; - } - if (bottom != -1) - { - g.drawLine(sx, bottom, sx + ex, bottom); - bottom = -1; - } + if (sx < 0) + { + ex += sx; + sx = 0; + } - inGroup = false; + if (sx + ex > imgWidth) + ex = imgWidth; + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; + + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; } - } - } - if (inGroup) - { + if (bottom != -1) + { + g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); + bottom = -1; + } - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; + inGroup = false; } - if (bottom != -1) - { - g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); - bottom = -1; - } - sy = offset + (i-starty)*av.charHeight; - g.drawLine(sx, oldY, sx, sy); - g.drawLine(sx + ex, oldY, sx + ex, sy); - inGroup = false; - } - groupIndex++; - if (groupIndex >= groups.size()) - { - break; - } + groupIndex++; - group = (SequenceGroup) groups.elementAt(groupIndex); + if (groupIndex >= groups.size()) + { + break; + } + group = (SequenceGroup) groups.elementAt(groupIndex); } while (groupIndex < groups.size()); } diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index f78f2e6..c80a830 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -140,11 +140,8 @@ public class OverviewPanel extends JPanel implements Runnable boxY = evt.getY(); checkValid(); - if (!resizing) - { - ap.setScrollValues((int) (boxX / scalew / av.getCharWidth()), + ap.setScrollValues((int) (boxX / scalew / av.getCharWidth()), (int) (boxY / scaleh / av.getCharHeight())); - } } /** @@ -158,11 +155,9 @@ public class OverviewPanel extends JPanel implements Runnable boxY = evt.getY(); checkValid(); - if (!resizing) - { - ap.setScrollValues((int) (boxX / scalew / av.getCharWidth()), - (int) (boxY / scaleh / av.getCharHeight())); - } + ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()), + (int) (boxY / scaleh / av.getCharHeight())); + repaint(); } /** @@ -204,6 +199,14 @@ public class OverviewPanel extends JPanel implements Runnable resizing = true; + if ( (getWidth() > 0) && (getHeight() > 0)) + { + width = getWidth(); + sequencesHeight = getHeight() - graphHeight; + } + setPreferredSize(new Dimension(width, sequencesHeight + graphHeight)); + setBoxPosition(); + Thread thread = new Thread(this); thread.start(); repaint(); @@ -223,12 +226,6 @@ public class OverviewPanel extends JPanel implements Runnable int alwidth = av.alignment.getWidth(); int alheight = av.alignment.getHeight(); - if ((getWidth() > 0) && (getHeight() > 0)) - { - width = getWidth(); - sequencesHeight = getHeight() - graphHeight; - } - setPreferredSize(new Dimension(width, sequencesHeight + graphHeight)); int fullsizeWidth = alwidth * av.getCharWidth(); @@ -240,13 +237,19 @@ public class OverviewPanel extends JPanel implements Runnable miniMe = new BufferedImage(width, sequencesHeight + graphHeight, BufferedImage.TYPE_INT_RGB); + + Graphics mg = miniMe.getGraphics(); - BufferedImage consensus = new BufferedImage(fullsizeWidth, 60, - BufferedImage.TYPE_3BYTE_BGR); - Graphics g = consensus.getGraphics(); - ap.annotationPanel.drawGraph(g, av.conservation, fullsizeWidth, 60); - mg.drawImage(consensus, 0, sequencesHeight, width, - sequencesHeight + graphHeight, 0, 0, fullsizeWidth, 60, this); + BufferedImage consensus; + Graphics cg; + Graphics g ; + + mg.setColor(Color.white); + mg.fillRect(0, 0, getWidth(), getHeight()); + mg.setColor(Color.black); + mg.setFont(new Font("Verdana", Font.BOLD, 15)); + mg.drawString("Recalculating", 5, sequencesHeight / 2); + mg.drawString("Overview.....", 5, (sequencesHeight / 2) + 20); boolean oldRenderGaps = av.renderGaps; @@ -284,6 +287,8 @@ public class OverviewPanel extends JPanel implements Runnable for (int sSeq = 0, chunky = 0; sSeq < alheight; sSeq += maxSize, chunky++) { + if (resizeAgain) + break; eSeq += maxSize; if (eSeq > alheight) @@ -309,12 +314,30 @@ public class OverviewPanel extends JPanel implements Runnable blocky += (int) ((float) sSeq / (float) alheight * sequencesHeight); + if(av.conservation!=null) + { + consensus = new BufferedImage( (eRes - sRes) * av.charWidth, 60, + BufferedImage.TYPE_3BYTE_BGR); + cg = consensus.getGraphics(); + + ap.annotationPanel.drawGraph(cg, av.conservation, + (eRes - sRes) * av.charWidth, 60, sRes, eRes); + + mg.drawImage(consensus, blockx, sequencesHeight, blockx + blockw, + + sequencesHeight + graphHeight, 0, 0, + (eRes - sRes) * av.charWidth, 60, this); + } + mg.drawImage(block, blockx, blocky, blockx + blockw, blocky + blockh, 0, 0, block.getWidth(), block.getHeight(), null); block = null; + repaint(); } + + } } catch (OutOfMemoryError error) @@ -363,26 +386,23 @@ public class OverviewPanel extends JPanel implements Runnable */ public void paintComponent(Graphics g) { - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); - g.setColor(Color.black); - - if (resizing) + if (miniMe != null) { - g.setFont(new Font("Verdana", Font.BOLD, 15)); - g.drawString("Recalculating", 5, sequencesHeight / 2); - g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20); + g.drawImage(miniMe, 0, 0, this); } else { - if (miniMe != null) - { - g.drawImage(miniMe, 0, 0, this); - } - - g.setColor(Color.red); - g.drawRect(boxX, boxY, boxWidth, boxHeight); - g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); + g.setColor(Color.black); + g.setFont(new Font("Verdana", Font.BOLD, 15)); + g.drawString("Recalculating", 5, sequencesHeight / 2); + g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20); } + + g.setColor(Color.red); + g.drawRect(boxX, boxY, boxWidth, boxHeight); + g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); + } } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index b1b63b3..9f1eb70 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -184,7 +184,7 @@ public class SeqCanvas extends JComponent */ public void fastPaint(int horizontal, int vertical) { - if (((horizontal == 0) && (vertical == 0)) || (gg == null)) + if (gg == null) { return; } @@ -201,12 +201,13 @@ public class SeqCanvas extends JComponent if (horizontal > 0) // scrollbar pulled right, image to the left { + er ++; transX = (er - sr - horizontal) * av.charWidth; sr = er - horizontal; } else if (horizontal < 0) { - er = sr - horizontal; + er = sr - horizontal-1; } else if (vertical > 0) // scroll down { @@ -232,10 +233,6 @@ public class SeqCanvas extends JComponent } gg.translate(transX, transY); - - gg.setColor(Color.white); - gg.fillRect(0, 0, (er - sr + 1) * av.charWidth, - (es - ss) * av.charHeight); drawPanel(gg, sr, er, ss, es, sr, ss, 0); gg.translate(-transX, -transY); @@ -282,8 +279,8 @@ public class SeqCanvas extends JComponent img = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB); gg = (Graphics2D) img.getGraphics(); gg.setFont(av.getFont()); - gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + // gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + // RenderingHints.VALUE_ANTIALIAS_ON); gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); @@ -424,11 +421,6 @@ public class SeqCanvas extends JComponent cWidth * av.charWidth, (int) clip.getBounds().getHeight()); } - if(av.alignment.getWidth() >= av.vconsensus.size()) - { - endx = av.vconsensus.size()-2; - } - drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); g.setClip(clip); g.translate(-LABEL_WEST, 0); @@ -522,8 +514,12 @@ public class SeqCanvas extends JComponent ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - 1; + if(sx+ex<0 || sx>imgWidth) + { + continue; + } - if ((sx < (x2-x1)*av.charWidth) && + if ( (sx <= (x2-x1)*av.charWidth) && group.sequences.contains(av.alignment.getSequenceAt( i))) { @@ -563,46 +559,75 @@ public class SeqCanvas extends JComponent } else { - if (inGroup) + if (inGroup) + { + if (sx >= 0 && sx < imgWidth) + g.drawLine(sx, oldY, sx, sy); + + if (sx + ex < imgWidth) + g.drawLine(sx + ex, oldY, sx + ex, sy); + + if (sx < 0) { - g.drawLine(sx, oldY, sx, sy); - g.drawLine(sx + ex, oldY, sx + ex, sy); + ex += sx; + sx = 0; + } - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; - } + if (sx + ex > imgWidth) + ex = imgWidth; - if (bottom != -1) - { - g.drawLine(sx, bottom, sx + ex, bottom); - bottom = -1; - } + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; - inGroup = false; + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; + } + + if (bottom != -1) + { + g.drawLine(sx, bottom, sx + ex, bottom); + bottom = -1; + } + + inGroup = false; } } } - if (inGroup) { - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; - } - - if (bottom != -1) - { - g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); - bottom = -1; - } - - sy = offset + ((i - starty) * av.charHeight); + sy = offset + ( (i - starty) * av.charHeight); + if (sx >= 0 && sx < imgWidth) g.drawLine(sx, oldY, sx, sy); + + if (sx + ex < imgWidth) g.drawLine(sx + ex, oldY, sx + ex, sy); + + if (sx < 0) + { + ex += sx; + sx = 0; + } + + if (sx + ex > imgWidth) + ex = imgWidth; + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; + + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; + } + + if (bottom != -1) + { + g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); + bottom = -1; + } + inGroup = false; }