X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAppJmol.java;h=dcca874286f0cd78afc91108171a829c4d368fa0;hb=136c0793b90b72b928c4d77dc109dd5c644e00d3;hp=c082463c2d762b3d09734d040106582b2a0ad4f9;hpb=bc602371e44210748b5cb75e24afc14818f3e726;p=jalview.git diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index c082463..68a847e 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -1,906 +1,672 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program 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 2 + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ 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. - * - * This program 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. - * + * + * 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.gui; -import java.util.regex.*; -import java.util.*; -import java.awt.*; -import javax.swing.*; -import javax.swing.event.*; -import java.awt.event.*; -import java.io.*; - -import jalview.jbgui.GStructureViewer; -import jalview.datamodel.*; -import jalview.gui.*; -import jalview.structure.*; +import jalview.bin.Cache; +import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; -import jalview.io.*; -import jalview.schemes.*; - -import org.jmol.api.*; -import org.jmol.adapter.smarter.SmarterJmolAdapter; -import org.jmol.popup.*; - - -public class AppJmol - extends GStructureViewer - implements StructureListener, JmolStatusListener, Runnable - +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; + +public class AppJmol extends StructureViewerBase { - JmolViewer viewer; - JmolPopup jmolpopup; - ScriptWindow scriptWindow; - PDBEntry pdbentry; - SequenceI[] sequence; - String [] chains; - StructureSelectionManager ssm; - JSplitPane splitPane; - RenderPanel renderPanel; - AlignmentPanel ap; - String fileLoadingError; - boolean colourBySequence = true; - boolean loadingFromArchive = false; - Vector atomsPicked = new Vector(); - - public AppJmol(String file, String id, - SequenceI[] seq, - AlignmentPanel ap, - String loadStatus, - Rectangle bounds) - { - loadingFromArchive = true; - pdbentry = new PDBEntry(); - pdbentry.setFile(file); - pdbentry.setId(id); - this.chains = chains; - this.sequence = seq; - this.ap = ap; - this.setBounds(bounds); - - colourBySequence = false; - seqColour.setSelected(false); + // ms to wait for Jmol to load files + private static final int JMOL_LOAD_TIMEOUT = 20000; - jalview.gui.Desktop.addInternalFrame(this, "Loading File", - bounds.width,bounds.height); + private static final String SPACE = " "; - initJmol(loadStatus); + private static final String BACKSLASH = "\""; - this.addInternalFrameListener(new InternalFrameAdapter() - { - public void internalFrameClosing(InternalFrameEvent internalFrameEvent) - { - closeViewer(); - } - }); - } + AppJmolBinding jmb; -public synchronized void addSequence(SequenceI [] seq) - { - Vector v = new Vector(); - for(int i=0; i 0) - cmd.setLength(cmd.length() - 4); - - viewer.evalStringQuiet("select *;restrict " - +cmd+";cartoon;center "+cmd); + /* + * If the options above are declined or do not apply, open a new viewer + */ + openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq }); } - void closeViewer() + private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, + SequenceI[][] seqs) { - viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE); - viewer.evalStringQuiet("zap"); - viewer.setJmolStatusListener(null); - viewer = null; - - //We'll need to find out what other - // listeners need to be shut down in Jmol - StructureSelectionManager - .getStructureSelectionManager() - .removeStructureViewerListener(this, pdbentry.getFile()); - } + progressBar = ap.alignFrame; + jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), + pdbentrys, seqs, null); + addAlignmentPanel(ap); + useAlignmentPanelForColourbyseq(ap); - public void run() - { - try + if (pdbentrys.length > 1) { - EBIFetchClient ebi = new EBIFetchClient(); - String query = "pdb:" + pdbentry.getId(); - pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw") - .getAbsolutePath()); - initJmol("load "+pdbentry.getFile()); + alignAddedStructures = true; + useAlignmentPanelForSuperposition(ap); } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - public void pdbFile_actionPerformed(ActionEvent actionEvent) - { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty( - "LAST_DIRECTORY")); - - chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle("Save PDB File"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); + jmb.setColourBySequence(true); + setSize(400, 400); // probably should be a configurable/dynamic default here + initMenus(); + addingStructures = false; + worker = new Thread(this); + worker.start(); - if (value == JalviewFileChooser.APPROVE_OPTION) + this.addInternalFrameListener(new InternalFrameAdapter() { - try - { - BufferedReader in = new BufferedReader(new FileReader(pdbentry.getFile())); - File outFile = chooser.getSelectedFile(); - - PrintWriter out = new PrintWriter(new FileOutputStream(outFile)); - String data; - while ( (data = in.readLine()) != null) - { - if ( - ! (data.indexOf("
") > -1 || data.indexOf("
") > -1) - ) - { - out.println(data); - } - } - out.close(); - } - catch (Exception ex) + @Override + public void internalFrameClosing(InternalFrameEvent internalFrameEvent) { - ex.printStackTrace(); + closeViewer(false); } - } - } + }); - public void viewMapping_actionPerformed(ActionEvent actionEvent) - { - jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); - jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, - 600); - cap.setText( - StructureSelectionManager.getStructureSelectionManager().printMapping( - pdbentry.getFile()) - ); } /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * create a new Jmol containing several structures superimposed using the + * given alignPanel. + * + * @param ap + * @param pe + * @param seqs */ - public void eps_actionPerformed(ActionEvent e) + public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs) { - makePDBImage(jalview.util.ImageMaker.EPS); + openNewJmol(ap, pe, seqs); } /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * Returns a list of any Jmol viewers. The list is restricted to those linked + * to the given alignment panel if it is not null. */ - public void png_actionPerformed(ActionEvent e) - { - makePDBImage(jalview.util.ImageMaker.PNG); - } - - void makePDBImage(int type) + @Override + protected List getViewersFor(AlignmentPanel apanel) { - int width = getWidth(); - int height = getHeight(); - - jalview.util.ImageMaker im; + List result = new ArrayList(); + JInternalFrame[] frames = Desktop.instance.getAllFrames(); - if (type == jalview.util.ImageMaker.PNG) + for (JInternalFrame frame : frames) { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.PNG, - "Make PNG image from view", - width, height, - null, null); + if (frame instanceof AppJmol) + { + if (apanel == null + || ((StructureViewerBase) frame).isLinkedWith(apanel)) + { + result.add((StructureViewerBase) frame); + } + } } - else + return result; + } + + void initJmol(String command) + { + jmb.setFinishedInit(false); + renderPanel = new RenderPanel(); + // TODO: consider waiting until the structure/view is fully loaded before + // displaying + this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER); + jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(), + getBounds().width, getBounds().height); + if (scriptWindow == null) { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.EPS, - "Make EPS file from view", - width, height, - null, this.getTitle()); + BorderLayout bl = new BorderLayout(); + bl.setHgap(0); + bl.setVgap(0); + scriptWindow = new JPanel(bl); + scriptWindow.setVisible(false); } - if (im.getGraphics() != null) + jmb.allocateViewer(renderPanel, true, "", null, null, "", + scriptWindow, null); + // jmb.newJmolPopup("Jmol"); + if (command == null) { - Rectangle rect = new Rectangle(width, height); - viewer.renderScreenImage(im.getGraphics(), - rect.getSize(), rect); - im.writeImage(); + command = ""; } + jmb.evalStateCommand(command); + jmb.evalStateCommand("set hoverDelay=0.1"); + jmb.setFinishedInit(true); } - public void seqColour_actionPerformed(ActionEvent actionEvent) - { - lastCommand = null; - colourBySequence = seqColour.isSelected(); - colourBySequence(ap.alignFrame.alignPanel); - } - - public void chainColour_actionPerformed(ActionEvent actionEvent) - { - colourBySequence = false; - seqColour.setSelected(false); - viewer.evalStringQuiet("select *;color chain"); - } - - public void chargeColour_actionPerformed(ActionEvent actionEvent) - { - colourBySequence = false; - seqColour.setSelected(false); - viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;" - +"select LYS,ARG;color blue;select CYS;color yellow"); - } - - public void zappoColour_actionPerformed(ActionEvent actionEvent) - { - setJalviewColourScheme(new ZappoColourScheme()); - } - - public void taylorColour_actionPerformed(ActionEvent actionEvent) - { - setJalviewColourScheme(new TaylorColourScheme()); - } - public void hydroColour_actionPerformed(ActionEvent actionEvent) - { - setJalviewColourScheme(new HydrophobicColourScheme()); - } - - public void helixColour_actionPerformed(ActionEvent actionEvent) - { - setJalviewColourScheme(new HelixColourScheme()); - } - - public void strandColour_actionPerformed(ActionEvent actionEvent) - { - setJalviewColourScheme(new StrandColourScheme()); - } - - public void turnColour_actionPerformed(ActionEvent actionEvent) - { - setJalviewColourScheme(new TurnColourScheme()); - } - - public void buriedColour_actionPerformed(ActionEvent actionEvent) - { - setJalviewColourScheme(new BuriedColourScheme()); - } + boolean allChainsSelected = false; - public void setJalviewColourScheme(ColourSchemeI cs) + @Override + void showSelectedChains() { - colourBySequence = false; - seqColour.setSelected(false); - - if(cs==null) - return; - - String res; - int index; - Color col; - - Enumeration en = ResidueProperties.aa3Hash.keys(); - StringBuffer command = new StringBuffer("select *;color white;"); - while(en.hasMoreElements()) + Vector toshow = new Vector(); + for (int i = 0; i < chainMenu.getItemCount(); i++) { - res = en.nextElement().toString(); - index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue(); - if(index>20) - continue; - - col = cs.findColour(ResidueProperties.aa[index].charAt(0)); - - command.append("select "+res+";color[" - + col.getRed() + "," - + col.getGreen() + "," - + col.getBlue() + "];"); + if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem) + { + JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i); + if (item.isSelected()) + { + toshow.addElement(item.getText()); + } + } } - - viewer.evalStringQuiet(command.toString()); - } - - public void userColour_actionPerformed(ActionEvent actionEvent) - { - new UserDefinedColours(this, null); + jmb.centerViewer(toshow); } - public void backGround_actionPerformed(ActionEvent actionEvent) + @Override + public void closeViewer(boolean closeExternalViewer) { - java.awt.Color col = JColorChooser.showDialog(this, - "Select Background Colour", - null); - - if (col != null) + // Jmol does not use an external viewer + if (jmb != null) { - viewer.evalStringQuiet("background [" - + col.getRed() + "," - + col.getGreen() + "," - + col.getBlue() + "];"); + jmb.closeViewer(); } + setAlignmentPanel(null); + _aps.clear(); + _alignwith.clear(); + _colourwith.clear(); + // TODO: check for memory leaks where instance isn't finalised because jmb + // holds a reference to the window + jmb = null; } - - public void jmolHelp_actionPerformed(ActionEvent actionEvent) - { - try{ - jalview.util.BrowserLauncher.openURL( - "http://jmol.sourceforge.net/docs/JmolUserGuide/"); - }catch(Exception ex){} - } - - - ////////////////////////////////// - ///StructureListener - public String getPdbFile() + @Override + public void run() { - return pdbentry.getFile(); + _started = true; + try + { + List files = fetchPdbFiles(); + if (files.size() > 0) + { + showFilesInViewer(files); + } + } finally + { + _started = false; + worker = null; + } } - Pattern pattern = Pattern.compile( - "\\[(.*)\\]([0-9]+)(:[a-zA-Z]*)?\\.([a-zA-Z]+)(/[0-9]*)?" - ); - - String lastMessage; - public void mouseOverStructure(int atomIndex, String strInfo) + /** + * Either adds the given files to a structure viewer or opens a new viewer to + * show them + * + * @param files + * list of absolute paths to structure files + */ + void showFilesInViewer(List files) { - Matcher matcher = pattern.matcher(strInfo); - matcher.find(); - matcher.group(1); - int pdbResNum = Integer.parseInt(matcher.group(2)); - String chainId = matcher.group(3); - - if (chainId != null) - chainId = chainId.substring(1, chainId.length()); - else + long lastnotify = jmb.getLoadNotifiesHandled(); + StringBuilder fileList = new StringBuilder(); + for (String s : files) { - chainId = " "; + fileList.append(SPACE).append(BACKSLASH) + .append(Platform.escapeString(s)).append(BACKSLASH); } + String filesString = fileList.toString(); - if (lastMessage == null || !lastMessage.equals(strInfo)) + if (!addingStructures) { - ssm.mouseOverStructure(pdbResNum, chainId, pdbentry.getFile()); + try + { + initJmol("load FILES " + filesString); + } catch (OutOfMemoryError oomerror) + { + new OOMWarning("When trying to open the Jmol viewer!", oomerror); + Cache.log.debug("File locations are " + filesString); + } catch (Exception ex) + { + Cache.log.error("Couldn't open Jmol viewer!", ex); + } } - lastMessage = strInfo; - } - - StringBuffer resetLastRes = new StringBuffer(); - StringBuffer eval = new StringBuffer(); + else + { + StringBuilder cmd = new StringBuilder(); + cmd.append("loadingJalviewdata=true\nload APPEND "); + cmd.append(filesString); + cmd.append("\nloadingJalviewdata=null"); + final String command = cmd.toString(); + lastnotify = jmb.getLoadNotifiesHandled(); - public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile) - { - if (!pdbfile.equals(pdbentry.getFile())) - return; + try + { + jmb.evalStateCommand(command); + } catch (OutOfMemoryError oomerror) + { + new OOMWarning("When trying to add structures to the Jmol viewer!", + oomerror); + Cache.log.debug("File locations are " + filesString); + } catch (Exception ex) + { + Cache.log.error("Couldn't add files to Jmol viewer!", ex); + } + } - if (resetLastRes.length() > 0) + // need to wait around until script has finished + int waitMax = JMOL_LOAD_TIMEOUT; + int waitFor = 35; + int waitTotal = 0; + while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled() + : !(jmb.isFinishedInit() && jmb.getStructureFiles() != null && jmb + .getStructureFiles().length == files.size())) { - viewer.evalStringQuiet(resetLastRes.toString()); + try + { + Cache.log.debug("Waiting around for jmb notify."); + Thread.sleep(waitFor); + waitTotal += waitFor; + } catch (Exception e) + { + } + 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.getStructureFiles(); + break; + } } - eval.setLength(0); - eval.append("select " + pdbResNum); - - resetLastRes.setLength(0); - resetLastRes.append("select " + pdbResNum); - - if (!chain.equals(" ")) + // refresh the sequence colours for the new structure(s) + for (AlignmentPanel ap : _colourwith) { - eval.append(":" + chain); - resetLastRes.append(":" + chain); + jmb.updateColours(ap); } - - eval.append(";wireframe 100;"+eval.toString()+".CA;"); - - resetLastRes.append(";wireframe 0;"+resetLastRes.toString()+".CA;spacefill 0;"); - - eval.append("spacefill 200;select none"); - - viewer.evalStringQuiet(eval.toString()); - } - - public Color getColour(int atomIndex, int pdbResNum, String chain, String pdbfile) - { - if (!pdbfile.equals(pdbentry.getFile())) - return null; - - return new Color(viewer.getAtomArgb(atomIndex)); - } - - public void updateColours(Object source) - { - colourBySequence( (AlignmentPanel) source); + // do superposition if asked to + if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures) + { + alignAddedStructures(); + } + addingStructures = false; } - -//End StructureListener -//////////////////////////// - - String lastCommand; - FeatureRenderer fr=null; - public void colourBySequence(AlignmentPanel sourceap) + /** + * Queues a thread to align structures with Jalview alignments + */ + void alignAddedStructures() { - this.ap = sourceap; - - if(!colourBySequence || ap.alignFrame.getCurrentView()!=ap.av) - return; - - StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile()); - - if (mapping.length < 1) - return; - - - SequenceRenderer sr = new SequenceRenderer(ap.av); - - boolean showFeatures = false; - - if (ap.av.showSequenceFeatures) + javax.swing.SwingUtilities.invokeLater(new Runnable() { - showFeatures = true; - if (fr == null) + @Override + public void run() { - fr = new jalview.gui.FeatureRenderer(ap); + if (jmb.viewer.isScriptExecuting()) + { + SwingUtilities.invokeLater(this); + try + { + Thread.sleep(5); + } catch (InterruptedException q) + { + } + return; + } + else + { + alignStructs_withAllAlignPanels(); + } } + }); + alignAddedStructures = false; + } - fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer()); - } - - StringBuffer command = new StringBuffer(); + /** + * Retrieves and saves as file any modelled PDB entries for which we do not + * already have a file saved. Returns a list of absolute paths to structure + * files which were either retrieved, or already stored but not modelled in + * the structure viewer (i.e. files to add to the viewer display). + * + * @return + */ + List fetchPdbFiles() + { + // todo - record which pdbids were successfully imported. + StringBuilder errormsgs = new StringBuilder(); - int lastPos = -1; - for (int s = 0; s < sequence.length; s++) + List files = new ArrayList(); + String pdbid = ""; + try { - for (int m = 0; m < mapping.length; m++) + String[] filesInViewer = jmb.getStructureFiles(); + // TODO: replace with reference fetching/transfer code (validate PDBentry + // as a DBRef?) + Pdb pdbclient = new Pdb(); + for (int pi = 0; pi < jmb.getPdbCount(); pi++) { - if (mapping[m].getSequence() == sequence[s] - && ap.av.alignment.findIndex(sequence[s])>-1) + String file = jmb.getPdbEntry(pi).getFile(); + if (file == null) { - for (int r = 0; r < sequence[s].getLength(); r++) + // retrieve the pdb and store it locally + AlignmentI pdbseq = null; + pdbid = jmb.getPdbEntry(pi).getId(); + long hdl = pdbid.hashCode() - System.currentTimeMillis(); + if (progressBar != null) { - int pos = mapping[m].getPDBResNum( - sequence[s].findPosition(r)); - - if (pos < 1 || pos==lastPos) - continue; - - lastPos = pos; - - Color col = sr.getResidueBoxColour(sequence[s], r); - - if (showFeatures) - col = fr.findFeatureColour(col, sequence[s], r); - - if (command.toString().endsWith(":" + mapping[m].getChain()+ - ";color[" - + col.getRed() + "," - + col.getGreen() + "," - + col.getBlue() + "]")) + progressBar.setProgressBar(MessageManager.formatMessage( + "status.fetching_pdb", new String[] { pdbid }), hdl); + } + try + { + pdbseq = pdbclient.getSequenceRecords(pdbid); + } catch (OutOfMemoryError oomerror) + { + new OOMWarning("Retrieving PDB id " + pdbid, oomerror); + } catch (Exception ex) + { + ex.printStackTrace(); + errormsgs.append("'").append(pdbid).append("'"); + } finally + { + if (progressBar != null) { - command = condenseCommand(command, pos); - continue; + progressBar.setProgressBar( + MessageManager.getString("label.state_completed"), + hdl); } - - command.append(";select " + pos); - - if (!mapping[m].getChain().equals(" ")) + } + if (pdbseq != null) + { + // just transfer the file name from the first sequence's first + // PDBEntry + file = new File(pdbseq.getSequenceAt(0).getAllPDBEntries() + .elementAt(0).getFile()).getAbsolutePath(); + jmb.getPdbEntry(pi).setFile(file); + files.add(file); + } + else + { + errormsgs.append("'").append(pdbid).append("' "); + } + } + else + { + if (filesInViewer != null && filesInViewer.length > 0) + { + addingStructures = true; // already files loaded. + for (int c = 0; c < filesInViewer.length; c++) { - command.append(":" + mapping[m].getChain()); + if (filesInViewer[c].equals(file)) + { + file = null; + break; + } } - - command.append(";color[" - + col.getRed() + "," - + col.getGreen() + "," - + col.getBlue() + "]"); - } - break; + if (file != null) + { + files.add(file); + } } } - } - - if (lastCommand == null || !lastCommand.equals(command.toString())) + } catch (OutOfMemoryError oomerror) { - viewer.evalStringQuiet(command.toString()); - } - lastCommand = command.toString(); - } - - StringBuffer condenseCommand(StringBuffer command, int pos) - { - StringBuffer sb = new StringBuffer(command.substring(0, command.lastIndexOf("select")+7)); - - command.delete(0, sb.length()); - - String start; - - if (command.indexOf("-") > -1) + new OOMWarning("Retrieving PDB files: " + pdbid, oomerror); + } catch (Exception ex) { - start = command.substring(0,command.indexOf("-")); + ex.printStackTrace(); + errormsgs.append("When retrieving pdbfiles : current was: '") + .append(pdbid).append("'"); } - else + if (errormsgs.length() > 0) { - start = command.substring(0, command.indexOf(":")); + 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); } - - sb.append(start+"-"+pos+command.substring(command.indexOf(":"))); - - return sb; + return files; } - ///////////////////////////////// - //JmolStatusListener - - public String eval(String strEval) + @Override + public void eps_actionPerformed(ActionEvent e) { - // System.out.println(strEval); - //"# 'eval' is implemented only for the applet."; - return null; + makePDBImage(jalview.util.ImageMaker.TYPE.EPS); } - public void createImage(String file, String type, int quality) + @Override + public void png_actionPerformed(ActionEvent e) { - System.out.println("JMOL CREATE IMAGE"); + makePDBImage(jalview.util.ImageMaker.TYPE.PNG); } - public void setCallbackFunction(String callbackType, - String callbackFunction) - {} - - public void notifyFileLoaded(String fullPathName, String fileName, - String modelName, Object clientFile, - String errorMsg) + void makePDBImage(jalview.util.ImageMaker.TYPE type) { - if(errorMsg!=null) - { - fileLoadingError = errorMsg; - repaint(); - return; - } + int width = getWidth(); + int height = getHeight(); - fileLoadingError = null; + jalview.util.ImageMaker im; - if (fileName != null) + if (type == jalview.util.ImageMaker.TYPE.PNG) { - - //FILE LOADED OK - ssm = StructureSelectionManager.getStructureSelectionManager(); - MCview.PDBfile pdbFile = ssm.setMapping(sequence,chains,pdbentry.getFile(), AppletFormatAdapter.FILE); - ssm.addStructureViewerListener(this); - Vector chains = new Vector(); - for(int i=0; i 20) + { + lines++; + g.drawString(sb.toString(), 20, currentSize.height / 2 - lines + * g.getFontMetrics().getHeight()); + } + } } - else if(fileLoadingError!=null) + else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit()) { g.setColor(Color.black); g.fillRect(0, 0, currentSize.width, currentSize.height); g.setColor(Color.white); g.setFont(new Font("Verdana", Font.BOLD, 14)); - g.drawString("Error loading file..." + pdbentry.getId(), 20, - currentSize.height / 2); + g.drawString(MessageManager.getString("label.retrieving_pdb_data"), + 20, currentSize.height / 2); } else { - viewer.renderScreenImage(g, currentSize, rectClip); + jmb.viewer.renderScreenImage(g, currentSize.width, + currentSize.height); } } } + @Override + public AAStructureBindingModel getBinding() + { + return this.jmb; + } + + @Override + public String getStateInfo() + { + return jmb == null ? null : jmb.viewer.getStateInfo(); + } + + @Override + public ViewerType getViewerType() + { + return ViewerType.JMOL; + } + + @Override + protected String getViewerName() + { + return "Jmol"; + } }