JAL-2962 remove Change Parameters menu from PCA panel
[jalview.git] / src / jalview / gui / PCAPanel.java
index 7ceceee..ec7994f 100644 (file)
@@ -21,7 +21,6 @@
 package jalview.gui;
 
 import jalview.analysis.scoremodels.ScoreModels;
-import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
 import jalview.datamodel.Alignment;
@@ -30,6 +29,7 @@ import jalview.datamodel.AlignmentView;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.SequenceI;
 import jalview.jbgui.GPCAPanel;
+import jalview.util.ImageMaker;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.PCAModel;
@@ -46,7 +46,6 @@ import java.awt.print.PrinterException;
 import java.awt.print.PrinterJob;
 
 import javax.swing.ButtonGroup;
-import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JColorChooser;
 import javax.swing.JMenuItem;
 import javax.swing.JRadioButtonMenuItem;
@@ -54,17 +53,11 @@ import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
 
 /**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
+ * The panel holding the Principal Component Analysis 3-d visualisation
  */
 public class PCAPanel extends GPCAPanel
         implements Runnable, IProgressIndicator
 {
-
-  private IProgressIndicator progressBar;
-
   RotatableCanvas rc;
 
   AlignmentPanel ap;
@@ -73,30 +66,17 @@ public class PCAPanel extends GPCAPanel
 
   PCAModel pcaModel;
 
+  int top = 0;
+
   private static final int MIN_WIDTH = 470;
 
   private static final int MIN_HEIGHT = 250;
 
-  int top = 0;
+  private IProgressIndicator progressBar;
 
   private boolean working;
 
   /**
-   * Creates a new PCAPanel object using default score model and parameters
-   * 
-   * @param alignPanel
-   */
-  public PCAPanel(AlignmentPanel alignPanel)
-  {
-    this(alignPanel,
-            ScoreModels.getInstance()
-                    .getDefaultModel(
-                            !alignPanel.av.getAlignment().isNucleotide())
-                    .getName(),
-            SimilarityParams.SeqSpace);
-  }
-
-  /**
    * Constructor given sequence data, a similarity (or distance) score model
    * name, and score calculation parameters
    * 
@@ -144,6 +124,10 @@ public class PCAPanel extends GPCAPanel
 
     rc = new RotatableCanvas(alignPanel);
     this.getContentPane().add(rc, BorderLayout.CENTER);
+
+    /*
+     * perform calculation in a new Thread
+     */
     Thread worker = new Thread(this);
     worker.start();
   }
@@ -157,58 +141,8 @@ public class PCAPanel extends GPCAPanel
     pcaModel = null;
   }
 
-  /**
-   * Repopulate the options and actions under the score model menu when it is
-   * selected. Options will depend on whether 'nucleotide' or 'peptide'
-   * modelling is selected (and also possibly on whether any additional score
-   * models have been added).
-   */
-  @Override
-  protected void scoreModel_menuSelected()
-  {
-    scoreModelMenu.removeAll();
-    for (final ScoreModelI sm : ScoreModels.getInstance().getModels())
-    {
-      final String name = sm.getName();
-      JCheckBoxMenuItem jm = new JCheckBoxMenuItem(name);
-
-      /*
-       * if the score model doesn't provide a description, try to look one
-       * up in the text bundle, falling back on its name
-       */
-      String tooltip = sm.getDescription();
-      if (tooltip == null)
-      {
-        tooltip = MessageManager.getStringOrReturn("label.score_model_",
-                name);
-      }
-      jm.setToolTipText(tooltip);
-      jm.setSelected(pcaModel.getScoreModelName().equals(name));
-      if ((pcaModel.isNucleotide() && sm.isDNA())
-              || (!pcaModel.isNucleotide() && sm.isProtein()))
-      {
-        jm.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent e)
-          {
-            if (!pcaModel.getScoreModelName().equals(name))
-            {
-              ScoreModelI sm2 = ScoreModels.getInstance()
-                      .getScoreModel(name, ap);
-              pcaModel.setScoreModel(sm2);
-              Thread worker = new Thread(PCAPanel.this);
-              worker.start();
-            }
-          }
-        });
-        scoreModelMenu.add(jm);
-      }
-    }
-  }
-
   @Override
-  public void bgcolour_actionPerformed(ActionEvent e)
+  protected void bgcolour_actionPerformed()
   {
     Color col = JColorChooser.showDialog(this,
             MessageManager.getString("label.select_background_colour"),
@@ -222,7 +156,7 @@ public class PCAPanel extends GPCAPanel
   }
 
   /**
-   * DOCUMENT ME!
+   * Calculates the PCA and displays the results
    */
   @Override
   public void run()
@@ -239,7 +173,6 @@ public class PCAPanel extends GPCAPanel
     working = true;
     try
     {
-      calcSettings.setEnabled(false);
       pcaModel.run();
       // ////////////////
       xCombobox.setSelectedIndex(0);
@@ -248,8 +181,6 @@ public class PCAPanel extends GPCAPanel
 
       pcaModel.updateRc(rc);
       // rc.invalidate();
-      nuclSetting.setSelected(pcaModel.isNucleotide());
-      protSetting.setSelected(!pcaModel.isNucleotide());
       top = pcaModel.getTop();
 
     } catch (OutOfMemoryError er)
@@ -261,50 +192,26 @@ public class PCAPanel extends GPCAPanel
     {
       progress.setProgressBar("", progId);
     }
-    calcSettings.setEnabled(true);
+
     repaint();
     if (getParent() == null)
     {
       addKeyListener(rc);
-      Desktop.addInternalFrame(this, MessageManager
-              .getString("label.principal_component_analysis"), 475, 450);
+      Desktop.addInternalFrame(this,
+              MessageManager.formatMessage("label.calc_title", "PCA",
+                      pcaModel.getScoreModelName()),
+              475, 450);
       this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
     }
     working = false;
   }
 
-  @Override
-  protected void nuclSetting_actionPerfomed(ActionEvent arg0)
-  {
-    if (!pcaModel.isNucleotide())
-    {
-      pcaModel.setNucleotide(true);
-      pcaModel.setScoreModel(
-              ScoreModels.getInstance().getDefaultModel(false));
-      Thread worker = new Thread(this);
-      worker.start();
-    }
-
-  }
-
-  @Override
-  protected void protSetting_actionPerfomed(ActionEvent arg0)
-  {
-
-    if (pcaModel.isNucleotide())
-    {
-      pcaModel.setNucleotide(false);
-      pcaModel.setScoreModel(
-              ScoreModels.getInstance().getDefaultModel(true));
-      Thread worker = new Thread(this);
-      worker.start();
-    }
-  }
-
   /**
-   * DOCUMENT ME!
+   * Updates the PCA display after a change of component to use for x, y or z
+   * axis
    */
-  void doDimensionChange()
+  @Override
+  protected void doDimensionChange()
   {
     if (top == 0)
     {
@@ -321,44 +228,8 @@ public class PCAPanel extends GPCAPanel
     rc.paint(rc.getGraphics());
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  protected void xCombobox_actionPerformed(ActionEvent e)
-  {
-    doDimensionChange();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
   @Override
-  protected void yCombobox_actionPerformed(ActionEvent e)
-  {
-    doDimensionChange();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  protected void zCombobox_actionPerformed(ActionEvent e)
-  {
-    doDimensionChange();
-  }
-
-  @Override
-  public void outputValues_actionPerformed(ActionEvent e)
+  protected void outputValues_actionPerformed()
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
     try
@@ -374,20 +245,20 @@ public class PCAPanel extends GPCAPanel
   }
 
   @Override
-  public void showLabels_actionPerformed(ActionEvent e)
+  protected void showLabels_actionPerformed()
   {
     rc.showLabels(showLabels.getState());
   }
 
   @Override
-  public void print_actionPerformed(ActionEvent e)
+  protected void print_actionPerformed()
   {
     PCAPrinter printer = new PCAPrinter();
     printer.start();
   }
 
   @Override
-  public void originalSeqData_actionPerformed(ActionEvent e)
+  public void originalSeqData_actionPerformed()
   {
     // this was cut'n'pasted from the equivalent TreePanel method - we should
     // make this an abstract function of all jalview analysis windows
@@ -412,7 +283,7 @@ public class PCAPanel extends GPCAPanel
     } catch (Exception ex)
     {
     }
-    ;
+
     Object[] alAndColsel = pcaModel.getSeqtrings()
             .getAlignmentAndHiddenColumns(gc);
 
@@ -497,7 +368,7 @@ public class PCAPanel extends GPCAPanel
 
       rc.drawBackground(pg, rc.bgColour);
       rc.drawScene(pg);
-      if (rc.drawAxes == true)
+      if (rc.drawAxes)
       {
         rc.drawAxes(pg);
       }
@@ -514,61 +385,54 @@ public class PCAPanel extends GPCAPanel
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Handler for 'Save as EPS' option
    */
   @Override
-  public void eps_actionPerformed(ActionEvent e)
+  protected void eps_actionPerformed()
   {
-    makePCAImage(jalview.util.ImageMaker.TYPE.EPS);
+    makePCAImage(ImageMaker.TYPE.EPS);
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Handler for 'Save as PNG' option
    */
   @Override
-  public void png_actionPerformed(ActionEvent e)
+  protected void png_actionPerformed()
   {
-    makePCAImage(jalview.util.ImageMaker.TYPE.PNG);
+    makePCAImage(ImageMaker.TYPE.PNG);
   }
 
-  void makePCAImage(jalview.util.ImageMaker.TYPE type)
+  void makePCAImage(ImageMaker.TYPE type)
   {
     int width = rc.getWidth();
     int height = rc.getHeight();
 
-    jalview.util.ImageMaker im;
+    ImageMaker im;
 
-    if (type == jalview.util.ImageMaker.TYPE.PNG)
+    if (type == ImageMaker.TYPE.PNG)
     {
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from PCA",
-              width, height, null, null, null, 0, false);
+      im = new ImageMaker(this, ImageMaker.TYPE.PNG,
+              "Make PNG image from PCA", width, height, null, null, null, 0,
+              false);
     }
     else if (type == jalview.util.ImageMaker.TYPE.EPS)
     {
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from PCA",
-              width, height, null, this.getTitle(), null, 0, false);
+      im = new ImageMaker(this, ImageMaker.TYPE.EPS,
+              "Make EPS file from PCA", width, height, null,
+              this.getTitle(), null, 0, false);
     }
     else
     {
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
-              width, height, null, this.getTitle(), null, 0, false);
-
+      im = new ImageMaker(this, ImageMaker.TYPE.SVG,
+              "Make SVG file from PCA", width, height, null,
+              this.getTitle(), null, 0, false);
     }
 
     if (im.getGraphics() != null)
     {
       rc.drawBackground(im.getGraphics(), Color.black);
       rc.drawScene(im.getGraphics());
-      if (rc.drawAxes == true)
+      if (rc.drawAxes)
       {
         rc.drawAxes(im.getGraphics());
       }
@@ -577,11 +441,15 @@ public class PCAPanel extends GPCAPanel
   }
 
   @Override
-  public void viewMenu_menuSelected()
+  protected void viewMenu_menuSelected()
   {
     buildAssociatedViewMenu();
   }
 
+  /**
+   * Builds the menu showing the choice of possible views (for the associated
+   * sequence data) to which the PCA may be linked
+   */
   void buildAssociatedViewMenu()
   {
     AlignmentPanel[] aps = PaintRefresher
@@ -604,12 +472,12 @@ public class PCAPanel extends GPCAPanel
 
     JRadioButtonMenuItem item;
     ButtonGroup buttonGroup = new ButtonGroup();
-    int i, iSize = aps.length;
-    final PCAPanel thisPCAPanel = this;
-    for (i = 0; i < iSize; i++)
+    int iSize = aps.length;
+
+    for (int i = 0; i < iSize; i++)
     {
-      final AlignmentPanel ap = aps[i];
-      item = new JRadioButtonMenuItem(ap.av.viewName, ap.av == rc.av);
+      final AlignmentPanel panel = aps[i];
+      item = new JRadioButtonMenuItem(panel.av.viewName, panel.av == rc.av);
       buttonGroup.add(item);
       item.addActionListener(new ActionListener()
       {
@@ -617,9 +485,10 @@ public class PCAPanel extends GPCAPanel
         public void actionPerformed(ActionEvent evt)
         {
           rc.applyToAllViews = false;
-          rc.av = ap.av;
-          rc.ap = ap;
-          PaintRefresher.Register(thisPCAPanel, ap.av.getSequenceSetId());
+          rc.av = panel.av;
+          rc.ap = panel;
+          PaintRefresher.Register(PCAPanel.this,
+                  panel.av.getSequenceSetId());
         }
       });
 
@@ -652,7 +521,7 @@ public class PCAPanel extends GPCAPanel
    * )
    */
   @Override
-  protected void outputPoints_actionPerformed(ActionEvent e)
+  protected void outputPoints_actionPerformed()
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
     try
@@ -678,7 +547,7 @@ public class PCAPanel extends GPCAPanel
    * .ActionEvent)
    */
   @Override
-  protected void outputProjPoints_actionPerformed(ActionEvent e)
+  protected void outputProjPoints_actionPerformed()
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
     try
@@ -793,7 +662,7 @@ public class PCAPanel extends GPCAPanel
   }
 
   @Override
-  protected void resetButton_actionPerformed(ActionEvent e)
+  protected void resetButton_actionPerformed()
   {
     int t = top;
     top = 0; // ugly - prevents dimensionChanged events from being processed