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