JAL-2422 pull-up refactoring of structure commands (continued)
[jalview.git] / src / jalview / gui / JalviewChimeraBindingModel.java
index 78ab68d..f9071ef 100644 (file)
 package jalview.gui;
 
 import jalview.api.AlignmentViewPanel;
+import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
+import jalview.io.DataSourceType;
 import jalview.structure.StructureSelectionManager;
 
+import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+
 public class JalviewChimeraBindingModel extends JalviewChimeraBinding
 {
-  private ChimeraViewFrame cvf;
-
-  private FeatureRenderer fr = null;
-
-
   public JalviewChimeraBindingModel(ChimeraViewFrame chimeraViewFrame,
           StructureSelectionManager ssm, PDBEntry[] pdbentry,
-          SequenceI[][] sequenceIs, String protocol)
+          SequenceI[][] sequenceIs, DataSourceType protocol)
   {
     super(ssm, pdbentry, sequenceIs, protocol);
-    cvf = chimeraViewFrame;
-  }
-
-  @Override
-  public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
-  {
-    AlignmentPanel ap = (alignment == null) ? cvf.getAlignmentPanel()
-            : (AlignmentPanel) alignment;
-    if (ap.av.isShowSequenceFeatures())
-    {
-      if (fr == null)
-      {
-        fr = (jalview.gui.FeatureRenderer) ap.cloneFeatureRenderer();
-      }
-      else
-      {
-        ap.updateFeatureRenderer(fr);
-      }
-    }
-
-    return fr;
+    setViewer(chimeraViewFrame);
   }
 
   @Override
@@ -76,8 +56,9 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
       @Override
       public void run()
       {
-        cvf.updateTitleAndMenus();
-        cvf.revalidate();
+        JalviewStructureDisplayI theViewer = getViewer();
+        theViewer.updateTitleAndMenus();
+        ((JComponent) theViewer).revalidate();
       }
     });
   }
@@ -85,15 +66,15 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
   @Override
   public void updateColours(Object source)
   {
-    AlignmentPanel ap = (AlignmentPanel) source;
+    AlignmentViewPanel ap = (AlignmentViewPanel) source;
     // ignore events from panels not used to colour this view
-    if (!cvf.isUsedforcolourby(ap))
+    if (!getViewer().isUsedForColourBy(ap))
     {
       return;
     }
     if (!isLoadingFromArchive())
     {
-      colourBySequence(ap.av.isShowSequenceFeatures(), ap);
+      colourBySequence(ap);
     }
   }
 
@@ -120,25 +101,25 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
   protected void sendAsynchronousCommand(final String command,
           final String progressMsg)
   {
-    Thread thread = new Thread(new Runnable()
+    final JalviewStructureDisplayI theViewer = getViewer();
+    final long handle = progressMsg == null ? 0
+            : theViewer.startProgressBar(progressMsg);
+    SwingUtilities.invokeLater(new Runnable()
     {
-
       @Override
       public void run()
       {
-        long stm = cvf.startProgressBar(progressMsg);
         try
         {
-          sendChimeraCommand(command, false);
+          executeCommand(command, false);
         } finally
         {
-          cvf.stopProgressBar(null, stm);
+          if (progressMsg != null)
+          {
+            theViewer.stopProgressBar(null, handle);
+          }
         }
       }
     });
-    thread.start();
-
   }
-
-
 }