- result.addElement(frame);
- }
- }
- }
- 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)
- {
- BorderLayout bl = new BorderLayout();
- bl.setHgap(0);
- bl.setVgap(0);
- scriptWindow = new JPanel(bl);
- scriptWindow.setVisible(false);
- }
- ;
- jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
- null);
- jmb.newJmolPopup(true, "Jmol", true);
- if (command == null)
- {
- command = "";
- }
- jmb.evalStateCommand(command);
- jmb.setFinishedInit(true);
- }
-
- void setChainMenuItems(Vector chains)
- {
- chainMenu.removeAll();
- if (chains == null)
- {
- return;
- }
- JMenuItem menuItem = new JMenuItem(
- MessageManager.getString("label.all"));
- menuItem.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent evt)
- {
- allChainsSelected = true;
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
- }
- }
- centerViewer();
- allChainsSelected = false;
- }
- });
-
- chainMenu.add(menuItem);
-
- for (int c = 0; c < chains.size(); c++)
- {
- menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
- menuItem.addItemListener(new ItemListener()
- {
- public void itemStateChanged(ItemEvent evt)
- {
- if (!allChainsSelected)
- {
- centerViewer();
- }
- }
- });
-
- chainMenu.add(menuItem);
- }
- }
-
- boolean allChainsSelected = false;
-
- private boolean alignAddedStructures = false;
-
- void centerViewer()
- {
- Vector toshow = new Vector();
- String lbl;
- int mlength, p, mnum;
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
- if (item.isSelected())
- {
- toshow.addElement(item.getText());
- }
- }
- }
- jmb.centerViewer(toshow);
- }
-
- public void closeViewer()
- {
- jmb.closeViewer();
- ap = 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;
- }
-
- /**
- * state flag for PDB retrieval thread
- */
- private boolean _started = false;
-
- public void run()
- {
- _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(MessageManager.formatMessage("status.fetching_pdb", new String[]{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(MessageManager.getString("label.state_completed"), hdl);
- }
- if (pdbseq != null)
- {
- // just transfer the file name from the first sequence's first
- // PDBEntry
- file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
- .elementAt(0)).getFile()).getAbsolutePath();
- jmb.pdbentry[pi].setFile(file);
-
- files.append(" \"" + Platform.escapeString(file) + "\"");
- }
- else
- {
- errormsgs.append("'" + pdbid + "' ");
- }
+ // todo: extract block as method and pull up (also ChimeraViewFrame)
+ // retrieve the pdb and store it locally
+ AlignmentI pdbseq = null;
+ pdbid = jmb.getPdbEntry(pi).getId();
+ long hdl = pdbid.hashCode() - System.currentTimeMillis();
+ setProgressMessage(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
+ {
+ setProgressMessage(
+ MessageManager.getString("label.state_completed"), hdl);
+ }
+ 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("' ");
+ }