public interface SequenceStructureBinding
{
- // todo: decide what this really means - we could return a reference to the
- // alignment/jmol binding, or some other binding.
+ /**
+ *
+ * @return true if Jalview or the Viewer is still restoring state or loading
+ * is still going on (see setFinsihedLoadingFromArchive)
+ */
+ void setLoadingFromArchive(boolean loadingFromArchive);
+
+ boolean isLoadingFromArchive();
+
+ /**
+ * modify flag which controls if sequence colouring events are honoured by the
+ * binding. Should be true for normal operation
+ *
+ * @param finishedLoading
+ */
+ void setFinishedLoadingFromArchive(boolean finishedLoading);
+
+ boolean isLoadingFinished();
+
}
--- /dev/null
+package jalview.api.structures;
+
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
+import jalview.api.SequenceStructureBinding;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.ext.jmol.JalviewJmolBinding;
+import jalview.structure.StructureMappingcommandSet;
+import jalview.structure.StructureSelectionManager;
+
+public interface JalviewStructureDisplayI
+{
+
+ SequenceStructureBinding getBinding();
+
+ /**
+ * @return true if there is an active GUI handling a structure display
+ */
+ boolean isVisible();
+
+ /**
+ * enable or disable the structure display - note this might just hide or show a GUI element, but not actually reset the display
+ * @param b
+ */
+ void setVisible(boolean b);
+
+ /**
+ * free up any external resources that were used by this display and collect garbage
+ */
+ void dispose();
+
+ /**
+ * shutdown any structure viewing processes started by this display
+ */
+ void closeViewer();
+
+
+}
public class AppletJmol extends EmbmenuFrame implements
// StructureListener,
- KeyListener, ActionListener, ItemListener, SequenceStructureBinding
+ KeyListener, ActionListener, ItemListener
{
Menu fileMenu = new Menu(MessageManager.getString("action.file"));
import jalview.structure.StructureListener;
import jalview.structure.StructureMapping;
import jalview.structure.StructureSelectionManager;
+import jalview.structures.models.SequenceStructureBindingModel;
import java.awt.Color;
import java.awt.Container;
import org.jmol.constant.EnumCallback;
import org.jmol.popup.JmolPopup;
-public abstract class JalviewJmolBinding implements StructureListener,
+public abstract class JalviewJmolBinding extends SequenceStructureBindingModel implements StructureListener,
JmolStatusListener, SequenceStructureBinding,
JmolSelectionListener, ComponentListener,
StructureSelectionManagerProvider
{
/**
- * set if Jmol state is being restored from some source - instructs binding
- * not to apply default display style when structure set is updated for first
- * time.
- */
- private boolean loadingFromArchive = false;
-
- /**
- * second flag to indicate if the jmol viewer should ignore sequence colouring
- * events from the structure manager because the GUI is still setting up
- */
- private boolean loadingFinished = true;
-
- /**
* state flag used to check if the Jmol viewer's paint method can be called
*/
private boolean finishedInit = false;
public void colourBySequence(boolean showFeatures,
jalview.api.AlignmentViewPanel alignmentv)
{
- if (!colourBySequence || !loadingFinished)
+ if (!colourBySequence || !isLoadingFinished())
return;
if (ssm == null)
{
showConsole(false);
}
- public void setLoadingFromArchive(boolean loadingFromArchive)
- {
- this.loadingFromArchive = loadingFromArchive;
- }
-
- /**
- *
- * @return true if Jmol is still restoring state or loading is still going on
- * (see setFinsihedLoadingFromArchive)
- */
- public boolean isLoadingFromArchive()
- {
- return loadingFromArchive && !loadingFinished;
- }
-
- /**
- * modify flag which controls if sequence colouring events are honoured by the
- * binding. Should be true for normal operation
- *
- * @param finishedLoading
- */
- public void setFinishedLoadingFromArchive(boolean finishedLoading)
- {
- loadingFinished = finishedLoading;
- }
-
public void setBackgroundColour(java.awt.Color col)
{
jmolHistory(false);
import jalview.api.SequenceStructureBinding;
import jalview.api.StructureSelectionManagerProvider;
import jalview.structure.*;
+import jalview.structures.models.SequenceStructureBindingModel;
-public abstract class JalviewVarnaBinding implements StructureListener,
+public abstract class JalviewVarnaBinding extends SequenceStructureBindingModel implements StructureListener,
SequenceStructureBinding, ComponentListener,
StructureSelectionManagerProvider
import java.util.*;
import java.awt.*;
+
import javax.swing.*;
import javax.swing.event.*;
import jalview.jbgui.GStructureViewer;
import jalview.api.SequenceStructureBinding;
+import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.Cache;
import jalview.datamodel.*;
import jalview.gui.ViewSelectionMenu.ViewSetProvider;
import jalview.datamodel.PDBEntry;
+import jalview.ext.jmol.JalviewJmolBinding;
import jalview.io.*;
import jalview.schemes.*;
import jalview.util.MessageManager;
import jalview.util.Platform;
public class AppJmol extends GStructureViewer implements Runnable,
- SequenceStructureBinding, ViewSetProvider
+ ViewSetProvider, JalviewStructureDisplayI
{
AppJmolBinding jmb;
jmb.centerViewer(toshow);
}
- void closeViewer()
+ public void closeViewer()
{
jmb.closeViewer();
ap = null;
return !jmb.isColourBySequence();
}
+ public JalviewJmolBinding getBinding()
+ {
+ return jmb;
+ }
+
}
import org.exolab.castor.xml.*;
+import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
try
{
// create list to store references for any new Jmol viewers created
- newStructureViewers = new Vector<AppJmol>();
+ newStructureViewers = new Vector<JalviewStructureDisplayI>();
// UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
// Workaround is to make sure caller implements the JarInputStreamProvider
// interface
@Override
public void run()
{
- AppJmol sview = null;
+ JalviewStructureDisplayI sview = null;
try
{
- sview = new AppJmol(pdbf, id, sq, alf.alignPanel,
+ // JAL-1333 note - we probably can't migrate Jmol views to UCSF Chimera!
+ sview = new StructureViewer(alf.alignPanel.getStructureSelectionManager()).createView(StructureViewer.Viewer.JMOL, pdbf, id, sq, alf.alignPanel,
useinJmolsuperpos, usetoColourbyseq,
jmolColouring, fileloc, rect, vid);
addNewStructureViewer(sview);
return true;
}
- Vector<AppJmol> newStructureViewers = null;
+ Vector<JalviewStructureDisplayI> newStructureViewers = null;
- protected void addNewStructureViewer(AppJmol sview)
+ protected void addNewStructureViewer(JalviewStructureDisplayI sview)
{
if (newStructureViewers != null)
{
- sview.jmb.setFinishedLoadingFromArchive(false);
+ sview.getBinding().setFinishedLoadingFromArchive(false);
newStructureViewers.add(sview);
}
}
{
if (newStructureViewers != null)
{
- for (AppJmol sview : newStructureViewers)
+ for (JalviewStructureDisplayI sview : newStructureViewers)
{
- sview.jmb.setFinishedLoadingFromArchive(true);
+ sview.getBinding().setFinishedLoadingFromArchive(true);
}
newStructureViewers.clear();
newStructureViewers = null;
{
// TODO re JAL-860: optionally open dialog or provide a menu entry
// allowing user to open just one structure per sequence
- new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
- { pdb })[0], null, ap);
- // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
+ //new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
+ //{ pdb })[0], null, ap);
+ new StructureViewer(ap.getStructureSelectionManager())
+ .viewStructures(pdb,
+ ap.av.collateForPDB(new PDBEntry[]
+ { pdb })[0], null, ap);
}
});
@Override
public void actionPerformed(ActionEvent e)
{
- new AppJmol(ap, pe, ap.av.collateForPDB(pe));
+ new StructureViewer(ap.getStructureSelectionManager()).viewStructures(ap, pe, ap.av.collateForPDB(pe));
}
});
if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
@Override
public void actionPerformed(ActionEvent e)
{
- new AppJmol(ap, pr, ap.av.collateForPDB(pr));
+ new StructureViewer(ap.getStructureSelectionManager()).viewStructures(ap, pr, ap.av.collateForPDB(pr));
}
});
}
--- /dev/null
+/*
+ * 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)
+ {
+ JalviewStructureDisplayI sview = null;
+ switch (getViewerType())
+ {
+ case JMOL:
+
+ sview = new AppJmol(ap, pr, ap.av.collateForPDB(pr));
+
+ break;
+ case CHIMERA:
+ break;
+ default:
+ Cache.log.error("Unknown structure viewer type "
+ + getViewerType().toString());
+ }
+ return sview;
+ }
+
+ public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
+ SequenceI[] sequenceIs, Object object, AlignmentPanel ap)
+ {
+ return viewStructures(ap, new PDBEntry[]
+ { pdb }, new SequenceI[][]
+ { 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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.structures.models;
+
+import jalview.api.SequenceStructureBinding;
+
+public class SequenceStructureBindingModel implements
+ SequenceStructureBinding
+{
+
+ /**
+ * set if Structure Viewer state is being restored from some source -
+ * instructs binding not to apply default display style when structure set is
+ * updated for first time.
+ */
+ private boolean loadingFromArchive = false;
+
+ /**
+ * second flag to indicate if the Structure viewer should ignore sequence
+ * colouring events from the structure manager because the GUI is still
+ * setting up
+ */
+ private boolean loadingFinished = true;
+
+ @Override
+ public void setLoadingFromArchive(boolean loadingFromArchive)
+ {
+ this.loadingFromArchive = loadingFromArchive;
+ }
+
+ /**
+ *
+ * @return true if Jmol is still restoring state or loading is still going on
+ * (see setFinsihedLoadingFromArchive)
+ */
+ @Override
+ public boolean isLoadingFromArchive()
+ {
+ return loadingFromArchive && !loadingFinished;
+ }
+
+ @Override
+ public boolean isLoadingFinished()
+ {
+ return loadingFinished;
+ }
+
+ @Override
+ public void setFinishedLoadingFromArchive(boolean finishedLoading)
+ {
+ loadingFinished = finishedLoading;
+ }
+
+}