X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqCanvas.java;h=42424d9dc8a4a30b95cd7f93905ec5d9e0385ec5;hb=32ce9ddb7ce1a68add53dd81785ae428ca136a83;hp=afb5a36e6262d79963dccdececf5749d8a214e0c;hpb=a6359c6eb746b06030b22135ed20417b971f580f;p=jalview.git diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index afb5a36..42424d9 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -24,6 +24,7 @@ import java.awt.*; import java.awt.image.*; import javax.swing.*; +import jalview.schemes.*; /** @@ -43,8 +44,6 @@ public class SeqCanvas extends JComponent AlignViewport av; boolean displaySearch = false; int[] searchResults = null; - int chunkHeight; - int chunkWidth; boolean fastPaint = false; int LABEL_WEST; int LABEL_EAST; @@ -64,6 +63,28 @@ public class SeqCanvas extends JComponent setBackground(Color.white); } + MCview.PDBCanvas pdbCanvas; + public SequenceRenderer getSequenceRenderer() + { + return sr; + } + + public FeatureRenderer getFeatureRenderer() + { + return fr; + } + + public void setPDBCanvas(MCview.PDBCanvas pc) + { + pdbCanvas = pc; + } + + public AlignViewport getViewport() + { + return av; + } + + /** * DOCUMENT ME! * @@ -184,13 +205,17 @@ public class SeqCanvas extends JComponent */ public void fastPaint(int horizontal, int vertical) { - if (((horizontal == 0) && (vertical == 0)) || (gg == null)) + if (gg == null) { return; } - gg.copyArea(0, 0, imgWidth, imgHeight, -horizontal * av.charWidth, - -vertical * av.charHeight); + gg.copyArea(horizontal * av.charWidth, + vertical * av.charHeight, + imgWidth, + imgHeight, + -horizontal * av.charWidth, + -vertical * av.charHeight); int sr = av.startRes; int er = av.endRes; @@ -201,12 +226,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 +258,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); @@ -257,16 +279,20 @@ public class SeqCanvas extends JComponent // Set this to false to force a full panel paint public void paintComponent(Graphics g) { - if ((img != null) && - (fastPaint || (getWidth() != g.getClipBounds().width) || - (getHeight() != g.getClipBounds().height))) + super.paintComponent(g); + + sr.renderGaps(av.renderGaps); + + if ( img != null && (fastPaint + || (getVisibleRect().width != g.getClipBounds().width) + || (getVisibleRect().height != g.getClipBounds().height))) { g.drawImage(img, 0, 0, this); fastPaint = false; - return; } + // this draws the whole of the alignment imgWidth = getWidth(); imgHeight = getHeight(); @@ -283,16 +309,11 @@ public class SeqCanvas extends JComponent gg = (Graphics2D) img.getGraphics(); gg.setFont(av.getFont()); gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + RenderingHints.VALUE_ANTIALIAS_ON); gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); - chunkWidth = getWrappedCanvasWidth(getWidth()); - chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - - av.setChunkHeight(chunkHeight); - av.setChunkWidth(chunkWidth); if (av.getWrapAlignment()) { @@ -305,6 +326,12 @@ public class SeqCanvas extends JComponent } g.drawImage(img, 0, 0, this); + + if (pdbCanvas != null) + { + pdbCanvas.updateSeqColours(); + } + } /** @@ -379,16 +406,25 @@ public class SeqCanvas extends JComponent LABEL_WEST = fm.stringWidth(getMask()); } + int hgap = av.charHeight; + if(av.scaleAboveWrapped) + hgap += av.charHeight; + int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth; - int cHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; + int cHeight = av.getAlignment().getHeight() * av.charHeight; + + av.setWrappedWidth(cWidth); av.endRes = av.startRes + cWidth; + int endx = (startRes + cWidth) - 1; - int ypos = 2 * av.charHeight; + int ypos = hgap; + while ((ypos <= canvasHeight) && (startRes < av.alignment.getWidth())) { + g.setFont(av.getFont()); g.setColor(Color.black); if (av.scaleLeftWrapped) @@ -424,11 +460,30 @@ public class SeqCanvas extends JComponent cWidth * av.charWidth, (int) clip.getBounds().getHeight()); } + if (av.vconsensus!=null && av.alignment.getWidth() >= av.vconsensus.size()) + { + endx = av.vconsensus.size() - 2; + } + + drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); + + if(av.showAnnotation) + { + g.translate(0, cHeight + ypos + 3); + if(annotations==null) + annotations = new AnnotationPanel(av); + + annotations.drawComponent( (Graphics2D) g, startRes, endx + 1); + g.translate(0, -cHeight - ypos); + } g.setClip(clip); g.translate(-LABEL_WEST, 0); - ypos += cHeight; + ypos += cHeight+getAnnotationHeight()+hgap; + if(av.showAnnotation) + ypos -= 3; + startRes += cWidth; endx = (startRes + cWidth) - 1; @@ -439,6 +494,18 @@ public class SeqCanvas extends JComponent } } + AnnotationPanel annotations; + int getAnnotationHeight() + { + if(!av.showAnnotation) + return 0; + + if(annotations==null) + annotations = new AnnotationPanel(av); + + return annotations.adjustPanelHeight(); + } + /** * DOCUMENT ME! * @@ -451,30 +518,103 @@ public class SeqCanvas extends JComponent * @param starty DOCUMENT ME! * @param offset DOCUMENT ME! */ + + float aaRatio = 2f/3f; + public void increaseAARatio() + { + aaRatio += .025; + if(aaRatio>1) + aaRatio = 1; + + repaint(); + } + + public void decreaseAARation() + { + aaRatio -= .025; + if(aaRatio<0) + aaRatio = 0; + + repaint(); + } + + synchronized public void drawPanel(Graphics g1, int x1, int x2, int y1, int y2, int startx, int starty, int offset) { - Graphics2D g = (Graphics2D) g1; - g.setFont(av.getFont()); - sr.renderGaps(av.renderGaps); + Graphics2D g = (Graphics2D) g1; + g.setFont(av.getFont()); - SequenceI nextSeq; + SequenceI nextSeq, dna = null; + int aaHeight = av.charHeight, dnaHeight = av.charHeight; + Font dnafont = null, aafont = av.getFont(); + + /* if (av.getShowTranslation()) + { + aaHeight = (int) (av.getCharHeight() * aaRatio); + dnaHeight = (int) (av.getCharHeight() * (1 - aaRatio)); + java.awt.geom.AffineTransform transform = new java.awt.geom.AffineTransform(); + transform.scale(1f / 3f, 1); + dnafont = new Font(av.getFont().getName(), av.getFont().getStyle(), + dnaHeight); + dnafont = dnafont.deriveFont(transform); + + aafont = new Font(av.getFont().getName(), av.getFont().getStyle(), + aaHeight); + transform = new java.awt.geom.AffineTransform(); + transform.scale(1 / aaRatio, 1); + aafont = aafont.deriveFont(transform); + } +*/ + + ColourSchemeI cs = av.getGlobalColourScheme(); /// First draw the sequences ///////////////////////////// for (int i = y1; i < y2; i++) { nextSeq = av.alignment.getSequenceAt(i); + g.setFont(aafont); + /* if(av.getShowTranslation()) + { + dna = nextSeq; + StringBuffer sb = new StringBuffer(); + for(int r = 0; r 0)) + if ((group == null) && (av.alignment.getGroups().size() > 0)) { - group = (SequenceGroup) groups.elementAt(0); + group = (SequenceGroup) av.alignment.getGroups().elementAt(0); groupIndex = 0; } - if (group != null) { do @@ -517,8 +655,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))) { @@ -558,59 +700,88 @@ 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; + + 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; + 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; } groupIndex++; - if (groupIndex >= groups.size()) + if (groupIndex >= av.alignment.getGroups().size()) { break; } - group = (SequenceGroup) groups.elementAt(groupIndex); + group = (SequenceGroup) av.alignment.getGroups().elementAt(groupIndex); } - while (groupIndex < groups.size()); + while (groupIndex < av.alignment.getGroups().size()); } /// Highlight search Results once all sequences have been drawn