JAL-1683 replace year/version strings with tokens in source
[jalview.git] / src / jalview / gui / StructureViewer.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.structures.JalviewStructureDisplayI;
24 import jalview.bin.Cache;
25 import jalview.datamodel.PDBEntry;
26 import jalview.datamodel.SequenceI;
27 import jalview.datamodel.StructureViewerModel;
28 import jalview.structure.StructureSelectionManager;
29
30 import java.awt.Rectangle;
31
32 /**
33  * proxy for handling structure viewers.
34  * 
35  * this allows new views to be created with the currently configured viewer, the
36  * preferred viewer to be set/read and existing views created previously with a
37  * particular viewer to be recovered
38  * 
39  * @author jprocter
40  */
41 public class StructureViewer
42 {
43   StructureSelectionManager ssm;
44
45   public enum ViewerType
46   {
47     JMOL, CHIMERA
48   };
49
50   public ViewerType getViewerType()
51   {
52     String viewType = Cache.getDefault(Preferences.STRUCTURE_DISPLAY,
53             ViewerType.JMOL.name());
54     return ViewerType.valueOf(viewType);
55   }
56
57   public void setViewerType(ViewerType type)
58   {
59     Cache.setProperty(Preferences.STRUCTURE_DISPLAY, type.name());
60   }
61
62   public StructureViewer(StructureSelectionManager structureSelectionManager)
63   {
64     ssm = structureSelectionManager;
65   }
66
67   public JalviewStructureDisplayI viewStructures(AlignmentPanel ap,
68           PDBEntry[] pr, SequenceI[][] collateForPDB)
69   {
70     return viewStructures(getViewerType(), ap, pr, collateForPDB);
71   }
72
73   public JalviewStructureDisplayI viewStructures(ViewerType viewerType,
74           AlignmentPanel ap, PDBEntry[] pr, SequenceI[][] collateForPDB)
75   {
76     JalviewStructureDisplayI sview = null;
77     if (viewerType.equals(ViewerType.JMOL))
78     {
79       sview = new AppJmol(ap, pr, ap.av.collateForPDB(pr));
80     }
81     else if (viewerType.equals(ViewerType.CHIMERA))
82     {
83       sview = new ChimeraViewFrame(ap, pr, ap.av.collateForPDB(pr));
84     }
85     else
86     {
87       Cache.log.error("Unknown structure viewer type "
88               + getViewerType().toString());
89     }
90     return sview;
91   }
92
93   public JalviewStructureDisplayI viewStructures(ViewerType viewerType,
94           AlignmentPanel ap, PDBEntry pr, SequenceI[] collateForPDB)
95   {
96     JalviewStructureDisplayI sview = null;
97     if (viewerType.equals(ViewerType.JMOL))
98     {
99       sview = new AppJmol(pr, collateForPDB, null, ap);
100     }
101     else if (viewerType.equals(ViewerType.CHIMERA))
102     {
103       sview = new ChimeraViewFrame(pr, collateForPDB, null, ap);
104     }
105     else
106     {
107       Cache.log.error("Unknown structure viewer type "
108               + getViewerType().toString());
109     }
110     return sview;
111   }
112
113   public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
114           SequenceI[] sequenceIs, Object object, AlignmentPanel ap)
115   {
116     return viewStructures(getViewerType(), ap, pdb, sequenceIs);
117   }
118
119   /**
120    * Create a new panel controlling a structure viewer.
121    * 
122    * @param type
123    * @param pdbf
124    * @param id
125    * @param sq
126    * @param alignPanel
127    * @param viewerData
128    * @param fileloc
129    * @param rect
130    * @param vid
131    * @return
132    */
133   public JalviewStructureDisplayI createView(ViewerType type,
134           String[] pdbf, String[] id, SequenceI[][] sq,
135           AlignmentPanel alignPanel, StructureViewerModel viewerData, String fileloc,
136           Rectangle rect, String vid)
137   {
138     final boolean useinViewerSuperpos = viewerData.isAlignWithPanel();
139     final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel();
140     final boolean viewerColouring = viewerData.isColourByViewer();
141
142     JalviewStructureDisplayI sview = null;
143     switch (type)
144     {
145     case JMOL:
146       sview = new AppJmol(pdbf, id, sq, alignPanel, usetoColourbyseq,
147               useinViewerSuperpos, viewerColouring, fileloc, rect, vid);
148       break;
149     case CHIMERA:
150       Cache.log.error("Unsupported structure viewer type "
151               + type.toString());
152       break;
153     default:
154       Cache.log.error("Unknown structure viewer type " + type.toString());
155     }
156     return sview;
157   }
158
159 }