JAL-1333 more abstraction and refactoring and working demo of Jalview talking to...
[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   public JalviewStructureDisplayI viewStructures(Viewer viewerType,AlignmentPanel ap,
72           PDBEntry[] pr, SequenceI[][] collateForPDB)
73   {
74     JalviewStructureDisplayI sview = null;
75     if (viewerType.equals(Viewer.JMOL)){
76       sview = new AppJmol(ap, pr, ap.av.collateForPDB(pr));
77     } else
78     if (viewerType.equals(Viewer.CHIMERA)) {
79       sview = new ChimeraViewFrame(ap, pr, ap.av.collateForPDB(pr));
80     }else 
81     {
82       Cache.log.error("Unknown structure viewer type "
83               + getViewerType().toString());
84     }
85     return sview;
86   }
87
88   public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
89           SequenceI[] sequenceIs, Object object, AlignmentPanel ap)
90   {
91     return viewStructures(ap, new PDBEntry[]
92     { pdb }, new SequenceI[][]
93     { sequenceIs });
94   }
95
96   public JalviewStructureDisplayI createView(Viewer jmol, String[] pdbf,
97           String[] id, SequenceI[][] sq, AlignmentPanel alignPanel,
98           boolean useinJmolsuperpos, boolean usetoColourbyseq,
99           boolean jmolColouring, String fileloc, Rectangle rect, String vid)
100   {
101     JalviewStructureDisplayI sview = null;
102     switch (getViewerType())
103     {
104     case JMOL:
105
106       sview = new AppJmol(pdbf, id, sq, alignPanel, useinJmolsuperpos,
107               usetoColourbyseq, jmolColouring, fileloc, rect, vid);
108
109       break;
110     case CHIMERA:
111       break;
112     default:
113       Cache.log.error("Unknown structure viewer type "
114               + getViewerType().toString());
115     }
116     return sview;
117   }
118
119 }