X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=d4c88de7acb8c238b51d0079145034ce66379d4b;hb=f1b17730086767d55e4f5fea54b72e4d30d52e65;hp=ed9677a56c1a8228695b276e6b33dbaa1cea92f2;hpb=577f505f54fe343e89f581461e780ea8308c20ec;p=jalview.git diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index ed9677a..d4c88de 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -27,7 +27,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print int offx = 20; int offy = 20; - int threshold; + float threshold; String longestName; int labelLength=-1; @@ -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,26 +293,41 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException { - font = new Font("Verdana",Font.PLAIN,fontSize); - 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; @@ -340,13 +356,6 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print draw( g,scrollPane.getWidth(), fm.getHeight() * nameHash.size()); } - - if (threshold != 0) - { - g.setColor(Color.red); - g.drawLine(threshold,0,threshold,getHeight()); - } - scrollPane.revalidate(); } public int getFontSize() { @@ -356,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(); @@ -372,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) { } @@ -382,6 +407,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print } public void mousePressed(MouseEvent e) { + + av.setCurrentTree(tree); + int x = e.getX(); int y = e.getY(); @@ -402,10 +430,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print // Find threshold if (tree.getMaxHeight() != 0) { - float fthreshold = (float)(x - offx)/(float)(getWidth()-labelLength - 2*offx); - this.threshold = x; + threshold = (float)(x - offx)/(float)(getWidth()-labelLength - 2*offx); + tree.getGroups().removeAllElements(); - tree.groupNodes(tree.getTopNode(),fthreshold); + tree.groupNodes(tree.getTopNode(),threshold); setColor(tree.getTopNode(),Color.black); av.setSelectionGroup(null); @@ -439,7 +467,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print sg.getEndRes()); c.calculate(); - c.verdict(false, 100); + c.verdict(false, av.ConsPercGaps); ccs = new ConservationColourScheme(c, ccs.cs); sg.cs = ccs;