JAL-1588 refactoring to StructureViewerBase and related
[jalview.git] / src / jalview / gui / StructureViewerBase.java
1 package jalview.gui;
2
3 import java.awt.Component;
4 import java.util.ArrayList;
5 import java.util.List;
6 import java.util.Vector;
7
8 import javax.swing.JMenuItem;
9
10 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
11 import jalview.jbgui.GStructureViewer;
12
13 /**
14  * Base class with common functionality for JMol, Chimera or other structure
15  * viewers.
16  * 
17  * @author gmcarstairs
18  *
19  */
20 public abstract class StructureViewerBase extends GStructureViewer
21         implements Runnable, ViewSetProvider
22 {
23
24   /**
25    * list of sequenceSet ids associated with the view
26    */
27   protected List<String> _aps = new ArrayList<String>();
28   /**
29    * list of alignment panels to use for superposition
30    */
31   protected Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
32   /**
33    * list of alignment panels that are used for colouring structures by aligned
34    * sequences
35    */
36   protected Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
37   private String viewId = null;
38   private AlignmentPanel ap;
39
40   /**
41    * 
42    * @param ap2
43    * @return true if this Jmol instance is linked with the given alignPanel
44    */
45   public boolean isLinkedWith(AlignmentPanel ap2)
46   {
47     return _aps.contains(ap2.av.getSequenceSetId());
48   }
49
50   public boolean isUsedforaligment(AlignmentPanel ap2)
51   {
52   
53     return (_alignwith != null) && _alignwith.contains(ap2);
54   }
55
56   public boolean isUsedforcolourby(AlignmentPanel ap2)
57   {
58     return (_colourwith != null) && _colourwith.contains(ap2);
59   }
60
61   /**
62    * 
63    * @return TRUE if the view is NOT being coloured by the alignment colours.
64    */
65   public boolean isColouredByViewer()
66   {
67     return !getBinding().isColourBySequence();
68   }
69
70   public String getViewId()
71   {
72     if (viewId == null)
73     {
74       viewId = System.currentTimeMillis() + "." + this.hashCode();
75     }
76     return viewId;
77   }
78
79   protected void setViewId(String viewId)
80   {
81     this.viewId = viewId;
82   }
83
84   public String getStateInfo()
85   {
86     return "";
87   }
88
89   protected void buildActionMenu()
90   {
91     if (_alignwith == null)
92     {
93       _alignwith = new Vector<AlignmentPanel>();
94     }
95     if (_alignwith.size() == 0 && ap != null)
96     {
97       _alignwith.add(ap);
98     }
99     ;
100     for (Component c : viewerActionMenu.getMenuComponents())
101     {
102       if (c != alignStructs)
103       {
104         viewerActionMenu.remove((JMenuItem) c);
105       }
106     }
107   }
108
109   public AlignmentPanel getAlignmentPanel()
110   {
111     return ap;
112   }
113
114   protected void setAlignmentPanel(AlignmentPanel alp)
115   {
116     this.ap = alp;
117   }
118 }