mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/hcl/HCLClusterInfoViewer.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2004, 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: HCLClusterInfoViewer.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.6 $
2 26 Feb 07 jari 8  * $Date: 2006/03/24 15:50:40 $
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.hcl;
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.Dimension;
2 26 Feb 07 jari 16 import java.awt.GridBagConstraints;
2 26 Feb 07 jari 17 import java.awt.GridBagLayout;
2 26 Feb 07 jari 18 import java.awt.Insets;
2 26 Feb 07 jari 19 import java.beans.Expression;
2 26 Feb 07 jari 20
2 26 Feb 07 jari 21 import javax.swing.JComponent;
2 26 Feb 07 jari 22 import javax.swing.JLabel;
2 26 Feb 07 jari 23 import javax.swing.JPanel;
2 26 Feb 07 jari 24 import javax.swing.JTextArea;
2 26 Feb 07 jari 25
2 26 Feb 07 jari 26 import org.tigr.microarray.mev.cluster.gui.impl.ViewerAdapter;
2 26 Feb 07 jari 27
2 26 Feb 07 jari 28 public class HCLClusterInfoViewer extends ViewerAdapter {
2 26 Feb 07 jari 29
2 26 Feb 07 jari 30     private JComponent header;
2 26 Feb 07 jari 31     private JTextArea  content;
2 26 Feb 07 jari 32     private boolean clusterGenes;
2 26 Feb 07 jari 33     private float zeroThreshold;
2 26 Feb 07 jari 34     
2 26 Feb 07 jari 35     /**
2 26 Feb 07 jari 36      * Constructs a <code>HCLClusterInfoViewer</code> with specified
2 26 Feb 07 jari 37      * clusters and number of genes.
2 26 Feb 07 jari 38      */
2 26 Feb 07 jari 39     public HCLClusterInfoViewer(int[][] clusters, int genes, float zThr) {
2 26 Feb 07 jari 40         zeroThreshold = zThr;
2 26 Feb 07 jari 41         header  = createHeader();
2 26 Feb 07 jari 42         this.clusterGenes = true;
2 26 Feb 07 jari 43         content = createContent(clusters, genes);
2 26 Feb 07 jari 44         setMaxWidth(content, header);        
2 26 Feb 07 jari 45     }
2 26 Feb 07 jari 46     
2 26 Feb 07 jari 47     /**
2 26 Feb 07 jari 48      * Constructs a <code>HCLClusterInfoViewer</code> with specified
2 26 Feb 07 jari 49      * clusters and number of genes.
2 26 Feb 07 jari 50      */
2 26 Feb 07 jari 51     public HCLClusterInfoViewer(int[][] clusters, int genes, boolean clusterGenes, float zThr) {
2 26 Feb 07 jari 52         zeroThreshold = zThr;
2 26 Feb 07 jari 53         header  = createHeader();
2 26 Feb 07 jari 54         this.clusterGenes = clusterGenes;
2 26 Feb 07 jari 55         content = createContent(clusters, genes);
2 26 Feb 07 jari 56         setMaxWidth(content, header);
2 26 Feb 07 jari 57     }
2 26 Feb 07 jari 58     /**
2 26 Feb 07 jari 59      * XMLEncoder/Decoder constructor
2 26 Feb 07 jari 60      * 
2 26 Feb 07 jari 61      * @param content
2 26 Feb 07 jari 62      * @param clusterGenes
2 26 Feb 07 jari 63      * @param zThr
2 26 Feb 07 jari 64      */
2 26 Feb 07 jari 65     public HCLClusterInfoViewer(JTextArea content, boolean clusterGenes, float zThr) {
2 26 Feb 07 jari 66       this.zeroThreshold = zThr;
2 26 Feb 07 jari 67       this.header = createHeader();
2 26 Feb 07 jari 68       this.clusterGenes = clusterGenes;
2 26 Feb 07 jari 69       this.content = content;
2 26 Feb 07 jari 70       setMaxWidth(content, header);
2 26 Feb 07 jari 71     }
2 26 Feb 07 jari 72     public Expression getExpression(){
2 26 Feb 07 jari 73       return new Expression(this, this.getClass(), "new", 
2 26 Feb 07 jari 74         new Object[]{this.content, new Boolean(this.clusterGenes), new Float(this.zeroThreshold)});
2 26 Feb 07 jari 75     }
2 26 Feb 07 jari 76
2 26 Feb 07 jari 77     
2 26 Feb 07 jari 78     /**
2 26 Feb 07 jari 79      * Returns component to be inserted into the framework scroll pane.
2 26 Feb 07 jari 80      */
2 26 Feb 07 jari 81     public JComponent getContentComponent() {
2 26 Feb 07 jari 82         return content;
2 26 Feb 07 jari 83     }
2 26 Feb 07 jari 84     
2 26 Feb 07 jari 85     /**
2 26 Feb 07 jari 86      * Returns the viewer header.
2 26 Feb 07 jari 87      */
2 26 Feb 07 jari 88     public JComponent getHeaderComponent() {
2 26 Feb 07 jari 89         return header;
2 26 Feb 07 jari 90     }
2 26 Feb 07 jari 91     
2 26 Feb 07 jari 92     /**
2 26 Feb 07 jari 93      * Creates the viewer header.
2 26 Feb 07 jari 94      */
2 26 Feb 07 jari 95     private JComponent createHeader() {
2 26 Feb 07 jari 96         JPanel panel = new JPanel(new GridBagLayout());
2 26 Feb 07 jari 97         panel.setBackground(Color.white);
2 26 Feb 07 jari 98         GridBagConstraints gbc = new GridBagConstraints();
2 26 Feb 07 jari 99         gbc.fill = GridBagConstraints.HORIZONTAL;
2 26 Feb 07 jari 100         gbc.insets = new Insets(10, 0, 10, 0);
2 26 Feb 07 jari 101         panel.add(new JLabel("<html><body bgcolor='#FFFFFF'><font face='serif' size='5' color='#000080'><b>Cluster Information</b></font></body></html>"), gbc);
2 26 Feb 07 jari 102         return panel;
2 26 Feb 07 jari 103     }
2 26 Feb 07 jari 104     
2 26 Feb 07 jari 105     /**
2 26 Feb 07 jari 106      * Creates the viewer content component.
2 26 Feb 07 jari 107      */
2 26 Feb 07 jari 108     private JTextArea createContent(int[][] clusters, int genes) {
2 26 Feb 07 jari 109         JTextArea area = new JTextArea(clusters.length*3, 20);
2 26 Feb 07 jari 110         area.setEditable(false);
2 26 Feb 07 jari 111         area.setMargin(new Insets(0, 10, 0, 0));
2 26 Feb 07 jari 112         StringBuffer sb = new StringBuffer(clusters.length*3*10);
2 26 Feb 07 jari 113         sb.append("\nDistance Threshold: "+String.valueOf(zeroThreshold)+"\n\n");
2 26 Feb 07 jari 114         if(clusterGenes){
2 26 Feb 07 jari 115             for (int counter = 0; counter < clusters.length; counter++) {
2 26 Feb 07 jari 116                 sb.append("Cluster "+(counter+1));
2 26 Feb 07 jari 117                 sb.append("\t");
2 26 Feb 07 jari 118                 sb.append("# of Genes in Cluster: "+clusters[counter].length);
2 26 Feb 07 jari 119                 sb.append("\n\t");
2 26 Feb 07 jari 120                 sb.append("% of Genes in Cluster: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%");
2 26 Feb 07 jari 121                 sb.append("\n\n");
2 26 Feb 07 jari 122             }
2 26 Feb 07 jari 123         }
2 26 Feb 07 jari 124         else{
2 26 Feb 07 jari 125             for (int counter = 0; counter < clusters.length; counter++) {
2 26 Feb 07 jari 126                 sb.append("Cluster "+(counter+1));
2 26 Feb 07 jari 127                 sb.append("\t");
2 26 Feb 07 jari 128                 sb.append("# of Experiments in Cluster: "+clusters[counter].length);
2 26 Feb 07 jari 129                 sb.append("\n\t");
2 26 Feb 07 jari 130                 sb.append("% of Experiments in Cluster: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%");
2 26 Feb 07 jari 131                 sb.append("\n\n");
2 26 Feb 07 jari 132             }
2 26 Feb 07 jari 133         }
2 26 Feb 07 jari 134         area.setText(sb.toString());
2 26 Feb 07 jari 135         area.setCaretPosition(0);
2 26 Feb 07 jari 136         return area;
2 26 Feb 07 jari 137     }
2 26 Feb 07 jari 138     
2 26 Feb 07 jari 139     /**
2 26 Feb 07 jari 140      * Synchronize content and header sizes.
2 26 Feb 07 jari 141      */
2 26 Feb 07 jari 142     private void setMaxWidth(JComponent content, JComponent header) {
2 26 Feb 07 jari 143         int c_width = content.getPreferredSize().width;
2 26 Feb 07 jari 144         int h_width = header.getPreferredSize().width;
2 26 Feb 07 jari 145         if (c_width > h_width) {
2 26 Feb 07 jari 146             header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height));
2 26 Feb 07 jari 147         } else {
2 26 Feb 07 jari 148             content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height));
2 26 Feb 07 jari 149         }
2 26 Feb 07 jari 150     }
2 26 Feb 07 jari 151     
2 26 Feb 07 jari 152     /** Returns a component to be inserted into the scroll pane row header
2 26 Feb 07 jari 153      */
2 26 Feb 07 jari 154     public JComponent getRowHeaderComponent() {
2 26 Feb 07 jari 155         return null;
2 26 Feb 07 jari 156     }
2 26 Feb 07 jari 157     
2 26 Feb 07 jari 158 }