JAL-1333 JAL-1527 refactors to create core structure viewer binding architecture...
[jalview.git] / src / jalview / gui / StructureViewer.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 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 java.awt.Rectangle;
24
25 import jalview.api.structures.JalviewStructureDisplayI;
26 import jalview.bin.Cache;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.StructureViewer.Viewer;
30 import jalview.structure.StructureSelectionManager;
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 Viewer
46   {
47     JMOL, CHIMERA
48   };
49
50   public Viewer getViewerType()
51   {
52     String viewType = Cache.getDefault("STRUCTURE_DISPLAY", "JMOL");
53     return Viewer.valueOf(viewType);
54   }
55
56   public void setViewerType(Viewer type)
57   {
58     Cache.setProperty("STRUCTURE_DISPLAY", type.toString());
59   }
60
61   public StructureViewer(StructureSelectionManager structureSelectionManager)
62   {
63     ssm = structureSelectionManager;
64   }
65
66   public JalviewStructureDisplayI viewStructures(AlignmentPanel ap,
67           PDBEntry[] pr, SequenceI[][] collateForPDB)
68   {
69     JalviewStructureDisplayI sview = null;
70     switch (getViewerType())
71     {
72     case JMOL:
73
74       sview = new AppJmol(ap, pr, ap.av.collateForPDB(pr));
75
76       break;
77     case CHIMERA:
78       break;
79     default:
80       Cache.log.error("Unknown structure viewer type "
81               + getViewerType().toString());
82     }
83     return sview;
84   }
85
86   public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
87           SequenceI[] sequenceIs, Object object, AlignmentPanel ap)
88   {
89     return viewStructures(ap, new PDBEntry[]
90     { pdb }, new SequenceI[][]
91     { sequenceIs });
92   }
93
94   public JalviewStructureDisplayI createView(Viewer jmol, String[] pdbf,
95           String[] id, SequenceI[][] sq, AlignmentPanel alignPanel,
96           boolean useinJmolsuperpos, boolean usetoColourbyseq,
97           boolean jmolColouring, String fileloc, Rectangle rect, String vid)
98   {
99     JalviewStructureDisplayI sview = null;
100     switch (getViewerType())
101     {
102     case JMOL:
103
104       sview = new AppJmol(pdbf, id, sq, alignPanel, useinJmolsuperpos,
105               usetoColourbyseq, jmolColouring, fileloc, rect, vid);
106
107       break;
108     case CHIMERA:
109       break;
110     default:
111       Cache.log.error("Unknown structure viewer type "
112               + getViewerType().toString());
113     }
114     return sview;
115   }
116
117 }