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)
- {
+ String filesString = fileList.toString();
- 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);
-
- }
- long lastnotify = jmb.getLoadNotifiesHandled();
- 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;
- lastnotify = jmb.getLoadNotifiesHandled();
-
- 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);
- }
- }
-
- // need to wait around until script has finished
- while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
- : (jmb.isFinishedInit() && jmb.getPdbFile().length!=jmb.pdbentry.length))
+ new OOMWarning("When trying to open the Jmol viewer!", oomerror);
+ Console.debug("File locations are " + filesString);
+ } catch (Exception ex)
{
- try
- {
- Cache.log.debug("Waiting around for jmb notify.");
- Thread.sleep(35);
- } catch (Exception e)
- {
- }
+ Console.error("Couldn't open Jmol viewer!", ex);
+ ex.printStackTrace();
+ return;
}
- // refresh the sequence colours for the new structure(s)
- for (AlignmentPanel ap : _colourwith)
+ }
+ 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
{
- jmb.updateColours(ap);
- }
- // do superposition if asked to
- if (alignAddedStructures)
+ jmb.executeCommand(command, false);
+ } catch (OutOfMemoryError oomerror)
{
- javax.swing.SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- alignStructs_withAllAlignPanels();
- // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
- }
- });
- alignAddedStructures = false;
+ 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;
}
- addingStructures = false;
-
}
- _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)
+ // 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
+ // refresh the sequence colours for the new structure(s)
+ for (AlignmentViewPanel ap : _colourwith)
{
- for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
- {
- cap.appendText(jmb.printMapping(
- jmb.pdbentry[pdbe].getFile()));
- cap.appendText("\n");
- }
- } catch (OutOfMemoryError e)
+ jmb.updateColours(ap);
+ }
+ // do superposition if asked to
+ if (alignAddedStructures)
{
- new OOMWarning(
- "composing sequence-structure alignments for display in text box.",
- e);
- cap.dispose();
- return;
+ alignAddedStructures();
}
- jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
- 550, 600);
+ 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 jmolColour_actionPerformed(ActionEvent actionEvent)
- {
- if (jmolColour.isSelected()) {
- // disable automatic sequence colouring.
- jmb.setColourBySequence(false);
- }
- }
- public void seqColour_actionPerformed(ActionEvent actionEvent)
- {
- jmb.setColourBySequence(seqColour.isSelected());
- if (_colourwith == null)
- {
- _colourwith = new Vector();
- }
- if (jmb.isColourBySequence())
- {
- if (!jmb.isLoadingFromArchive())
- {
- if (_colourwith.size()==0 && ap!=null) {
- // Make the currently displayed alignment panel the associated view
- _colourwith.add(ap.alignFrame.alignPanel);
- }
- }
- // Set the colour using the current view for the associated alignframe
- for (AlignmentPanel ap : _colourwith)
+ @Override
+ public void exportImage(Graphics g) throws Exception
{
- jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
+ 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 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 purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
- {
- setJalviewColourScheme(new PurinePyrimidineColourScheme());
- }
-
- 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);
- }
- }
-
- 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());
}
}
+ @Override
public void showConsole(boolean showConsole)
{
-
if (showConsole)
{
if (splitPane == null)
@@ -1126,211 +491,70 @@ public class AppJmol extends GStructureViewer implements Runnable,
{
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()
- {
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
- {
- repaint();
- return;
- }
- setChainMenuItems(jmb.chainNames);
-
- this.setTitle(jmb.getViewerTitle());
- if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
- {
- jmolActionMenu.setVisible(true);
- }
- if (!jmb.isLoadingFromArchive())
- {
- seqColour_actionPerformed(null);
- }
- }
-
- protected void buildJmolActionMenu()
- {
- if (_alignwith == null)
- {
- _alignwith = new Vector();
- }
- if (_alignwith.size() == 0 && ap != null)
- {
- _alignwith.add(ap);
- }
- ;
- for (Component c : jmolActionMenu.getMenuComponents())
- {
- if (c != alignStructs)
- {
- jmolActionMenu.remove((JMenuItem) c);
- }
- }
- final ItemListener handler;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
- * .ActionEvent)
- */
@Override
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
- {
- alignStructs_withAllAlignPanels();
- }
-
- private void alignStructs_withAllAlignPanels()
- {
- if (ap == null)
- {
- return;
- }
- ;
- if (_alignwith.size() == 0)
- {
- _alignwith.add(ap);
- }
- ;
- try
- {
- AlignmentI[] als = new Alignment[_alignwith.size()];
- ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
- int[] alm = new int[_alignwith.size()];
- int a = 0;
-
- for (AlignmentPanel ap : _alignwith)
- {
- als[a] = ap.av.getAlignment();
- alm[a] = -1;
- alc[a++] = ap.av.getColumnSelection();
- }
- jmb.superposeStructures(als, alm, alc);
- } catch (Exception e)
- {
- StringBuffer sp = new StringBuffer();
- for (AlignmentPanel ap : _alignwith)
- {
- sp.append("'" + ap.alignFrame.getTitle() + "' ");
- }
- Cache.log.info("Couldn't align structures with the " + sp.toString()
- + "associated alignment panels.", e);
-
- }
-
- }
-
- public void setJalviewColourScheme(ColourSchemeI ucs)
+ public AAStructureBindingModel getBinding()
{
- jmb.setJalviewColourScheme(ucs);
-
+ return this.jmb;
}
- /**
- *
- * @param alignment
- * @return first alignment panel displaying given alignment, or the default
- * alignment panel
- */
- public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
- {
- for (AlignmentPanel ap : getAllAlignmentPanels())
- {
- if (ap.av.getAlignment() == alignment)
- {
- return ap;
- }
- }
- return ap;
- }
-
- /**
- *
- * @param ap2
- * @return true if this Jmol instance is linked with the given alignPanel
- */
- public boolean isLinkedWith(AlignmentPanel ap2)
- {
- return _aps.contains(ap2.av.getSequenceSetId());
- }
-
- public boolean isUsedforaligment(AlignmentPanel ap2)
+ @Override
+ public ViewerType getViewerType()
{
-
- return (_alignwith != null) && _alignwith.contains(ap2);
+ return ViewerType.JMOL;
}
- public boolean isUsedforcolourby(AlignmentPanel ap2)
+ @Override
+ protected String getViewerName()
{
- return (_colourwith != null) && _colourwith.contains(ap2);
+ return "Jmol";
}
-
- /**
- *
- * @return TRUE if the view is NOT being coloured by sequence associations.
- */
- public boolean isColouredByJmol()
- {
- return !jmb.isColourBySequence();
- }
-
-
}