JAL-2295 handle no progress bar message properly
[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       @Override
76       public void run()
77       {
78         cvf.updateTitleAndMenus();
79         cvf.revalidate();
80       }
81     });
82   }
83
84   @Override
85   public void updateColours(Object source)
86   {
87     AlignmentPanel ap = (AlignmentPanel) source;
88     // ignore events from panels not used to colour this view
89     if (!cvf.isUsedforcolourby(ap))
90     {
91       return;
92     }
93     if (!isLoadingFromArchive())
94     {
95       colourBySequence(ap.av.isShowSequenceFeatures(), ap);
96     }
97   }
98
99   @Override
100   public void releaseReferences(Object svl)
101   {
102   }
103
104   @Override
105   protected void releaseUIResources()
106   {
107   }
108
109   @Override
110   public void refreshPdbEntries()
111   {
112   }
113
114   /**
115    * Send an asynchronous command to Chimera, in a new thread, optionally with
116    * an 'in progress' message in a progress bar somewhere
117    */
118   @Override
119   protected void sendAsynchronousCommand(final String command,
120           final String progressMsg)
121   {
122     Thread thread = new Thread(new Runnable()
123     {
124
125       @Override
126       public void run()
127       {
128         long handle = 0;
129         if (progressMsg != null)
130         {
131           handle = cvf.startProgressBar(progressMsg);
132         }
133         try
134         {
135           sendChimeraCommand(command, false);
136         } finally
137         {
138           if (progressMsg != null)
139           {
140             cvf.stopProgressBar(null, handle);
141           }
142         }
143       }
144     });
145     thread.start();
146
147   }
148 }