JAL-1588 refactoring to StructureViewerBase and related
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index 567a14c..bc985df 100644 (file)
@@ -27,11 +27,9 @@ import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
-import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
-import jalview.jbgui.GStructureViewer;
 import jalview.schemes.BuriedColourScheme;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.HelixColourScheme;
@@ -46,7 +44,6 @@ import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.dbsources.Pdb;
 
-import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
@@ -78,8 +75,7 @@ import javax.swing.event.MenuListener;
  * @author jprocter
  *
  */
-public class ChimeraViewFrame extends GStructureViewer implements Runnable,
-        ViewSetProvider
+public class ChimeraViewFrame extends StructureViewerBase
 {
   private JalviewChimeraBinding jmb;
 
@@ -87,8 +83,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
 
   private boolean alignAddedStructures = false;
 
-  AlignmentPanel ap;
-
   /*
    * state flag for PDB retrieval thread
    */
@@ -252,7 +246,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
                 topView.addAlignmentPanel(ap);
                 // add it to the set used for colouring
                 topView.useAlignmentPanelForColourbyseq(ap);
-                topView.buildChimeraActionMenu();
+                topView.buildActionMenu();
                 ap.getStructureSelectionManager()
                         .sequenceColoursChanged(ap);
                 break;
@@ -368,9 +362,9 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
    */
   public void addAlignmentPanel(AlignmentPanel nap)
   {
-    if (ap == null)
+    if (getAlignmentPanel() == null)
     {
-      ap = nap;
+      setAlignmentPanel(nap);
     }
     if (!_aps.contains(nap.av.getSequenceSetId()))
     {
@@ -389,14 +383,14 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     {
       _alignwith.remove(nap);
       _colourwith.remove(nap);
-      if (ap == nap)
+      if (getAlignmentPanel() == nap)
       {
-        ap = null;
+        setAlignmentPanel(null);
         for (AlignmentPanel aps : getAllAlignmentPanels())
         {
           if (aps != nap)
           {
-            ap = aps;
+            setAlignmentPanel(aps);
             break;
           }
         }
@@ -404,9 +398,9 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     } catch (Exception ex)
     {
     }
-    if (ap != null)
+    if (getAlignmentPanel() != null)
     {
-      buildChimeraActionMenu();
+      buildActionMenu();
     }
   }
 
@@ -431,7 +425,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
           boolean enableColourBySeq)
   {
     useAlignmentPanelForColourbyseq(nap);
-    jmb.setColourBySequence(enableColourBySeq);
+    getBinding().setColourBySequence(enableColourBySeq);
     seqColour.setSelected(enableColourBySeq);
     viewerColour.setSelected(!enableColourBySeq);
   }
@@ -518,7 +512,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     {
       if (frame instanceof ChimeraViewFrame)
       {
-        if (((ChimeraViewFrame) frame).isLinkedWith(apanel))
+        if (((StructureViewerBase) frame).isLinkedWith(apanel))
         {
           result.add((ChimeraViewFrame) frame);
         }
@@ -623,7 +617,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
               JOptionPane.YES_NO_OPTION);
       jmb.closeViewer(confirm == JOptionPane.YES_OPTION);
     }
-    ap = null;
+    setAlignmentPanel(null);
     _aps.clear();
     _alignwith.clear();
     _colourwith.clear();
@@ -959,10 +953,10 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     {
       if (!jmb.isLoadingFromArchive())
       {
-        if (_colourwith.size() == 0 && ap != null)
+        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
         {
           // Make the currently displayed alignment panel the associated view
-          _colourwith.add(ap.alignFrame.alignPanel);
+          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
         }
       }
       // Set the colour using the current view for the associated alignframe
@@ -1093,26 +1087,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     }
   }
 
-  protected void buildChimeraActionMenu()
-  {
-    if (_alignwith == null)
-    {
-      _alignwith = new Vector<AlignmentPanel>();
-    }
-    if (_alignwith.size() == 0 && ap != null)
-    {
-      _alignwith.add(ap);
-    }
-    ;
-    for (Component c : viewerActionMenu.getMenuComponents())
-    {
-      if (c != alignStructs)
-      {
-        viewerActionMenu.remove((JMenuItem) c);
-      }
-    }
-  }
-
   /*
    * (non-Javadoc)
    * 
@@ -1128,14 +1102,14 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
 
   private void alignStructs_withAllAlignPanels()
   {
-    if (ap == null)
+    if (getAlignmentPanel() == null)
     {
       return;
     }
     ;
     if (_alignwith.size() == 0)
     {
-      _alignwith.add(ap);
+      _alignwith.add(getAlignmentPanel());
     }
     ;
     try
@@ -1187,7 +1161,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
         return ap;
       }
     }
-    return ap;
+    return getAlignmentPanel();
   }
 
   @Override