From 0ca159283d6fdd7b76b033421393209ee8c0c8a8 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 5 Apr 2018 14:17:01 +0100 Subject: [PATCH] JAL-2944 remove modal prompt logic and expose methods for adding structure data to a view via the StructureDisplay API --- .../api/structures/JalviewStructureDisplayI.java | 11 +++ src/jalview/gui/AppJmol.java | 32 +------- src/jalview/gui/ChimeraViewFrame.java | 25 +------ src/jalview/gui/StructureViewerBase.java | 77 ++++++-------------- 4 files changed, 40 insertions(+), 105 deletions(-) diff --git a/src/jalview/api/structures/JalviewStructureDisplayI.java b/src/jalview/api/structures/JalviewStructureDisplayI.java index b4612cf..69d08fa 100644 --- a/src/jalview/api/structures/JalviewStructureDisplayI.java +++ b/src/jalview/api/structures/JalviewStructureDisplayI.java @@ -20,6 +20,9 @@ */ package jalview.api.structures; +import jalview.api.AlignmentViewPanel; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; import jalview.schemes.ColourSchemeI; import jalview.structures.models.AAStructureBindingModel; @@ -69,4 +72,12 @@ public interface JalviewStructureDisplayI */ boolean hasMapping(); + // construction method - move to another interface ? + boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains, + AlignmentViewPanel apanel, String pdbId); + + // construction method - move to another interface ? + boolean addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq, + String[] chains, AlignmentViewPanel apanel, String pdbId); + } diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index af25653..29f02d6 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -44,7 +44,6 @@ import java.util.List; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; -import javax.swing.JInternalFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.SwingUtilities; @@ -162,8 +161,9 @@ public class AppJmol extends StructureViewerBase { return progressBar; } + /** - * add a single PDB structure to a new or existing Jmol view + * display a single PDB structure in a new Jmol view * * @param pdbentry * @param seq @@ -174,29 +174,7 @@ public class AppJmol extends StructureViewerBase final AlignmentPanel ap) { progressBar = ap.alignFrame; - String pdbId = pdbentry.getId(); - /* - * If the PDB file is already loaded, the user may just choose to add to an - * existing viewer (or cancel) - */ - if (addAlreadyLoadedFile(seq, chains, ap, pdbId)) - { - return; - } - - /* - * Check if there are other Jmol views involving this alignment and prompt - * user about adding this molecule to one of them - */ - if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId)) - { - return; - } - - /* - * If the options above are declined or do not apply, open a new viewer - */ openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq }); } @@ -209,11 +187,9 @@ public class AppJmol extends StructureViewerBase addAlignmentPanel(ap); useAlignmentPanelForColourbyseq(ap); - if (pdbentrys.length > 1) - { - alignAddedStructures = true; + alignAddedStructures = true; useAlignmentPanelForSuperposition(ap); - } + jmb.setColourBySequence(true); setSize(400, 400); // probably should be a configurable/dynamic default here initMenus(); diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 87512f5..c595d9d 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -202,7 +202,7 @@ public class ChimeraViewFrame extends StructureViewerBase } /** - * add a single PDB structure to a new or existing Chimera view + * open a single PDB structure in a new Chimera view * * @param pdbentry * @param seq @@ -213,30 +213,7 @@ public class ChimeraViewFrame extends StructureViewerBase String[] chains, final AlignmentPanel ap) { this(); - String pdbId = pdbentry.getId(); - /* - * If the PDB file is already loaded, the user may just choose to add to an - * existing viewer (or cancel) - */ - if (addAlreadyLoadedFile(seq, chains, ap, pdbId)) - { - return; - } - - /* - * Check if there are other Chimera views involving this alignment and give - * user the option to add and align this molecule to one of them (or cancel) - */ - if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId)) - { - return; - } - - /* - * If the options above are declined or do not apply, show the structure in - * a new viewer - */ openNewChimera(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq }); diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 0b45417..e084417 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -424,41 +424,23 @@ public abstract class StructureViewerBase extends GStructureViewer * @param pdbId * @return true if user adds to a view, or cancels entirely, else false */ - protected boolean addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq, - String[] chains, final AlignmentPanel apanel, String pdbId) + @Override + public boolean addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq, + String[] chains, final AlignmentViewPanel apanel, String pdbId) { - for (StructureViewerBase view : getViewersFor(apanel)) - { - // TODO: highlight the view somehow - /* - * JAL-1742 exclude view with this structure already mapped (don't offer - * to align chain B to chain A of the same structure) - */ - if (view.hasPdbId(pdbId)) - { - continue; - } - int option = chooseAlignStructureToViewer(pdbId, view); - if (option == JvOptionPane.CANCEL_OPTION) - { - return true; - } - else if (option == JvOptionPane.YES_OPTION) - { - view.useAlignmentPanelForSuperposition(apanel); - view.addStructure(pdbentry, seq, chains, true, apanel.alignFrame); - return true; - } - else - { - // NO_OPTION - offer the next viewer if any - } - } - /* - * nothing offered and selected + * JAL-1742 exclude view with this structure already mapped (don't offer + * to align chain B to chain A of the same structure) */ - return false; + if (hasPdbId(pdbId)) + { + return false; + } + AlignmentPanel ap = (AlignmentPanel) apanel; // Implementation error if this + // cast fails + useAlignmentPanelForSuperposition(ap); + addStructure(pdbentry, seq, chains, true, ap.alignFrame); + return true; } /** @@ -470,9 +452,12 @@ public abstract class StructureViewerBase extends GStructureViewer * @param apanel * @param pdbFilename */ - protected void addSequenceMappingsToStructure(SequenceI[] seq, - String[] chains, final AlignmentPanel apanel, String pdbFilename) + public void addSequenceMappingsToStructure(SequenceI[] seq, + String[] chains, final AlignmentViewPanel alpanel, + String pdbFilename) { + AlignmentPanel apanel = (AlignmentPanel) alpanel; + // TODO : Fix multiple seq to one chain issue here. /* * create the mappings @@ -529,8 +514,9 @@ public abstract class StructureViewerBase extends GStructureViewer * @param pdbId * @return true if the user chooses to add to a viewer, or to cancel entirely */ - protected boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains, - final AlignmentPanel apanel, String pdbId) + @Override + public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains, + final AlignmentViewPanel apanel, String pdbId) { boolean finished = false; String alreadyMapped = apanel.getStructureSelectionManager() @@ -541,23 +527,8 @@ public abstract class StructureViewerBase extends GStructureViewer /* * the PDB file is already loaded */ - int option = JvOptionPane.showInternalConfirmDialog(Desktop.desktop, - MessageManager.formatMessage( - "label.pdb_entry_is_already_displayed", new Object[] - { pdbId }), - MessageManager.formatMessage( - "label.map_sequences_to_visible_window", new Object[] - { pdbId }), - JvOptionPane.YES_NO_CANCEL_OPTION); - if (option == JvOptionPane.CANCEL_OPTION) - { - finished = true; - } - else if (option == JvOptionPane.YES_OPTION) - { - addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped); - finished = true; - } + addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped); + finished = true; } return finished; } -- 1.7.10.2