From: gmungoc Date: Thu, 8 Dec 2016 09:32:29 +0000 (+0000) Subject: JAL-2358 ensure mappings removed on close Chimera; pull up method; X-Git-Tag: Release_2_11_0~62^2~33^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9b717f5894d6df63a55ab46a97f4de2e1cc18e9e;p=jalview.git JAL-2358 ensure mappings removed on close Chimera; pull up method; case-insensitive pdbId check --- diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index e2e54aa..a30f6d3 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -64,9 +64,7 @@ import java.util.Vector; import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; -import javax.swing.JInternalFrame; import javax.swing.JMenu; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.SwingUtilities; @@ -338,30 +336,6 @@ public class AppJmol extends StructureViewerBase openNewJmol(ap, pe, seqs); } - /** - * Returns a list of any Jmol viewers. The list is restricted to those linked - * to the given alignment panel if it is not null. - */ - @Override - protected List getViewersFor(AlignmentPanel apanel) - { - List result = new ArrayList(); - JInternalFrame[] frames = Desktop.instance.getAllFrames(); - - for (JInternalFrame frame : frames) - { - if (frame instanceof AppJmol) - { - if (apanel == null - || ((StructureViewerBase) frame).isLinkedWith(apanel)) - { - result.add((StructureViewerBase) frame); - } - } - } - return result; - } - void initJmol(String command) { jmb.setFinishedInit(false); diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index b82eef3..7cf3bfc 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -66,7 +66,6 @@ import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; import javax.swing.JInternalFrame; import javax.swing.JMenu; -import javax.swing.JOptionPane; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; import javax.swing.event.MenuEvent; @@ -341,28 +340,6 @@ public class ChimeraViewFrame extends StructureViewerBase setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); } - /** - * Returns a list of any Chimera viewers in the desktop. The list is - * restricted to those linked to the given alignment panel if it is not null. - */ - @Override - protected List getViewersFor(AlignmentPanel ap) - { - List result = new ArrayList(); - JInternalFrame[] frames = Desktop.instance.getAllFrames(); - - for (JInternalFrame frame : frames) - { - if (frame instanceof ChimeraViewFrame) - { - if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap)) - { - result.add((StructureViewerBase) frame); - } - } - } - return result; - } /** * Launch Chimera. If we have a chimera session file name, send Chimera the @@ -427,35 +404,47 @@ public class ChimeraViewFrame extends StructureViewerBase * option to close the associated Chimera window (process). They may wish to * keep it open until they have had an opportunity to save any work. * - * @param closeChimera + * @param forceCloseChimera * if true, close any linked Chimera process; if false, prompt first */ @Override - public void closeViewer(boolean closeChimera) + public void closeViewer(boolean forceCloseChimera) { - if (jmb != null && jmb.isChimeraRunning()) + if (jmb != null) { - if (!closeChimera) + if (jmb.isChimeraRunning()) { - String prompt = MessageManager.formatMessage( - "label.confirm_close_chimera", - new Object[] { jmb.getViewerTitle("Chimera", false) }); - prompt = JvSwingUtils.wrapTooltip(true, prompt); - int confirm = JvOptionPane.showConfirmDialog(this, prompt, - MessageManager.getString("label.close_viewer"), - JvOptionPane.YES_NO_CANCEL_OPTION); /* - * abort closure if user hits escape or Cancel + * force close, or prompt to close, Chimera */ - if (confirm == JvOptionPane.CANCEL_OPTION - || confirm == JvOptionPane.CLOSED_OPTION) + if (!forceCloseChimera) { - return; + String prompt = MessageManager.formatMessage( + "label.confirm_close_chimera", + new Object[] { jmb.getViewerTitle("Chimera", false) }); + prompt = JvSwingUtils.wrapTooltip(true, prompt); + int confirm = JvOptionPane.showConfirmDialog(this, prompt, + MessageManager.getString("label.close_viewer"), + JvOptionPane.YES_NO_CANCEL_OPTION); + /* + * abort closure if user hits escape or Cancel + */ + if (confirm == JvOptionPane.CANCEL_OPTION + || confirm == JvOptionPane.CLOSED_OPTION) + { + return; + } + forceCloseChimera = confirm == JvOptionPane.YES_OPTION; } - closeChimera = confirm == JvOptionPane.YES_OPTION; } - jmb.closeViewer(closeChimera); + + /* + * close the viewer plus any side-effects e.g. remove mappings + * note we do this also if closing Chimera triggered this method + */ + jmb.closeViewer(forceCloseChimera); } + setAlignmentPanel(null); _aps.clear(); _alignwith.clear(); diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 91d7130..19291ac 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -26,6 +26,7 @@ import jalview.gui.StructureViewer.ViewerType; import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.DataSourceType; import jalview.jbgui.GStructureViewer; +import jalview.structure.StructureSelectionManager; import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; @@ -39,8 +40,8 @@ import java.util.List; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; +import javax.swing.JInternalFrame; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; /** * Base class with common functionality for JMol, Chimera or other structure @@ -352,8 +353,29 @@ public abstract class StructureViewerBase extends GStructureViewer protected abstract boolean hasPdbId(String pdbId); - protected abstract List getViewersFor( - AlignmentPanel alp); + /** + * Returns a list of any structure viewers of the same type. The list is + * restricted to those linked to the given alignment panel if it is not null. + */ + protected List getViewersFor(AlignmentPanel alp){ + + List result = new ArrayList(); + JInternalFrame[] frames = Desktop.instance.getAllFrames(); + + for (JInternalFrame frame : frames) + { + if (this.getClass().isAssignableFrom(frame.getClass())) + { + if (alp == null + || ((StructureViewerBase) frame).isLinkedWith(alp)) + { + result.add((StructureViewerBase) frame); + } + } + } + return result; + + } /** * Check for any existing views involving this alignment and give user the @@ -473,8 +495,8 @@ public abstract class StructureViewerBase extends GStructureViewer final AlignmentPanel apanel, String pdbId) { boolean finished = false; - String alreadyMapped = apanel.getStructureSelectionManager() - .alreadyMappedToFile(pdbId); + StructureSelectionManager ssm = apanel.getStructureSelectionManager(); + String alreadyMapped = ssm.alreadyMappedToFile(pdbId); if (alreadyMapped != null) { diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 65fd5e7..2fd1966 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -299,7 +299,7 @@ public class StructureSelectionManager { for (StructureMapping sm : mappings) { - if (sm.getPdbId().equals(pdbid)) + if (sm.getPdbId().equalsIgnoreCase(pdbid)) { return sm.pdbfile; }