package jalview.gui;\r
\r
import java.awt.*;\r
+import java.awt.image.*;\r
import javax.swing.*;\r
import jalview.datamodel.*;\r
import jalview.analysis.*;\r
\r
\r
-public class SeqCanvas extends JPanel\r
+public class SeqCanvas extends JComponent\r
{\r
FeatureRenderer fr;\r
- Image img;\r
+ SequenceRenderer sr;\r
+ BufferedImage img;\r
Graphics2D gg;\r
int imgWidth;\r
int imgHeight;\r
\r
AlignViewport av;\r
\r
- public boolean paintFlag = false;\r
-\r
boolean showScores = false;\r
boolean displaySearch = false;\r
int [] searchResults = null;\r
int chunkHeight;\r
int chunkWidth;\r
\r
+ boolean fastPaint = false;\r
+\r
\r
public SeqCanvas(AlignViewport av)\r
{\r
this.av = av;\r
fr = new FeatureRenderer(av);\r
+ sr = new SequenceRenderer(av);\r
setLayout(new BorderLayout());\r
PaintRefresher.Register(this);\r
\r
}\r
\r
- public void drawScale(Graphics g, int startx, int endx,int ypos) {\r
- int scalestartx = startx - startx%10 + 10;\r
+ void drawNorthScale(Graphics g, int startx, int endx,int ypos) {\r
+ int scalestartx = startx - startx % 10 + 10;\r
+\r
+ g.setColor(Color.black);\r
+\r
+ // NORTH SCALE\r
+ for (int i = scalestartx; i < endx; i += 10)\r
+ {\r
+ String string = String.valueOf(i);\r
+ g.drawString(string, (i - startx - 1) * av.charWidth,\r
+ ypos - av.charHeight / 2);\r
+\r
+ g.drawLine( (i - startx - 1) * av.charWidth + av.charWidth / 2,\r
+ ypos + 2 - av.charHeight / 2,\r
+ (i - startx - 1) * av.charWidth + av.charWidth / 2, ypos - 2);\r
\r
- g.setColor(Color.black);\r
+ }\r
+ }\r
\r
- for (int i=scalestartx;i < endx;i+= 10)\r
+ void drawWestScale(Graphics g, int startx, int endx, int ypos)\r
+ {\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
+ ypos+= av.charHeight;\r
+ // EAST SCALE\r
+ for (int i = 0; i < av.alignment.getHeight(); i++)\r
+ {\r
+ SequenceI seq = av.alignment.getSequenceAt(i);\r
+ int index = startx;\r
+ int value = -1;\r
+ while (index < endx)\r
{\r
- String string = String.valueOf(i);\r
- g.drawString(string,(i-startx-1)*av.charWidth,ypos - av.charHeight/2);\r
+ if (jalview.util.Comparison.isGap(seq.getCharAt(index)))\r
+ {\r
+ index++;\r
+ continue;\r
+ }\r
\r
- g.drawLine( (i-startx-1)*av.charWidth +av.charWidth/2, ypos+2 - av.charHeight/2,\r
- (i-startx-1)*av.charWidth +av.charWidth/2, ypos-2 );\r
+ value = av.alignment.getSequenceAt(i).findPosition(index);\r
+ break;\r
+ }\r
+ if(value!=-1)\r
+ {\r
+ int x = LABEL_WEST - fm.stringWidth(value+"");\r
+ g.drawString(value + "", x, ypos + i*av.charHeight - av.charHeight/5);\r
+ }\r
+ }\r
+ }\r
\r
+ void drawEastScale(Graphics g, int startx, int endx, int ypos)\r
+{\r
+ ypos+= av.charHeight;\r
+ // EAST SCALE\r
+ for (int i = 0; i < av.alignment.getHeight(); i++)\r
+ {\r
+ SequenceI seq = av.alignment.getSequenceAt(i);\r
+ int index = endx;\r
+ int value = -1;\r
+ while (index > startx)\r
+ {\r
+ if (jalview.util.Comparison.isGap(seq.getCharAt(index)))\r
+ {\r
+ index--;\r
+ continue;\r
}\r
\r
+ value = av.alignment.getSequenceAt(i).findPosition(index);\r
+ break;\r
+ }\r
+ if(value!=-1)\r
+ g.drawString(value + "", 0, ypos + i*av.charHeight - av.charHeight/5);\r
}\r
\r
+}\r
+\r
+\r
+\r
+\r
\r
public void fastPaint(int horizontal, int vertical)\r
{\r
- if (horizontal == 0 && vertical == 0)\r
+ if (horizontal == 0 && vertical == 0 || gg==null)\r
return;\r
\r
- if (img == null || paintFlag)\r
- {\r
- repaint();\r
- return;\r
- }\r
-\r
gg.copyArea(0, 0, imgWidth, imgHeight, -horizontal * av.charWidth,\r
-vertical * av.charHeight);\r
\r
- int sr = av.startRes, er = av.endRes + 1, ss = av.startSeq, es = av.endSeq,\r
+ int sr = av.startRes, er = av.endRes, ss = av.startSeq, es = av.endSeq,\r
transX = 0, transY = 0;\r
if (horizontal > 0) // scrollbar pulled right, image to the left\r
{\r
\r
else if (vertical > 0) // scroll down\r
{\r
- transY = imgHeight - vertical * av.charHeight;\r
ss = es - vertical;\r
+ if(ss<av.startSeq) // ie scrolling too fast, more than a page at a time\r
+ ss = av.startSeq;\r
+ else\r
+ transY = imgHeight - vertical * av.charHeight;\r
}\r
else if (vertical < 0)\r
+ {\r
es = ss - vertical;\r
+ if(es > av.endSeq)\r
+ es = av.endSeq;\r
+ }\r
+\r
\r
gg.translate(transX, transY);\r
\r
+ gg.setColor(Color.white);\r
+ gg.fillRect(0,0, (er-sr+1)*av.charWidth, (es-ss)*av.charHeight);\r
drawPanel(gg, sr, er, ss, es, sr, ss, 0);\r
-\r
gg.translate( -transX, -transY);\r
- getGraphics().drawImage(img, 0, 0, this);\r
+\r
+ fastPaint = true;\r
+ repaint();\r
\r
}\r
\r
\r
public void paintComponent(Graphics g)\r
{\r
+ g.setColor(Color.white);\r
+ g.fillRect(0, 0, getWidth(), getHeight());\r
+\r
+ if (fastPaint)\r
+ {\r
+ g.drawImage(img, 0, 0, this);\r
+ fastPaint = false;\r
+ return;\r
+ }\r
+\r
// this draws the whole of the alignment\r
imgWidth = getWidth();\r
imgHeight = getHeight();\r
imgWidth -= imgWidth%av.charWidth;\r
imgHeight-= imgHeight%av.charHeight;\r
\r
- img = createImage(imgWidth,imgHeight);\r
+ if(imgWidth<1 || imgHeight<1)\r
+ return;\r
+\r
+ img = new BufferedImage(imgWidth,imgHeight,BufferedImage.TYPE_INT_RGB);\r
gg = (Graphics2D)img.getGraphics();\r
gg.setFont(av.getFont());\r
gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);\r
- paintFlag = false;\r
\r
gg.setColor(Color.white);\r
gg.fillRect(0,0,imgWidth,imgHeight);\r
\r
- chunkWidth = getWidth()/av.charWidth;\r
+ chunkWidth = getWrappedCanvasWidth( getWidth() );\r
chunkHeight = (av.getAlignment().getHeight() + 2)*av.charHeight;\r
\r
av.setChunkHeight(chunkHeight);\r
else\r
drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, av.startRes, av.startSeq, 0);\r
\r
- g.setColor(Color.white);\r
- g.fillRect(0,0,getWidth(),getHeight());\r
- g.drawImage(img,0,0,this);\r
+ g.drawImage(img, 0, 0, this);\r
\r
}\r
\r
+ int LABEL_WEST, LABEL_EAST;\r
+ public int getWrappedCanvasWidth(int cwidth)\r
+ {\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
+\r
+ LABEL_EAST = 0;\r
+ LABEL_WEST = 0;\r
+\r
+ if(av.scaleRightWrapped)\r
+ LABEL_EAST = fm.stringWidth( av.alignment.getWidth()+"000" );\r
+\r
+ if(av.scaleLeftWrapped)\r
+ LABEL_WEST = fm.stringWidth( av.alignment.getWidth()+"" );\r
+\r
+ return (cwidth - LABEL_EAST -LABEL_WEST)/av.charWidth;\r
+ }\r
+\r
public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes)\r
{\r
- AlignmentI da = av.getAlignment();\r
+ AlignmentI al = av.getAlignment();\r
+\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
+\r
+ int LABEL_EAST = 0;\r
+ if(av.scaleRightWrapped)\r
+ LABEL_EAST = fm.stringWidth( al.getWidth()+"000" );\r
+ int LABEL_WEST = 0;\r
+ if(av.scaleLeftWrapped)\r
+ LABEL_WEST = fm.stringWidth(al.getWidth()+"0");\r
\r
- int cWidth = canvasWidth/av.charWidth;\r
+\r
+ int cWidth = (canvasWidth - LABEL_EAST -LABEL_WEST)/av.charWidth;\r
int cHeight = (av.getAlignment().getHeight() + 2)*av.charHeight;\r
\r
+ av.endRes = av.startRes + cWidth;\r
+\r
int endx = startRes+cWidth-1;\r
- int ypos = 2*av.charHeight;\r
+ int ypos = 2*av.charHeight;\r
\r
- while (ypos <= canvasHeight)\r
+ while (ypos <= canvasHeight && startRes<av.alignment.getWidth() )\r
{\r
- drawScale(g, startRes, endx, ypos);\r
- drawPanel(g, startRes, endx, 0, da.getHeight(), startRes, 0, ypos);\r
+ g.setColor(Color.black);\r
+\r
+ if(av.scaleLeftWrapped)\r
+ drawWestScale(g, startRes, endx, ypos);\r
+\r
+ if(av.scaleRightWrapped)\r
+ {\r
+ g.translate(canvasWidth - LABEL_EAST +av.charWidth, 0);\r
+ drawEastScale(g, startRes, endx, ypos);\r
+ g.translate( - (canvasWidth - LABEL_EAST+av.charWidth), 0);\r
+ }\r
+\r
+ g.translate(LABEL_WEST,0);\r
+ if(av.scaleAboveWrapped)\r
+ drawNorthScale(g, startRes, endx, ypos);\r
+\r
+\r
+ // When printing we have an extra clipped region,\r
+ // the Printable page which we need to account for here\r
+ Shape clip = g.getClip();\r
+ if(clip==null)\r
+ g.setClip(0, 0, cWidth*av.charWidth, canvasHeight);\r
+ else\r
+ g.setClip(0,\r
+ (int)clip.getBounds().getY(),\r
+ cWidth*av.charWidth,\r
+ (int)clip.getBounds().getHeight()\r
+ );\r
+\r
+ drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos);\r
+ g.setClip(clip);\r
+ g.translate(-LABEL_WEST,0);\r
\r
ypos += cHeight;\r
startRes += cWidth;\r
endx = startRes + cWidth - 1;\r
\r
- if (endx > da.getWidth())\r
- endx = da.getWidth();\r
+ if (endx > al.getWidth())\r
+ endx = al.getWidth();\r
}\r
\r
}\r
\r
\r
- public void drawPanel(Graphics g1,int x1,int x2, int y1, int y2,int startx, int starty,int offset) {\r
-\r
+ synchronized public void drawPanel(Graphics g1,int x1,int x2, int y1, int y2,int startx, int starty,int offset) {\r
\r
- Graphics2D g = (Graphics2D)g1;\r
+ Graphics2D g = (Graphics2D)g1;\r
g.setFont(av.getFont());\r
- RendererI sr = av.getRenderer();\r
-\r
- /*Vector pid = av.getConsensus(false);\r
- Vector tmpseq = new Vector();\r
- for (int i = 0; i < av.getAlignment().getHeight(); i++)\r
- if (!av.getSelection().contains(av.getAlignment().getSequenceAt(i)))\r
- tmpseq.addElement(av.getAlignment().getSequenceAt(i));\r
-\r
- if (sr instanceof SequenceRenderer)\r
- pid = AAFrequency.calculate(tmpseq,x1,x2);\r
-\r
- else if (sr instanceof GraphRenderer)\r
- pid = AAFrequency.calculatePID(av.getAlignment().getSequenceAt(0),\r
- av.getAlignment().getSequences(),\r
- av.getPIDWindow(),x1,x2);\r
+ sr.renderGaps(av.renderGaps);\r
\r
-*/\r
-\r
- /* if (y2 > starty && y1 < av.getEndSeq())\r
- {\r
- fillBackground(g,\r
- Color.red,\r
- (x1-startx)*charWidth,\r
- offset + AlignmentUtil.getPixelHeight(starty,y1,av.getCharHeight()),\r
- (x2-x1+1)*charWidth,\r
- offset + AlignmentUtil.getPixelHeight(y1,y2,av.getCharHeight()));\r
- }*/\r
\r
SequenceI nextSeq;\r
\r
/////////////////////////////\r
for (int i = y1 ; i < y2 ;i++)\r
{\r
- nextSeq = av.getAlignment().getSequenceAt(i);\r
+ nextSeq = av.alignment.getSequenceAt(i);\r
\r
sr.drawSequence(g, nextSeq, av.alignment.findAllGroups( nextSeq ),x1,x2,\r
(x1 - startx) * av.charWidth,\r
offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight),\r
- av.charWidth,av.charHeight,null, i);\r
+ av.charWidth,av.charHeight);\r
\r
if(av.showSequenceFeatures)\r
{\r
(x1 - startx) * av.charWidth,\r
offset +\r
AlignmentUtil.getPixelHeight(starty, i, av.charHeight),\r
- av.charWidth, av.charHeight, null, i);\r
+ av.charWidth, av.charHeight);\r
}\r
}\r
//\r
int oldY = -1;\r
int i = 0;\r
boolean inGroup = false;\r
+ int top=-1, bottom =-1;\r
for (i = y1; i < y2; i++)\r
{\r
sx = (group.getStartRes() - startx) * av.charWidth;\r
sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
- ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth;\r
+ ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth -1;\r
\r
- if (group.sequences.contains(av.alignment.getSequenceAt(i))\r
- && sx < getWidth()\r
- && ex > 0)\r
+ if (sx < getWidth()\r
+ && ex > 0\r
+ && group.sequences.contains(av.alignment.getSequenceAt(i)))\r
{\r
+ if (bottom == -1 &&\r
+ !group.sequences.contains(av.alignment.getSequenceAt(i + 1)))\r
+ bottom = sy + av.charHeight ;\r
+\r
if (!inGroup)\r
{\r
+ if (top == -1 && i==0 ||\r
+ !group.sequences.contains(av.alignment.getSequenceAt(i - 1)))\r
+ top = sy;\r
+\r
+\r
oldY = sy;\r
inGroup = true;\r
if (group == av.getSelectionGroup())\r
{\r
- // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 3f, new float[]{5f,2f,2f}, 0f ));\r
+ g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 3f, new float[]{5f,3f}, 0f ));\r
g.setColor(Color.RED);\r
}\r
else\r
{\r
if (inGroup)\r
{\r
- g.drawRect(sx, oldY, ex, (sy - oldY));\r
+ g.drawLine(sx, oldY, sx, sy );\r
+ g.drawLine(sx+ex, oldY, sx+ex, sy );\r
+\r
+ if (top != -1)\r
+ {\r
+ g.drawLine(sx, top, sx + ex, top);\r
+ top =-1;\r
+ }\r
+ if (bottom != -1)\r
+ {\r
+ g.drawLine(sx, bottom, sx + ex, bottom);\r
+ bottom = -1;\r
+ }\r
+\r
+\r
inGroup = false;\r
}\r
}\r
}\r
+\r
if (inGroup)\r
{\r
+\r
+ if(top!=-1)\r
+ {\r
+ g.drawLine(sx, top, sx + ex, top);\r
+ top =-1;\r
+ }\r
+ if(bottom!=-1)\r
+ {\r
+ g.drawLine(sx, bottom-1, sx + ex, bottom-1);\r
+ bottom = -1;\r
+\r
+ }\r
sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
- g.drawRect(sx, oldY, ex, (sy - oldY));\r
+ g.drawLine(sx, oldY, sx, sy );\r
+ g.drawLine(sx+ex, oldY, sx+ex, sy );\r
inGroup = false;\r
}\r
-\r
groupIndex++;\r
if (groupIndex >= groups.size())\r
break;\r
for(int r=0; r<searchResults.length; r+=3)\r
{\r
int searchSeq = searchResults[r];\r
- int searchStart = searchResults[r+1];\r
- int searchEnd = searchResults[r+2];\r
\r
if (searchSeq >= y1 && searchSeq < y2)\r
{\r
+ SequenceI seq = av.getAlignment().getSequenceAt(searchSeq);\r
+\r
+ int searchStart = seq.findIndex( searchResults[r+1] )-1;\r
+ int searchEnd = seq.findIndex( searchResults[r+2] )-1;\r
+\r
SequenceRenderer ssr = (SequenceRenderer) sr;\r
- ssr.drawHighlightedText(av.getAlignment().getSequenceAt(searchSeq),\r
+ if(searchStart<x1)\r
+ searchStart = x1;\r
+ if(searchEnd > x2)\r
+ searchEnd = x2;\r
+\r
+ ssr.drawHighlightedText(seq,\r
searchStart,\r
searchEnd,\r
(searchStart - startx) * av.charWidth,\r
}\r
\r
\r
- public int getChunkWidth() {\r
- return chunkWidth;\r
- }\r
\r
public void highlightSearchResults(int [] results)\r
{\r
\r
searchResults = results;\r
\r
- paintFlag = true;\r
repaint();\r
}\r
\r