+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
package jalview.gui;\r
\r
import java.awt.*;\r
+import java.awt.image.*;\r
import javax.swing.*;\r
-import java.util.*;\r
-import jalview.datamodel.*;\r
-import jalview.schemes.*;\r
-import jalview.analysis.*;\r
\r
+import jalview.analysis.*;\r
+import jalview.datamodel.*;\r
\r
-public class SeqCanvas extends JPanel\r
+public class SeqCanvas\r
+ extends JComponent\r
{\r
- Image img;\r
- Graphics gg;\r
- int imgWidth;\r
- int imgHeight;\r
-\r
- AlignViewport av;\r
- int pady = 2;\r
- int oldstartx;\r
- int oldstarty;\r
- int oldendx;\r
- int oldendy;\r
-\r
- public boolean paintFlag = false;\r
- boolean showScores = false;\r
-\r
- int chunkHeight;\r
- int chunkWidth;\r
+ FeatureRenderer fr;\r
+ SequenceRenderer sr;\r
+ BufferedImage img;\r
+ Graphics2D gg;\r
+ int imgWidth;\r
+ int imgHeight;\r
+ AlignViewport av;\r
+ boolean showScores = false;\r
+ boolean displaySearch = false;\r
+ int[] searchResults = null;\r
+ int chunkHeight;\r
+ int chunkWidth;\r
+ boolean fastPaint = false;\r
+ int LABEL_WEST;\r
+ int LABEL_EAST;\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
- Graphics debugG;\r
- FeatureRenderer fr = new FeatureRenderer();\r
- BlockRenderer br = new BlockRenderer();\r
- CpGRenderer cgr = new CpGRenderer();\r
+ void drawNorthScale(Graphics g, int startx, int endx, int ypos)\r
+ {\r
+ int scalestartx = startx - (startx % 10) + 10;\r
\r
- ColourSchemeI cs = new ZappoColourScheme();\r
+ g.setColor(Color.black);\r
\r
- public SeqCanvas(AlignViewport av)\r
+ // NORTH SCALE\r
+ for (int i = scalestartx; i < endx; i += 10)\r
{\r
- this.av = av;\r
- setLayout(new BorderLayout());\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 -\r
+ 2);\r
}\r
+ }\r
\r
- public void drawScale(int startx, int endx,double charWidth, int charHeight,int ypos) {\r
- int scalestartx = startx - startx%10 + 10;\r
+ void drawWestScale(Graphics g, int startx, int endx, int ypos)\r
+ {\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
+ ypos += av.charHeight;\r
\r
- gg.setColor(Color.black);\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
\r
- for (int i=scalestartx;i < endx;i+= 10) {\r
- String string = String.valueOf(i);\r
- gg.drawString(string,(int)((i-startx-1)*charWidth),ypos+15 - charHeight*(2));\r
- }\r
- }\r
+ while (index < endx)\r
+ {\r
+ if (jalview.util.Comparison.isGap(seq.getCharAt(index)))\r
+ {\r
+ index++;\r
\r
+ continue;\r
+ }\r
\r
-/**\r
- * Definitions of startx and endx (hopefully):\r
- * SMJS This is what I'm working towards!\r
- * startx is the first residue (starting at 0) to display.\r
- * endx is the last residue to display (starting at 0).\r
- * starty is the first sequence to display (starting at 0).\r
- * endy is the last sequence to display (starting at 0).\r
- * NOTE 1: The av limits are set in setFont in this class and\r
- * in the adjustment listener in SeqPanel when the scrollbars move.\r
- */\r
+ value = av.alignment.getSequenceAt(i).findPosition(index);\r
\r
- public void paintComponent(Graphics g) {\r
- debugG = g;\r
+ break;\r
+ }\r
\r
- AlignmentI da = av.getAlignment();\r
+ if (value != -1)\r
+ {\r
+ int x = LABEL_WEST - fm.stringWidth(value + "");\r
+ g.drawString(value + "", x,\r
+ (ypos + (i * av.charHeight)) - (av.charHeight / 5));\r
+ }\r
+ }\r
+ }\r
\r
- if (img == null ||\r
- imgWidth != getWidth() ||\r
- imgHeight != getHeight() ||\r
- paintFlag == true) {\r
+ void drawEastScale(Graphics g, int startx, int endx, int ypos)\r
+ {\r
+ ypos += av.charHeight;\r
\r
- imgWidth = (getWidth() > 0 ? getWidth() : 1);\r
- imgHeight = (getHeight() > 0 ? getHeight() : 1);\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
\r
- img = createImage(imgWidth,imgHeight);\r
- gg = img.getGraphics();\r
+ while (index > startx)\r
+ {\r
+ if (jalview.util.Comparison.isGap(seq.getCharAt(index)))\r
+ {\r
+ index--;\r
\r
- // SMJS I added this in to update the AV when the size changes\r
- // until I figure out how this should be done\r
- setFont(av.getFont());\r
+ continue;\r
+ }\r
\r
- gg.setFont(av.getFont());\r
+ value = av.alignment.getSequenceAt(i).findPosition(index);\r
\r
- paintFlag = false;\r
+ break;\r
+ }\r
\r
- oldstartx = -1;\r
- oldendx = -1;\r
- oldstarty = -1;\r
- oldendy = -1;\r
+ if (value != -1)\r
+ {\r
+ g.drawString(value + "", 0,\r
+ (ypos + (i * av.charHeight)) - (av.charHeight / 5));\r
+ }\r
}\r
+ }\r
\r
- int startx = av.getStartRes();\r
- int starty = av.getStartSeq();\r
-\r
- int endx = av.getEndRes();\r
- int endy = av.getEndSeq();\r
+ public void fastPaint(int horizontal, int vertical)\r
+ {\r
+ if ( ( (horizontal == 0) && (vertical == 0)) || (gg == null))\r
+ {\r
+ return;\r
+ }\r
\r
- double charWidth = av.getCharWidth();\r
- int charHeight = av.getCharHeight();\r
+ gg.copyArea(0, 0, imgWidth, imgHeight, -horizontal * av.charWidth,\r
+ -vertical * av.charHeight);\r
\r
- chunkWidth = (int)(getWidth()/charWidth);\r
- chunkHeight = (da.getHeight() + 2)*charHeight;\r
+ int sr = av.startRes;\r
+ int er = av.endRes;\r
+ int ss = av.startSeq;\r
+ int es = av.endSeq;\r
+ int transX = 0;\r
+ int transY = 0;\r
\r
- av.setChunkHeight(chunkHeight);\r
- av.setChunkWidth(chunkWidth);\r
+ if (horizontal > 0) // scrollbar pulled right, image to the left\r
+ {\r
+ transX = (er - sr - horizontal) * av.charWidth;\r
+ sr = er - horizontal;\r
+ }\r
+ else if (horizontal < 0)\r
+ {\r
+ er = sr - horizontal;\r
+ }\r
+ else if (vertical > 0) // scroll down\r
+ {\r
+ ss = es - vertical;\r
\r
- int offy = av.getStartSeq();\r
+ if (ss < av.startSeq)\r
+ { // ie scrolling too fast, more than a page at a time\r
+ ss = av.startSeq;\r
+ }\r
+ else\r
+ {\r
+ transY = imgHeight - (vertical * av.charHeight);\r
+ }\r
+ }\r
+ else if (vertical < 0)\r
+ {\r
+ es = ss - vertical;\r
\r
- if (oldendx == -1) {\r
- fillBackground(gg,Color.WHITE,0,0,imgWidth,imgHeight);\r
+ if (es > av.endSeq)\r
+ {\r
+ es = av.endSeq;\r
+ }\r
+ }\r
\r
- /* if (av.getWrapAlignment() == true) {\r
- startx = (int)(offy/chunkWidth)*chunkWidth;\r
- endx = startx + chunkWidth;\r
- starty = offy%chunkHeight;\r
- endy = starty + da.getHeight();\r
+ gg.translate(transX, transY);\r
\r
- int ypos = 0;\r
- int rowstart = starty;\r
+ gg.setColor(Color.white);\r
+ gg.fillRect(0, 0, (er - sr + 1) * av.charWidth,\r
+ (es - ss) * av.charHeight);\r
+ drawPanel(gg, sr, er, ss, es, sr, ss, 0);\r
+ gg.translate( -transX, -transY);\r
\r
- if (starty == 0) {\r
- ypos = 2*charHeight;\r
- } else if (starty == 1) {\r
- starty = 0;\r
- ypos = charHeight;\r
- }\r
+ fastPaint = true;\r
+ repaint();\r
+ }\r
\r
- if (endy > da.getHeight()) {\r
- endy = da.getHeight();\r
- }\r
+ /**\r
+ * Definitions of startx and endx (hopefully):\r
+ * SMJS This is what I'm working towards!\r
+ * startx is the first residue (starting at 0) to display.\r
+ * endx is the last residue to display (starting at 0).\r
+ * starty is the first sequence to display (starting at 0).\r
+ * endy is the last sequence to display (starting at 0).\r
+ * NOTE 1: The av limits are set in setFont in this class and\r
+ * in the adjustment listener in SeqPanel when the scrollbars move.\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
\r
- if (endx > da.getWidth()) {\r
- endx = da.getWidth();\r
- }\r
+ return;\r
+ }\r
\r
- if (rowstart < 2) {\r
- drawScale(startx,endx,charWidth,charHeight,ypos);\r
- }\r
+ // this draws the whole of the alignment\r
+ imgWidth = getWidth();\r
+ imgHeight = getHeight();\r
\r
- drawPanel(gg,startx,endx,starty,endy,startx,starty,ypos);\r
+ imgWidth -= (imgWidth % av.charWidth);\r
+ imgHeight -= (imgHeight % av.charHeight);\r
\r
- if (rowstart == 0) {\r
- ypos = ypos + chunkHeight;\r
- } else if (rowstart == 1) {\r
- ypos = ypos + chunkHeight;\r
- } else {\r
- ypos = ypos + chunkHeight - rowstart*charHeight;\r
- }\r
+ if ( (imgWidth < 1) || (imgHeight < 1))\r
+ {\r
+ return;\r
+ }\r
\r
- startx += chunkWidth;\r
- endx = startx + chunkWidth;\r
- starty = 0;\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,\r
+ RenderingHints.VALUE_ANTIALIAS_ON);\r
\r
- if (endx > da.getWidth()) {\r
- endx = da.getWidth();\r
- }\r
- // Draw the rest of the panels\r
+ gg.setColor(Color.white);\r
+ gg.fillRect(0, 0, imgWidth, imgHeight);\r
\r
- while (ypos <= getHeight()) {\r
- drawScale(startx,endx,charWidth,charHeight,ypos);\r
- drawPanel(gg,startx,endx,0,da.getHeight(),startx,starty,ypos);\r
+ chunkWidth = getWrappedCanvasWidth(getWidth());\r
+ chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight;\r
\r
- ypos += chunkHeight;\r
- startx += chunkWidth;\r
- endx = startx + chunkWidth;\r
+ av.setChunkHeight(chunkHeight);\r
+ av.setChunkWidth(chunkWidth);\r
\r
- if (endy > da.getHeight()) {\r
- endy = da.getHeight();\r
- }\r
+ if (av.getWrapAlignment())\r
+ {\r
+ drawWrappedPanel(gg, getWidth(), getHeight(), av.startRes);\r
+ }\r
+ else\r
+ {\r
+ drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq,\r
+ av.startRes, av.startSeq, 0);\r
+ }\r
\r
- if (endx > da.getWidth()) {\r
- endx = da.getWidth();\r
- }\r
+ g.drawImage(img, 0, 0, this);\r
+ }\r
\r
- }\r
- } else*/ {\r
- drawPanel(gg,startx,endx,starty,endy,startx,starty,0);\r
+ public int getWrappedCanvasWidth(int cwidth)\r
+ {\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
\r
- oldstartx = startx;\r
- oldendx = endx;\r
- oldstarty = starty;\r
- oldendy = endy;\r
+ LABEL_EAST = 0;\r
+ LABEL_WEST = 0;\r
\r
- }\r
+ if (av.scaleRightWrapped)\r
+ {\r
+ LABEL_EAST = fm.stringWidth(av.alignment.getWidth() + "000");\r
}\r
\r
- else if (oldstartx < startx)\r
+ if (av.scaleLeftWrapped)\r
{\r
- // This is dragging horizontal scrollbar to the right\r
-\r
- int delx = (int)((startx - oldstartx) * charWidth);\r
- int delx2 = (int)((oldendx - startx + 1) * charWidth);\r
+ LABEL_WEST = fm.stringWidth(av.alignment.getWidth() + "");\r
+ }\r
\r
- gg.copyArea(delx,0,delx2,AlignmentUtil.getPixelHeight(starty,endy,charHeight),-delx,0);\r
+ return (cwidth - LABEL_EAST - LABEL_WEST) / av.charWidth;\r
+ }\r
\r
- if (startx > oldendx)\r
- drawPanel(gg,startx,endx,starty,endy,startx,starty,0);\r
- else\r
- drawPanel(gg,oldendx+1,endx,starty,endy,startx,starty,0);\r
+ public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight,\r
+ int startRes)\r
+ {\r
+ AlignmentI al = av.getAlignment();\r
\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
\r
- oldstartx = startx;\r
- oldendx = endx;\r
+ int LABEL_EAST = 0;\r
\r
- } else if (oldstartx > startx)\r
+ if (av.scaleRightWrapped)\r
{\r
- // Horizontal scrollbar pulled to the left\r
+ LABEL_EAST = fm.stringWidth(al.getWidth() + "000");\r
+ }\r
\r
- int delx = (int)((oldstartx - startx) * charWidth);\r
- int delx2 = (int)((endx - oldstartx +1) * charWidth);\r
+ int LABEL_WEST = 0;\r
\r
- gg.copyArea(0,0,delx2,AlignmentUtil.getPixelHeight(starty,endy,charHeight),delx,0);\r
+ if (av.scaleLeftWrapped)\r
+ {\r
+ LABEL_WEST = fm.stringWidth(al.getWidth() + "0");\r
+ }\r
\r
- if (oldstartx > endx) {\r
- drawPanel(gg,startx,endx,starty,endy,startx,starty,0);\r
- } else {\r
- drawPanel(gg,startx,oldstartx-1,starty,endy,startx,starty,0);\r
- }\r
+ int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth;\r
+ int cHeight = (av.getAlignment().getHeight() + 2) * av.charHeight;\r
\r
- oldstartx = startx;\r
- oldendx = endx;\r
+ av.endRes = av.startRes + cWidth;\r
\r
- } else if (oldstarty < starty) {\r
- // Vertical scrollbar down\r
- int dely = AlignmentUtil.getPixelHeight(oldstarty,starty,charHeight);\r
- int dely2 = AlignmentUtil.getPixelHeight(starty,oldendy,charHeight);\r
+ int endx = (startRes + cWidth) - 1;\r
+ int ypos = 2 * av.charHeight;\r
\r
- gg.copyArea(0,dely,(int)((endx-startx+1)*charWidth),dely2,0,-dely);\r
+ while ( (ypos <= canvasHeight) && (startRes < av.alignment.getWidth()))\r
+ {\r
+ g.setColor(Color.black);\r
\r
- if (starty > oldendy) {\r
- drawPanel(gg,startx,endx,starty,endy,startx,starty,0);\r
- } else {\r
- drawPanel(gg,startx,endx,oldendy,endy,startx,starty,0);\r
+ if (av.scaleLeftWrapped)\r
+ {\r
+ drawWestScale(g, startRes, endx, ypos);\r
}\r
\r
- oldstarty = starty;\r
- oldendy = endy;\r
-\r
- } else if (oldstarty > starty) {\r
-\r
- // Vertical scrollbar up\r
- int dely = AlignmentUtil.getPixelHeight(endy,oldendy,charHeight);\r
- int dely2 = AlignmentUtil.getPixelHeight(oldstarty,endy,charHeight);\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
- gg.copyArea(0,0,(int)((endx-startx+1)*charWidth),dely2,0,dely);\r
+ g.translate(LABEL_WEST, 0);\r
\r
- if (oldstarty > endy) {\r
- drawPanel(gg,startx,endx,starty,endy,startx,starty,0);\r
- } else {\r
- drawPanel(gg,startx,endx,starty,oldstarty,startx,starty,0);\r
+ if (av.scaleAboveWrapped)\r
+ {\r
+ drawNorthScale(g, startRes, endx, ypos);\r
}\r
\r
- oldstarty = starty;\r
- oldendy = endy;\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
\r
- if ((oldendy -oldstarty) > (int)((getWidth() / av.getCharWidth()))) {\r
- System.out.println("LIMITS ERROR LIMITS ERROR");\r
- System.out.println("Corrds " + (oldendy-oldstarty) + " " + (int)(getWidth()/av.getCharWidth()) + " " + getWidth() + " " + av.getCharWidth());\r
- }\r
+ if (clip == null)\r
+ {\r
+ g.setClip(0, 0, cWidth * av.charWidth, canvasHeight);\r
+ }\r
+ else\r
+ {\r
+ g.setClip(0, (int) clip.getBounds().getY(),\r
+ cWidth * av.charWidth, (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
- g.drawImage(img,0,0,this);\r
+ ypos += cHeight;\r
+ startRes += cWidth;\r
+ endx = (startRes + cWidth) - 1;\r
\r
+ if (endx > al.getWidth())\r
+ {\r
+ endx = al.getWidth();\r
+ }\r
+ }\r
}\r
\r
-\r
-\r
-\r
- public void drawPanel(Graphics g,int x1,int x2, int y1, int y2,int startx, int starty,int offset) {\r
-\r
-/*\r
- System.out.println("drawPanel called with g = " + g);\r
- System.out.println(" x1 = " + x1);\r
- System.out.println(" x2 = " + x2);\r
- System.out.println(" y1 = " + y1);\r
- System.out.println(" y2 = " + y2);\r
- System.out.println(" startx = " + startx);\r
- System.out.println(" starty = " + starty);\r
-*/\r
-\r
+ synchronized public void drawPanel(Graphics g1, int x1, int x2, int y1,\r
+ int y2, int startx, int starty, int offset)\r
+ {\r
+ Graphics2D g = (Graphics2D) g1;\r
g.setFont(av.getFont());\r
- double charWidth = av.getCharWidth();\r
- int charHeight = av.getCharHeight();\r
-\r
- // Vector pid = av.calcNewConsensus();\r
+ sr.renderGaps(av.renderGaps);\r
\r
- RendererI sr = av.getRenderer();\r
+ SequenceI nextSeq;\r
\r
-/* Vector tmpseq = new Vector();\r
-\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
+ /// First draw the sequences\r
+ /////////////////////////////\r
+ for (int i = y1; i < y2; i++)\r
+ {\r
+ nextSeq = av.alignment.getSequenceAt(i);\r
+\r
+ sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq),\r
+ x1, x2, (x1 - startx) * av.charWidth,\r
+ offset +\r
+ AlignmentUtil.getPixelHeight(starty, i, av.charHeight),\r
+ av.charWidth, av.charHeight);\r
+\r
+ if (av.showSequenceFeatures)\r
+ {\r
+ fr.drawSequence(g, nextSeq,\r
+ av.alignment.findAllGroups(nextSeq), x1, x2,\r
+ (x1 - startx) * av.charWidth,\r
+ offset +\r
+ AlignmentUtil.getPixelHeight(starty, i, av.charHeight),\r
+ av.charWidth, av.charHeight);\r
+ }\r
}\r
\r
- if (sr instanceof SequenceRenderer) {\r
- pid = AAFrequency.calculate(tmpseq,x1,x2);\r
+ //\r
+ /////////////////////////////////////\r
+ // Now outline any areas if necessary\r
+ /////////////////////////////////////\r
+ SequenceGroup group = av.getSelectionGroup();\r
+ java.util.Vector groups = av.alignment.getGroups();\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
+ int sx = -1;\r
+ int sy = -1;\r
+ int ex = -1;\r
+ int groupIndex = -1;\r
\r
- }*/\r
-\r
- if (y2 > starty && y1 < av.getEndSeq()) {\r
-\r
- fillBackground(g,\r
- Color.white,\r
- (int)((x1-startx)*charWidth),\r
- offset + AlignmentUtil.getPixelHeight(starty,y1,av.getCharHeight()),\r
- (int)((x2-x1+1)*charWidth),\r
- offset + AlignmentUtil.getPixelHeight(y1,y2,av.getCharHeight()));\r
+ if ( (group == null) && (groups.size() > 0))\r
+ {\r
+ group = (SequenceGroup) groups.elementAt(0);\r
+ groupIndex = 0;\r
}\r
\r
- for (int i = y1 ; i < y2 ;i++) {\r
-\r
- RendererI r = sr;\r
-\r
- /* if (av.getSelection().contains(av.getAlignment().getSequenceAt(i))) {\r
- r = fr;\r
- System.out.println("use feature renderer");\r
- // } else if ( i == 0) {\r
- // r = br;\r
- } else if (av.getAlignment().getSequenceAt(i).getName().equals("CpG")) {\r
- r = cgr;\r
- System.out.println("cg renderer");\r
- }*/\r
-\r
- r.drawSequence(g,cs,av.getAlignment().getSequenceAt(i),\r
- x1,\r
- x2,\r
- (int)((x1-startx)*charWidth),\r
- offset + AlignmentUtil.getPixelHeight(starty,i,av.getCharHeight()),\r
- charWidth,\r
- charHeight,showScores,av.getShowBoxes(),av.getShowText(),null,i,av);\r
+ if (group != null)\r
+ {\r
+ do\r
+ {\r
+ int oldY = -1;\r
+ int i = 0;\r
+ boolean inGroup = false;\r
+ int top = -1;\r
+ int bottom = -1;\r
+\r
+ for (i = y1; i < y2; i++)\r
+ {\r
+ sx = (group.getStartRes() - startx) * av.charWidth;\r
+ sy = offset +\r
+ AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
+ ex = ( ( (group.getEndRes() + 1) - group.getStartRes()) *\r
+ av.charWidth) -\r
+ 1;\r
+\r
+ if ( (sx < getWidth()) && (ex > 0) &&\r
+ group.sequences.contains(av.alignment.getSequenceAt(\r
+ i)))\r
+ {\r
+ if ( (bottom == -1) &&\r
+ !group.sequences.contains(\r
+ av.alignment.getSequenceAt(i + 1)))\r
+ {\r
+ bottom = sy + av.charHeight;\r
+ }\r
+\r
+ if (!inGroup)\r
+ {\r
+ if ( ( (top == -1) && (i == 0)) ||\r
+ !group.sequences.contains(\r
+ av.alignment.getSequenceAt(i - 1)))\r
+ {\r
+ top = sy;\r
+ }\r
+\r
+ oldY = sy;\r
+ inGroup = true;\r
+\r
+ if (group == av.getSelectionGroup())\r
+ {\r
+ g.setStroke(new BasicStroke(1,\r
+ BasicStroke.CAP_BUTT,\r
+ BasicStroke.JOIN_ROUND, 3f,\r
+ new float[]\r
+ {5f, 3f}, 0f));\r
+ g.setColor(Color.RED);\r
+ }\r
+ else\r
+ {\r
+ g.setStroke(new BasicStroke());\r
+ g.setColor(group.getOutlineColour());\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (inGroup)\r
+ {\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
+\r
+ if (bottom != -1)\r
+ {\r
+ g.drawLine(sx, bottom, sx + ex, bottom);\r
+ bottom = -1;\r
+ }\r
+\r
+ inGroup = false;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (inGroup)\r
+ {\r
+ if (top != -1)\r
+ {\r
+ g.drawLine(sx, top, sx + ex, top);\r
+ top = -1;\r
+ }\r
+\r
+ if (bottom != -1)\r
+ {\r
+ g.drawLine(sx, bottom - 1, sx + ex, bottom - 1);\r
+ bottom = -1;\r
+ }\r
+\r
+ sy = offset +\r
+ AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
+ g.drawLine(sx, oldY, sx, sy);\r
+ g.drawLine(sx + ex, oldY, sx + ex, sy);\r
+ inGroup = false;\r
+ }\r
+\r
+ groupIndex++;\r
+\r
+ if (groupIndex >= groups.size())\r
+ {\r
+ break;\r
+ }\r
+\r
+ group = (SequenceGroup) groups.elementAt(groupIndex);\r
+ }\r
+ while (groupIndex < groups.size());\r
+ }\r
\r
+ /// Highlight search Results once all sequences have been drawn\r
+ //////////////////////////////////////////////////////////\r
+ if (displaySearch)\r
+ {\r
+ for (int r = 0; r < searchResults.length; r += 3)\r
+ {\r
+ int searchSeq = searchResults[r];\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
+\r
+ if (searchStart < x1)\r
+ {\r
+ searchStart = x1;\r
+ }\r
+\r
+ if (searchEnd > x2)\r
+ {\r
+ searchEnd = x2;\r
+ }\r
+\r
+ ssr.drawHighlightedText(seq, searchStart, searchEnd,\r
+ (searchStart - startx) * av.charWidth,\r
+ offset +\r
+ AlignmentUtil.getPixelHeight(starty,\r
+ searchSeq,\r
+ av.charHeight), av.charWidth, av.charHeight);\r
+ }\r
+ }\r
}\r
}\r
\r
+ public void highlightSearchResults(int[] results)\r
+ {\r
+ // results are in the order sequence, startRes, endRes\r
+ if (results == null)\r
+ {\r
+ displaySearch = false;\r
+ }\r
+ else\r
+ {\r
+ displaySearch = true;\r
+ }\r
\r
+ searchResults = results;\r
\r
- public void fillBackground(Graphics g,Color c, int x1,int y1,int width,int height) {\r
- g.setColor(c);\r
- g.fillRect(x1,y1,width,height);\r
- }\r
-\r
- public int getChunkWidth() {\r
- return chunkWidth;\r
+ repaint();\r
}\r
-\r
}\r