ensure input data can be recovered for tree and PCA even if alignment view was closed
authorjprocter <Jim Procter>
Wed, 13 Aug 2008 13:31:06 +0000 (13:31 +0000)
committerjprocter <Jim Procter>
Wed, 13 Aug 2008 13:31:06 +0000 (13:31 +0000)
src/jalview/appletgui/PCAPanel.java
src/jalview/appletgui/TreePanel.java
src/jalview/gui/PCAPanel.java
src/jalview/gui/TreePanel.java

index a5268bf..ee54478 100755 (executable)
@@ -219,8 +219,14 @@ public class PCAPanel
     // 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[])
-    Object[] alAndColsel = seqstrings.getAlignmentAndColumnSelection(av.
-        getGapCharacter());
+    char gc = '-';
+    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) {};
+    Object[] alAndColsel = seqstrings.getAlignmentAndColumnSelection(gc);
 
     if (alAndColsel != null && alAndColsel[0] != null)
     {
index 5ddea1d..6ab01aa 100755 (executable)
@@ -120,8 +120,14 @@ public class TreePanel
     // test Alignment(SeqCigar[])
     if (tree.seqData != null)
     {
-      Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(av.
-          getGapCharacter());
+      char gc = '-';
+      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) {};
+      Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(gc);
 
       if (alAndColsel != null && alAndColsel[0] != null)
       {
index 772e67e..15c3d59 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package jalview.gui;\r
-\r
-import java.util.*;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import java.awt.print.*;\r
-import javax.swing.*;\r
-\r
-import jalview.analysis.*;\r
-import jalview.datamodel.*;\r
-import jalview.jbgui.*;\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class PCAPanel\r
-    extends GPCAPanel implements Runnable\r
-{\r
-  PCA pca;\r
-  int top;\r
-  RotatableCanvas rc;\r
-  AlignmentPanel ap;\r
-  AlignViewport av;\r
-  AlignmentView seqstrings;\r
-  SequenceI[] seqs;\r
-\r
-  /**\r
-   * Creates a new PCAPanel object.\r
-   *\r
-   * @param av DOCUMENT ME!\r
-   * @param s DOCUMENT ME!\r
-   */\r
-  public PCAPanel(AlignmentPanel ap)\r
-  {\r
-    this.av = ap.av;\r
-    this.ap = ap;\r
-\r
-    boolean sameLength = true;\r
-\r
-    seqstrings = av.getAlignmentView(av.getSelectionGroup() != null);\r
-    if (av.getSelectionGroup() == null)\r
-    {\r
-      seqs = av.alignment.getSequencesArray();\r
-    }\r
-    else\r
-    {\r
-      seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);\r
-    }\r
-    SeqCigar sq[] = seqstrings.getSequences();\r
-    int length = sq[0].getWidth();\r
-\r
-    for (int i = 0; i < seqs.length; i++)\r
-    {\r
-      if (sq[i].getWidth() != length)\r
-      {\r
-        sameLength = false;\r
-        break;\r
-      }\r
-    }\r
-\r
-    if (!sameLength)\r
-    {\r
-      JOptionPane.showMessageDialog(Desktop.desktop,\r
-                                    "The sequences must be aligned before calculating PCA.\n" +\r
-                                    "Try using the Pad function in the edit menu,\n" +\r
-                                    "or one of the multiple sequence alignment web services.",\r
-                                    "Sequences not aligned",\r
-                                    JOptionPane.WARNING_MESSAGE);\r
-\r
-      return;\r
-    }\r
-\r
-    Desktop.addInternalFrame(this, "Principal component analysis",\r
-                             400, 400);\r
-\r
-    PaintRefresher.Register(this, av.getSequenceSetId());\r
-\r
-    rc = new RotatableCanvas(ap);\r
-    this.getContentPane().add(rc, BorderLayout.CENTER);\r
-    Thread worker = new Thread(this);\r
-    worker.start();\r
-  }\r
-\r
-  public void bgcolour_actionPerformed(ActionEvent e)\r
-  {\r
-    Color col = JColorChooser.showDialog(this, "Select Background Colour",\r
-                                         rc.bgColour);\r
-\r
-    if (col != null)\r
-    {\r
-      rc.bgColour = col;\r
-    }\r
-    rc.repaint();\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   */\r
-  public void run()\r
-  {\r
-    try\r
-    {\r
-      pca = new PCA(seqstrings.getSequenceStrings(' '));\r
-      pca.run();\r
-\r
-      // Now find the component coordinates\r
-      int ii = 0;\r
-\r
-      while ( (ii < seqs.length) && (seqs[ii] != null))\r
-      {\r
-        ii++;\r
-      }\r
-\r
-      double[][] comps = new double[ii][ii];\r
-\r
-      for (int i = 0; i < ii; i++)\r
-      {\r
-        if (pca.getEigenvalue(i) > 1e-4)\r
-        {\r
-          comps[i] = pca.component(i);\r
-        }\r
-      }\r
-\r
-      //////////////////\r
-      xCombobox.setSelectedIndex(0);\r
-      yCombobox.setSelectedIndex(1);\r
-      zCombobox.setSelectedIndex(2);\r
-\r
-      top = pca.getM().rows - 1;\r
-\r
-      Vector points = new Vector();\r
-      float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);\r
-\r
-      for (int i = 0; i < pca.getM().rows; i++)\r
-      {\r
-        SequencePoint sp = new SequencePoint(seqs[i], scores[i]);\r
-        points.addElement(sp);\r
-      }\r
-\r
-      rc.setPoints(points, pca.getM().rows);\r
-      rc.repaint();\r
-\r
-      addKeyListener(rc);\r
-\r
-    }\r
-    catch (OutOfMemoryError er)\r
-    {\r
-      JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                                            "Out of memory calculating PCA!!"\r
-                                            +\r
-                                            "\nSee help files for increasing Java Virtual Machine memory."\r
-                                            , "Out of memory",\r
-                                            JOptionPane.WARNING_MESSAGE);\r
-      System.out.println("PCAPanel: " + er);\r
-      System.gc();\r
-\r
-    }\r
-\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   */\r
-  void doDimensionChange()\r
-  {\r
-    if (top == 0)\r
-    {\r
-      return;\r
-    }\r
-\r
-    int dim1 = top - xCombobox.getSelectedIndex();\r
-    int dim2 = top - yCombobox.getSelectedIndex();\r
-    int dim3 = top - zCombobox.getSelectedIndex();\r
-\r
-    float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);\r
-\r
-    for (int i = 0; i < pca.getM().rows; i++)\r
-    {\r
-      ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];\r
-    }\r
-\r
-    rc.img = null;\r
-    rc.rotmat.setIdentity();\r
-    rc.initAxes();\r
-    rc.paint(rc.getGraphics());\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param e DOCUMENT ME!\r
-   */\r
-  protected void xCombobox_actionPerformed(ActionEvent e)\r
-  {\r
-    doDimensionChange();\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param e DOCUMENT ME!\r
-   */\r
-  protected void yCombobox_actionPerformed(ActionEvent e)\r
-  {\r
-    doDimensionChange();\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param e DOCUMENT ME!\r
-   */\r
-  protected void zCombobox_actionPerformed(ActionEvent e)\r
-  {\r
-    doDimensionChange();\r
-  }\r
-\r
-  public void outputValues_actionPerformed(ActionEvent e)\r
-  {\r
-    CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
-    Desktop.addInternalFrame(cap, "PCA details", 500,\r
-                             500);\r
-\r
-    cap.setText(pca.getDetails());\r
-  }\r
-\r
-  public void showLabels_actionPerformed(ActionEvent e)\r
-  {\r
-    rc.showLabels(showLabels.getState());\r
-  }\r
-\r
-  public void print_actionPerformed(ActionEvent e)\r
-  {\r
-    PCAPrinter printer = new PCAPrinter();\r
-    printer.start();\r
-  }\r
-\r
-  public void originalSeqData_actionPerformed(ActionEvent e)\r
-  {\r
-    // this was cut'n'pasted from the equivalent TreePanel method - we should make this an abstract function of all jalview analysis windows\r
-    if (seqstrings == null)\r
-    {\r
-      jalview.bin.Cache.log.info("Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action.");\r
-      return;\r
-    }\r
-    // decide if av alignment is sufficiently different to original data to warrant a new window to be created\r
-    // create new alignmnt window with hidden regions (unhiding hidden regions yields unaligned seqs)\r
-    // or create a selection box around columns in alignment view\r
-    // test Alignment(SeqCigar[])\r
-    Object[] alAndColsel = seqstrings.getAlignmentAndColumnSelection(av.\r
-        getGapCharacter());\r
-\r
-    if (alAndColsel != null && alAndColsel[0] != null)\r
-    {\r
-      // AlignmentOrder origorder = new AlignmentOrder(alAndColsel[0]);\r
-\r
-      Alignment al = new Alignment( (SequenceI[]) alAndColsel[0]);\r
-      Alignment dataset = av.getAlignment().getDataset();\r
-      if (dataset != null)\r
-      {\r
-        al.setDataset(dataset);\r
-      }\r
-\r
-      if (true)\r
-      {\r
-        // make a new frame!\r
-        AlignFrame af = new AlignFrame(al, (ColumnSelection) alAndColsel[1],\r
-                                       AlignFrame.DEFAULT_WIDTH,\r
-                                       AlignFrame.DEFAULT_HEIGHT\r
-            );\r
-\r
-        //>>>This is a fix for the moment, until a better solution is found!!<<<\r
-        // af.getFeatureRenderer().transferSettings(alignFrame.getFeatureRenderer());\r
-\r
-        //           af.addSortByOrderMenuItem(ServiceName + " Ordering",\r
-        //                                     msaorder);\r
-\r
-        Desktop.addInternalFrame(af, "Original Data for " + this.title,\r
-                                 AlignFrame.DEFAULT_WIDTH,\r
-                                 AlignFrame.DEFAULT_HEIGHT);\r
-      }\r
-    }\r
-    /*      CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
-           for (int i = 0; i < seqs.length; i++)\r
-           {\r
-             cap.appendText(new jalview.util.Format("%-" + 15 + "s").form(\r
-      seqs[i].getName()));\r
-             cap.appendText(" " + seqstrings[i] + "\n");\r
-\r
-           }\r
-\r
-           Desktop.addInternalFrame(cap, "Original Data",\r
-               400, 400);\r
-     */\r
-  }\r
-\r
-  class PCAPrinter\r
-      extends Thread implements Printable\r
-  {\r
-    public void run()\r
-    {\r
-      PrinterJob printJob = PrinterJob.getPrinterJob();\r
-      PageFormat pf = printJob.pageDialog(printJob.defaultPage());\r
-\r
-      printJob.setPrintable(this, pf);\r
-\r
-      if (printJob.printDialog())\r
-      {\r
-        try\r
-        {\r
-          printJob.print();\r
-        }\r
-        catch (Exception PrintException)\r
-        {\r
-          PrintException.printStackTrace();\r
-        }\r
-      }\r
-    }\r
-\r
-    public int print(Graphics pg, PageFormat pf, int pi)\r
-        throws PrinterException\r
-    {\r
-      pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());\r
-\r
-      rc.drawBackground(pg, rc.bgColour);\r
-      rc.drawScene(pg);\r
-      if (rc.drawAxes == true)\r
-      {\r
-        rc.drawAxes(pg);\r
-      }\r
-\r
-      if (pi == 0)\r
-      {\r
-        return Printable.PAGE_EXISTS;\r
-      }\r
-      else\r
-      {\r
-        return Printable.NO_SUCH_PAGE;\r
-      }\r
-    }\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param e DOCUMENT ME!\r
-   */\r
-  public void eps_actionPerformed(ActionEvent e)\r
-  {\r
-    makePCAImage(jalview.util.ImageMaker.EPS);\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param e DOCUMENT ME!\r
-   */\r
-  public void png_actionPerformed(ActionEvent e)\r
-  {\r
-    makePCAImage(jalview.util.ImageMaker.PNG);\r
-  }\r
-\r
-  void makePCAImage(int type)\r
-  {\r
-    int width = rc.getWidth();\r
-    int height = rc.getHeight();\r
-\r
-    jalview.util.ImageMaker im;\r
-\r
-    if (type == jalview.util.ImageMaker.PNG)\r
-    {\r
-      im = new jalview.util.ImageMaker(this,\r
-                                       jalview.util.ImageMaker.PNG,\r
-                                       "Make PNG image from PCA",\r
-                                       width, height,\r
-                                       null, null);\r
-    }\r
-    else\r
-    {\r
-      im = new jalview.util.ImageMaker(this,\r
-                                       jalview.util.ImageMaker.EPS,\r
-                                       "Make EPS file from PCA",\r
-                                       width, height,\r
-                                       null, this.getTitle());\r
-    }\r
-\r
-    if (im.getGraphics() != null)\r
-    {\r
-      rc.drawBackground(im.getGraphics(), Color.black);\r
-      rc.drawScene(im.getGraphics());\r
-      if (rc.drawAxes == true)\r
-      {\r
-        rc.drawAxes(im.getGraphics());\r
-      }\r
-      im.writeImage();\r
-    }\r
-  }\r
-\r
-  public void viewMenu_menuSelected()\r
-  {\r
-    buildAssociatedViewMenu();\r
-  }\r
-\r
-  void buildAssociatedViewMenu()\r
-  {\r
-    AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(av.\r
-        getSequenceSetId());\r
-    if (aps.length == 1 && rc.av == aps[0].av)\r
-    {\r
-      associateViewsMenu.setVisible(false);\r
-      return;\r
-    }\r
-\r
-    associateViewsMenu.setVisible(true);\r
-\r
-    if ( (viewMenu.getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem))\r
-    {\r
-      viewMenu.insertSeparator(viewMenu.getItemCount() - 1);\r
-    }\r
-\r
-    associateViewsMenu.removeAll();\r
-\r
-    JRadioButtonMenuItem item;\r
-    ButtonGroup buttonGroup = new ButtonGroup();\r
-    int i, iSize = aps.length;\r
-    final PCAPanel thisPCAPanel = this;\r
-    for (i = 0; i < iSize; i++)\r
-    {\r
-      final AlignmentPanel ap = aps[i];\r
-      item = new JRadioButtonMenuItem(ap.av.viewName, ap.av == rc.av);\r
-      buttonGroup.add(item);\r
-      item.addActionListener(new ActionListener()\r
-      {\r
-        public void actionPerformed(ActionEvent evt)\r
-        {\r
-          rc.applyToAllViews = false;\r
-          rc.av = ap.av;\r
-          rc.ap = ap;\r
-          PaintRefresher.Register(thisPCAPanel, ap.av.getSequenceSetId());\r
-        }\r
-      });\r
-\r
-      associateViewsMenu.add(item);\r
-    }\r
-\r
-    final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem("All Views");\r
-\r
-    buttonGroup.add(itemf);\r
-\r
-    itemf.setSelected(rc.applyToAllViews);\r
-    itemf.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent evt)\r
-      {\r
-        rc.applyToAllViews = itemf.isSelected();\r
-      }\r
-    });\r
-    associateViewsMenu.add(itemf);\r
-\r
-  }\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 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
+ */
+package jalview.gui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import javax.swing.*;
+
+import jalview.analysis.*;
+import jalview.datamodel.*;
+import jalview.jbgui.*;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+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!
+   */
+  public PCAPanel(AlignmentPanel ap)
+  {
+    this.av = ap.av;
+    this.ap = ap;
+
+    boolean sameLength = true;
+
+    seqstrings = av.getAlignmentView(av.getSelectionGroup() != null);
+    if (av.getSelectionGroup() == null)
+    {
+      seqs = av.alignment.getSequencesArray();
+    }
+    else
+    {
+      seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
+    }
+    SeqCigar sq[] = seqstrings.getSequences();
+    int length = sq[0].getWidth();
+
+    for (int i = 0; i < seqs.length; i++)
+    {
+      if (sq[i].getWidth() != length)
+      {
+        sameLength = false;
+        break;
+      }
+    }
+
+    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);
+
+      return;
+    }
+
+    Desktop.addInternalFrame(this, "Principal component analysis",
+                             400, 400);
+
+    PaintRefresher.Register(this, av.getSequenceSetId());
+
+    rc = new RotatableCanvas(ap);
+    this.getContentPane().add(rc, BorderLayout.CENTER);
+    Thread worker = new Thread(this);
+    worker.start();
+  }
+
+  public void bgcolour_actionPerformed(ActionEvent e)
+  {
+    Color col = JColorChooser.showDialog(this, "Select Background Colour",
+                                         rc.bgColour);
+
+    if (col != null)
+    {
+      rc.bgColour = col;
+    }
+    rc.repaint();
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  public void run()
+  {
+    try
+    {
+      pca = new PCA(seqstrings.getSequenceStrings(' '));
+      pca.run();
+
+      // Now find the component coordinates
+      int ii = 0;
+
+      while ( (ii < seqs.length) && (seqs[ii] != null))
+      {
+        ii++;
+      }
+
+      double[][] comps = new double[ii][ii];
+
+      for (int i = 0; i < ii; i++)
+      {
+        if (pca.getEigenvalue(i) > 1e-4)
+        {
+          comps[i] = pca.component(i);
+        }
+      }
+
+      //////////////////
+      xCombobox.setSelectedIndex(0);
+      yCombobox.setSelectedIndex(1);
+      zCombobox.setSelectedIndex(2);
+
+      top = pca.getM().rows - 1;
+
+      Vector points = new Vector();
+      float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
+
+      for (int i = 0; i < pca.getM().rows; i++)
+      {
+        SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
+        points.addElement(sp);
+      }
+
+      rc.setPoints(points, pca.getM().rows);
+      rc.repaint();
+
+      addKeyListener(rc);
+
+    }
+    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();
+
+    }
+
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  void doDimensionChange()
+  {
+    if (top == 0)
+    {
+      return;
+    }
+
+    int dim1 = top - xCombobox.getSelectedIndex();
+    int dim2 = top - yCombobox.getSelectedIndex();
+    int dim3 = top - zCombobox.getSelectedIndex();
+
+    float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);
+
+    for (int i = 0; i < pca.getM().rows; i++)
+    {
+      ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];
+    }
+
+    rc.img = null;
+    rc.rotmat.setIdentity();
+    rc.initAxes();
+    rc.paint(rc.getGraphics());
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param e DOCUMENT ME!
+   */
+  protected void xCombobox_actionPerformed(ActionEvent e)
+  {
+    doDimensionChange();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param e DOCUMENT ME!
+   */
+  protected void yCombobox_actionPerformed(ActionEvent e)
+  {
+    doDimensionChange();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param e DOCUMENT ME!
+   */
+  protected void zCombobox_actionPerformed(ActionEvent e)
+  {
+    doDimensionChange();
+  }
+
+  public void outputValues_actionPerformed(ActionEvent e)
+  {
+    CutAndPasteTransfer cap = new CutAndPasteTransfer();
+    Desktop.addInternalFrame(cap, "PCA details", 500,
+                             500);
+
+    cap.setText(pca.getDetails());
+  }
+
+  public void showLabels_actionPerformed(ActionEvent e)
+  {
+    rc.showLabels(showLabels.getState());
+  }
+
+  public void print_actionPerformed(ActionEvent e)
+  {
+    PCAPrinter printer = new PCAPrinter();
+    printer.start();
+  }
+
+  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
+    if (seqstrings == null)
+    {
+      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)
+    // or create a selection box around columns in alignment view
+    // test Alignment(SeqCigar[])
+    char gc = '-';
+    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) {};
+    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.getAlignment().getDataset();
+      if (dataset != null)
+      {
+        al.setDataset(dataset);
+      }
+
+      if (true)
+      {
+        // make a new frame!
+        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!!<<<
+        // af.getFeatureRenderer().transferSettings(alignFrame.getFeatureRenderer());
+
+        //           af.addSortByOrderMenuItem(ServiceName + " Ordering",
+        //                                     msaorder);
+
+        Desktop.addInternalFrame(af, "Original Data for " + this.title,
+                                 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);
+     */
+  }
+
+  class PCAPrinter
+      extends Thread implements Printable
+  {
+    public void run()
+    {
+      PrinterJob printJob = PrinterJob.getPrinterJob();
+      PageFormat pf = printJob.pageDialog(printJob.defaultPage());
+
+      printJob.setPrintable(this, pf);
+
+      if (printJob.printDialog())
+      {
+        try
+        {
+          printJob.print();
+        }
+        catch (Exception PrintException)
+        {
+          PrintException.printStackTrace();
+        }
+      }
+    }
+
+    public int print(Graphics pg, PageFormat pf, int pi)
+        throws PrinterException
+    {
+      pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
+
+      rc.drawBackground(pg, rc.bgColour);
+      rc.drawScene(pg);
+      if (rc.drawAxes == true)
+      {
+        rc.drawAxes(pg);
+      }
+
+      if (pi == 0)
+      {
+        return Printable.PAGE_EXISTS;
+      }
+      else
+      {
+        return Printable.NO_SUCH_PAGE;
+      }
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param e DOCUMENT ME!
+   */
+  public void eps_actionPerformed(ActionEvent e)
+  {
+    makePCAImage(jalview.util.ImageMaker.EPS);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param e DOCUMENT ME!
+   */
+  public void png_actionPerformed(ActionEvent e)
+  {
+    makePCAImage(jalview.util.ImageMaker.PNG);
+  }
+
+  void makePCAImage(int type)
+  {
+    int width = rc.getWidth();
+    int height = rc.getHeight();
+
+    jalview.util.ImageMaker im;
+
+    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);
+    }
+    else
+    {
+      im = new jalview.util.ImageMaker(this,
+                                       jalview.util.ImageMaker.EPS,
+                                       "Make EPS file from PCA",
+                                       width, height,
+                                       null, this.getTitle());
+    }
+
+    if (im.getGraphics() != null)
+    {
+      rc.drawBackground(im.getGraphics(), Color.black);
+      rc.drawScene(im.getGraphics());
+      if (rc.drawAxes == true)
+      {
+        rc.drawAxes(im.getGraphics());
+      }
+      im.writeImage();
+    }
+  }
+
+  public void viewMenu_menuSelected()
+  {
+    buildAssociatedViewMenu();
+  }
+
+  void buildAssociatedViewMenu()
+  {
+    AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(av.
+        getSequenceSetId());
+    if (aps.length == 1 && rc.av == aps[0].av)
+    {
+      associateViewsMenu.setVisible(false);
+      return;
+    }
+
+    associateViewsMenu.setVisible(true);
+
+    if ( (viewMenu.getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem))
+    {
+      viewMenu.insertSeparator(viewMenu.getItemCount() - 1);
+    }
+
+    associateViewsMenu.removeAll();
+
+    JRadioButtonMenuItem item;
+    ButtonGroup buttonGroup = new ButtonGroup();
+    int i, iSize = aps.length;
+    final PCAPanel thisPCAPanel = this;
+    for (i = 0; i < iSize; i++)
+    {
+      final AlignmentPanel ap = aps[i];
+      item = new JRadioButtonMenuItem(ap.av.viewName, ap.av == rc.av);
+      buttonGroup.add(item);
+      item.addActionListener(new ActionListener()
+      {
+        public void actionPerformed(ActionEvent evt)
+        {
+          rc.applyToAllViews = false;
+          rc.av = ap.av;
+          rc.ap = ap;
+          PaintRefresher.Register(thisPCAPanel, ap.av.getSequenceSetId());
+        }
+      });
+
+      associateViewsMenu.add(item);
+    }
+
+    final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem("All Views");
+
+    buttonGroup.add(itemf);
+
+    itemf.setSelected(rc.applyToAllViews);
+    itemf.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent evt)
+      {
+        rc.applyToAllViews = itemf.isSelected();
+      }
+    });
+    associateViewsMenu.add(itemf);
+
+  }
+
+}
index 72bdbf1..762ad58 100755 (executable)
@@ -410,8 +410,14 @@ public class TreePanel
     // 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[])
-    Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(av.
-        getGapCharacter());
+    char gc = '-';
+    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) {};
+    Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(gc);
 
     if (alAndColsel != null && alAndColsel[0] != null)
     {