From 0ca29f995f7312625c5fb3c1d439b6a309fd0010 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 13 Nov 2014 11:15:42 +0000 Subject: [PATCH] JAL-1528 Chimera tidy errors, focus after align, close option --- resources/lang/Messages.properties | 4 +- .../ext/rbvi/chimera/JalviewChimeraBinding.java | 68 ++++++++++++++------ src/jalview/gui/ChimeraViewFrame.java | 33 +++++++--- src/jalview/gui/JalviewChimeraBindingModel.java | 2 + 4 files changed, 77 insertions(+), 30 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 72801dd..9eee9cc 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -383,7 +383,7 @@ label.pdb_entry_is_already_displayed = {0} is already displayed.\nDo you want to label.map_sequences_to_visible_window = Map Sequences to Visible Window: {0} label.add_pdbentry_to_view = Do you want to add {0} to the view called\n{1}\n label.align_to_existing_structure_view = Align to existing structure view -label.pdb_entries_couldnt_be_retrieved = The following pdb entries could not be retrieved from the PDB\:\n{0}\nPlease try downloading them manually. +label.pdb_entries_couldnt_be_retrieved = The following pdb entries could not be retrieved from the PDB\:\n{0}\nPlease retry, or try downloading them manually. label.couldnt_load_file = Couldn't load file label.couldnt_find_pdb_id_in_file = Couldn't find a PDB id in the file supplied. Please enter an Id to identify this structure. label.no_pdb_id_in_file = No PDB Id in File @@ -487,7 +487,7 @@ label.sequence_details = Sequence Details label.jmol_help = Jmol Help label.chimera_help = Chimera Help label.close_viewer = Close Viewer -label.confirm_close_chimera = Do you want to close the Chimera window? +label.confirm_close_chimera = This will close Jalview''s connection to {0}.
Do you want to close the Chimera window as well? label.chimera_help = Chimera Help label.all = All label.sort_by = Sort alignment by diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 3f2d5e4..7033ba7 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -254,12 +254,13 @@ public abstract class JalviewChimeraBinding extends } /** - * construct a title string for the viewer window based on the data jalview + * Construct a title string for the viewer window based on the data Jalview * knows about * + * @param verbose * @return */ - public String getViewerTitle() + public String getViewerTitle(boolean verbose) { if (sequence == null || pdbentry == null || sequence.length < 1 || pdbentry.length < 1 || sequence[0].length < 1) @@ -268,20 +269,24 @@ public abstract class JalviewChimeraBinding extends } // TODO: give a more informative title when multiple structures are // displayed. - StringBuffer title = new StringBuffer("Chimera view for " - + sequence[0][0].getName() + ":" + pdbentry[0].getId()); + StringBuilder title = new StringBuilder(64); + title.append("Chimera view for " + sequence[0][0].getName() + ":" + + pdbentry[0].getId()); - if (pdbentry[0].getProperty() != null) + if (verbose) { - if (pdbentry[0].getProperty().get("method") != null) + if (pdbentry[0].getProperty() != null) { - title.append(" Method: "); - title.append(pdbentry[0].getProperty().get("method")); - } - if (pdbentry[0].getProperty().get("chains") != null) - { - title.append(" Chain:"); - title.append(pdbentry[0].getProperty().get("chains")); + if (pdbentry[0].getProperty().get("method") != null) + { + title.append(" Method: "); + title.append(pdbentry[0].getProperty().get("method")); + } + if (pdbentry[0].getProperty().get("chains") != null) + { + title.append(" Chain:"); + title.append(pdbentry[0].getProperty().get("chains")); + } } } return title.toString(); @@ -319,11 +324,17 @@ public abstract class JalviewChimeraBinding extends + ";focus " + cmdstring, false); } - public void closeViewer() + /** + * Close down the Jalview viewer, and (optionally) the associate Chimera + * window. + */ + public void closeViewer(boolean closeChimera) { ssm.removeStructureViewerListener(this, this.getPdbFile()); - // and shut down Chimera - viewer.exitChimera(); + if (closeChimera) + { + viewer.exitChimera(); + } // viewer.evalStringQuiet("zap"); // viewer.setJmolStatusListener(null); lastCommand = null; @@ -670,7 +681,7 @@ public abstract class JalviewChimeraBinding extends } System.out.println("Select regions:\n" + selectioncom.toString()); allComs.append("; ~display all; chain @CA|P; ribbon " - + selectioncom.toString() + ""); + + selectioncom.toString() + "; focus"); // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString()); evalStateCommand(allComs.toString(), true /* false */); } @@ -689,7 +700,24 @@ public abstract class JalviewChimeraBinding extends } } - public void evalStateCommand(final String command, boolean resp) + /** + * Answers true if the Chimera process is still running, false if ended or not + * started. + * + * @return + */ + public boolean isChimeraRunning() + { + return viewer.isChimeraLaunched(); + } + + /** + * Send a command to Chimera, and optionally log any responses. + * + * @param command + * @param logResponse + */ + public void evalStateCommand(final String command, boolean logResponse) { viewerCommandHistory(false); checkLaunched(); @@ -701,8 +729,8 @@ public abstract class JalviewChimeraBinding extends // public void run() // { // trim command or it may never find a match in the replyLog!! - lastReply = viewer.sendChimeraCommand(command.trim(), resp); - if (debug && resp) + lastReply = viewer.sendChimeraCommand(command.trim(), logResponse); + if (debug && logResponse) { log("Response from command ('" + command + "') was:\n" + lastReply); diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 6278536..3c53762 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -546,7 +546,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, jmb.setFinishedInit(false); // TODO: consider waiting until the structure/view is fully loaded before // displaying - jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(), + jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(true), getBounds().width, getBounds().height); if (command == null) { @@ -619,9 +619,24 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, jmb.centerViewer(toshow); } + /** + * Close down this instance of Jalview's Chimera viewer, giving the user the + * 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. + */ public void closeViewer() { - jmb.closeViewer(); + if (jmb.isChimeraRunning()) + { + String prompt = MessageManager + .formatMessage("label.confirm_close_chimera", new Object[] + { jmb.getViewerTitle(false) }); + prompt = JvSwingUtils.wrapTooltip(true, prompt); + int confirm = JOptionPane.showConfirmDialog(this, prompt, + MessageManager.getString("label.close_viewer"), + JOptionPane.YES_NO_OPTION); + jmb.closeViewer(confirm == JOptionPane.YES_OPTION); + } ap = null; _aps.clear(); _alignwith.clear(); @@ -698,7 +713,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, } catch (Exception ex) { ex.printStackTrace(); - errormsgs.append("When retrieving pdbfiles : current was: '" + errormsgs.append("When retrieving pdbfiles for '" + thePdbEntry.getId() + "'"); } if (errormsgs.length() > 0) @@ -818,11 +833,13 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, } catch (OutOfMemoryError oomerror) { new OOMWarning("Retrieving PDB id " + pdbid, oomerror); - } - if (progressBar != null) + } finally { - progressBar.setProgressBar( - MessageManager.getString("label.state_completed"), hdl); + if (progressBar != null) + { + progressBar.setProgressBar( + MessageManager.getString("label.state_completed"), hdl); + } } /* * If PDB data were saved and are not invalid (empty alignment), return the @@ -1082,7 +1099,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, } setChainMenuItems(jmb.chainNames); - this.setTitle(jmb.getViewerTitle()); + this.setTitle(jmb.getViewerTitle(true)); if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1) { viewerActionMenu.setVisible(true); diff --git a/src/jalview/gui/JalviewChimeraBindingModel.java b/src/jalview/gui/JalviewChimeraBindingModel.java index f7c4878..c582c5d 100644 --- a/src/jalview/gui/JalviewChimeraBindingModel.java +++ b/src/jalview/gui/JalviewChimeraBindingModel.java @@ -66,7 +66,9 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding AlignmentPanel ap = (AlignmentPanel) source, topap; // ignore events from panels not used to colour this view if (!cvf.isUsedforcolourby(ap)) + { return; + } if (!isLoadingFromArchive()) { colourBySequence(ap.av.getShowSequenceFeatures(), ap); -- 1.7.10.2