From a11e13d8fffacf8115a4d83e4254bf94a87d6600 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 3 Dec 2004 16:32:23 +0000 Subject: [PATCH] Preparing for groupselect mode --- src/jalview/gui/SeqCanvas.java | 170 ++++++++++++++++++++++----------- src/jalview/gui/SeqPanel.java | 105 +++++++++++++++++--- src/jalview/gui/SequenceRenderer.java | 75 ++++++++++----- 3 files changed, 259 insertions(+), 91 deletions(-) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 3850244..00b4e95 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -2,7 +2,7 @@ package jalview.gui; import java.awt.*; import javax.swing.*; -import java.util.*; +import java.awt.event.*; import jalview.datamodel.*; import jalview.schemes.*; import jalview.analysis.*; @@ -10,6 +10,7 @@ import jalview.analysis.*; public class SeqCanvas extends JPanel { + ColourSchemeI globalColorScheme = null; Image img; Graphics gg; int imgWidth; @@ -30,15 +31,15 @@ public class SeqCanvas extends JPanel int chunkHeight; int chunkWidth; - ColourSchemeI cs = new ZappoColourScheme(); public SeqCanvas(AlignViewport av) { this.av = av; setLayout(new BorderLayout()); + } - public void drawScale(int startx, int endx,double charWidth, int charHeight,int ypos) { + public void drawScale(int startx, int endx,int charWidth, int charHeight,int ypos) { int scalestartx = startx - startx%10 + 10; gg.setColor(Color.black); @@ -92,10 +93,10 @@ public class SeqCanvas extends JPanel int endx = av.getEndRes(); int endy = av.getEndSeq(); - double charWidth = av.getCharWidth(); - int charHeight = av.getCharHeight(); + int charWidth = av.getCharWidth(); + int charHeight = av.getCharHeight(); - chunkWidth = (int)(getWidth()/charWidth); + chunkWidth = getWidth()/charWidth; chunkHeight = (da.getHeight() + 2)*charHeight; av.setChunkHeight(chunkHeight); @@ -187,8 +188,8 @@ public class SeqCanvas extends JPanel { // This is dragging horizontal scrollbar to the right - int delx = (int)((startx - oldstartx) * charWidth); - int delx2 = (int)((oldendx - startx + 1) * charWidth); + int delx = (startx - oldstartx) * charWidth; + int delx2 = (oldendx - startx + 1) * charWidth; gg.copyArea(delx,0,delx2,AlignmentUtil.getPixelHeight(starty,endy,charHeight),-delx,0); @@ -205,8 +206,8 @@ public class SeqCanvas extends JPanel { // Horizontal scrollbar pulled to the left - int delx = (int)((oldstartx - startx) * charWidth); - int delx2 = (int)((endx - oldstartx +1) * charWidth); + int delx = (oldstartx - startx) * charWidth; + int delx2 = (endx - oldstartx +1) * charWidth; gg.copyArea(0,0,delx2,AlignmentUtil.getPixelHeight(starty,endy,charHeight),delx,0); @@ -224,7 +225,7 @@ public class SeqCanvas extends JPanel int dely = AlignmentUtil.getPixelHeight(oldstarty,starty,charHeight); int dely2 = AlignmentUtil.getPixelHeight(starty,oldendy,charHeight); - gg.copyArea(0,dely,(int)((endx-startx+1)*charWidth),dely2,0,-dely); + gg.copyArea(0,dely,(endx-startx+1)*charWidth,dely2,0,-dely); if (starty > oldendy) { drawPanel(gg,startx,endx,starty,endy,startx,starty,0); @@ -241,7 +242,7 @@ public class SeqCanvas extends JPanel int dely = AlignmentUtil.getPixelHeight(endy,oldendy,charHeight); int dely2 = AlignmentUtil.getPixelHeight(oldstarty,endy,charHeight); - gg.copyArea(0,0,(int)((endx-startx+1)*charWidth),dely2,0,dely); + gg.copyArea(0,0,(endx-startx+1)*charWidth,dely2,0,dely); if (oldstarty > endy) { drawPanel(gg,startx,endx,starty,endy,startx,starty,0); @@ -253,9 +254,9 @@ public class SeqCanvas extends JPanel oldendy = endy; } - if ((oldendy -oldstarty) > (int)((getWidth() / av.getCharWidth()))) { + if ((oldendy -oldstarty) > (getWidth() / av.getCharWidth())) { System.out.println("LIMITS ERROR LIMITS ERROR"); - System.out.println("Corrds " + (oldendy-oldstarty) + " " + (int)(getWidth()/av.getCharWidth()) + " " + getWidth() + " " + av.getCharWidth()); + System.out.println("Corrds " + (oldendy-oldstarty) + " " + (getWidth()/av.getCharWidth()) + " " + getWidth() + " " + av.getCharWidth()); } @@ -274,6 +275,16 @@ public class SeqCanvas extends JPanel public void drawPanel(Graphics g,int x1,int x2, int y1, int y2,int startx, int starty,int offset) { /* + Startx and starty appear to be the same as x1, y1, unless you find different + x1 x2 + y1************************************************** + * * + * * + * * + * * + **************************************************y2 + +/* System.out.println("drawPanel called with g = " + g); System.out.println(" x1 = " + x1); System.out.println(" x2 = " + x2); @@ -284,8 +295,8 @@ public class SeqCanvas extends JPanel */ g.setFont(av.getFont()); - double charWidth = av.getCharWidth(); - int charHeight = av.getCharHeight(); + int charWidth = av.getCharWidth(); + int charHeight = av.getCharHeight(); RendererI sr = av.getRenderer(); @@ -309,56 +320,64 @@ public class SeqCanvas extends JPanel { fillBackground(g, Color.WHITE, - (int)((x1-startx)*charWidth), + (x1-startx)*charWidth, offset + AlignmentUtil.getPixelHeight(starty,y1,av.getCharHeight()), - (int)((x2-x1+1)*charWidth), + (x2-x1+1)*charWidth, offset + AlignmentUtil.getPixelHeight(y1,y2,av.getCharHeight())); } SequenceI nextSeq; - SequenceGroup group; + SequenceGroup group=null; + boolean newGroup=false; + int sx, sy, ex, ey; + int oldStartX=0,oldEndX=0,oldY=0; for (int i = y1 ; i < y2 ;i++) { - /* if (av.getSelection().contains(av.getAlignment().getSequenceAt(i))) { - r = fr; - System.out.println("use feature renderer"); - } else if ( i == 0) { - // r = br; - } else if (av.getAlignment().getSequenceAt(i).getName().equals("CpG")) { - r = cgr; - System.out.println("cg renderer"); - } -*/ nextSeq = av.getAlignment().getSequenceAt(i); - group = av.alignment.findGroup( nextSeq ); - if( group!=null ) - { - sr.drawSequence(g, group.cs, nextSeq, - x1, - x2, - (int) ( (x1 - startx) * charWidth), - offset + AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight()), - charWidth, charHeight, - false, group.getDisplayBoxes(), group.getDisplayText(), group.getColourText(), - null, i); - } + if(group==null || group!=av.alignment.findGroup( nextSeq )) + newGroup = true; else + newGroup = false; + + group = av.alignment.findGroup( nextSeq ); + + sr.drawSequence(g, nextSeq, group,x1,x2, + (x1 - startx) * charWidth, + offset + AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight()), + charWidth,charHeight,null, i); + + + if( group!=null ) { - sr.drawSequence(g, cs, nextSeq, - x1, - x2, - (int) ( (x1 - startx) * charWidth), - offset + AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight()), - charWidth,charHeight, - showScores, av.getShowBoxes(), av.getShowText(), av.getColourText(), - null, i); - } + g.setColor(Color.GREEN); + sx = (group.getStartRes()-startx)*charWidth; + sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight()); + ex = (group.getEndRes()+1-startx)*charWidth; + ey = offset + AlignmentUtil.getPixelHeight(starty, i+1, av.getCharHeight()); - } + if (newGroup) + { + g.drawLine(oldStartX, oldY, oldEndX, oldY); // Horizontal, bottom of old box + g.drawLine(sx, sy, ex, sy); // Horizontal, top of new box + } + + g.drawLine(sx, sy, sx, ey ); // vertical line, left hand side + g.drawLine( ex,sy,ex,ey); // vertical line, right hand side + if (i == y2 - 1)// last line of alignment, seal the box + g.drawLine(sx, ey, ex, ey); // Horizontal, bottom of old box + + oldStartX = sx; + oldEndX = ex; + oldY = ey; + + } + + } + /// Highlight search Results once all sequences have been drawn if(displaySearch) { for(int r=0; r0) return av.alignment.findGroup((Sequence)av.sel.sequenceAt(0)).cs; else - return seqCanvas.cs; + return seqCanvas.globalColorScheme; + } + + public void doMousePressedDefineMode(MouseEvent evt) + { + int res = evt.getX()/av.getCharWidth() + av.getStartRes(); + int seq = evt.getY()/av.getCharHeight() + av.getStartSeq(); + + stretchGroup = av.alignment.findGroup((Sequence)av.getAlignment().getSequenceAt(seq)); + + if(stretchGroup!=null && stretchGroup.getEndRes()==res) + { + // Edit end res position of selected group + changeEndRes = true; + } + else if(stretchGroup!=null && stretchGroup.getStartRes()==res) + { + // Edit end res position of selected group + changeStartRes = true; + } + + + } + + boolean changeEndRes = false; + boolean changeStartRes = false; + SequenceGroup stretchGroup = null; + + public void doMouseReleasedDefineMode(MouseEvent evt) + { + changeEndRes = false; + changeStartRes = false; + } + + public void doMouseDraggedDefineMode(MouseEvent evt) + { + int res = evt.getX()/av.getCharWidth() + av.getStartRes(); + int seq = evt.getY()/av.getCharHeight() + av.getStartSeq(); + + if(resav.getEndRes()) + res = av.getEndRes(); + + if(changeEndRes) + { + if(res>stretchGroup.getStartRes()-1) + stretchGroup.setEndRes( res ); + } + else if(changeStartRes) + { + if(res=res)?true:false; } public void drawHighlightedText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height) -- 1.7.10.2