Bugfix to enable accurate chain extraction/association with models loaded in Chimera...
[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.datamodel.PDBEntry;
25 import jalview.datamodel.SequenceI;
26 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
27 import jalview.structure.StructureSelectionManager;
28
29 public class JalviewChimeraBindingModel extends JalviewChimeraBinding
30 {
31   private ChimeraViewFrame cvf;
32
33   private FeatureRenderer fr = null;
34
35
36   public JalviewChimeraBindingModel(ChimeraViewFrame chimeraViewFrame,
37           StructureSelectionManager ssm, PDBEntry[] pdbentry,
38           SequenceI[][] sequenceIs, String protocol)
39   {
40     super(ssm, pdbentry, sequenceIs, protocol);
41     cvf = chimeraViewFrame;
42   }
43
44   @Override
45   public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
46   {
47     AlignmentPanel ap = (alignment == null) ? cvf.getAlignmentPanel()
48             : (AlignmentPanel) alignment;
49     if (ap.av.isShowSequenceFeatures())
50     {
51       if (fr == null)
52       {
53         fr = (jalview.gui.FeatureRenderer) ap.cloneFeatureRenderer();
54       }
55       else
56       {
57         ap.updateFeatureRenderer(fr);
58       }
59     }
60
61     return fr;
62   }
63
64   @Override
65   public jalview.api.SequenceRenderer getSequenceRenderer(
66           AlignmentViewPanel alignment)
67   {
68     return new SequenceRenderer(((AlignmentPanel) alignment).av);
69   }
70
71   @Override
72   public void refreshGUI()
73   {
74     javax.swing.SwingUtilities.invokeLater(new Runnable()
75     {
76       @Override
77       public void run()
78       {
79         cvf.updateTitleAndMenus();
80         cvf.revalidate();
81       }
82     });
83   }
84
85   @Override
86   public void updateColours(Object source)
87   {
88     AlignmentPanel ap = (AlignmentPanel) source;
89     // ignore events from panels not used to colour this view
90     if (!cvf.isUsedforcolourby(ap))
91     {
92       return;
93     }
94     if (!isLoadingFromArchive())
95     {
96       colourBySequence(ap.av.isShowSequenceFeatures(), ap);
97     }
98   }
99
100   @Override
101   public void releaseReferences(Object svl)
102   {
103   }
104
105   @Override
106   protected void releaseUIResources()
107   {
108   }
109
110   @Override
111   public void refreshPdbEntries()
112   {
113   }
114
115   /**
116    * Send an asynchronous command to Chimera, in a new thread, optionally with
117    * an 'in progress' message in a progress bar somewhere
118    */
119   @Override
120   protected void sendAsynchronousCommand(final String command,
121           final String progressMsg)
122   {
123     Thread thread = new Thread(new Runnable()
124     {
125
126       @Override
127       public void run()
128       {
129         long stm = cvf.startProgressBar(progressMsg);
130         try
131         {
132           sendChimeraCommand(command, false);
133         } finally
134         {
135           cvf.stopProgressBar(null, stm);
136         }
137       }
138     });
139     thread.start();
140
141   }
142
143
144 }