1   package baseCode.gui;
2   
3   import java.awt.BorderLayout;
4   import java.awt.Dimension;
5   import java.awt.Toolkit;
6   
7   import javax.swing.JFrame;
8   import javax.swing.UIManager;
9   
10  import baseCode.gui.ColorMap;
11  import baseCode.gui.JMatrixDisplay;
12  
13  /***
14   * This is an example of how you'd display a microarray.
15   * 
16   * @author Will Braynen
17   * @version $Id: MatrixDisplayApp.java,v 1.1 2005/03/17 13:58:42 pavlidis Exp $
18   */
19  public class MatrixDisplayApp {
20     boolean packFrame = false;
21  
22     //Construct the application
23     public MatrixDisplayApp( String inDataFilename, String outPngFilename ) {
24  
25        JFrame frame = new JFrame();
26        frame.getContentPane().setLayout( new BorderLayout() );
27        frame.setSize( new Dimension( 600, 550 ) );
28        frame.setTitle( "Eisen Plot" );
29  
30        //
31        // Here is an example of how you'd display a matrix of doubles
32        // visually with colors
33        //
34        JMatrixDisplay matrixDisplay = null;
35        try {
36           matrixDisplay = new JMatrixDisplay( inDataFilename );
37        } catch ( java.io.IOException e ) {
38           System.err.println( "Unable to open file " + inDataFilename );
39           return;
40        }
41  
42        matrixDisplay.setLabelsVisible( true );
43  
44        try {
45           boolean showLabels = true;
46  
47           matrixDisplay.saveImage( outPngFilename, showLabels );
48        } catch ( java.io.IOException e ) {
49           System.err.println( "Unable to save screenshot to file "
50                 + outPngFilename );
51           return;
52        }
53  
54        frame.getContentPane().add( matrixDisplay, BorderLayout.CENTER );
55  
56        //Validate frames that have preset sizes
57        //Pack frames that have useful preferred size info, e.g. from their
58        // layout
59        if ( packFrame ) {
60           frame.pack();
61        } else {
62           frame.validate();
63        }
64        //Center the window
65        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
66        Dimension frameSize = frame.getSize();
67        if ( frameSize.height > screenSize.height ) {
68           frameSize.height = screenSize.height;
69        }
70        if ( frameSize.width > screenSize.width ) {
71           frameSize.width = screenSize.width;
72        }
73        frame.setLocation( ( screenSize.width - frameSize.width ) / 2,
74              ( screenSize.height - frameSize.height ) / 2 );
75        frame.setVisible( true );
76        
77        matrixDisplay.setStandardizedEnabled( true );
78  
79        // use the green-red color map
80        try {
81           matrixDisplay.setColorMap( ColorMap.GREENRED_COLORMAP );
82        }
83        catch( IllegalArgumentException e ) {e.printStackTrace();}
84        
85        matrixDisplay.setStandardizedEnabled( false );
86        
87        
88  //      for ( int i = 0; i < 5; i++ ) {
89  //         try {
90  //            Thread.sleep( 1000 );
91  //            isShowingStandardized = !isShowingStandardized;
92  //            matrixDisplay.setStandardizedEnabled( isShowingStandardized );
93  //            matrixDisplay.repaint();
94  //         } catch ( InterruptedException e ) {
95  //         }
96  //      }
97     }
98  
99     //Main method: args[0] can contain the name of the data file
100    public static void main( String[] args ) {
101       try {
102          UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
103       } catch ( Exception e ) {
104          e.printStackTrace();
105       }
106       if ( args.length > 1 ) {
107          new MatrixDisplayApp( args[0], args[1] );
108       } else {
109          System.err
110                .println( "Please specify dataFilename and outPngFilename by passing them as program arguments" );
111       }
112    }
113 }