X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=d4c88de7acb8c238b51d0079145034ce66379d4b;hb=f1b17730086767d55e4f5fea54b72e4d30d52e65;hp=600683fc841a36f8e3329ffc3da6a43fec9bce90;hpb=ac07859006686a2c62bcf57b24742eb610bc46f0;p=jalview.git diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 600683f..d4c88de 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -275,6 +275,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print { PrinterJob printJob = PrinterJob.getPrinterJob(); PageFormat pf = printJob.pageDialog(printJob.defaultPage()); + printJob.setPrintable(this, pf); if (printJob.printDialog()) { @@ -292,25 +293,41 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException { - pg.setFont(font); - FontMetrics fm = pg.getFontMetrics(font); + pg.setFont(font); pg.translate((int)pf.getImageableX(), (int)pf.getImageableY()); - int pwidth = (int) pf.getImageableWidth(); int pheight = (int) pf.getImageableHeight(); - // adjust pheight to row height - pheight -= (pheight%fm.getHeight()); - pg.setClip(0,0, pwidth, pheight); - - int noPages = (fm.getHeight() * nameHash.size()) / pheight; - + int noPages = getHeight() / pheight; if(pi>noPages) return Printable.NO_SUCH_PAGE; - pg.translate(0, -pheight*pi ); - draw(pg, pwidth, fm.getHeight() * nameHash.size()); + + if (pwidth > getWidth()) + pwidth = getWidth(); + + if(fitToWindow) + { + if (pheight > getHeight()) + pheight = getHeight(); + + noPages = 0; + } + else + { + + FontMetrics fm = pg.getFontMetrics(font); + int height = fm.getHeight() * nameHash.size(); + pg.translate(0, -pi*pheight ); + pg.setClip(0,pi*pheight, pwidth,pi*pheight + pheight); + // translate number of pages, + // height is screen size as this is the + // non overlapping text size + pheight = height; + } + + draw(pg, pwidth, pheight); return Printable.PAGE_EXISTS; @@ -339,19 +356,6 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print draw( g,scrollPane.getWidth(), fm.getHeight() * nameHash.size()); } - - if (threshold != 0) - { - if(av.getCurrentTree() == tree) - g.setColor(Color.red); - else - g.setColor(Color.gray); - - int x = (int)( threshold * (float)(getWidth()-labelLength - 2*offx) +offx ) ; - - g.drawLine(x,0,x,getHeight()); - } - scrollPane.revalidate(); } public int getFontSize() { @@ -361,12 +365,15 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print this.fontSize = fontSize; repaint(); } - public void draw(Graphics g, int width, int height) { - g.setColor(Color.white); - g.fillRect(0,0,width,height); + public void draw(Graphics g1, int width, int height) { + Graphics2D g2 = (Graphics2D)g1; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setColor(Color.white); + g2.fillRect(0,0,width,height); - labelLength = g.getFontMetrics(font).stringWidth(longestName)+ 20;//20 allows for scrollbar + + labelLength = g2.getFontMetrics(font).stringWidth(longestName)+ 20;//20 allows for scrollbar float wscale =(float)(width - labelLength -offx*2)/tree.getMaxHeight(); @@ -377,7 +384,20 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print } float chunk = (float)(height-offy*2)/top.count ; - drawNode(g,tree.getTopNode(),chunk,wscale,width,offx,offy); + drawNode(g2,tree.getTopNode(),chunk,wscale,width,offx,offy); + + if (threshold != 0) + { + if(av.getCurrentTree() == tree) + g2.setColor(Color.red); + else + g2.setColor(Color.gray); + + int x = (int)( threshold * (float)(getWidth()-labelLength - 2*offx) +offx ) ; + + g2.drawLine(x,0,x,getHeight()); + } + } public void mouseReleased(MouseEvent e) { }