X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=5ebf323be7e10d75b14ad580c163c8109fbb72e7;hb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;hp=9435716e3cf9c63f75416d81cb5c5ece259a8dfe;hpb=ee2fab02e829035b825cea4046266a6994978b96;p=jalview.git diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 9435716..5ebf323 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -1,3 +1,22 @@ +/* +* Jalview - A Sequence Alignment Editor and Viewer +* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + package jalview.gui; @@ -16,18 +35,19 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print NJTree tree; JScrollPane scrollPane; AlignViewport av; - + public static final String PLACEHOLDER=" * "; Font font; int fontSize = 12; boolean fitToWindow = true; boolean showDistances = false; boolean showBootstrap = false; + boolean markPlaceholders = false; int offx = 20; int offy = 20; - int threshold; + float threshold; String longestName; int labelLength=-1; @@ -122,10 +142,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print g.drawString(nodeLabel,xstart,ypos - 10); } - // Colour selected leaves differently - String name = node.getName(); + String name = (markPlaceholders && node.isPlaceholder()) ? (PLACEHOLDER+node.getName()) : node.getName(); FontMetrics fm = g.getFontMetrics(font); - int charWidth = fm.stringWidth(node.getName()) + 3; + int charWidth = fm.stringWidth(name) + 3; int charHeight = fm.getHeight(); Rectangle rect = new Rectangle(xend+20,ypos-charHeight, @@ -133,6 +152,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print nameHash.put((SequenceI)node.element(),rect); + // Colour selected leaves differently SequenceGroup selected = av.getSelectionGroup(); if (selected!=null && selected.sequences.contains((SequenceI)node.element())) { g.setColor(Color.gray); @@ -140,7 +160,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print g.fillRect(xend + 10, ypos - charHeight + 3,charWidth,charHeight); g.setColor(Color.white); } - g.drawString(node.getName(),xend+10,ypos); + g.drawString(name,xend+10,ypos); g.setColor(Color.black); } else { drawNode(g,(SequenceNode)node.left(), chunk,scale,width,offx,offy); @@ -275,6 +295,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 +313,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,13 +376,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() { @@ -355,12 +385,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(); @@ -371,7 +404,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) { } @@ -381,6 +427,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(); @@ -401,10 +450,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); @@ -438,7 +487,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; @@ -467,6 +516,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Print this.showBootstrap = state; repaint(); } + public void setMarkPlaceholders(boolean state) { + this.markPlaceholders = state; + repaint(); + } }