3 import java.awt.Component;
4 import java.util.ArrayList;
6 import java.util.Vector;
8 import javax.swing.JMenuItem;
10 import jalview.gui.StructureViewer.ViewerType;
11 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
12 import jalview.jbgui.GStructureViewer;
15 * Base class with common functionality for JMol, Chimera or other structure
21 public abstract class StructureViewerBase extends GStructureViewer
22 implements Runnable, ViewSetProvider
26 * list of sequenceSet ids associated with the view
28 protected List<String> _aps = new ArrayList<String>();
30 * list of alignment panels to use for superposition
32 protected Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
34 * list of alignment panels that are used for colouring structures by aligned
37 protected Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
38 private String viewId = null;
39 private AlignmentPanel ap;
44 * @return true if this Jmol instance is linked with the given alignPanel
46 public boolean isLinkedWith(AlignmentPanel ap2)
48 return _aps.contains(ap2.av.getSequenceSetId());
51 public boolean isUsedforaligment(AlignmentPanel ap2)
54 return (_alignwith != null) && _alignwith.contains(ap2);
57 public boolean isUsedforcolourby(AlignmentPanel ap2)
59 return (_colourwith != null) && _colourwith.contains(ap2);
64 * @return TRUE if the view is NOT being coloured by the alignment colours.
66 public boolean isColouredByViewer()
68 return !getBinding().isColourBySequence();
71 public String getViewId()
75 viewId = System.currentTimeMillis() + "." + this.hashCode();
80 protected void setViewId(String viewId)
85 public abstract String getStateInfo();
87 protected void buildActionMenu()
89 if (_alignwith == null)
91 _alignwith = new Vector<AlignmentPanel>();
93 if (_alignwith.size() == 0 && ap != null)
98 for (Component c : viewerActionMenu.getMenuComponents())
100 if (c != alignStructs)
102 viewerActionMenu.remove((JMenuItem) c);
107 public AlignmentPanel getAlignmentPanel()
112 protected void setAlignmentPanel(AlignmentPanel alp)
117 public AlignmentPanel[] getAllAlignmentPanels()
119 AlignmentPanel[] t, list = new AlignmentPanel[0];
120 for (String setid : _aps)
122 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
125 t = new AlignmentPanel[list.length + panels.length];
126 System.arraycopy(list, 0, t, 0, list.length);
127 System.arraycopy(panels, 0, t, list.length, panels.length);
136 * set the primary alignmentPanel reference and add another alignPanel to the
137 * list of ones to use for colouring and aligning
141 public void addAlignmentPanel(AlignmentPanel nap)
143 if (getAlignmentPanel() == null)
145 setAlignmentPanel(nap);
147 if (!_aps.contains(nap.av.getSequenceSetId()))
149 _aps.add(nap.av.getSequenceSetId());
154 * remove any references held to the given alignment panel
158 public void removeAlignmentPanel(AlignmentPanel nap)
162 _alignwith.remove(nap);
163 _colourwith.remove(nap);
164 if (getAlignmentPanel() == nap)
166 setAlignmentPanel(null);
167 for (AlignmentPanel aps : getAllAlignmentPanels())
171 setAlignmentPanel(aps);
176 } catch (Exception ex)
179 if (getAlignmentPanel() != null)
185 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
187 addAlignmentPanel(nap);
188 if (!_alignwith.contains(nap))
194 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
196 if (_alignwith.contains(nap))
198 _alignwith.remove(nap);
202 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
204 useAlignmentPanelForColourbyseq(nap);
205 getBinding().setColourBySequence(enableColourBySeq);
206 seqColour.setSelected(enableColourBySeq);
207 viewerColour.setSelected(!enableColourBySeq);
210 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
212 addAlignmentPanel(nap);
213 if (!_colourwith.contains(nap))
215 _colourwith.add(nap);
219 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
221 if (_colourwith.contains(nap))
223 _colourwith.remove(nap);
227 public abstract ViewerType getViewerType();