JAL-1632 one PCA/Tree per panel, closed when panel is closed
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 12 Apr 2017 10:30:37 +0000 (11:30 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 12 Apr 2017 10:30:37 +0000 (11:30 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/CalculationChooser.java

index a69cd59..8fc106f 100644 (file)
@@ -372,7 +372,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        new CalculationChooser(AlignFrame.this);
+        openTreePcaDialog();
       }
     });
     buildColourMenu();
@@ -5641,6 +5641,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
     ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
   }
+
+  /**
+   * Open a dialog (if not already open) that allows the user to select and
+   * calculate PCA or Tree analysis
+   */
+  protected void openTreePcaDialog()
+  {
+    if (alignPanel.getCalculationDialog() == null)
+    {
+      new CalculationChooser(AlignFrame.this);
+    }
+  }
 }
 
 class PrintThread extends Thread
index 8ade5d6..ccb3464 100644 (file)
@@ -106,6 +106,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
   private PropertyChangeListener propertyChangeListener;
 
+  private CalculationChooser calculationDialog;
+
   /**
    * Creates a new AlignmentPanel object.
    * 
@@ -1647,6 +1649,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
     PaintRefresher.RemoveComponent(getIdPanel().getIdCanvas());
     PaintRefresher.RemoveComponent(this);
 
+    closeChildFrames();
+
     /*
      * try to ensure references are nulled
      */
@@ -1678,6 +1682,17 @@ public class AlignmentPanel extends GAlignmentPanel implements
   }
 
   /**
+   * Close any open dialogs that would be orphaned when this one is closed
+   */
+  protected void closeChildFrames()
+  {
+    if (calculationDialog != null)
+    {
+      calculationDialog.closeFrame();
+    }
+  }
+
+  /**
    * hides or shows dynamic annotation rows based on groups and av state flags
    */
   public void updateAnnotation()
@@ -1906,4 +1921,24 @@ public class AlignmentPanel extends GAlignmentPanel implements
       repaint();
     }
   }
+
+  /**
+   * Set the reference to the PCA/Tree chooser dialog for this panel. This
+   * reference should be nulled when the dialog is closed.
+   * 
+   * @param calculationChooser
+   */
+  public void setCalculationDialog(CalculationChooser calculationChooser)
+  {
+    calculationDialog = calculationChooser;
+  }
+
+  /**
+   * Returns the reference to the PCA/Tree chooser dialog for this panel (null
+   * if none is open)
+   */
+  public CalculationChooser getCalculationDialog()
+  {
+    return calculationDialog;
+  }
 }
index d3b7cfc..7b3bf22 100644 (file)
@@ -50,6 +50,8 @@ import javax.swing.JLabel;
 import javax.swing.JLayeredPane;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
 
 /**
  * A dialog where a user can choose and action Tree or PCA calculation options
@@ -99,6 +101,7 @@ public class CalculationChooser extends JPanel
   {
     this.af = alignFrame;
     init();
+    af.alignPanel.setCalculationDialog(this);
   }
 
   /**
@@ -221,10 +224,28 @@ public class CalculationChooser extends JPanel
 
     int width = 350;
     int height = includeParams ? 400 : 220;
+    String title = MessageManager.getString("label.choose_calculation");
+    if (af.getViewport().viewName != null)
+    {
+      title = title + " (" + af.getViewport().viewName + ")";
+    }
+
     Desktop.addInternalFrame(frame,
-            MessageManager.getString("label.choose_calculation"), width,
+            title, width,
             height, false);
 
+    /*
+     * null the AlignmentPanel's reference to the dialog when it is closed
+     */
+    frame.addInternalFrameListener(new InternalFrameAdapter()
+    {
+      @Override
+      public void internalFrameClosed(InternalFrameEvent evt)
+      {
+        af.alignPanel.setCalculationDialog(null);
+      };
+    });
+
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
   }