apply gpl development license
[jalview.git] / src / jalview / gui / PCAPanel.java
index 06f1b25..1a9f466 100755 (executable)
@@ -1,17 +1,17 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
+ * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
+ * Copyright (C) 2009 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
@@ -31,26 +31,33 @@ import jalview.jbgui.*;
 
 /**
  * DOCUMENT ME!
- *
+ * 
  * @author $author$
  * @version $Revision$
  */
-public class PCAPanel
-    extends GPCAPanel implements Runnable
+public class PCAPanel extends GPCAPanel implements Runnable
 {
   PCA pca;
+
   int top;
+
   RotatableCanvas rc;
+
   AlignmentPanel ap;
+
   AlignViewport av;
+
   AlignmentView seqstrings;
+
   SequenceI[] seqs;
 
   /**
    * Creates a new PCAPanel object.
-   *
-   * @param av DOCUMENT ME!
-   * @param s DOCUMENT ME!
+   * 
+   * @param av
+   *                DOCUMENT ME!
+   * @param s
+   *                DOCUMENT ME!
    */
   public PCAPanel(AlignmentPanel ap)
   {
@@ -82,18 +89,20 @@ public class PCAPanel
 
     if (!sameLength)
     {
-      JOptionPane.showMessageDialog(Desktop.desktop,
-                                    "The sequences must be aligned before calculating PCA.\n" +
-                                    "Try using the Pad function in the edit menu,\n" +
-                                    "or one of the multiple sequence alignment web services.",
-                                    "Sequences not aligned",
-                                    JOptionPane.WARNING_MESSAGE);
+      JOptionPane
+              .showMessageDialog(
+                      Desktop.desktop,
+                      "The sequences must be aligned before calculating PCA.\n"
+                              + "Try using the Pad function in the edit menu,\n"
+                              + "or one of the multiple sequence alignment web services.",
+                      "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
 
       return;
     }
 
-    Desktop.addInternalFrame(this, "Principal component analysis",
-                             400, 400);
+    Desktop
+            .addInternalFrame(this, "Principal component analysis", 400,
+                    400);
 
     PaintRefresher.Register(this, av.getSequenceSetId());
 
@@ -106,7 +115,7 @@ public class PCAPanel
   public void bgcolour_actionPerformed(ActionEvent e)
   {
     Color col = JColorChooser.showDialog(this, "Select Background Colour",
-                                         rc.bgColour);
+            rc.bgColour);
 
     if (col != null)
     {
@@ -128,7 +137,7 @@ public class PCAPanel
       // Now find the component coordinates
       int ii = 0;
 
-      while ( (ii < seqs.length) && (seqs[ii] != null))
+      while ((ii < seqs.length) && (seqs[ii] != null))
       {
         ii++;
       }
@@ -143,7 +152,7 @@ public class PCAPanel
         }
       }
 
-      //////////////////
+      // ////////////////
       xCombobox.setSelectedIndex(0);
       yCombobox.setSelectedIndex(1);
       zCombobox.setSelectedIndex(2);
@@ -164,17 +173,9 @@ public class PCAPanel
 
       addKeyListener(rc);
 
-    }
-    catch (OutOfMemoryError er)
+    } catch (OutOfMemoryError er)
     {
-      JOptionPane.showInternalMessageDialog(Desktop.desktop,
-                                            "Out of memory calculating PCA!!"
-                                            +
-                                            "\nSee help files for increasing Java Virtual Machine memory."
-                                            , "Out of memory",
-                                            JOptionPane.WARNING_MESSAGE);
-      System.out.println("PCAPanel: " + er);
-      System.gc();
+      new OOMWarning("calculating PCA", er);
 
     }
 
@@ -198,7 +199,7 @@ public class PCAPanel
 
     for (int i = 0; i < pca.getM().rows; i++)
     {
-      ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];
+      ((SequencePoint) rc.points.elementAt(i)).coord = scores[i];
     }
 
     rc.img = null;
@@ -209,8 +210,9 @@ public class PCAPanel
 
   /**
    * DOCUMENT ME!
-   *
-   * @param e DOCUMENT ME!
+   * 
+   * @param e
+   *                DOCUMENT ME!
    */
   protected void xCombobox_actionPerformed(ActionEvent e)
   {
@@ -219,8 +221,9 @@ public class PCAPanel
 
   /**
    * DOCUMENT ME!
-   *
-   * @param e DOCUMENT ME!
+   * 
+   * @param e
+   *                DOCUMENT ME!
    */
   protected void yCombobox_actionPerformed(ActionEvent e)
   {
@@ -229,8 +232,9 @@ public class PCAPanel
 
   /**
    * DOCUMENT ME!
-   *
-   * @param e DOCUMENT ME!
+   * 
+   * @param e
+   *                DOCUMENT ME!
    */
   protected void zCombobox_actionPerformed(ActionEvent e)
   {
@@ -240,8 +244,7 @@ public class PCAPanel
   public void outputValues_actionPerformed(ActionEvent e)
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
-    Desktop.addInternalFrame(cap, "PCA details", 500,
-                             500);
+    Desktop.addInternalFrame(cap, "PCA details", 500, 500);
 
     cap.setText(pca.getDetails());
   }
@@ -259,31 +262,39 @@ public class PCAPanel
 
   public void originalSeqData_actionPerformed(ActionEvent e)
   {
-    // this was cut'n'pasted from the equivalent TreePanel method - we should make this an abstract function of all jalview analysis windows
+    // this was cut'n'pasted from the equivalent TreePanel method - we should
+    // make this an abstract function of all jalview analysis windows
     if (seqstrings == null)
     {
-      jalview.bin.Cache.log.info("Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action.");
+      jalview.bin.Cache.log
+              .info("Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action.");
       return;
     }
-    // decide if av alignment is sufficiently different to original data to warrant a new window to be created
-    // create new alignmnt window with hidden regions (unhiding hidden regions yields unaligned seqs)
+    // decide if av alignment is sufficiently different to original data to
+    // warrant a new window to be created
+    // create new alignmnt window with hidden regions (unhiding hidden regions
+    // yields unaligned seqs)
     // or create a selection box around columns in alignment view
     // test Alignment(SeqCigar[])
     char gc = '-';
-    try {
+    try
+    {
       // we try to get the associated view's gap character
       // but this may fail if the view was closed...
-      gc = av.
-      getGapCharacter();
-    } catch (Exception ex) {};
+      gc = av.getGapCharacter();
+    } catch (Exception ex)
+    {
+    }
+    ;
     Object[] alAndColsel = seqstrings.getAlignmentAndColumnSelection(gc);
 
     if (alAndColsel != null && alAndColsel[0] != null)
     {
       // AlignmentOrder origorder = new AlignmentOrder(alAndColsel[0]);
 
-      Alignment al = new Alignment( (SequenceI[]) alAndColsel[0]);
-      Alignment dataset = (av!=null && av.getAlignment()!=null) ? av.getAlignment().getDataset() : null;
+      Alignment al = new Alignment((SequenceI[]) alAndColsel[0]);
+      Alignment dataset = (av != null && av.getAlignment() != null) ? av
+              .getAlignment().getDataset() : null;
       if (dataset != null)
       {
         al.setDataset(dataset);
@@ -292,38 +303,33 @@ public class PCAPanel
       if (true)
       {
         // make a new frame!
-        AlignFrame af = new AlignFrame(al, (ColumnSelection) alAndColsel[1],
-                                       AlignFrame.DEFAULT_WIDTH,
-                                       AlignFrame.DEFAULT_HEIGHT
-            );
+        AlignFrame af = new AlignFrame(al,
+                (ColumnSelection) alAndColsel[1], AlignFrame.DEFAULT_WIDTH,
+                AlignFrame.DEFAULT_HEIGHT);
 
-        //>>>This is a fix for the moment, until a better solution is found!!<<<
+        // >>>This is a fix for the moment, until a better solution is
+        // found!!<<<
         // af.getFeatureRenderer().transferSettings(alignFrame.getFeatureRenderer());
 
-        //           af.addSortByOrderMenuItem(ServiceName + " Ordering",
-        //                                     msaorder);
+        // af.addSortByOrderMenuItem(ServiceName + " Ordering",
+        // msaorder);
 
         Desktop.addInternalFrame(af, "Original Data for " + this.title,
-                                 AlignFrame.DEFAULT_WIDTH,
-                                 AlignFrame.DEFAULT_HEIGHT);
+                AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
       }
     }
-    /*      CutAndPasteTransfer cap = new CutAndPasteTransfer();
-           for (int i = 0; i < seqs.length; i++)
-           {
-             cap.appendText(new jalview.util.Format("%-" + 15 + "s").form(
-      seqs[i].getName()));
-             cap.appendText(" " + seqstrings[i] + "\n");
-
-           }
-
-           Desktop.addInternalFrame(cap, "Original Data",
-               400, 400);
+    /*
+     * CutAndPasteTransfer cap = new CutAndPasteTransfer(); for (int i = 0; i <
+     * seqs.length; i++) { cap.appendText(new jalview.util.Format("%-" + 15 +
+     * "s").form( seqs[i].getName())); cap.appendText(" " + seqstrings[i] +
+     * "\n");
+     *  }
+     * 
+     * Desktop.addInternalFrame(cap, "Original Data", 400, 400);
      */
   }
 
-  class PCAPrinter
-      extends Thread implements Printable
+  class PCAPrinter extends Thread implements Printable
   {
     public void run()
     {
@@ -337,8 +343,7 @@ public class PCAPanel
         try
         {
           printJob.print();
-        }
-        catch (Exception PrintException)
+        } catch (Exception PrintException)
         {
           PrintException.printStackTrace();
         }
@@ -346,9 +351,9 @@ public class PCAPanel
     }
 
     public int print(Graphics pg, PageFormat pf, int pi)
-        throws PrinterException
+            throws PrinterException
     {
-      pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
+      pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
 
       rc.drawBackground(pg, rc.bgColour);
       rc.drawScene(pg);
@@ -370,8 +375,9 @@ public class PCAPanel
 
   /**
    * DOCUMENT ME!
-   *
-   * @param e DOCUMENT ME!
+   * 
+   * @param e
+   *                DOCUMENT ME!
    */
   public void eps_actionPerformed(ActionEvent e)
   {
@@ -380,8 +386,9 @@ public class PCAPanel
 
   /**
    * DOCUMENT ME!
-   *
-   * @param e DOCUMENT ME!
+   * 
+   * @param e
+   *                DOCUMENT ME!
    */
   public void png_actionPerformed(ActionEvent e)
   {
@@ -397,19 +404,14 @@ public class PCAPanel
 
     if (type == jalview.util.ImageMaker.PNG)
     {
-      im = new jalview.util.ImageMaker(this,
-                                       jalview.util.ImageMaker.PNG,
-                                       "Make PNG image from PCA",
-                                       width, height,
-                                       null, null);
+      im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
+              "Make PNG image from PCA", width, height, null, null);
     }
     else
     {
-      im = new jalview.util.ImageMaker(this,
-                                       jalview.util.ImageMaker.EPS,
-                                       "Make EPS file from PCA",
-                                       width, height,
-                                       null, this.getTitle());
+      im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
+              "Make EPS file from PCA", width, height, null, this
+                      .getTitle());
     }
 
     if (im.getGraphics() != null)
@@ -431,8 +433,8 @@ public class PCAPanel
 
   void buildAssociatedViewMenu()
   {
-    AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(av.
-        getSequenceSetId());
+    AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(av
+            .getSequenceSetId());
     if (aps.length == 1 && rc.av == aps[0].av)
     {
       associateViewsMenu.setVisible(false);
@@ -441,7 +443,7 @@ public class PCAPanel
 
     associateViewsMenu.setVisible(true);
 
-    if ( (viewMenu.getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem))
+    if ((viewMenu.getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem))
     {
       viewMenu.insertSeparator(viewMenu.getItemCount() - 1);
     }