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