mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/fom/CastFOMContentComponentA.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: CastFOMContentComponentA.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.6 $
2 26 Feb 07 jari 8  * $Date: 2006/03/24 15:50:09 $
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.fom;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.awt.GridBagConstraints;
2 26 Feb 07 jari 15 import java.awt.GridBagLayout;
2 26 Feb 07 jari 16 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 17 import java.awt.event.ActionListener;
2 26 Feb 07 jari 18 import java.awt.image.BufferedImage;
2 26 Feb 07 jari 19
2 26 Feb 07 jari 20 import javax.swing.JButton;
2 26 Feb 07 jari 21 import javax.swing.JComponent;
2 26 Feb 07 jari 22 import javax.swing.JFrame;
2 26 Feb 07 jari 23 import javax.swing.JList;
2 26 Feb 07 jari 24 import javax.swing.JPanel;
2 26 Feb 07 jari 25 import javax.swing.JScrollPane;
2 26 Feb 07 jari 26 import javax.swing.JTextArea;
2 26 Feb 07 jari 27
2 26 Feb 07 jari 28 import org.tigr.microarray.mev.cluster.gui.IDisplayMenu;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 30
2 26 Feb 07 jari 31 public class CastFOMContentComponentA extends JPanel implements java.io.Serializable {
2 26 Feb 07 jari 32     
2 26 Feb 07 jari 33     private FOMGraph fomGraphA;
2 26 Feb 07 jari 34     private FOMGraph fomGraphB;
2 26 Feb 07 jari 35     
2 26 Feb 07 jari 36     private float[] fom_values;
2 26 Feb 07 jari 37     float interval;
2 26 Feb 07 jari 38     GridBagConstraints gbc;
2 26 Feb 07 jari 39     int[] numOfCastClusters;
2 26 Feb 07 jari 40     
2 26 Feb 07 jari 41     public CastFOMContentComponentA(float[] fom_values, float interval, int[] numOfCastClusters) { // take average by default
2 26 Feb 07 jari 42   setLayout(new GridBagLayout());
2 26 Feb 07 jari 43   this.fom_values = fom_values;
2 26 Feb 07 jari 44   this.interval = interval;
2 26 Feb 07 jari 45     this.numOfCastClusters = numOfCastClusters;
2 26 Feb 07 jari 46   this.fomGraphA = new FOMGraph(fom_values, null, "FOM value vs. Threshold", "Threshold", "Adjusted FOM", false);
2 26 Feb 07 jari 47   this.fomGraphA.setItems(createXThresholdItems(fom_values.length), createYItems(fom_values));
2 26 Feb 07 jari 48   this.fomGraphA.setMaxYValue((float)Math.ceil(getMaxValue(fom_values)));
2 26 Feb 07 jari 49   GridBagConstraints gbc = new GridBagConstraints();
2 26 Feb 07 jari 50   gbc.fill = GridBagConstraints.BOTH;
2 26 Feb 07 jari 51   gbc.gridx = 0;
2 26 Feb 07 jari 52   gbc.gridy = 0;
2 26 Feb 07 jari 53   gbc.weightx = 0.9;
2 26 Feb 07 jari 54   gbc.weighty = 1.0;
2 26 Feb 07 jari 55   add(this.fomGraphA, gbc);
2 26 Feb 07 jari 56   gbc.gridx = 1;
2 26 Feb 07 jari 57   gbc.weightx = 0.1;
2 26 Feb 07 jari 58   add(createValuesList(fom_values), gbc);
2 26 Feb 07 jari 59     }
2 26 Feb 07 jari 60     
2 26 Feb 07 jari 61     public static String[] getPersistenceDelegateArgs(){
2 26 Feb 07 jari 62       return new String[] {"fom_values", "interval", "numOfCastClusters"};
2 26 Feb 07 jari 63     }
2 26 Feb 07 jari 64     
2 26 Feb 07 jari 65     public BufferedImage getImageA() {
2 26 Feb 07 jari 66   return this.fomGraphA.getImage();
2 26 Feb 07 jari 67     }
2 26 Feb 07 jari 68     
2 26 Feb 07 jari 69     public BufferedImage getImageB() {
2 26 Feb 07 jari 70   return this.fomGraphB.getImage();
2 26 Feb 07 jari 71     }
2 26 Feb 07 jari 72     
2 26 Feb 07 jari 73     
2 26 Feb 07 jari 74     private JComponent createValuesList(float[] fom_values) {
2 26 Feb 07 jari 75   String[] items = new String[fom_values.length];
2 26 Feb 07 jari 76   float threshold = interval;
2 26 Feb 07 jari 77   for (int i=0; i<fom_values.length; i++) {
2 26 Feb 07 jari 78       String s = "0.";
2 26 Feb 07 jari 79       int d = (int)Math.floor(threshold*100);
2 26 Feb 07 jari 80       //System.out.println ("Inside CastFOMContentComponent.createXThresholdItems(): d = " + d);
2 26 Feb 07 jari 81       if (d < 10) s = s + "0";
2 26 Feb 07 jari 82       s = s + d;
2 26 Feb 07 jari 83       if (d >= 100) s = "1.00";
2 26 Feb 07 jari 84       threshold = threshold + interval;
2 26 Feb 07 jari 85       items[i] = s + "---->" + String.valueOf(Math.round(fom_values[i]*1000)/1000f);
2 26 Feb 07 jari 86   }
2 26 Feb 07 jari 87   JPanel listPanel = new JPanel(new GridBagLayout());
2 26 Feb 07 jari 88   JScrollPane scroll = new JScrollPane(new JList(items));
2 26 Feb 07 jari 89   
2 26 Feb 07 jari 90   GridBagConstraints gbc = new GridBagConstraints();
2 26 Feb 07 jari 91   gbc.fill = GridBagConstraints.BOTH;
2 26 Feb 07 jari 92   gbc.gridx = 0;
2 26 Feb 07 jari 93   gbc.gridy = 0;
2 26 Feb 07 jari 94   gbc.weightx = 1.0;
2 26 Feb 07 jari 95   gbc.weighty = 1.0;
2 26 Feb 07 jari 96   listPanel.add(scroll, gbc);
2 26 Feb 07 jari 97   gbc.fill = GridBagConstraints.HORIZONTAL;
2 26 Feb 07 jari 98   gbc.gridy = 1;
2 26 Feb 07 jari 99   gbc.weighty = 0.0;
2 26 Feb 07 jari 100   JButton button = new JButton("Details");
2 26 Feb 07 jari 101   button.addActionListener(new ActionListener() {
2 26 Feb 07 jari 102       public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 103     onDetails();
2 26 Feb 07 jari 104       }
2 26 Feb 07 jari 105   });
2 26 Feb 07 jari 106   listPanel.add(button, gbc);
2 26 Feb 07 jari 107   return listPanel;
2 26 Feb 07 jari 108     }
2 26 Feb 07 jari 109     
2 26 Feb 07 jari 110     private void onDetails() {
2 26 Feb 07 jari 111   JFrame f = new JFrame("Details");
2 26 Feb 07 jari 112   JTextArea t = new JTextArea();
2 26 Feb 07 jari 113   t.setEditable(false);
2 26 Feb 07 jari 114   JScrollPane sp = new JScrollPane(t);
2 26 Feb 07 jari 115   StringBuffer sb = new StringBuffer();
2 26 Feb 07 jari 116   float threshold = interval;
2 26 Feb 07 jari 117   for (int i=0; i<fom_values.length; i++) {
2 26 Feb 07 jari 118       String s = "0.";
2 26 Feb 07 jari 119       int d = (int)Math.floor(threshold*100);
2 26 Feb 07 jari 120       //System.out.println ("Inside CastFOMContentComponent.createXThresholdItems(): d = " + d);
2 26 Feb 07 jari 121       if (d < 10) s = s + "0";
2 26 Feb 07 jari 122       s = s + d;
2 26 Feb 07 jari 123       if (d >= 100) s = "1.00";
2 26 Feb 07 jari 124       threshold = threshold + interval;
2 26 Feb 07 jari 125       sb.append(s + "\t" + String.valueOf(Math.round(fom_values[i]*1000)/1000f)+"\n");
2 26 Feb 07 jari 126   }
2 26 Feb 07 jari 127   t.setText(sb.toString());
2 26 Feb 07 jari 128   t.setCaretPosition(0);
2 26 Feb 07 jari 129   f.getContentPane().add(sp);
2 26 Feb 07 jari 130   f.setSize(200, 200);
2 26 Feb 07 jari 131   java.awt.Dimension screenSize = f.getToolkit().getScreenSize();
2 26 Feb 07 jari 132   f.setLocation(screenSize.width/2 - f.getSize().width/2, screenSize.height/2 - f.getSize().height/2);
2 26 Feb 07 jari 133   f.setVisible(true);
2 26 Feb 07 jari 134     }
2 26 Feb 07 jari 135     
2 26 Feb 07 jari 136     public void onSelected(IFramework framework) {
2 26 Feb 07 jari 137   this.fomGraphA.setAntiAliasing(framework.getDisplayMenu().isAntiAliasing());
2 26 Feb 07 jari 138     }
2 26 Feb 07 jari 139     
2 26 Feb 07 jari 140     public void onMenuChanged(IDisplayMenu menu) {
2 26 Feb 07 jari 141   this.fomGraphA.setAntiAliasing(menu.isAntiAliasing());
2 26 Feb 07 jari 142     }
2 26 Feb 07 jari 143     
2 26 Feb 07 jari 144     private String[] createXItems(int iterations) {
2 26 Feb 07 jari 145   String[] items = new String[iterations];
2 26 Feb 07 jari 146   for (int i=0; i<items.length; i++) {
2 26 Feb 07 jari 147       if ((i+1)%5 == 0 || i == 0 || i == items.length-1) {
2 26 Feb 07 jari 148     items[i] = String.valueOf(i+1);
2 26 Feb 07 jari 149       }
2 26 Feb 07 jari 150   }
2 26 Feb 07 jari 151   return items;
2 26 Feb 07 jari 152     }
2 26 Feb 07 jari 153     
2 26 Feb 07 jari 154     
2 26 Feb 07 jari 155     private String[] createXThresholdItems(int iterations) {
2 26 Feb 07 jari 156   String[] items = new String[iterations];
2 26 Feb 07 jari 157   float threshold = interval;
2 26 Feb 07 jari 158   for (int i=0; i<items.length; i++) {
2 26 Feb 07 jari 159       //if ((i+1)%5 == 0 || i == 0 || i == items.length-1) {
2 26 Feb 07 jari 160       String s = "0.";
2 26 Feb 07 jari 161       int d = (int)Math.floor(threshold*100);
2 26 Feb 07 jari 162       //System.out.println ("Inside CastFOMContentComponent.createXThresholdItems(): d = " + d);
2 26 Feb 07 jari 163       if (d < 10) s = s + "0";
2 26 Feb 07 jari 164       s = s + d;
2 26 Feb 07 jari 165       if (d >= 100) s = "1.00";
2 26 Feb 07 jari 166       items[i] = s;//String.valueOf(threshold);
2 26 Feb 07 jari 167       threshold = threshold + interval;
2 26 Feb 07 jari 168       //System.out.println("Inside CastFOMContentComponent.createXThresholdItems(): threshold[" + i + "] =" + threshold);
2 26 Feb 07 jari 169       //}
2 26 Feb 07 jari 170   }
2 26 Feb 07 jari 171   return items;
2 26 Feb 07 jari 172     }
2 26 Feb 07 jari 173     
2 26 Feb 07 jari 174     private float getMaxValue(float[] fom_values) {
2 26 Feb 07 jari 175   float max_value = -Float.MAX_VALUE;
2 26 Feb 07 jari 176   for (int i=0; i<fom_values.length; i++) {
2 26 Feb 07 jari 177       max_value = Math.max(max_value, fom_values[i]);
2 26 Feb 07 jari 178   }
2 26 Feb 07 jari 179   return max_value;
2 26 Feb 07 jari 180     }
2 26 Feb 07 jari 181     
2 26 Feb 07 jari 182     private String[] createYItems(float[] fom_values) {
2 26 Feb 07 jari 183   int number_of_items = (int)Math.ceil(getMaxValue(fom_values))+1;
2 26 Feb 07 jari 184   String[] items = new String[number_of_items];
2 26 Feb 07 jari 185   for (int i=0; i<items.length; i++) {
2 26 Feb 07 jari 186       if (i%2 == 0 || i == items.length-1) {
2 26 Feb 07 jari 187     items[i] = String.valueOf(i);
2 26 Feb 07 jari 188       }
2 26 Feb 07 jari 189   }
2 26 Feb 07 jari 190   return items;
2 26 Feb 07 jari 191     }
2 26 Feb 07 jari 192     
2 26 Feb 07 jari 193     /////////////////////////////////////////////////////////////////
2 26 Feb 07 jari 194  /*   public static void main(String[] args) throws Exception {
2 26 Feb 07 jari 195   javax.swing.JFrame frame = new javax.swing.JFrame();
2 26 Feb 07 jari 196   frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
2 26 Feb 07 jari 197   float[] fom_values = new float[] {1.5f, 0.88888888888f, 0.6666666666f, 2.5f, 0.33333333333f, 0.0f};
2 26 Feb 07 jari 198   FOMContentComponent content = new FOMContentComponent(fom_values);
2 26 Feb 07 jari 199   frame.getContentPane().add(content);
2 26 Feb 07 jari 200   frame.setSize(700, 400);
2 26 Feb 07 jari 201   java.awt.Dimension screenSize = frame.getToolkit().getScreenSize();
2 26 Feb 07 jari 202   frame.setLocation(screenSize.width/2 - frame.getSize().width/2, screenSize.height/2 - frame.getSize().height/2);
2 26 Feb 07 jari 203   frame.setVisible(true);
2 26 Feb 07 jari 204     }
2 26 Feb 07 jari 205   */
2 26 Feb 07 jari 206   /**
2 26 Feb 07 jari 207    * @return Returns the fom_values.
2 26 Feb 07 jari 208    */
2 26 Feb 07 jari 209   public float[] getFom_values() {
2 26 Feb 07 jari 210     return fom_values;
2 26 Feb 07 jari 211   }
2 26 Feb 07 jari 212   /**
2 26 Feb 07 jari 213    * @return Returns the interval.
2 26 Feb 07 jari 214    */
2 26 Feb 07 jari 215   public float getInterval() {
2 26 Feb 07 jari 216     return interval;
2 26 Feb 07 jari 217   }
2 26 Feb 07 jari 218   /**
2 26 Feb 07 jari 219    * @return Returns the numOfCastClusters.
2 26 Feb 07 jari 220    */
2 26 Feb 07 jari 221   public int[] getNumOfCastClusters() {
2 26 Feb 07 jari 222     return numOfCastClusters;
2 26 Feb 07 jari 223   }
2 26 Feb 07 jari 224 }