mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/st/HCLSupportTree.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2005, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4  */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: HCLSupportTree.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.4 $
2 26 Feb 07 jari 8  * $Date: 2006/03/24 15:51:48 $
2 26 Feb 07 jari 9  * $Author: eleanorahowe $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.microarray.mev.cluster.gui.impl.st;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.awt.Color;
2 26 Feb 07 jari 15 import java.awt.Composite;
2 26 Feb 07 jari 16 import java.awt.Font;
2 26 Feb 07 jari 17 import java.awt.FontMetrics;
2 26 Feb 07 jari 18 import java.awt.Graphics;
2 26 Feb 07 jari 19 import java.awt.Graphics2D;
2 26 Feb 07 jari 20 import java.beans.Encoder;
2 26 Feb 07 jari 21 import java.beans.Expression;
2 26 Feb 07 jari 22 import java.beans.PersistenceDelegate;
2 26 Feb 07 jari 23 import java.text.DecimalFormat;
2 26 Feb 07 jari 24 import java.util.Vector;
2 26 Feb 07 jari 25
2 26 Feb 07 jari 26 import javax.swing.JPanel;
2 26 Feb 07 jari 27
2 26 Feb 07 jari 28 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTree;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTreeData;
2 26 Feb 07 jari 30
2 26 Feb 07 jari 31 public class HCLSupportTree extends HCLTree {
2 26 Feb 07 jari 32     
2 26 Feb 07 jari 33     private Vector geneTreeSupportVector, exptTreeSupportVector;
2 26 Feb 07 jari 34     private boolean showSupportValues;
2 26 Feb 07 jari 35     private int MIN_VALUE_TIC_HEIGHT = 2;
2 26 Feb 07 jari 36     private FontMetrics fm;
2 26 Feb 07 jari 37     private DecimalFormat format;
2 26 Feb 07 jari 38     private String supportString;
2 26 Feb 07 jari 39     private int supportValueHeight;
2 26 Feb 07 jari 40     private int supportValueWidth;
2 26 Feb 07 jari 41     private int index;
2 26 Feb 07 jari 42     private Float supportPercentage;
2 26 Feb 07 jari 43     private Color currentColor;
2 26 Feb 07 jari 44     
2 26 Feb 07 jari 45     public HCLSupportTree(HCLTreeData treeData, int orientation, Vector geneTreeSupportVector, Vector exptTreeSupportVector) {
2 26 Feb 07 jari 46         super(treeData, orientation);
2 26 Feb 07 jari 47         showSupportValues = false;
2 26 Feb 07 jari 48         this.geneTreeSupportVector = geneTreeSupportVector;
2 26 Feb 07 jari 49         this.exptTreeSupportVector = exptTreeSupportVector;
2 26 Feb 07 jari 50         this.format = new DecimalFormat();
2 26 Feb 07 jari 51         format.setMaximumFractionDigits(0);
2 26 Feb 07 jari 52     }
2 26 Feb 07 jari 53     
2 26 Feb 07 jari 54
2 26 Feb 07 jari 55     public static PersistenceDelegate getPersistenceDelegate(){
2 26 Feb 07 jari 56       return new HCLSupportTreePersistenceDelegate();
2 26 Feb 07 jari 57     }
2 26 Feb 07 jari 58
2 26 Feb 07 jari 59     /*
2 26 Feb 07 jari 60     protected void updateSize(Dimension elementSize) {
2 26 Feb 07 jari 61         super.updateSize(elementSize);
2 26 Feb 07 jari 62         Graphics g = getGraphics();
2 26 Feb 07 jari 63         if(g != null) {
2 26 Feb 07 jari 64             g.setFont(new Font("mono-spaced", Font.PLAIN, this.stepSize <= 15 ? this.stepSize : 15));
2 26 Feb 07 jari 65             fm = g.getFontMetrics();
2 26 Feb 07 jari 66         }
2 26 Feb 07 jari 67         this.adjustPixelHeightsForValueDisplay();
2 26 Feb 07 jari 68     }
2 26 Feb 07 jari 69      */
2 26 Feb 07 jari 70     
2 26 Feb 07 jari 71     /**
2 26 Feb 07 jari 72      * Paints the tree into specified graphics.
2 26 Feb 07 jari 73      */
2 26 Feb 07 jari 74     public void paint(Graphics g) {
2 26 Feb 07 jari 75         super.paintSubTree(g);
2 26 Feb 07 jari 76         
2 26 Feb 07 jari 77         Graphics2D g2 = (Graphics2D)g;
2 26 Feb 07 jari 78         Composite composite = g2.getComposite();
2 26 Feb 07 jari 79         
2 26 Feb 07 jari 80         //        g.setFont(g.getFont().deriveFont(this.stepSize));
2 26 Feb 07 jari 81         //  if(this.orientation == HORIZONTAL)
2 26 Feb 07 jari 82         g.setFont(new Font("mono-spaced", Font.PLAIN, this.stepSize <= 15 ? this.stepSize : 15));
2 26 Feb 07 jari 83         
2 26 Feb 07 jari 84         fm = g.getFontMetrics();
2 26 Feb 07 jari 85         
2 26 Feb 07 jari 86         supportValueHeight = fm.getHeight();
2 26 Feb 07 jari 87         
2 26 Feb 07 jari 88         if (this.treeData.node_order.length < 2) {
2 26 Feb 07 jari 89             return;
2 26 Feb 07 jari 90         }
2 26 Feb 07 jari 91         
2 26 Feb 07 jari 92         for(int i = 0 ; i < terminalNodes.length; i++){
2 26 Feb 07 jari 93             terminalNodes[i] = false;
2 26 Feb 07 jari 94         }
2 26 Feb 07 jari 95         
2 26 Feb 07 jari 96         int sign = 1;
2 26 Feb 07 jari 97         if (this.orientation == VERTICAL) {
2 26 Feb 07 jari 98             ((Graphics2D)g).rotate(-Math.PI/2.0);
2 26 Feb 07 jari 99             sign = -1;
2 26 Feb 07 jari 100         }
2 26 Feb 07 jari 101         int max_node_height = this.pHeights[this.treeData.node_order[this.treeData.node_order.length-2]];
2 26 Feb 07 jari 102         int node;
2 26 Feb 07 jari 103         int child_1, child_2;
2 26 Feb 07 jari 104         int child_1_x1, child_1_x2, child_1_y;
2 26 Feb 07 jari 105         int child_2_x1, child_2_x2, child_2_y;
2 26 Feb 07 jari 106         for (int i=0; i<this.treeData.node_order.length-1; i++) {
2 26 Feb 07 jari 107             node = this.treeData.node_order[i];
2 26 Feb 07 jari 108             child_1 = this.treeData.child_1_array[node];
2 26 Feb 07 jari 109             child_2 = this.treeData.child_2_array[node];
2 26 Feb 07 jari 110             child_1_x1 = (max_node_height-this.pHeights[node])*sign;
2 26 Feb 07 jari 111             child_1_x2 = (max_node_height-this.pHeights[child_1])*sign;
2 26 Feb 07 jari 112             child_1_y  = (int)(this.positions[child_1]*this.stepSize)+this.stepSize/2;
2 26 Feb 07 jari 113             child_2_x1 = (max_node_height-this.pHeights[node])*sign;
2 26 Feb 07 jari 114             child_2_x2 = (max_node_height-this.pHeights[child_2])*sign;
2 26 Feb 07 jari 115             child_2_y  = (int)(this.positions[child_2]*this.stepSize)+this.stepSize/2;
2 26 Feb 07 jari 116             /*
2 26 Feb 07 jari 117             if (this.selected[node]) {
2 26 Feb 07 jari 118                 g.setColor(selectedLineColor);
2 26 Feb 07 jari 119             } else {
2 26 Feb 07 jari 120                 if (this.nodesColors[node] == null) {
2 26 Feb 07 jari 121                     g.setColor(lineColor);
2 26 Feb 07 jari 122                 } else {
2 26 Feb 07 jari 123                     g.setColor(this.nodesColors[node]);
2 26 Feb 07 jari 124                 }
2 26 Feb 07 jari 125             }
2 26 Feb 07 jari 126              */
2 26 Feb 07 jari 127             
2 26 Feb 07 jari 128             if ((geneTreeSupportVector != null) || (exptTreeSupportVector != null)) {
2 26 Feb 07 jari 129                 index = node - (this.treeData.node_order.length);
2 26 Feb 07 jari 130                 supportPercentage = null;
2 26 Feb 07 jari 131                 
2 26 Feb 07 jari 132                 try {
2 26 Feb 07 jari 133                     if (orientation == HCLTree.HORIZONTAL) {
2 26 Feb 07 jari 134                         if (geneTreeSupportVector != null) supportPercentage = (Float) geneTreeSupportVector.get(index);
2 26 Feb 07 jari 135                     } else {
2 26 Feb 07 jari 136                         if (exptTreeSupportVector != null) supportPercentage = (Float) exptTreeSupportVector.get(index);
2 26 Feb 07 jari 137                     }
2 26 Feb 07 jari 138                 } catch (ArrayIndexOutOfBoundsException e) {
2 26 Feb 07 jari 139                     
2 26 Feb 07 jari 140                 }
2 26 Feb 07 jari 141                 
2 26 Feb 07 jari 142                 if (supportPercentage != null) {
2 26 Feb 07 jari 143                     g.setColor(getColorFromPercentage(supportPercentage.doubleValue())); //Parameter is the percentage of support for this node
2 26 Feb 07 jari 144                     currentColor = g.getColor();
2 26 Feb 07 jari 145                 }
2 26 Feb 07 jari 146             }
2 26 Feb 07 jari 147             
2 26 Feb 07 jari 148             
2 26 Feb 07 jari 149             if(this.treeData.height[node] >= zero_threshold) {
2 26 Feb 07 jari 150                 this.terminalNodes[node] = false;
2 26 Feb 07 jari 151                 if(this.pHeights[child_1] == 0)
2 26 Feb 07 jari 152                     this.terminalNodes[child_1] = true;
2 26 Feb 07 jari 153                 if(this.pHeights[child_2] == 0)
2 26 Feb 07 jari 154                     this.terminalNodes[child_2] = true;
2 26 Feb 07 jari 155             } else{
2 26 Feb 07 jari 156                 
2 26 Feb 07 jari 157                 this.terminalNodes[node] = false;
2 26 Feb 07 jari 158                 
2 26 Feb 07 jari 159                 if(this.treeData.height[parentNodes[node]] >= zero_threshold){
2 26 Feb 07 jari 160                     drawWedge(g, node, child_1_x1+xOrigin, child_2_x1+xOrigin, child_1_y, child_2_y);
2 26 Feb 07 jari 161                     this.terminalNodes[node] = true;
2 26 Feb 07 jari 162                     this.terminalNodes[child_1] = false;
2 26 Feb 07 jari 163                     this.terminalNodes[child_2] = false;
2 26 Feb 07 jari 164                 }
2 26 Feb 07 jari 165             }
2 26 Feb 07 jari 166             
2 26 Feb 07 jari 167             selectedLineColor = Color.lightGray;
2 26 Feb 07 jari 168             
2 26 Feb 07 jari 169             if (this.selected[node]) {
2 26 Feb 07 jari 170                 g.setColor(selectedLineColor);
2 26 Feb 07 jari 171             }
2 26 Feb 07 jari 172             if(!showSupportValues) {
2 26 Feb 07 jari 173                 if(this.orientation == HORIZONTAL){
2 26 Feb 07 jari 174                     g.drawLine(child_1_x1 + xOrigin, child_1_y, child_1_x2 + xOrigin, child_1_y);
2 26 Feb 07 jari 175                     g.drawLine(child_2_x1 + xOrigin, child_2_y, child_2_x2 + xOrigin, child_2_y);
2 26 Feb 07 jari 176                     g.drawLine(child_1_x1 + xOrigin, child_1_y, child_2_x1 + xOrigin, child_2_y);
2 26 Feb 07 jari 177                 }
2 26 Feb 07 jari 178                 else{
2 26 Feb 07 jari 179                     g.drawLine(child_1_x1, child_1_y + horizontalOffset, child_1_x2, child_1_y + horizontalOffset);
2 26 Feb 07 jari 180                     g.drawLine(child_2_x1, child_2_y + horizontalOffset, child_2_x2, child_2_y + horizontalOffset);
2 26 Feb 07 jari 181                     g.drawLine(child_1_x1, child_1_y + horizontalOffset, child_2_x1, child_2_y + horizontalOffset);
2 26 Feb 07 jari 182                 }
2 26 Feb 07 jari 183             } else {
2 26 Feb 07 jari 184                 
2 26 Feb 07 jari 185                 if(this.orientation == HORIZONTAL){  //gene tree
2 26 Feb 07 jari 186                     
2 26 Feb 07 jari 187                     if (geneTreeSupportVector != null && !geneTreeSupportVector.isEmpty())
2 26 Feb 07 jari 188                         supportPercentage = (Float) geneTreeSupportVector.get(index);
2 26 Feb 07 jari 189                                         
2 26 Feb 07 jari 190                     g.drawLine(child_1_x1 + xOrigin, child_1_y, child_1_x2 + xOrigin, child_1_y);
2 26 Feb 07 jari 191                     g.drawLine(child_2_x1 + xOrigin, child_2_y, child_2_x2 + xOrigin, child_2_y);
2 26 Feb 07 jari 192                     g.drawLine(child_1_x1 + xOrigin, child_1_y, child_2_x1 + xOrigin, child_2_y);                    
2 26 Feb 07 jari 193                                         
2 26 Feb 07 jari 194                     if(i == this.treeData.node_order.length-2 || geneTreeSupportVector.isEmpty())
2 26 Feb 07 jari 195                         continue;
2 26 Feb 07 jari 196                     
2 26 Feb 07 jari 197                     supportString = format.format(Math.round(supportPercentage.floatValue()));
2 26 Feb 07 jari 198                     supportValueWidth = fm.stringWidth(supportString);
2 26 Feb 07 jari 199                     
2 26 Feb 07 jari 200                     if(supportString.equals("0"))
2 26 Feb 07 jari 201                         continue;
2 26 Feb 07 jari 202
2 26 Feb 07 jari 203                     g.setColor(new Color(192, 200, 228));
2 26 Feb 07 jari 204                     g2.setComposite(composite);
2 26 Feb 07 jari 205
2 26 Feb 07 jari 206                     g.fillRect(child_1_x1-(int)(supportValueWidth)-4 + xOrigin, ((child_2_y - child_1_y)/2)+child_1_y - fm.getAscent() - 2, supportValueWidth+4, fm.getAscent()+2);
2 26 Feb 07 jari 207                   
2 26 Feb 07 jari 208                     g.setColor(Color.black);
2 26 Feb 07 jari 209                     g.drawRect(child_1_x1-(int)(supportValueWidth)-4 + xOrigin, ((child_2_y - child_1_y)/2)+child_1_y - fm.getAscent() - 2, supportValueWidth+4, fm.getAscent()+2);
2 26 Feb 07 jari 210                     
2 26 Feb 07 jari 211                     g.drawString(supportString, child_1_x1-supportValueWidth-2+xOrigin, ((child_2_y - child_1_y)/2)+child_1_y - 2);
2 26 Feb 07 jari 212                     
2 26 Feb 07 jari 213                     g2.setComposite(composite);
2 26 Feb 07 jari 214                     
2 26 Feb 07 jari 215                 } else {
2 26 Feb 07 jari 216                     
2 26 Feb 07 jari 217                     if (exptTreeSupportVector != null && !exptTreeSupportVector.isEmpty())
2 26 Feb 07 jari 218                         supportPercentage = (Float) exptTreeSupportVector.get(index);
2 26 Feb 07 jari 219                                                             
2 26 Feb 07 jari 220                     g.drawLine(child_1_x1, child_1_y + horizontalOffset, child_1_x2, child_1_y + horizontalOffset);
2 26 Feb 07 jari 221                     g.drawLine(child_2_x1, child_2_y + horizontalOffset, child_2_x2, child_2_y + horizontalOffset);
2 26 Feb 07 jari 222                     g.drawLine(child_1_x1, child_1_y + horizontalOffset, child_2_x1, child_2_y + horizontalOffset);
2 26 Feb 07 jari 223                     
2 26 Feb 07 jari 224                     
2 26 Feb 07 jari 225                     if(i == this.treeData.node_order.length-2 || exptTreeSupportVector.isEmpty())
2 26 Feb 07 jari 226                         continue;
2 26 Feb 07 jari 227                     
2 26 Feb 07 jari 228                     supportString = format.format(Math.round(supportPercentage.floatValue()));
2 26 Feb 07 jari 229                     supportValueWidth = fm.stringWidth(supportString);
2 26 Feb 07 jari 230                     
2 26 Feb 07 jari 231                     supportString = format.format(Math.round(supportPercentage.floatValue()));
2 26 Feb 07 jari 232                     supportValueWidth = fm.stringWidth(supportString);
2 26 Feb 07 jari 233                     
2 26 Feb 07 jari 234                     if(supportString.equals("0"))
2 26 Feb 07 jari 235                         continue;
2 26 Feb 07 jari 236                     
2 26 Feb 07 jari 237                     if(node % 50 == 0)
2 26 Feb 07 jari 238                         System.out.println("support string width ="+supportValueWidth);
2 26 Feb 07 jari 239                     //   g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
2 26 Feb 07 jari 240                     
2 26 Feb 07 jari 241                     g.setColor(new Color(192, 200, 228));
2 26 Feb 07 jari 242                     g2.setComposite(composite);
2 26 Feb 07 jari 243                     // g.setColor(Color.blue);
2 26 Feb 07 jari 244                     //      g.fillRect(10,110,100,100);
2 26 Feb 07 jari 245                     
2 26 Feb 07 jari 246                     
2 26 Feb 07 jari 247                     // g.setColor(new Color(192, 200, 228));
2 26 Feb 07 jari 248                     //                    g.fillRect(child_1_x1-(int)(supportValueWidth/2.0)-2, ((child_2_y - child_1_y)/2)+child_1_y - fm.getAscent()/2 + 2, supportValueWidth+4, fm.getAscent()+4);
2 26 Feb 07 jari 249                     //  g.fillRect(child_1_x1-(int)(supportValueWidth)-4, ((int)(child_2_y - child_1_y)/2.0)+child_1_y + fm.getAscent()/2 + 2, supportValueWidth+4, fm.getAscent()+4);
2 26 Feb 07 jari 250                     // g.fillRect(child_1_x1-(int)(supportValueWidth)-4 + xOrigin, ((child_2_y - child_1_y)/2)+child_1_y + 2, supportValueWidth+4, fm.getAscent()+4);
2 26 Feb 07 jari 251                     g.fillRect(child_1_x1, ((child_2_y - child_1_y)/2)+child_1_y - fm.getAscent() - 2 + horizontalOffset, supportValueWidth+4, fm.getAscent()+2);
2 26 Feb 07 jari 252                     
2 26 Feb 07 jari 253                     //  g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
2 26 Feb 07 jari 254                     
2 26 Feb 07 jari 255                     g.setColor(Color.black);
2 26 Feb 07 jari 256                     g.drawRect(child_1_x1, ((child_2_y - child_1_y)/2)+child_1_y - fm.getAscent() - 2 +horizontalOffset, supportValueWidth+4, fm.getAscent()+2);
2 26 Feb 07 jari 257                     
2 26 Feb 07 jari 258                     //    g.drawRect(child_1_x1-(int)(supportValueWidth/2.0)-2, ((child_2_y - child_1_y)/2)+child_1_y - fm.getAscent()/2 + 2, supportValueWidth+4, fm.getAscent()+4);
2 26 Feb 07 jari 259                     //g.setColor(Color.black);
2 26 Feb 07 jari 260                     //   g.drawString(supportString, child_1_x1-(supportValueWidth/2), ((child_2_y - child_1_y)/2)+child_1_y + fm.getAscent()/2);
2 26 Feb 07 jari 261                     g.drawString(supportString, child_1_x1+2, ((child_2_y - child_1_y)/2)+child_1_y - 2 + horizontalOffset);
2 26 Feb 07 jari 262                     
2 26 Feb 07 jari 263                     g2.setComposite(composite);
2 26 Feb 07 jari 264                 }
2 26 Feb 07 jari 265             }
2 26 Feb 07 jari 266         }
2 26 Feb 07 jari 267     }
2 26 Feb 07 jari 268     
2 26 Feb 07 jari 269     public void toggleShowSupportValues(boolean showValues) {
2 26 Feb 07 jari 270         showSupportValues = showValues;
2 26 Feb 07 jari 271         adjustPixelHeightsForValueDisplay();
2 26 Feb 07 jari 272     }
2 26 Feb 07 jari 273     
2 26 Feb 07 jari 274     public void adjustPixelHeightsForValueDisplay() {
2 26 Feb 07 jari 275         
2 26 Feb 07 jari 276         if(showSupportValues) {
2 26 Feb 07 jari 277             Graphics g = getGraphics();
2 26 Feb 07 jari 278             
2 26 Feb 07 jari 279             if(g == null)
2 26 Feb 07 jari 280                 return;
2 26 Feb 07 jari 281             
2 26 Feb 07 jari 282             g.setFont(new Font("mono-spaced", Font.PLAIN, this.stepSize <= 15 ? this.stepSize : 15));
2 26 Feb 07 jari 283             fm = g.getFontMetrics();
2 26 Feb 07 jari 284             int stringWidth = fm.stringWidth("000");
2 26 Feb 07 jari 285             
2 26 Feb 07 jari 286             if(this.orientation == VERTICAL) {
2 26 Feb 07 jari 287                 if(this.min_pixels < stringWidth + MIN_VALUE_TIC_HEIGHT) {
2 26 Feb 07 jari 288                     this.setPixelHeightLimits(stringWidth+MIN_VALUE_TIC_HEIGHT+4, this.max_pixels >= stringWidth+MIN_VALUE_TIC_HEIGHT+4 ? this.max_pixels : stringWidth+MIN_VALUE_TIC_HEIGHT+4);
2 26 Feb 07 jari 289                 }
2 26 Feb 07 jari 290             } else {
2 26 Feb 07 jari 291                 if(this.min_pixels < stringWidth + MIN_VALUE_TIC_HEIGHT) {
2 26 Feb 07 jari 292                     this.setPixelHeightLimits(stringWidth+MIN_VALUE_TIC_HEIGHT+4, this.max_pixels >= stringWidth+MIN_VALUE_TIC_HEIGHT+4 ? this.max_pixels : stringWidth+MIN_VALUE_TIC_HEIGHT+4);
2 26 Feb 07 jari 293                 }
2 26 Feb 07 jari 294             }
2 26 Feb 07 jari 295         }
2 26 Feb 07 jari 296     }
2 26 Feb 07 jari 297     
2 26 Feb 07 jari 298     public static JPanel getColorLegendPanel() {
2 26 Feb 07 jari 299         JPanel legendPanel = new JPanel() {
2 26 Feb 07 jari 300             public void paintComponent(Graphics g1D) {
2 26 Feb 07 jari 301                 
2 26 Feb 07 jari 302                 Graphics2D g = (Graphics2D) g1D;
2 26 Feb 07 jari 303                 super.paintComponent(g);
2 26 Feb 07 jari 304                 
2 26 Feb 07 jari 305                 int width = getSize().width;
2 26 Feb 07 jari 306                 int height = getSize().height;
2 26 Feb 07 jari 307                 int blockWidth = width;
2 26 Feb 07 jari 308                 int blockHeight = height / 9;
2 26 Feb 07 jari 309                 
2 26 Feb 07 jari 310                 Font font = new Font("monospaced", Font.PLAIN, 12);
2 26 Feb 07 jari 311                 g.setFont(font);
2 26 Feb 07 jari 312                 FontMetrics fm = g.getFontMetrics();
2 26 Feb 07 jari 313                 int stringHeight = fm.getHeight();
2 26 Feb 07 jari 314                 int stringWidth = 0;
2 26 Feb 07 jari 315                 String labelString = null;
2 26 Feb 07 jari 316                 
2 26 Feb 07 jari 317                 labelString = "100% Support";
2 26 Feb 07 jari 318                 g.setColor(Color.black);
2 26 Feb 07 jari 319                 g.fillRect(0, blockHeight * 0, blockWidth, blockHeight);
2 26 Feb 07 jari 320                 g.setColor(Color.white);
2 26 Feb 07 jari 321                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 322                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 0 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 323                 
2 26 Feb 07 jari 324                 labelString = "90-100% Support";
2 26 Feb 07 jari 325                 g.setColor(Color.darkGray);
2 26 Feb 07 jari 326                 g.fillRect(0, blockHeight * 1, blockWidth, blockHeight);
2 26 Feb 07 jari 327                 g.setColor(Color.white);
2 26 Feb 07 jari 328                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 329                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 1 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 330                 
2 26 Feb 07 jari 331                 labelString = "80-90% Support";
2 26 Feb 07 jari 332                 g.setColor(Color.blue);
2 26 Feb 07 jari 333                 g.fillRect(0, blockHeight * 2, blockWidth, blockHeight);
2 26 Feb 07 jari 334                 g.setColor(Color.white);
2 26 Feb 07 jari 335                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 336                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 2 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 337                 
2 26 Feb 07 jari 338                 labelString = "70-80% Support";
2 26 Feb 07 jari 339                 g.setColor(Color.green);
2 26 Feb 07 jari 340                 g.fillRect(0, blockHeight * 3, blockWidth, blockHeight);
2 26 Feb 07 jari 341                 g.setColor(Color.white);
2 26 Feb 07 jari 342                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 343                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 3 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 344                 
2 26 Feb 07 jari 345                 labelString = "60-70% Support";
2 26 Feb 07 jari 346                 g.setColor(Color.yellow);
2 26 Feb 07 jari 347                 g.fillRect(0, blockHeight * 4, blockWidth, blockHeight);
2 26 Feb 07 jari 348                 g.setColor(Color.white);
2 26 Feb 07 jari 349                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 350                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 4 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 351                 
2 26 Feb 07 jari 352                 labelString = "50-60% Support";
2 26 Feb 07 jari 353                 g.setColor(Color.orange);
2 26 Feb 07 jari 354                 g.fillRect(0, blockHeight * 5, blockWidth, blockHeight);
2 26 Feb 07 jari 355                 g.setColor(Color.white);
2 26 Feb 07 jari 356                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 357                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 5 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 358                 
2 26 Feb 07 jari 359                 labelString = "0-50% Support";
2 26 Feb 07 jari 360                 g.setColor(Color.magenta);
2 26 Feb 07 jari 361                 g.fillRect(0, blockHeight * 6, blockWidth, blockHeight);
2 26 Feb 07 jari 362                 g.setColor(Color.white);
2 26 Feb 07 jari 363                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 364                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 6 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 365                 
2 26 Feb 07 jari 366                 labelString = "0% Support";
2 26 Feb 07 jari 367                 g.setColor(Color.red);
2 26 Feb 07 jari 368                 g.fillRect(0, blockHeight * 7, blockWidth, blockHeight);
2 26 Feb 07 jari 369                 g.setColor(Color.white);
2 26 Feb 07 jari 370                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 371                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 7 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 372                 
2 26 Feb 07 jari 373                 labelString = "Unrecovered Node";
2 26 Feb 07 jari 374                 g.setColor(Color.pink);
2 26 Feb 07 jari 375                 g.fillRect(0, blockHeight * 8, blockWidth, blockHeight);
2 26 Feb 07 jari 376                 g.setColor(Color.white);
2 26 Feb 07 jari 377                 stringWidth = fm.stringWidth(labelString);
2 26 Feb 07 jari 378                 g.drawString(labelString, 0 + (blockWidth / 2) - (stringWidth / 2), blockHeight * 8 + (blockHeight / 2) + (stringHeight / 2));
2 26 Feb 07 jari 379             }
2 26 Feb 07 jari 380         };
2 26 Feb 07 jari 381         
2 26 Feb 07 jari 382         return legendPanel;
2 26 Feb 07 jari 383     }
2 26 Feb 07 jari 384     
2 26 Feb 07 jari 385     public static Color getColorFromPercentage(double percent) {
2 26 Feb 07 jari 386         if (percent > 100) {
2 26 Feb 07 jari 387             return Color.gray;
2 26 Feb 07 jari 388         } else if (percent == 100) {
2 26 Feb 07 jari 389             return Color.black;
2 26 Feb 07 jari 390         } else if ((percent < 100) && (percent >= 90)) {
2 26 Feb 07 jari 391             return Color.darkGray;
2 26 Feb 07 jari 392         } else if ((percent < 90) && (percent >= 80)) {
2 26 Feb 07 jari 393             return Color.blue;
2 26 Feb 07 jari 394         } else if ((percent < 80) && (percent >= 70)) {
2 26 Feb 07 jari 395             return Color.green;
2 26 Feb 07 jari 396         } else if ((percent < 70) && (percent >= 60)) {
2 26 Feb 07 jari 397             return Color.yellow;
2 26 Feb 07 jari 398         } else if ((percent < 60) && (percent >= 50)) {
2 26 Feb 07 jari 399             return Color.orange;
2 26 Feb 07 jari 400         } else if ((percent < 50) && (percent > 0)) {
2 26 Feb 07 jari 401             return Color.magenta;
2 26 Feb 07 jari 402         } else if (percent == 0) {
2 26 Feb 07 jari 403             return Color.red;
2 26 Feb 07 jari 404         } else /* percent < 0 */ {
2 26 Feb 07 jari 405             return Color.pink;
2 26 Feb 07 jari 406         }
2 26 Feb 07 jari 407     }
2 26 Feb 07 jari 408     private static class HCLSupportTreePersistenceDelegate extends PersistenceDelegate {
2 26 Feb 07 jari 409       public Expression instantiate(Object oldInstance, Encoder encoder) {
2 26 Feb 07 jari 410         HCLSupportTree aTree = (HCLSupportTree) oldInstance;
2 26 Feb 07 jari 411         return new Expression(aTree, aTree.getClass(), "new", new Object[]{aTree.treeData, new Integer(aTree.orientation), aTree.geneTreeSupportVector, aTree.exptTreeSupportVector});
2 26 Feb 07 jari 412       }
2 26 Feb 07 jari 413     }
2 26 Feb 07 jari 414     
2 26 Feb 07 jari 415 }