From 393371998dc63a471dbb64ad868bc09188a01c64 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 21 Apr 2005 17:22:27 +0000 Subject: [PATCH] Printing changes --- src/jalview/gui/AlignmentPanel.java | 252 +++++++++++++++++++++-------------- 1 file changed, 150 insertions(+), 102 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index f1874b1..59717a9 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -11,6 +11,7 @@ import java.io.*; import java.awt.image.*; import org.jibble.epsgraphics.*; import javax.imageio.*; +import javax.swing.*; @@ -107,6 +108,11 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene { // set idCanvas bufferedImage to null // to prevent drawing old image + FontMetrics fm = getFontMetrics(av.getFont()); + + scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight+fm.getDescent())); + idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight+fm.getDescent())); + idPanel.idCanvas.gg = null; annotationPanel.adjustPanelHeight(); Dimension d = calculateIdWidth(); @@ -404,148 +410,159 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException { - int idWidth = calculateIdWidth().width + 4; + int idWidth = calculateIdWidth().width + 4; + FontMetrics fm = getFontMetrics(av.getFont()); + int scaleHeight = av.charHeight + fm.getDescent(); + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); - 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? + int totalRes = (pwidth - idWidth) / av.getCharWidth(); - //////////////////////////////////// - /// How many sequences and residues can we fit on a printable page? - int totalRes = (pwidth - idWidth)/av.getCharWidth(); - int totalSeq = (int)((pheight - 30)/av.getCharHeight())-1; - int pagesWide = av.getAlignment().getWidth() / totalRes +1; - int pagesHigh = av.getAlignment().getHeight() / totalSeq +1; + int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) - 1; - if (pi >= pagesWide*pagesHigh) - return Printable.NO_SUCH_PAGE; + int pagesWide = av.getAlignment().getWidth() / totalRes + 1; - ///////////////////////////// - /// Only print these sequences and residues on this page - int startRes, endRes, startSeq, endSeq; - startRes = (pi % pagesWide) * totalRes; - endRes = startRes + totalRes-1; - if(endRes>av.getAlignment().getWidth()) - endRes = av.getAlignment().getWidth(); + ///////////////////////////// + /// Only print these sequences and residues on this page + int startRes, endRes, startSeq, endSeq; + startRes = (pi % pagesWide) * totalRes; + endRes = startRes + totalRes - 1; + if (endRes > av.getAlignment().getWidth()-1) + endRes = av.getAlignment().getWidth()-1; - startSeq = (pi / pagesWide) * totalSeq; - endSeq = startSeq + totalSeq; - if(endSeq > av.getAlignment().getHeight()) - endSeq = av.getAlignment().getHeight(); + startSeq = (pi / pagesWide) * totalSeq; + endSeq = startSeq + totalSeq; + if (endSeq > av.getAlignment().getHeight()) + endSeq = av.getAlignment().getHeight(); + int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight; - //////////////// - //draw Scale - pg.translate(idWidth,0); - scalePanel.drawScale(pg, startRes, endRes, pwidth-idWidth); + if (av.showAnnotation) + pagesHigh += annotationPanel.getHeight(); - pg.translate(-idWidth, 30); - //////////////// - // Draw the ids - Color currentColor=null; - Color currentTextColor=null; - for(int i=startSeq; i= pagesWide * pagesHigh) + return Printable.NO_SUCH_PAGE; + + //draw Scale + pg.translate(idWidth, 0); + scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight); + pg.translate( -idWidth, scaleHeight); + //////////////// + // Draw the ids + Color currentColor = null; + Color currentTextColor = null; + for (int i = startSeq; i < endSeq; i++) { - currentColor = av.getAlignment().getSequenceAt(i).getColor(); - currentTextColor = Color.black; - } + if (av.getSelectionGroup() != null && + av.getSelectionGroup().sequences. + contains(av.getAlignment().getSequenceAt(i))) + { + currentColor = Color.gray; + currentTextColor = Color.black; + } + else + { + currentColor = av.getAlignment().getSequenceAt(i).getColor(); + currentTextColor = Color.black; + } - pg.setColor(currentColor); - pg.fillRect(0, jalview.analysis.AlignmentUtil.getPixelHeight(startSeq, i, av.getCharHeight()), - idWidth, - av.getCharHeight()); + pg.setColor(currentColor); + pg.fillRect(0, + jalview.analysis.AlignmentUtil.getPixelHeight(startSeq, i, + av.getCharHeight()), + idWidth, + av.getCharHeight()); - pg.setColor(currentTextColor); + pg.setColor(currentTextColor); - String string = av.getAlignment().getSequenceAt(i).getName(); - if(av.getShowFullId()) - string = av.getAlignment().getSequenceAt(i).getDisplayId(); + String string = av.getAlignment().getSequenceAt(i).getName(); + if (av.getShowFullId()) + string = av.getAlignment().getSequenceAt(i).getDisplayId(); - pg.drawString(string, 0, jalview.analysis.AlignmentUtil.getPixelHeight - (startSeq, i, av.getCharHeight()) + av.getCharHeight() - (av.getCharHeight() / 5)); - } + pg.drawString(string, 0, jalview.analysis.AlignmentUtil.getPixelHeight + (startSeq, i, av.getCharHeight()) + av.getCharHeight() - + (av.getCharHeight() / 5)); + } - // draw main sequence panel - pg.translate(idWidth,0); - seqPanel.seqCanvas.drawPanel(pg,startRes,endRes,startSeq,endSeq,startRes,startSeq,0); + // draw main sequence panel + pg.translate(idWidth, 0); + seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, + startRes, startSeq, 0); - if(av.getShowAnnotation()) + if (av.showAnnotation && endSeq == av.alignment.getHeight()) { - pg.translate(-idWidth,(endSeq-startSeq)*av.charHeight); - alabels.drawComponent((Graphics2D)pg); - pg.translate(idWidth,0); - annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes+1); + pg.translate( -idWidth, (endSeq - startSeq) * av.charHeight); + alabels.drawComponent( (Graphics2D) pg); + pg.translate(idWidth, 0); + annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes+1); } - return Printable.PAGE_EXISTS; + return Printable.PAGE_EXISTS; + } public int printWrappedAlignment(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException { + int idWidth = calculateIdWidth().width + 4; - int idWidth = calculateIdWidth().width+4; + int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - idWidth); + int totalHeight = totalHeight = (av.alignment.getHeight() + 2) * + ( (av.alignment.getWidth() + / resWidth) + 1) * av.charHeight; - if( seqPanel.seqCanvas.getWidth() < pwidth-idWidth) - pwidth = seqPanel.seqCanvas.getWidth() + idWidth; + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); - pg.setColor(Color.white); - pg.fillRect(0,0,pwidth, pheight); - pg.setFont( av.getFont() ); + //////////////// + // Draw the ids + pg.setColor(Color.black); - //////////////////////////////////// - /// 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; + pg.translate(0, -pi * pheight); - int noChunksOnPage = pheight / chunkHeight; - int totalChunks = da.getWidth() / chunkWidth; + pg.setClip(0,pi*pheight,pwidth, pheight); - if ( pi*noChunksOnPage > totalChunks ) - return Printable.NO_SUCH_PAGE; + int ypos = 2 * av.charHeight; + do + { + for (int i = 0; i < av.alignment.getHeight(); i++) + { + SequenceI s = av.alignment.getSequenceAt(i); + String string = s.getName(); + if (av.getShowFullId()) + string = s.getDisplayId(); - //////////////// - // Draw the ids -// pg.setClip(0,0,pwidth, noChunksOnPage*chunkHeight); + pg.drawString(string, 0, + AlignmentUtil.getPixelHeight(0, i, av.charHeight) + + ypos + + av.charHeight - (av.charHeight / 5)); - pg.setColor(Color.black); + } - int rowSize = av.getEndRes() - av.getStartRes(); - for(int ypos=2*av.charHeight, row=av.getEndRes()-rowSize; - ypos <= pheight && row