files)
{
- _started = true;
- String pdbid = "";
- // todo - record which pdbids were successfuly imported.
- StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
- try
- {
- String[] curfiles = jmb.getPdbFile(); // files currently in viewer
- // 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++)
- {
- String file = jmb.pdbentry[pi].getFile();
- if (file == null)
- {
- // retrieve the pdb and store it locally
- AlignmentI pdbseq = null;
- pdbid = jmb.pdbentry[pi].getId();
- long hdl=pdbid.hashCode()-System.currentTimeMillis();
- if (progressBar != null)
- {
- progressBar.setProgressBar("Fetching PDB " + pdbid,
- hdl);
- }
- try
- {
- pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
- .getId());
- } catch (OutOfMemoryError oomerror)
- {
- new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- errormsgs.append("'" + pdbid + "'");
- }
- if (progressBar != null)
- {
- progressBar.setProgressBar("Finished.", hdl);
- }
- if (pdbseq != null)
- {
- // 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 + "' ");
- }
- }
- else
- {
- if (curfiles != null && curfiles.length > 0)
- {
- addingStructures = true; // already files loaded.
- for (int c = 0; c < curfiles.length; c++)
- {
- if (curfiles[c].equals(file))
- {
- file = null;
- break;
- }
- }
- }
- if (file != null)
- {
- files.append(" \"" + file + "\"");
- }
- }
- }
- } catch (OutOfMemoryError oomerror)
- {
- new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
- } catch (Exception ex)
+ long lastnotify = jmb.getLoadNotifiesHandled();
+ StringBuilder fileList = new StringBuilder();
+ for (String s : files)
{
- ex.printStackTrace();
- errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
- + "'");
+ fileList.append(SPACE).append(QUOTE)
+ .append(Platform.escapeBackslashes(s)).append(QUOTE);
}
- if (errormsgs.length() > 0)
- {
-
- 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);
+ String filesString = fileList.toString();
- }
- if (files.length() > 0)
+ if (!addingStructures)
{
- if (!addingStructures)
+ try
{
-
- try
- {
- initJmol("load FILES " + files.toString());
- } catch (OutOfMemoryError oomerror)
- {
- new OOMWarning("When trying to open the Jmol viewer!", oomerror);
- Cache.log.debug("File locations are " + files);
- } catch (Exception ex)
- {
- Cache.log.error("Couldn't open Jmol viewer!", ex);
- }
- }
- else
+ initJmol("load FILES " + filesString);
+ } catch (OutOfMemoryError oomerror)
{
- StringBuffer cmd = new StringBuffer();
- cmd.append("loadingJalviewdata=true\nload APPEND ");
- cmd.append(files.toString());
- cmd.append("\nloadingJalviewdata=null");
- final String command = cmd.toString();
- cmd = null;
- 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 " + files);
- } catch (Exception ex)
- {
- Cache.log.error("Couldn't add files to Jmol viewer!", ex);
- }
- long lastnotify=jmb.getLoadNotifiesHandled();
- // need to wait around until script has finished
- while (lastnotify>=jmb.getLoadNotifiesHandled());
- {
- try
- {
- Thread.sleep(35);
- } catch (Exception e)
- {
- }
- }
- // refresh the sequence colours for the new structure(s)
- jmb.updateColours(ap);
- // do superposition if asked to
- if (alignAddedStructures)
- {
- javax.swing.SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- jmb.superposeStructures(ap.av.getAlignment(), -1, null);
- }
- });
- alignAddedStructures = false;
- }
- addingStructures = false;
+ 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;
}
}
- _started = false;
- worker = null;
- }
-
- 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)
+ 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();
+
try
{
- // TODO: cope with multiple PDB files in view
- BufferedReader in = new BufferedReader(new FileReader(
- jmb.getPdbFile()[0]));
- 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();
+ jmb.executeCommand(command, false);
+ } catch (OutOfMemoryError oomerror)
+ {
+ new OOMWarning("When trying to add structures to the Jmol viewer!",
+ oomerror);
+ Console.debug("File locations are " + filesString);
+ return;
} catch (Exception ex)
{
+ Console.error("Couldn't add files to Jmol viewer!", ex);
ex.printStackTrace();
+ return;
}
}
- }
- public void viewMapping_actionPerformed(ActionEvent actionEvent)
- {
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- try
+ // 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()))
{
- for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
+ try
+ {
+ Console.debug("Waiting around for jmb notify.");
+ waitTotal += waitFor;
+
+ // Thread.sleep() throws an exception in JS
+ Thread.sleep(waitFor);
+ } catch (Exception e)
+ {
+ }
+ if (waitTotal > waitMax)
{
- cap.appendText(StructureSelectionManager
- .getStructureSelectionManager().printMapping(
- jmb.pdbentry[pdbe].getFile()));
- cap.appendText("\n");
+ 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;
}
- } catch (OutOfMemoryError e)
+ }
+
+ // refresh the sequence colours for the new structure(s)
+ for (AlignmentViewPanel ap : _colourwith)
{
- new OOMWarning(
- "composing sequence-structure alignments for display in text box.",
- e);
- cap.dispose();
- return;
+ jmb.updateColours(ap);
}
- jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
- 550, 600);
+ // do superposition if asked to
+ if (alignAddedStructures)
+ {
+ alignAddedStructures();
+ }
+ addingStructures = false;
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Queues a thread to align structures with Jalview alignments
*/
- public void eps_actionPerformed(ActionEvent e)
+ void alignAddedStructures()
{
- makePDBImage(jalview.util.ImageMaker.EPS);
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ if (jmb.jmolViewer.isScriptExecuting())
+ {
+ SwingUtilities.invokeLater(this);
+ try
+ {
+ Thread.sleep(5);
+ } catch (InterruptedException q)
+ {
+ }
+ return;
+ }
+ else
+ {
+ alignStructsWithAllAlignPanels();
+ }
+ }
+ });
+
}
/**
- * DOCUMENT ME!
+ * Outputs the Jmol viewer image as an image file, after prompting the user to
+ * choose a file and (for EPS) choice of Text or Lineart character rendering
+ * (unless a preference for this is set)
*
- * @param e
- * DOCUMENT ME!
+ * @param type
*/
- public void png_actionPerformed(ActionEvent e)
- {
- makePDBImage(jalview.util.ImageMaker.PNG);
- }
-
- void makePDBImage(int type)
+ @Override
+ public void makePDBImage(ImageMaker.TYPE type)
{
int width = getWidth();
int height = getHeight();
-
- jalview.util.ImageMaker im;
-
- if (type == jalview.util.ImageMaker.PNG)
+ ImageWriterI writer = new ImageWriterI()
{
- im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
- "Make PNG image from view", width, height, null, null);
- }
- else
- {
- im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
- "Make EPS file from view", width, height, null,
- this.getTitle());
- }
-
- if (im.getGraphics() != null)
- {
- Rectangle rect = new Rectangle(width, height);
- jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
- im.writeImage();
- }
- }
-
- public void seqColour_actionPerformed(ActionEvent actionEvent)
- {
- jmb.setColourBySequence(seqColour.isSelected());
- // Set the colour using the current view for the associated alignframe
- jmb.colourBySequence(ap.alignFrame.viewport.showSequenceFeatures,
- ap.alignFrame.viewport.alignment);
- }
-
- public void chainColour_actionPerformed(ActionEvent actionEvent)
- {
- chainColour.setSelected(true);
- jmb.colourByChain();
- }
-
- public void chargeColour_actionPerformed(ActionEvent actionEvent)
- {
- chargeColour.setSelected(true);
- jmb.colourByCharge();
- }
-
- public void zappoColour_actionPerformed(ActionEvent actionEvent)
- {
- zappoColour.setSelected(true);
- jmb.setJalviewColourScheme(new ZappoColourScheme());
- }
-
- public void taylorColour_actionPerformed(ActionEvent actionEvent)
- {
- taylorColour.setSelected(true);
- jmb.setJalviewColourScheme(new TaylorColourScheme());
- }
-
- public void hydroColour_actionPerformed(ActionEvent actionEvent)
- {
- hydroColour.setSelected(true);
- jmb.setJalviewColourScheme(new HydrophobicColourScheme());
- }
-
- public void helixColour_actionPerformed(ActionEvent actionEvent)
- {
- helixColour.setSelected(true);
- jmb.setJalviewColourScheme(new HelixColourScheme());
- }
-
- public void strandColour_actionPerformed(ActionEvent actionEvent)
- {
- strandColour.setSelected(true);
- jmb.setJalviewColourScheme(new StrandColourScheme());
- }
-
- public void turnColour_actionPerformed(ActionEvent actionEvent)
- {
- turnColour.setSelected(true);
- jmb.setJalviewColourScheme(new TurnColourScheme());
- }
-
- public void buriedColour_actionPerformed(ActionEvent actionEvent)
- {
- buriedColour.setSelected(true);
- jmb.setJalviewColourScheme(new BuriedColourScheme());
- }
-
- public void userColour_actionPerformed(ActionEvent actionEvent)
- {
- userColour.setSelected(true);
- new UserDefinedColours(this, null);
- }
-
- public void backGround_actionPerformed(ActionEvent actionEvent)
- {
- java.awt.Color col = JColorChooser.showDialog(this,
- "Select Background Colour", null);
- if (col != null)
- {
- jmb.setBackgroundColour(col);
- }
+ @Override
+ public void exportImage(Graphics g) throws Exception
+ {
+ jmb.jmolViewer.renderScreenImage(g, width, height);
+ }
+ };
+ String view = MessageManager.getString("action.view")
+ .toLowerCase(Locale.ROOT);
+ ImageExporter exporter = new ImageExporter(writer,
+ getProgressIndicator(), type, getTitle());
+ exporter.doExport(null, this, width, height, view);
}
- public void jmolHelp_actionPerformed(ActionEvent actionEvent)
+ @Override
+ public void showHelp_actionPerformed()
{
try
{
- jalview.util.BrowserLauncher
- .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
+ BrowserLauncher // BH 2018
+ .openURL("http://wiki.jmol.org");// http://jmol.sourceforge.net/docs/JmolUserGuide/");
} catch (Exception ex)
{
+ System.err.println("Show Jmol help failed with: " + ex.getMessage());
}
}
-public void showConsole(boolean showConsole)
+
+ @Override
+ public void showConsole(boolean showConsole)
{
if (showConsole)
@@ -808,9 +474,9 @@ public void showConsole(boolean showConsole)
else
{
if (splitPane != null)
- {
- splitPane.setVisible(false);
- }
+ {
+ splitPane.setVisible(false);
+ }
splitPane = null;
@@ -819,112 +485,75 @@ public void showConsole(boolean showConsole)
validate();
}
+
class RenderPanel extends JPanel
{
final Dimension currentSize = new Dimension();
- final Rectangle rectClip = new Rectangle();
-
+ @Override
public void paintComponent(Graphics g)
{
getSize(currentSize);
- g.getClipBounds(rectClip);
- if (jmb.fileLoadingError != null)
+ if (jmb != null && jmb.hasFileLoadingError())
{
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...", 20, currentSize.height / 2);
+ g.drawString(MessageManager.getString("label.error_loading_file")
+ + "...", 20, currentSize.height / 2);
StringBuffer sb = new StringBuffer();
int lines = 0;
- for (int e = 0; e < jmb.pdbentry.length; e++)
+ for (int e = 0; e < jmb.getPdbCount(); e++)
{
- sb.append(jmb.pdbentry[e].getId());
- if (e < jmb.pdbentry.length - 1)
+ sb.append(jmb.getPdbEntry(e).getId());
+ if (e < jmb.getPdbCount() - 1)
{
sb.append(",");
}
- if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
+ 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);
g.setColor(Color.white);
g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
+ g.drawString(MessageManager.getString("label.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";
}
-
}