From 07c25ef5f4631d5d385191bb01630f02fd1e06bb Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 2 Feb 2005 16:12:55 +0000 Subject: [PATCH] Modified for wrappingAlignment --- src/jalview/gui/AlignFrame.java | 2 +- src/jalview/gui/AlignmentPanel.java | 132 +++++++++++++++++++++++++++++++-- src/jalview/gui/IdCanvas.java | 73 ++++--------------- src/jalview/gui/IdPanel.java | 11 ++- src/jalview/gui/SeqCanvas.java | 137 +++++++++++------------------------ src/jalview/gui/SeqPanel.java | 11 ++- 6 files changed, 203 insertions(+), 163 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 9a87b90..2542216 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -408,7 +408,7 @@ public class AlignFrame extends GAlignFrame protected void wrapMenuItem_actionPerformed(ActionEvent e) { viewport.setWrapAlignment( wrapMenuItem.isSelected() ); - alignPanel.RefreshPanels(); + alignPanel.setWrapAlignment( wrapMenuItem.isSelected() ); } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 9d6467a..de6e057 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -112,12 +112,17 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene public void setWrapAlignment(boolean wrap) { - scalePanelHolder.setVisible(!wrap); - scorePanelHolder.setVisible(!wrap); + scorePanelHolder.setVisible(!wrap); + scalePanelHolder.setVisible(!wrap); + secondaryPanelHolder.setVisible(!wrap); + + hscroll.setVisible(!wrap); + + idSpaceFillerPanel.setVisible(!wrap); + idSpaceFillerPanel1.setVisible(!wrap); + + RefreshPanels(); - hscroll.setVisible(!wrap); - idSpaceFillerPanel.setVisible(!wrap); - idSpaceFillerPanel1.setVisible(!wrap); } @@ -151,6 +156,17 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene seqPanel.seqCanvas.paintFlag = true; idPanel.idCanvas.paintFlag = true; idPanelHolder.setPreferredSize( idPanel.idCanvas.getPreferredSize() ); + + if(av.getWrapAlignment()) + { + int max = av.alignment.getWidth()/ (seqPanel.seqCanvas.getWidth()/av.charWidth)+1; + + int h = (av.alignment.getHeight() + 2)*av.charHeight; + vextent = seqPanel.seqCanvas.getHeight()/h; + vscroll.setValues(0,vextent,0,max); + } + else + setScrollValues(av.getStartRes(), av.getStartSeq()); av.getConsensus(true); if(overviewPanel!=null) @@ -202,9 +218,24 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene if (evt.getSource() == vscroll) { - int offy = vscroll.getValue(); + int offy = vscroll.getValue(); + if (av.getWrapAlignment()) + { + av.setStartRes( vscroll.getValue() * av.getChunkWidth()); + // System.out.println(vscroll.getValue()+" "+ av.getChunkWidth()); + // int resSpan = av.alignment.getWidth()/ (seqPanel.seqCanvas.getWidth()/av.charWidth)+1; + // int h = (av.alignment.getHeight() + 2)*av.charHeight; + // vextent = seqPanel.seqCanvas.getHeight()/h; + // vscroll.setValues(0,vextent,0,max); + + + // av.setStartSeq( ); + } + else + { av.setStartSeq(offy); - av.setEndSeq(offy + seqPanel.seqCanvas.getHeight()/av.getCharHeight()); + av.setEndSeq(offy + seqPanel.seqCanvas.getHeight() / av.getCharHeight()); + } } @@ -216,8 +247,13 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene } + public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException { + if(av.getWrapAlignment()) + { + return PrintWrappedAlignment(pg, pf, pi); + } pg.translate((int)pf.getImageableX(), (int)pf.getImageableY()); @@ -225,6 +261,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene int pheight = (int)pf.getImageableHeight(); int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth(); + pg.setColor(Color.white); pg.fillRect(0,0,pwidth, pheight); pg.setFont( av.getFont() ); @@ -296,6 +333,87 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene return Printable.PAGE_EXISTS; } + class VPanel extends javax.swing.JPanel + { + Image image; + public VPanel(Image i) + { + image = i; + repaint(); + } + public void paintComponent(Graphics g) + { + if(image!=null) + g.drawImage(image,0,0,this); + } + + } + + public int PrintWrappedAlignment(Graphics pg, PageFormat pf, int pi) + { + pg.translate((int)pf.getImageableX(), (int)pf.getImageableY()); + + int pwidth = (int)pf.getImageableWidth(); + int pheight = (int)pf.getImageableHeight(); + int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth(); + + if( seqPanel.seqCanvas.getWidth() < pwidth-idWidth) + pwidth = seqPanel.seqCanvas.getWidth() + idWidth; + + Image image = createImage(pwidth, pheight); + pg = image.getGraphics(); + + pg.setColor(Color.white); + pg.fillRect(0,0,pwidth, pheight); + pg.setFont( av.getFont() ); + + //////////////////////////////////// + /// How many sequences and residues can we fit on a printable page? + AlignmentI da = av.alignment; + int endy = da.getHeight(); + int chunkHeight = (da.getHeight() + 2)*av.charHeight; + int chunkWidth = (pwidth-idWidth)/av.charWidth; + + int noChunksOnPage = pheight / chunkHeight; + int totalChunks = endy / chunkHeight; + + if ( pi*noChunksOnPage > totalChunks ) + return Printable.NO_SUCH_PAGE; + + //////////////// + // Draw the ids + pg.setClip(0,0,pwidth, noChunksOnPage*chunkHeight); + + int row = pi*noChunksOnPage; + pg.setColor(Color.black); + for(int ypos=2*av.charHeight; + ypos <= pheight && row*chunkWidth da.getHeight()) { - endy = da.getHeight(); - } - - for (int i = starty; i < endy; i++) { - SequenceI s = da.getSequenceAt(i); - drawIdString(gg,s,i,starty,ypos); - } - if (rowstart == 0) { - ypos = ypos + av.getChunkHeight(); - } else if (rowstart == 1) { - ypos = ypos + av.getChunkHeight(); - } else { - ypos = ypos + av.getChunkHeight() - rowstart*charHeight; - } - - starty = 0; - - int chunkwidth = av.getChunkWidth(); - int startx = (int)(av.getEndSeq()/chunkwidth)*chunkwidth; - int endx = startx + chunkwidth; - - - while (ypos <= getHeight() && endx < da.getWidth()) { - - for (int i = starty; i < endy; i++) { - SequenceI s = da.getSequenceAt(i); - drawIdString(gg,s,i,starty,ypos); - } - - ypos += av.getChunkHeight(); - startx += chunkwidth; - endx = startx + chunkwidth; - - if (endx > da.getWidth()) { - endx = da.getWidth(); - } - - starty = 0; - - if (endy > da.getHeight()) { - endy = da.getHeight(); - } - - } } else { diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 939a65e..0e528a2 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -73,6 +73,8 @@ public class IdPanel extends JPanel implements MouseListener, MouseMotionListene public void mouseDragged(MouseEvent e) { int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; int seq = av.getIndex(y); if (seq < lastid) @@ -89,7 +91,11 @@ public class IdPanel extends JPanel implements MouseListener, MouseMotionListene { if (e.getClickCount() == 2) { - int seq = av.getIndex(e.getY()); + int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; + + int seq = av.getIndex(y); String id = av.getAlignment().getSequenceAt(seq).getName(); try{ @@ -108,6 +114,9 @@ public class IdPanel extends JPanel implements MouseListener, MouseMotionListene return; int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; + int seq = av.getIndex(y); if (javax.swing.SwingUtilities.isRightMouseButton(e)) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 27a8a9c..3c9bf51db 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -35,15 +35,21 @@ public class SeqCanvas extends JPanel } - public void drawScale(int startx, int endx,int charWidth, int charHeight,int ypos) { + public void drawScale(Graphics g, int startx, int endx,int ypos) { int scalestartx = startx - startx%10 + 10; - gg.setColor(Color.black); + g.setColor(Color.black); + + for (int i=scalestartx;i < endx;i+= 10) + { + String string = String.valueOf(i); + g.drawString(string,(i-startx-1)*av.charWidth,ypos - av.charHeight/2); + + g.drawLine( (i-startx-1)*av.charWidth +av.charWidth/2, ypos+2 - av.charHeight/2, + (i-startx-1)*av.charWidth +av.charWidth/2, ypos-2 ); - for (int i=scalestartx;i < endx;i+= 10) { - String string = String.valueOf(i); - gg.drawString(string,(int)((i-startx-1)*charWidth),ypos+15 - charHeight*(2)); } + } @@ -58,119 +64,62 @@ public class SeqCanvas extends JPanel * in the adjustment listener in SeqPanel when the scrollbars move. */ - public void paintComponent(Graphics g) { - - AlignmentI da = av.getAlignment(); + public void paintComponent(Graphics g) + { - if (img == null || - imgWidth != getWidth() || - imgHeight != getHeight() - || paintFlag) + if (img==null || imgWidth!=getWidth() || imgHeight!=getHeight() || paintFlag) { - imgWidth = getWidth(); imgHeight = getHeight(); - img = createImage(imgWidth,imgHeight); gg = img.getGraphics(); - gg.setFont(av.getFont()); - paintFlag = false; } + chunkWidth = getWidth()/av.charWidth; - chunkHeight = (da.getHeight() + 2)*av.charHeight; + chunkHeight = (av.getAlignment().getHeight() + 2)*av.charHeight; av.setChunkHeight(chunkHeight); av.setChunkWidth(chunkWidth); - - fillBackground(gg,Color.WHITE,0,0,imgWidth,imgHeight); - /* if (av.getWrapAlignment()) { - int offy = av.getStartSeq(); - startx = (int)(offy/chunkWidth)*chunkWidth; - endx = startx + chunkWidth; - starty = offy%chunkHeight; - endy = starty + da.getHeight(); - - int ypos = 0; - int rowstart = starty; - - if (starty == 0) { - ypos = 2*charHeight; - } else if (starty == 1) { - starty = 0; - ypos = charHeight; - } - - if (endy > da.getHeight()) { - endy = da.getHeight(); - } - - if (endx > da.getWidth()) { - endx = da.getWidth(); - } - - if (rowstart < 2) { - drawScale(startx,endx,charWidth,charHeight,ypos); - } - - drawPanel(gg,startx,endx,starty,endy,startx,starty,ypos); - - if (rowstart == 0) { - ypos = ypos + chunkHeight; - } else if (rowstart == 1) { - ypos = ypos + chunkHeight; - } else { - ypos = ypos + chunkHeight - rowstart*charHeight; - } - - startx += chunkWidth; - endx = startx + chunkWidth; - starty = 0; - - if (endx > da.getWidth()) { - endx = da.getWidth(); - } - // Draw the rest of the panels - - while (ypos <= getHeight()) { - drawScale(startx,endx,charWidth,charHeight,ypos); - drawPanel(gg,startx,endx,0,da.getHeight(),startx,starty,ypos); - - ypos += chunkHeight; - startx += chunkWidth; - endx = startx + chunkWidth; - - if (endy > da.getHeight()) { - endy = da.getHeight(); - } - - if (endx > da.getWidth()) { - endx = da.getWidth(); - } - - } - } - else*/ - { - drawPanel(gg,av.startRes,av.endRes,av.startSeq,av.endSeq,av.startRes,av.startSeq,0); - } - + if (av.getWrapAlignment()) + drawWrappedPanel(gg, getWidth(), getHeight(), av.startRes); + else + drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, av.startRes, av.startSeq, 0); - /* if ((oldendy -oldstarty) > (getWidth() / av.getCharWidth())) { - System.out.println("LIMITS ERROR LIMITS ERROR"); - System.out.println("Corrds " + (oldendy-oldstarty) + " " + (getWidth()/av.getCharWidth()) + " " + getWidth() + " " + av.getCharWidth()); - }*/ g.drawImage(img,0,0,this); } + public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes) + { + AlignmentI da = av.getAlignment(); + + int cWidth = canvasWidth/av.charWidth; + int cHeight = (av.getAlignment().getHeight() + 2)*av.charHeight; + int endx = startRes+cWidth-1; + int ypos = 2*av.charHeight; + + while (ypos <= canvasHeight) + { + drawScale(g, startRes, endx, ypos); + drawPanel(g, startRes, endx, 0, da.getHeight(), startRes, 0, ypos); + + ypos += cHeight; + startRes += cWidth; + endx = startRes + cWidth - 1; + + if (endx > da.getWidth()) + endx = da.getWidth(); + } + + } public void drawPanel(Graphics g,int x1,int x2, int y1, int y2,int startx, int starty,int offset) { diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index ab2e1ef..aa4a456 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -38,10 +38,15 @@ public class SeqPanel extends JPanel addMouseMotionListener( new MouseMotionAdapter() { public void mouseMoved(MouseEvent evt) - { doMouseMoved(evt); } + { + if(av.getWrapAlignment()) + return; + doMouseMoved(evt); } public void mouseDragged(MouseEvent evt) { + if(av.getWrapAlignment()) + return; if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) doMouseDragged(evt); else @@ -53,6 +58,8 @@ public class SeqPanel extends JPanel { public void mouseReleased(MouseEvent evt) { + if(av.getWrapAlignment()) + return; if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) doMouseReleased(evt); else @@ -60,6 +67,8 @@ public class SeqPanel extends JPanel } public void mousePressed(MouseEvent evt) { + if(av.getWrapAlignment()) + return; if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) doMousePressed(evt); else -- 1.7.10.2