3 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
4 import jalview.jbgui.GStructureViewer;
6 import java.awt.Component;
7 import java.util.ArrayList;
9 import java.util.Vector;
11 import javax.swing.JMenuItem;
14 * Base class with common functionality for JMol, Chimera or other structure
20 public abstract class StructureViewerBase extends GStructureViewer
21 implements Runnable, ViewSetProvider
25 * list of sequenceSet ids associated with the view
27 protected List<String> _aps = new ArrayList<String>();
29 * list of alignment panels to use for superposition
31 protected Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
33 * list of alignment panels that are used for colouring structures by aligned
36 protected Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
37 private String viewId = null;
38 private AlignmentPanel ap;
43 * @return true if this Jmol instance is linked with the given alignPanel
45 public boolean isLinkedWith(AlignmentPanel ap2)
47 return _aps.contains(ap2.av.getSequenceSetId());
50 public boolean isUsedforaligment(AlignmentPanel ap2)
53 return (_alignwith != null) && _alignwith.contains(ap2);
56 public boolean isUsedforcolourby(AlignmentPanel ap2)
58 return (_colourwith != null) && _colourwith.contains(ap2);
63 * @return TRUE if the view is NOT being coloured by the alignment colours.
65 public boolean isColouredByViewer()
67 return !getBinding().isColourBySequence();
70 public String getViewId()
74 viewId = System.currentTimeMillis() + "." + this.hashCode();
79 protected void setViewId(String viewId)
84 public abstract String getStateInfo();
86 protected void buildActionMenu()
88 if (_alignwith == null)
90 _alignwith = new Vector<AlignmentPanel>();
92 if (_alignwith.size() == 0 && ap != null)
97 for (Component c : viewerActionMenu.getMenuComponents())
99 if (c != alignStructs)
101 viewerActionMenu.remove((JMenuItem) c);
106 public AlignmentPanel getAlignmentPanel()
111 protected void setAlignmentPanel(AlignmentPanel alp)
116 public AlignmentPanel[] getAllAlignmentPanels()
118 AlignmentPanel[] t, list = new AlignmentPanel[0];
119 for (String setid : _aps)
121 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
124 t = new AlignmentPanel[list.length + panels.length];
125 System.arraycopy(list, 0, t, 0, list.length);
126 System.arraycopy(panels, 0, t, list.length, panels.length);
135 * set the primary alignmentPanel reference and add another alignPanel to the
136 * list of ones to use for colouring and aligning
140 public void addAlignmentPanel(AlignmentPanel nap)
142 if (getAlignmentPanel() == null)
144 setAlignmentPanel(nap);
146 if (!_aps.contains(nap.av.getSequenceSetId()))
148 _aps.add(nap.av.getSequenceSetId());
153 * remove any references held to the given alignment panel
157 public void removeAlignmentPanel(AlignmentPanel nap)
161 _alignwith.remove(nap);
162 _colourwith.remove(nap);
163 if (getAlignmentPanel() == nap)
165 setAlignmentPanel(null);
166 for (AlignmentPanel aps : getAllAlignmentPanels())
170 setAlignmentPanel(aps);
175 } catch (Exception ex)
178 if (getAlignmentPanel() != null)
184 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
186 addAlignmentPanel(nap);
187 if (!_alignwith.contains(nap))
193 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
195 if (_alignwith.contains(nap))
197 _alignwith.remove(nap);
201 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
203 useAlignmentPanelForColourbyseq(nap);
204 getBinding().setColourBySequence(enableColourBySeq);
205 seqColour.setSelected(enableColourBySeq);
206 viewerColour.setSelected(!enableColourBySeq);
209 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
211 addAlignmentPanel(nap);
212 if (!_colourwith.contains(nap))
214 _colourwith.add(nap);
218 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
220 if (_colourwith.contains(nap))
222 _colourwith.remove(nap);