files)
{
- jmb.closeViewer();
- // TODO: check for memory leaks where instance isn't finalised because jmb
- // holds a reference to the window
- jmb = null;
- }
+ long lastnotify = jmb.getLoadNotifiesHandled();
+ StringBuilder fileList = new StringBuilder();
+ for (String s : files)
+ {
+ fileList.append(SPACE).append(QUOTE)
+ .append(Platform.escapeBackslashes(s)).append(QUOTE);
+ }
+ String filesString = fileList.toString();
- public void run()
- {
- String pdbid = "";
- // todo - record which pdbids were successfuly imported.
- StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
- try
+ if (!addingStructures)
{
- // TODO: replace with reference fetching/transfer code (validate PDBentry
- // as a DBRef?)
- jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
- for (int pi = 0; pi < jmb.pdbentry.length; pi++)
+ try
{
- AlignmentI pdbseq;
- if ((pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
- .getId())) != null)
- {
- String file;
- // just transfer the file name from the first sequence's first
- // PDBEntry
- jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq.getSequenceAt(
- 0).getPDBId().elementAt(0)).getFile());
- files.append("\"" + file + "\"");
- }
- else
- {
- errormsgs.append("'" + pdbid + "' ");
- }
+ initJmol("load FILES " + filesString);
+ } catch (OutOfMemoryError oomerror)
+ {
+ new OOMWarning("When trying to open the Jmol viewer!", oomerror);
+ Console.debug("File locations are " + filesString);
+ } catch (Exception ex)
+ {
+ Console.error("Couldn't open Jmol viewer!", ex);
+ ex.printStackTrace();
+ return;
}
- } catch (OutOfMemoryError oomerror)
- {
- new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- errormsgs.append("'" + pdbid + "'");
}
- if (errormsgs.length() > 0)
+ else
{
+ StringBuilder cmd = new StringBuilder();
+ cmd.append("loadingJalviewdata=true\nload APPEND ");
+ cmd.append(filesString);
+ cmd.append("\nloadingJalviewdata=null");
+ final StructureCommand command = new StructureCommand(cmd.toString());
+ lastnotify = jmb.getLoadNotifiesHandled();
- JOptionPane.showInternalMessageDialog(Desktop.desktop,
- "The following pdb entries could not be retrieved from the PDB:\n"
- + errormsgs.toString()
- + "\nPlease try downloading them manually.",
- "Couldn't load file", JOptionPane.ERROR_MESSAGE);
-
- }
- if (files.length() > 0)
- {
try
{
- initJmol("load FILES " + files.toString());
+ jmb.executeCommand(command, false);
} catch (OutOfMemoryError oomerror)
{
- new OOMWarning("When trying to open the Jmol viewer!", oomerror);
- Cache.log.debug("File locations are " + files);
+ new OOMWarning("When trying to add structures to the Jmol viewer!",
+ oomerror);
+ Console.debug("File locations are " + filesString);
+ return;
} catch (Exception ex)
{
- Cache.log.error("Couldn't open Jmol viewer!", ex);
+ Console.error("Couldn't add files to Jmol viewer!", ex);
+ ex.printStackTrace();
+ return;
}
}
- }
-
- 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);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ // 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()))
{
try
{
- // TODO: cope with multiple PDB files in view
- BufferedReader in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
- File outFile = chooser.getSelectedFile();
+ Console.debug("Waiting around for jmb notify.");
+ waitTotal += waitFor;
- 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)
+ // Thread.sleep() throws an exception in JS
+ Thread.sleep(waitFor);
+ } catch (Exception e)
{
- ex.printStackTrace();
+ }
+ 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;
}
}
- }
- public void viewMapping_actionPerformed(ActionEvent actionEvent)
- {
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- try {for (int pdbe = 0; pdbe20)
+ 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.jmolViewer == 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(MessageManager.getString("label.retrieving_pdb_data"),
+ 20, currentSize.height / 2);
+ }
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("Retrieving PDB data....", 20, currentSize.height / 2);
- }
- else
{
- jmb.viewer.renderScreenImage(g, currentSize, rectClip);
+ jmb.jmolViewer.renderScreenImage(g, currentSize.width,
+ currentSize.height);
}
}
}
- String viewId = null;
-
- public String getViewId()
- {
- if (viewId == null)
- {
- viewId = System.currentTimeMillis() + "." + this.hashCode();
- }
- return viewId;
- }
- public void updateTitleAndMenus()
+ @Override
+ public AAStructureBindingModel getBinding()
{
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
- {
- repaint();
- return;
- }
- setChainMenuItems(jmb.chainNames);
- jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
-
- this.setTitle(jmb.getViewerTitle());
- if (jmb.getPdbFile().length>1 && jmb.sequence.length>1) {
- jmolActionMenu.setVisible(true);
- }
+ return this.jmb;
}
- /* (non-Javadoc)
- * @see jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event.ActionEvent)
- */
@Override
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
+ public ViewerType getViewerType()
{
-
- try {
- jmb.superposeStructures(ap.av.getAlignment(), -1, ap.av.getColumnSelection());
- } catch (Exception e)
- {
- Cache.log.info("Couldn't align structures in alignframe "+ap.alignFrame.getTitle(),e);
-
- }
+ return ViewerType.JMOL;
}
- public void setJalviewColourScheme(ColourSchemeI ucs)
+ @Override
+ protected String getViewerName()
{
- jmb.setJalviewColourScheme(ucs);
-
+ return "Jmol";
}
-
}