Merge branch 'features/JAL-1333' into Release_2_8_2_Branch
[jalview.git] / src / jalview / gui / StructureViewer.java
diff --git a/src/jalview/gui/StructureViewer.java b/src/jalview/gui/StructureViewer.java
new file mode 100644 (file)
index 0000000..ccb3c18
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.gui;
+
+import java.awt.Rectangle;
+
+import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.bin.Cache;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+import jalview.gui.StructureViewer.Viewer;
+import jalview.structure.StructureSelectionManager;
+
+/**
+ * proxy for handling structure viewers.
+ * 
+ * this allows new views to be created with the currently configured viewer, the
+ * preferred viewer to be set/read and existing views created previously with a
+ * particular viewer to be recovered
+ * 
+ * @author jprocter
+ */
+public class StructureViewer
+{
+  StructureSelectionManager ssm;
+
+  public enum Viewer
+  {
+    JMOL, CHIMERA
+  };
+
+  public Viewer getViewerType()
+  {
+    String viewType = Cache.getDefault("STRUCTURE_DISPLAY", "JMOL");
+    return Viewer.valueOf(viewType);
+  }
+
+  public void setViewerType(Viewer type)
+  {
+    Cache.setProperty("STRUCTURE_DISPLAY", type.toString());
+  }
+
+  public StructureViewer(StructureSelectionManager structureSelectionManager)
+  {
+    ssm = structureSelectionManager;
+  }
+
+  public JalviewStructureDisplayI viewStructures(AlignmentPanel ap,
+          PDBEntry[] pr, SequenceI[][] collateForPDB)
+  {
+    return viewStructures(getViewerType(), ap, pr, collateForPDB);
+  }
+
+  public JalviewStructureDisplayI viewStructures(Viewer viewerType,
+          AlignmentPanel ap, PDBEntry[] pr, SequenceI[][] collateForPDB)
+  {
+    JalviewStructureDisplayI sview = null;
+    if (viewerType.equals(Viewer.JMOL))
+    {
+      sview = new AppJmol(ap, pr, ap.av.collateForPDB(pr));
+    }
+    else if (viewerType.equals(Viewer.CHIMERA))
+    {
+      sview = new ChimeraViewFrame(ap, pr, ap.av.collateForPDB(pr));
+    }
+    else
+    {
+      Cache.log.error("Unknown structure viewer type "
+              + getViewerType().toString());
+    }
+    return sview;
+  }
+
+  public JalviewStructureDisplayI viewStructures(Viewer viewerType,
+          AlignmentPanel ap, PDBEntry pr, SequenceI[] collateForPDB)
+  {
+    JalviewStructureDisplayI sview = null;
+    if (viewerType.equals(Viewer.JMOL))
+    {
+      sview = new AppJmol(pr, collateForPDB, null, ap);
+    }
+    else if (viewerType.equals(Viewer.CHIMERA))
+    {
+      sview = new ChimeraViewFrame(pr, collateForPDB, null, ap);
+    }
+    else
+    {
+      Cache.log.error("Unknown structure viewer type "
+              + getViewerType().toString());
+    }
+    return sview;
+  }
+
+  public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
+          SequenceI[] sequenceIs, Object object, AlignmentPanel ap)
+  {
+    return viewStructures(getViewerType(), ap, pdb, sequenceIs);
+  }
+
+  public JalviewStructureDisplayI createView(Viewer jmol, String[] pdbf,
+          String[] id, SequenceI[][] sq, AlignmentPanel alignPanel,
+          boolean useinJmolsuperpos, boolean usetoColourbyseq,
+          boolean jmolColouring, String fileloc, Rectangle rect, String vid)
+  {
+    JalviewStructureDisplayI sview = null;
+    switch (getViewerType())
+    {
+    case JMOL:
+
+      sview = new AppJmol(pdbf, id, sq, alignPanel, useinJmolsuperpos,
+              usetoColourbyseq, jmolColouring, fileloc, rect, vid);
+
+      break;
+    case CHIMERA:
+      break;
+    default:
+      Cache.log.error("Unknown structure viewer type "
+              + getViewerType().toString());
+    }
+    return sview;
+  }
+
+}