+ /**
+ * Show only the selected chain(s) in the viewer
+ */
+ protected void showSelectedChains()
+ {
+ List<String> toshow = new ArrayList<>();
+ for (int i = 0; i < chainMenu.getItemCount(); i++)
+ {
+ if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
+ {
+ JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
+ if (item.isSelected())
+ {
+ toshow.add(item.getText());
+ }
+ }
+ }
+ getBinding().showChains(toshow);
+ }
+
+ /**
+ * Tries to fetch a PDB file and save to a temporary local file. Returns the
+ * saved file path if successful, or null if not.
+ *
+ * @param processingEntry
+ * @return
+ */
+ protected String fetchPdbFile(PDBEntry processingEntry)
+ {
+ String filePath = null;
+ Pdb pdbclient = new Pdb();
+ EBIAlfaFold afclient = new EBIAlfaFold();
+ AlignmentI pdbseq = null;
+ String pdbid = processingEntry.getId();
+ long handle = System.currentTimeMillis()
+ + Thread.currentThread().hashCode();
+
+ /*
+ * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
+ */
+ String msg = MessageManager.formatMessage("status.fetching_pdb",
+ new Object[]
+ { pdbid });
+ getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
+ // long hdl = startProgressBar(MessageManager.formatMessage(
+ // "status.fetching_pdb", new Object[]
+ // { pdbid }));
+ try
+ {
+ if (afclient.isValidReference(pdbid))
+ {
+ pdbseq = afclient.getSequenceRecords(pdbid,
+ processingEntry.getRetrievalUrl());
+ }
+ else
+ {
+ if (processingEntry.hasRetrievalUrl())
+ {
+ String safePDBId = java.net.URLEncoder.encode(pdbid, "UTF-8")
+ .replace("%", "__");
+
+ // retrieve from URL to new local tmpfile
+ File tmpFile = File.createTempFile(safePDBId,
+ "." + (PDBEntry.Type.MMCIF.toString().equals(
+ processingEntry.getType().toString()) ? "cif"
+ : "pdb"));
+ String fromUrl = processingEntry.getRetrievalUrl();
+ UrlDownloadClient.download(fromUrl, tmpFile);
+
+ // may not need this check ?
+ String file = tmpFile.getAbsolutePath();
+ if (file != null)
+ {
+ pdbseq = EBIAlfaFold.importDownloadedStructureFromUrl(fromUrl,
+ tmpFile, pdbid, null, null, null);
+ }
+ }
+ else
+ {
+ pdbseq = pdbclient.getSequenceRecords(pdbid);
+ }
+ }
+ } catch (Exception e)
+ {
+ System.err.println(
+ "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
+ } finally
+ {
+ msg = pdbid + " " + MessageManager.getString("label.state_completed");
+ getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
+ // stopProgressBar(msg, hdl);
+ }
+ /*
+ * If PDB data were saved and are not invalid (empty alignment), return the
+ * file path.
+ */
+ if (pdbseq != null && pdbseq.getHeight() > 0)
+ {
+ // just use the file name from the first sequence's first PDBEntry
+ filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
+ .elementAt(0).getFile()).getAbsolutePath();
+ processingEntry.setFile(filePath);
+ }
+ return filePath;
+ }
+
+ /**
+ * If supported, saves the state of the structure viewer to a temporary file
+ * and returns the file, else returns null
+ *
+ * @return
+ */
+ public File saveSession()
+ {
+ if (getBinding() == null)
+ {
+ return null;
+ }
+ File session = getBinding().saveSession();
+ long l = session.length();
+ int wait = 50;
+ do
+ {
+ try
+ {
+ Thread.sleep(5);
+ } catch (InterruptedException e)
+ {
+ }
+ long nextl = session.length();
+ if (nextl != l)
+ {
+ wait = 50;
+ l = nextl;
+ }
+ } while (--wait > 0);
+ return session;
+ }
+
+ /**
+ * Close down this instance of Jalview's Chimera viewer, giving the user the
+ * option to close the associated Chimera window (process). They may wish to
+ * keep it open until they have had an opportunity to save any work.
+ *
+ * @param forceClose
+ * if true, close any linked Chimera process; if false, prompt first
+ */
+ @Override
+ public void closeViewer(boolean forceClose)
+ {
+ AAStructureBindingModel binding = getBinding();
+ if (binding != null && binding.isViewerRunning())
+ {
+ if (!forceClose)
+ {
+ String viewerName = getViewerName();
+ String prompt = MessageManager
+ .formatMessage("label.confirm_close_viewer", new Object[]
+ { binding.getViewerTitle(viewerName, false), viewerName });
+ prompt = JvSwingUtils.wrapTooltip(true, prompt);
+ int confirm = JvOptionPane.showConfirmDialog(this, prompt,
+ MessageManager.getString("label.close_viewer"),
+ JvOptionPane.YES_NO_CANCEL_OPTION);
+ /*
+ * abort closure if user hits escape or Cancel
+ */
+ if (confirm == JvOptionPane.CANCEL_OPTION
+ || confirm == JvOptionPane.CLOSED_OPTION)
+ {
+ return;
+ }
+ forceClose = confirm == JvOptionPane.YES_OPTION;
+ }
+ }
+ if (binding != null)
+ {
+ binding.closeViewer(forceClose);
+ }
+ 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;
+ dispose();
+ }
+
+ @Override
+ public void showHelp_actionPerformed()
+ {
+ /*
+ try
+ {
+ */
+ String url = getBinding().getHelpURL();
+ if (url != null)
+ {
+ BrowserLauncher.openURL(url);
+ }
+ /*
+ }
+ catch (IOException ex)
+ {
+ System.err
+ .println("Show " + getViewerName() + " failed with: "
+ + ex.getMessage());
+ }
+ */
+ }
+
+ @Override
+ public boolean hasViewerActionsMenu()
+ {
+ return viewerActionMenu != null && viewerActionMenu.isEnabled()
+ && viewerActionMenu.getItemCount() > 0
+ && viewerActionMenu.isVisible();
+ }