X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAppJmol.java;h=0dde2550942de057b4f08f8622e1cd9a07cdec04;hb=aa643d0f2f5f506df2771e216af1618549d32050;hp=5d23f493cd3a48fa4ece2e6a3a6acd0fbf35f6b6;hpb=20bb45279db7745e7d0062c1084f97644c60db19;p=jalview.git diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 5d23f49..0dde255 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -20,37 +20,36 @@ */ package jalview.gui; -import jalview.bin.Cache; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; -import jalview.gui.StructureViewer.ViewerType; -import jalview.structures.models.AAStructureBindingModel; -import jalview.util.BrowserLauncher; -import jalview.util.MessageManager; -import jalview.util.Platform; -import jalview.ws.dbsources.Pdb; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Rectangle; -import java.awt.event.ActionEvent; import java.io.File; import java.util.ArrayList; 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; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; +import jalview.api.AlignmentViewPanel; +import jalview.bin.Cache; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.gui.StructureViewer.ViewerType; +import jalview.structure.StructureCommand; +import jalview.structures.models.AAStructureBindingModel; +import jalview.util.BrowserLauncher; +import jalview.util.ImageMaker; +import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.ws.dbsources.Pdb; + public class AppJmol extends StructureViewerBase { // ms to wait for Jmol to load files @@ -58,7 +57,7 @@ public class AppJmol extends StructureViewerBase private static final String SPACE = " "; - private static final String BACKSLASH = "\""; + private static final String QUOTE = "\""; AppJmolBinding jmb; @@ -89,8 +88,8 @@ public class AppJmol extends StructureViewerBase */ public AppJmol(String[] files, String[] ids, SequenceI[][] seqs, AlignmentPanel ap, boolean usetoColour, boolean useToAlign, - boolean leaveColouringToJmol, String loadStatus, - Rectangle bounds, String viewid) + boolean leaveColouringToJmol, String loadStatus, Rectangle bounds, + String viewid) { PDBEntry[] pdbentrys = new PDBEntry[files.length]; for (int i = 0; i < pdbentrys.length; i++) @@ -133,7 +132,8 @@ public class AppJmol extends StructureViewerBase this.addInternalFrameListener(new InternalFrameAdapter() { @Override - public void internalFrameClosing(InternalFrameEvent internalFrameEvent) + public void internalFrameClosing( + InternalFrameEvent internalFrameEvent) { closeViewer(false); } @@ -154,10 +154,8 @@ public class AppJmol extends StructureViewerBase .getString("label.let_jmol_manage_structure_colours")); } - IProgressIndicator progressBar = null; - /** - * 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 @@ -167,47 +165,29 @@ public class AppJmol extends StructureViewerBase public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains, final AlignmentPanel ap) { - progressBar = ap.alignFrame; - String pdbId = pdbentry.getId(); + setProgressIndicator(ap.alignFrame); - /* - * 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 }); + openNewJmol(ap, alignAddedStructures, new PDBEntry[] { pdbentry }, + new SequenceI[][] + { seq }); } - private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, + private void openNewJmol(AlignmentPanel ap, boolean alignAdded, + PDBEntry[] pdbentrys, SequenceI[][] seqs) { - progressBar = ap.alignFrame; + setProgressIndicator(ap.alignFrame); jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null); addAlignmentPanel(ap); useAlignmentPanelForColourbyseq(ap); + alignAddedStructures = alignAdded; if (pdbentrys.length > 1) { - alignAddedStructures = true; useAlignmentPanelForSuperposition(ap); } + jmb.setColourBySequence(true); setSize(400, 400); // probably should be a configurable/dynamic default here initMenus(); @@ -218,7 +198,8 @@ public class AppJmol extends StructureViewerBase this.addInternalFrameListener(new InternalFrameAdapter() { @Override - public void internalFrameClosing(InternalFrameEvent internalFrameEvent) + public void internalFrameClosing( + InternalFrameEvent internalFrameEvent) { closeViewer(false); } @@ -227,41 +208,21 @@ public class AppJmol extends StructureViewerBase } /** - * create a new Jmol containing several structures superimposed using the - * given alignPanel. + * create a new Jmol containing several structures optionally superimposed + * using the given alignPanel. * * @param ap + * @param alignAdded + * - true to superimpose * @param pe * @param seqs */ - public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs) + public AppJmol(AlignmentPanel ap, boolean alignAdded, PDBEntry[] pe, + SequenceI[][] seqs) { - openNewJmol(ap, pe, seqs); + openNewJmol(ap, alignAdded, 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) { @@ -281,40 +242,18 @@ public class AppJmol extends StructureViewerBase scriptWindow.setVisible(false); } - jmb.allocateViewer(renderPanel, true, "", null, null, "", - scriptWindow, null); + jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow, + null); // jmb.newJmolPopup("Jmol"); if (command == null) { command = ""; } - jmb.evalStateCommand(command); - jmb.evalStateCommand("set hoverDelay=0.1"); + jmb.executeCommand(new StructureCommand(command), false); + jmb.executeCommand(new StructureCommand("set hoverDelay=0.1"), false); jmb.setFinishedInit(true); } - - - boolean allChainsSelected = false; - - @Override - void showSelectedChains() - { - Vector toshow = new Vector(); - for (int i = 0; i < chainMenu.getItemCount(); i++) - { - if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem) - { - JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i); - if (item.isSelected()) - { - toshow.addElement(item.getText()); - } - } - } - jmb.centerViewer(toshow); - } - @Override public void closeViewer(boolean closeExternalViewer) { @@ -363,8 +302,8 @@ public class AppJmol extends StructureViewerBase StringBuilder fileList = new StringBuilder(); for (String s : files) { - fileList.append(SPACE).append(BACKSLASH) - .append(Platform.escapeString(s)).append(BACKSLASH); + fileList.append(SPACE).append(QUOTE) + .append(Platform.escapeBackslashes(s)).append(QUOTE); } String filesString = fileList.toString(); @@ -388,12 +327,12 @@ public class AppJmol extends StructureViewerBase cmd.append("loadingJalviewdata=true\nload APPEND "); cmd.append(filesString); cmd.append("\nloadingJalviewdata=null"); - final String command = cmd.toString(); + final StructureCommand command = new StructureCommand(cmd.toString()); lastnotify = jmb.getLoadNotifiesHandled(); try { - jmb.evalStateCommand(command); + jmb.executeCommand(command, false); } catch (OutOfMemoryError oomerror) { new OOMWarning("When trying to add structures to the Jmol viewer!", @@ -410,8 +349,8 @@ public class AppJmol extends StructureViewerBase int waitFor = 35; int waitTotal = 0; while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled() - : !(jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb - .getPdbFile().length == files.size())) + : !(jmb.isFinishedInit() && jmb.getStructureFiles() != null + && jmb.getStructureFiles().length == files.size())) { try { @@ -423,24 +362,23 @@ public class AppJmol extends StructureViewerBase } if (waitTotal > waitMax) { - System.err - .println("Timed out waiting for Jmol to load files after " - + waitTotal + "ms"); -// System.err.println("finished: " + jmb.isFinishedInit() -// + "; loaded: " + Arrays.toString(jmb.getPdbFile()) -// + "; files: " + files.toString()); - jmb.getPdbFile(); + System.err.println("Timed out waiting for Jmol to load files after " + + waitTotal + "ms"); + // System.err.println("finished: " + jmb.isFinishedInit() + // + "; loaded: " + Arrays.toString(jmb.getPdbFile()) + // + "; files: " + files.toString()); + jmb.getStructureFiles(); break; } } // refresh the sequence colours for the new structure(s) - for (AlignmentPanel ap : _colourwith) + for (AlignmentViewPanel ap : _colourwith) { jmb.updateColours(ap); } // do superposition if asked to - if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures) + if (alignAddedStructures) { alignAddedStructures(); } @@ -457,7 +395,7 @@ public class AppJmol extends StructureViewerBase @Override public void run() { - if (jmb.viewer.isScriptExecuting()) + if (jmb.jmolViewer.isScriptExecuting()) { SwingUtilities.invokeLater(this); try @@ -470,11 +408,11 @@ public class AppJmol extends StructureViewerBase } else { - alignStructs_withAllAlignPanels(); + alignStructsWithAllAlignPanels(); } } }); - alignAddedStructures = false; + } /** @@ -490,11 +428,11 @@ public class AppJmol extends StructureViewerBase // todo - record which pdbids were successfully imported. StringBuilder errormsgs = new StringBuilder(); - List files = new ArrayList(); + List files = new ArrayList<>(); String pdbid = ""; try { - String[] filesInViewer = jmb.getPdbFile(); + String[] filesInViewer = jmb.getStructureFiles(); // TODO: replace with reference fetching/transfer code (validate PDBentry // as a DBRef?) Pdb pdbclient = new Pdb(); @@ -503,15 +441,14 @@ public class AppJmol extends StructureViewerBase String file = jmb.getPdbEntry(pi).getFile(); if (file == null) { + // todo: extract block as method and pull up (also ChimeraViewFrame) // retrieve the pdb and store it locally AlignmentI pdbseq = null; pdbid = jmb.getPdbEntry(pi).getId(); long hdl = pdbid.hashCode() - System.currentTimeMillis(); - if (progressBar != null) - { - progressBar.setProgressBar(MessageManager.formatMessage( - "status.fetching_pdb", new String[] { pdbid }), hdl); - } + setProgressMessage(MessageManager + .formatMessage("status.fetching_pdb", new String[] + { pdbid }), hdl); try { pdbseq = pdbclient.getSequenceRecords(pdbid); @@ -524,12 +461,8 @@ public class AppJmol extends StructureViewerBase errormsgs.append("'").append(pdbid).append("'"); } finally { - if (progressBar != null) - { - progressBar.setProgressBar( - MessageManager.getString("label.state_completed"), - hdl); - } + setProgressMessage( + MessageManager.getString("label.state_completed"), hdl); } if (pdbseq != null) { @@ -552,7 +485,7 @@ public class AppJmol extends StructureViewerBase addingStructures = true; // already files loaded. for (int c = 0; c < filesInViewer.length; c++) { - if (filesInViewer[c].equals(file)) + if (Platform.pathEquals(filesInViewer[c], file)) { file = null; break; @@ -576,9 +509,10 @@ public class AppJmol extends StructureViewerBase } if (errormsgs.length() > 0) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager - .formatMessage("label.pdb_entries_couldnt_be_retrieved", - new String[] { errormsgs.toString() }), + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.formatMessage( + "label.pdb_entries_couldnt_be_retrieved", new String[] + { errormsgs.toString() }), MessageManager.getString("label.couldnt_load_file"), JvOptionPane.ERROR_MESSAGE); } @@ -586,53 +520,52 @@ public class AppJmol extends StructureViewerBase } @Override - public void eps_actionPerformed(ActionEvent e) + public void eps_actionPerformed() { - makePDBImage(jalview.util.ImageMaker.TYPE.EPS); + makePDBImage(ImageMaker.TYPE.EPS); } @Override - public void png_actionPerformed(ActionEvent e) + public void png_actionPerformed() { - makePDBImage(jalview.util.ImageMaker.TYPE.PNG); + makePDBImage(ImageMaker.TYPE.PNG); } - void makePDBImage(jalview.util.ImageMaker.TYPE type) + void makePDBImage(ImageMaker.TYPE type) { int width = getWidth(); int height = getHeight(); - jalview.util.ImageMaker im; + ImageMaker im; - if (type == jalview.util.ImageMaker.TYPE.PNG) + if (type == ImageMaker.TYPE.PNG) { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from view", + im = new ImageMaker(this, ImageMaker.TYPE.PNG, + "Make PNG image from view", width, height, null, null, null, 0, false); } - else if (type == jalview.util.ImageMaker.TYPE.EPS) + else if (type == ImageMaker.TYPE.EPS) { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from view", + im = new ImageMaker(this, ImageMaker.TYPE.EPS, + "Make EPS file from view", width, height, null, this.getTitle(), null, 0, false); } else { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA", + ImageMaker.TYPE.SVG, "Make SVG file from PCA", width, height, null, this.getTitle(), null, 0, false); } if (im.getGraphics() != null) { - jmb.viewer.renderScreenImage(im.getGraphics(), width, height); + jmb.jmolViewer.renderScreenImage(im.getGraphics(), width, height); im.writeImage(); } } @Override - public void showHelp_actionPerformed(ActionEvent actionEvent) + public void showHelp_actionPerformed() { try { @@ -640,12 +573,13 @@ public class AppJmol extends StructureViewerBase .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/"); } catch (Exception ex) { + System.err.println("Show Jmol help failed with: " + ex.getMessage()); } } + @Override public void showConsole(boolean showConsole) { - if (showConsole) { if (splitPane == null) @@ -706,12 +640,12 @@ public class AppJmol extends StructureViewerBase if (e == jmb.getPdbCount() - 1 || sb.length() > 20) { lines++; - g.drawString(sb.toString(), 20, currentSize.height / 2 - lines - * g.getFontMetrics().getHeight()); + g.drawString(sb.toString(), 20, currentSize.height / 2 + - lines * g.getFontMetrics().getHeight()); } } } - else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit()) + else if (jmb == null || jmb.jmolViewer == null || !jmb.isFinishedInit()) { g.setColor(Color.black); g.fillRect(0, 0, currentSize.width, currentSize.height); @@ -722,7 +656,7 @@ public class AppJmol extends StructureViewerBase } else { - jmb.viewer.renderScreenImage(g, currentSize.width, + jmb.jmolViewer.renderScreenImage(g, currentSize.width, currentSize.height); } } @@ -735,12 +669,6 @@ public class AppJmol extends StructureViewerBase } @Override - public String getStateInfo() - { - return jmb == null ? null : jmb.viewer.getStateInfo(); - } - - @Override public ViewerType getViewerType() { return ViewerType.JMOL;