ccb3c185b0281f938ecbf3ee06fc8c13561c4436
[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     return viewStructures(getViewerType(), ap, pr, collateForPDB);
70   }
71
72   public JalviewStructureDisplayI viewStructures(Viewer viewerType,
73           AlignmentPanel ap, PDBEntry[] pr, SequenceI[][] collateForPDB)
74   {
75     JalviewStructureDisplayI sview = null;
76     if (viewerType.equals(Viewer.JMOL))
77     {
78       sview = new AppJmol(ap, pr, ap.av.collateForPDB(pr));
79     }
80     else if (viewerType.equals(Viewer.CHIMERA))
81     {
82       sview = new ChimeraViewFrame(ap, pr, ap.av.collateForPDB(pr));
83     }
84     else
85     {
86       Cache.log.error("Unknown structure viewer type "
87               + getViewerType().toString());
88     }
89     return sview;
90   }
91
92   public JalviewStructureDisplayI viewStructures(Viewer viewerType,
93           AlignmentPanel ap, PDBEntry pr, SequenceI[] collateForPDB)
94   {
95     JalviewStructureDisplayI sview = null;
96     if (viewerType.equals(Viewer.JMOL))
97     {
98       sview = new AppJmol(pr, collateForPDB, null, ap);
99     }
100     else if (viewerType.equals(Viewer.CHIMERA))
101     {
102       sview = new ChimeraViewFrame(pr, collateForPDB, null, ap);
103     }
104     else
105     {
106       Cache.log.error("Unknown structure viewer type "
107               + getViewerType().toString());
108     }
109     return sview;
110   }
111
112   public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
113           SequenceI[] sequenceIs, Object object, AlignmentPanel ap)
114   {
115     return viewStructures(getViewerType(), ap, pdb, sequenceIs);
116   }
117
118   public JalviewStructureDisplayI createView(Viewer jmol, String[] pdbf,
119           String[] id, SequenceI[][] sq, AlignmentPanel alignPanel,
120           boolean useinJmolsuperpos, boolean usetoColourbyseq,
121           boolean jmolColouring, String fileloc, Rectangle rect, String vid)
122   {
123     JalviewStructureDisplayI sview = null;
124     switch (getViewerType())
125     {
126     case JMOL:
127
128       sview = new AppJmol(pdbf, id, sq, alignPanel, useinJmolsuperpos,
129               usetoColourbyseq, jmolColouring, fileloc, rect, vid);
130
131       break;
132     case CHIMERA:
133       break;
134     default:
135       Cache.log.error("Unknown structure viewer type "
136               + getViewerType().toString());
137     }
138     return sview;
139   }
140
141 }