JAL-2422 pull up refactoring in preparation for ChimeraX subclasses
[jalview.git] / src / jalview / gui / JalviewChimeraBindingModel.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.api.AlignmentViewPanel;
24 import jalview.api.structures.JalviewStructureDisplayI;
25 import jalview.datamodel.PDBEntry;
26 import jalview.datamodel.SequenceI;
27 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
28 import jalview.io.DataSourceType;
29 import jalview.structure.StructureSelectionManager;
30
31 import javax.swing.JComponent;
32 import javax.swing.SwingUtilities;
33
34 public class JalviewChimeraBindingModel extends JalviewChimeraBinding
35 {
36   public JalviewChimeraBindingModel(ChimeraViewFrame chimeraViewFrame,
37           StructureSelectionManager ssm, PDBEntry[] pdbentry,
38           SequenceI[][] sequenceIs, DataSourceType protocol)
39   {
40     super(ssm, pdbentry, sequenceIs, protocol);
41     setViewer(chimeraViewFrame);
42   }
43
44   @Override
45   public jalview.api.SequenceRenderer getSequenceRenderer(
46           AlignmentViewPanel alignment)
47   {
48     return new SequenceRenderer(((AlignmentPanel) alignment).av);
49   }
50
51   @Override
52   public void refreshGUI()
53   {
54     javax.swing.SwingUtilities.invokeLater(new Runnable()
55     {
56       @Override
57       public void run()
58       {
59         JalviewStructureDisplayI theViewer = getViewer();
60         theViewer.updateTitleAndMenus();
61         ((JComponent) theViewer).revalidate();
62       }
63     });
64   }
65
66   @Override
67   public void updateColours(Object source)
68   {
69     AlignmentViewPanel ap = (AlignmentViewPanel) source;
70     // ignore events from panels not used to colour this view
71     if (!getViewer().isUsedForColourBy(ap))
72     {
73       return;
74     }
75     if (!isLoadingFromArchive())
76     {
77       colourBySequence(ap);
78     }
79   }
80
81   @Override
82   public void releaseReferences(Object svl)
83   {
84   }
85
86   @Override
87   protected void releaseUIResources()
88   {
89   }
90
91   @Override
92   public void refreshPdbEntries()
93   {
94   }
95
96   /**
97    * Send an asynchronous command to Chimera, in a new thread, optionally with
98    * an 'in progress' message in a progress bar somewhere
99    */
100   @Override
101   protected void sendAsynchronousCommand(final String command,
102           final String progressMsg)
103   {
104     final long handle = progressMsg == null ? 0
105             : getViewer().startProgressBar(progressMsg);
106     SwingUtilities.invokeLater(new Runnable()
107     {
108       @Override
109       public void run()
110       {
111         try
112         {
113           sendChimeraCommand(command, false);
114         } finally
115         {
116           if (progressMsg != null)
117           {
118             getViewer().stopProgressBar(null, handle);
119           }
120         }
121       }
122     });
123   }
124 }