2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
\r
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
\r
11 * Jalview is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
14 * PURPOSE. See the GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
18 package jalview.gui;
\r
22 import javax.swing.*;
\r
23 import javax.swing.event.*;
\r
25 import java.awt.event.*;
\r
28 import jalview.jbgui.GStructureViewer;
\r
29 import jalview.api.SequenceStructureBinding;
\r
30 import jalview.bin.Cache;
\r
31 import jalview.datamodel.*;
\r
32 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
\r
33 import jalview.datamodel.PDBEntry;
\r
34 import jalview.io.*;
\r
35 import jalview.schemes.*;
\r
36 import jalview.util.MessageManager;
\r
37 import jalview.util.Platform;
\r
39 public class AppJmol extends GStructureViewer implements Runnable,
\r
40 SequenceStructureBinding, ViewSetProvider
\r
45 JPanel scriptWindow;
\r
47 JSplitPane splitPane;
\r
49 RenderPanel renderPanel;
\r
53 Vector atomsPicked = new Vector();
\r
55 private boolean addingStructures = false;
\r
65 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
\r
67 public AppJmol(String file, String id, SequenceI[] seq,
\r
68 AlignmentPanel ap, String loadStatus, Rectangle bounds)
\r
70 this(file, id, seq, ap, loadStatus, bounds, null);
\r
76 public AppJmol(String file, String id, SequenceI[] seq,
\r
77 AlignmentPanel ap, String loadStatus, Rectangle bounds,
\r
81 { file }, new String[]
\r
82 { id }, new SequenceI[][]
\r
83 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
\r
86 ViewSelectionMenu seqColourBy;
\r
94 * @param usetoColour
\r
95 * - add the alignment panel to the list used for colouring these
\r
98 * - add the alignment panel to the list used for aligning these
\r
100 * @param leaveColouringToJmol
\r
101 * - do not update the colours from any other source. Jmol is
\r
103 * @param loadStatus
\r
107 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
\r
108 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
\r
109 boolean leaveColouringToJmol, String loadStatus,
\r
110 Rectangle bounds, String viewid)
\r
112 PDBEntry[] pdbentrys = new PDBEntry[files.length];
\r
113 for (int i = 0; i < pdbentrys.length; i++)
\r
115 PDBEntry pdbentry = new PDBEntry();
\r
116 pdbentry.setFile(files[i]);
\r
117 pdbentry.setId(ids[i]);
\r
118 pdbentrys[i] = pdbentry;
\r
120 // / TODO: check if protocol is needed to be set, and if chains are
\r
122 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
\r
123 pdbentrys, seqs, null, null);
\r
125 jmb.setLoadingFromArchive(true);
\r
126 addAlignmentPanel(ap);
\r
129 useAlignmentPanelForSuperposition(ap);
\r
131 if (leaveColouringToJmol || !usetoColour)
\r
133 jmb.setColourBySequence(false);
\r
134 seqColour.setSelected(false);
\r
135 jmolColour.setSelected(true);
\r
139 useAlignmentPanelForColourbyseq(ap);
\r
140 jmb.setColourBySequence(true);
\r
141 seqColour.setSelected(true);
\r
142 jmolColour.setSelected(false);
\r
144 this.setBounds(bounds);
\r
147 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
\r
148 // bounds.width,bounds.height);
\r
150 this.addInternalFrameListener(new InternalFrameAdapter()
\r
152 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
\r
157 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
\r
161 private void initMenus()
\r
163 seqColour.setSelected(jmb.isColourBySequence());
\r
164 jmolColour.setSelected(!jmb.isColourBySequence());
\r
165 if (_colourwith == null)
\r
167 _colourwith = new Vector<AlignmentPanel>();
\r
169 if (_alignwith == null)
\r
171 _alignwith = new Vector<AlignmentPanel>();
\r
174 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
\r
179 public void itemStateChanged(ItemEvent e)
\r
181 if (!seqColour.isSelected())
\r
183 seqColour.doClick();
\r
187 // update the jmol display now.
\r
188 seqColour_actionPerformed(null);
\r
192 viewMenu.add(seqColourBy);
\r
193 final ItemListener handler;
\r
194 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
\r
195 _alignwith, handler = new ItemListener()
\r
199 public void itemStateChanged(ItemEvent e)
\r
201 alignStructs.setEnabled(_alignwith.size() > 0);
\r
202 alignStructs.setToolTipText(MessageManager.formatMessage("label.align_structures_using_linked_alignment_views", new String[] {new Integer(_alignwith.size()).toString()}));
\r
205 handler.itemStateChanged(null);
\r
206 jmolActionMenu.add(alpanels);
\r
207 jmolActionMenu.addMenuListener(new MenuListener()
\r
211 public void menuSelected(MenuEvent e)
\r
213 handler.itemStateChanged(null);
\r
217 public void menuDeselected(MenuEvent e)
\r
219 // TODO Auto-generated method stub
\r
224 public void menuCanceled(MenuEvent e)
\r
226 // TODO Auto-generated method stub
\r
232 IProgressIndicator progressBar = null;
\r
235 * add a single PDB structure to a new or existing Jmol view
\r
242 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
\r
243 final AlignmentPanel ap)
\r
245 progressBar = ap.alignFrame;
\r
246 // ////////////////////////////////
\r
247 // Is the pdb file already loaded?
\r
248 String alreadyMapped = ap.getStructureSelectionManager()
\r
249 .alreadyMappedToFile(pdbentry.getId());
\r
251 if (alreadyMapped != null)
\r
253 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
254 MessageManager.formatMessage("label.pdb_entry_is_already_displayed", new String[]{pdbentry.getId()}),
\r
255 MessageManager.formatMessage("label.map_sequences_to_visible_window", new String[]{pdbentry.getId()}),
\r
256 JOptionPane.YES_NO_OPTION);
\r
258 if (option == JOptionPane.YES_OPTION)
\r
260 // TODO : Fix multiple seq to one chain issue here.
\r
261 ap.getStructureSelectionManager().setMapping(seq, chains,
\r
262 alreadyMapped, AppletFormatAdapter.FILE);
\r
263 if (ap.seqPanel.seqCanvas.fr != null)
\r
265 ap.seqPanel.seqCanvas.fr.featuresAdded();
\r
266 ap.paintAlignment(true);
\r
269 // Now this AppJmol is mapped to new sequences. We must add them to
\r
270 // the exisiting array
\r
271 JInternalFrame[] frames = Desktop.instance.getAllFrames();
\r
273 for (int i = 0; i < frames.length; i++)
\r
275 if (frames[i] instanceof AppJmol)
\r
277 final AppJmol topJmol = ((AppJmol) frames[i]);
\r
278 // JBPNOTE: this looks like a binding routine, rather than a gui
\r
280 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
\r
282 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
\r
284 topJmol.jmb.addSequence(pe, seq);
\r
285 topJmol.addAlignmentPanel(ap);
\r
286 // add it to the set used for colouring
\r
287 topJmol.useAlignmentPanelForColourbyseq(ap);
\r
288 topJmol.buildJmolActionMenu();
\r
289 ap.getStructureSelectionManager()
\r
290 .sequenceColoursChanged(ap);
\r
300 // /////////////////////////////////
\r
301 // Check if there are other Jmol views involving this alignment
\r
302 // and prompt user about adding this molecule to one of them
\r
303 Vector existingViews = getJmolsFor(ap);
\r
304 if (existingViews.size() > 0)
\r
306 Enumeration jm = existingViews.elements();
\r
307 while (jm.hasMoreElements())
\r
309 AppJmol topJmol = (AppJmol) jm.nextElement();
\r
310 // TODO: highlight topJmol in view somehow
\r
311 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
312 MessageManager.formatMessage("label.add_pdbentry_to_view", new String[]{pdbentry.getId(),topJmol.getTitle()}),
\r
313 MessageManager.getString("label.align_to_existing_structure_view"),
\r
314 JOptionPane.YES_NO_OPTION);
\r
315 if (option == JOptionPane.YES_OPTION)
\r
317 topJmol.useAlignmentPanelForSuperposition(ap);
\r
318 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
\r
323 // /////////////////////////////////
\r
324 openNewJmol(ap, new PDBEntry[]
\r
325 { pdbentry }, new SequenceI[][]
\r
329 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
\r
330 SequenceI[][] seqs)
\r
332 progressBar = ap.alignFrame;
\r
333 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
\r
334 pdbentrys, seqs, null, null);
\r
335 addAlignmentPanel(ap);
\r
336 useAlignmentPanelForColourbyseq(ap);
\r
337 if (pdbentrys.length > 1)
\r
339 alignAddedStructures = true;
\r
340 useAlignmentPanelForSuperposition(ap);
\r
342 jmb.setColourBySequence(true);
\r
343 setSize(400, 400); // probably should be a configurable/dynamic default here
\r
347 addingStructures = false;
\r
348 worker = new Thread(this);
\r
351 this.addInternalFrameListener(new InternalFrameAdapter()
\r
353 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
\r
362 * create a new Jmol containing several structures superimposed using the
\r
363 * given alignPanel.
\r
369 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
\r
371 openNewJmol(ap, pe, seqs);
\r
375 * list of sequenceSet ids associated with the view
\r
377 ArrayList<String> _aps = new ArrayList();
\r
379 public AlignmentPanel[] getAllAlignmentPanels()
\r
381 AlignmentPanel[] t, list = new AlignmentPanel[0];
\r
382 for (String setid : _aps)
\r
384 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
\r
385 if (panels != null)
\r
387 t = new AlignmentPanel[list.length + panels.length];
\r
388 System.arraycopy(list, 0, t, 0, list.length);
\r
389 System.arraycopy(panels, 0, t, list.length, panels.length);
\r
398 * list of alignment panels to use for superposition
\r
400 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
\r
403 * list of alignment panels that are used for colouring structures by aligned
\r
406 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
\r
409 * set the primary alignmentPanel reference and add another alignPanel to the
\r
410 * list of ones to use for colouring and aligning
\r
414 public void addAlignmentPanel(AlignmentPanel nap)
\r
420 if (!_aps.contains(nap.av.getSequenceSetId()))
\r
422 _aps.add(nap.av.getSequenceSetId());
\r
427 * remove any references held to the given alignment panel
\r
431 public void removeAlignmentPanel(AlignmentPanel nap)
\r
435 _alignwith.remove(nap);
\r
436 _colourwith.remove(nap);
\r
440 for (AlignmentPanel aps : getAllAlignmentPanels())
\r
449 } catch (Exception ex)
\r
454 buildJmolActionMenu();
\r
458 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
\r
460 addAlignmentPanel(nap);
\r
461 if (!_alignwith.contains(nap))
\r
463 _alignwith.add(nap);
\r
467 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
\r
469 if (_alignwith.contains(nap))
\r
471 _alignwith.remove(nap);
\r
475 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
\r
476 boolean enableColourBySeq)
\r
478 useAlignmentPanelForColourbyseq(nap);
\r
479 jmb.setColourBySequence(enableColourBySeq);
\r
480 seqColour.setSelected(enableColourBySeq);
\r
481 jmolColour.setSelected(!enableColourBySeq);
\r
484 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
\r
486 addAlignmentPanel(nap);
\r
487 if (!_colourwith.contains(nap))
\r
489 _colourwith.add(nap);
\r
493 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
\r
495 if (_colourwith.contains(nap))
\r
497 _colourwith.remove(nap);
\r
502 * pdb retrieval thread.
\r
504 private Thread worker = null;
\r
507 * add a new structure (with associated sequences and chains) to this viewer,
\r
508 * retrieving it if necessary first.
\r
513 * @param alignFrame
\r
515 * if true, new structure(s) will be align using associated alignment
\r
517 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
\r
518 final String[] chains, final boolean b,
\r
519 final IProgressIndicator alignFrame)
\r
521 if (pdbentry.getFile() == null)
\r
523 if (worker != null && worker.isAlive())
\r
525 // a retrieval is in progress, wait around and add ourselves to the
\r
527 new Thread(new Runnable()
\r
531 while (worker != null && worker.isAlive() && _started)
\r
535 Thread.sleep(100 + ((int) Math.random() * 100));
\r
537 } catch (Exception e)
\r
542 // and call ourselves again.
\r
543 addStructure(pdbentry, seq, chains, b, alignFrame);
\r
549 // otherwise, start adding the structure.
\r
550 jmb.addSequenceAndChain(new PDBEntry[]
\r
551 { pdbentry }, new SequenceI[][]
\r
552 { seq }, new String[][]
\r
554 addingStructures = true;
\r
556 alignAddedStructures = b;
\r
557 progressBar = alignFrame; // visual indication happens on caller frame.
\r
558 (worker = new Thread(this)).start();
\r
562 private Vector getJmolsFor(AlignmentPanel ap2)
\r
564 Vector otherJmols = new Vector();
\r
565 // Now this AppJmol is mapped to new sequences. We must add them to
\r
566 // the exisiting array
\r
567 JInternalFrame[] frames = Desktop.instance.getAllFrames();
\r
569 for (int i = 0; i < frames.length; i++)
\r
571 if (frames[i] instanceof AppJmol)
\r
573 AppJmol topJmol = ((AppJmol) frames[i]);
\r
574 if (topJmol.isLinkedWith(ap2))
\r
576 otherJmols.addElement(topJmol);
\r
583 void initJmol(String command)
\r
585 jmb.setFinishedInit(false);
\r
586 renderPanel = new RenderPanel();
\r
587 // TODO: consider waiting until the structure/view is fully loaded before
\r
589 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
\r
590 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
\r
591 getBounds().width, getBounds().height);
\r
592 if (scriptWindow == null)
\r
594 BorderLayout bl = new BorderLayout();
\r
597 scriptWindow = new JPanel(bl);
\r
598 scriptWindow.setVisible(false);
\r
601 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
\r
603 jmb.newJmolPopup(true, "Jmol", true);
\r
604 if (command == null)
\r
608 jmb.evalStateCommand(command);
\r
609 jmb.setFinishedInit(true);
\r
612 void setChainMenuItems(Vector chains)
\r
614 chainMenu.removeAll();
\r
615 if (chains == null)
\r
619 JMenuItem menuItem = new JMenuItem(MessageManager.getString("label.all"));
\r
620 menuItem.addActionListener(new ActionListener()
\r
622 public void actionPerformed(ActionEvent evt)
\r
624 allChainsSelected = true;
\r
625 for (int i = 0; i < chainMenu.getItemCount(); i++)
\r
627 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
\r
628 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
\r
631 allChainsSelected = false;
\r
635 chainMenu.add(menuItem);
\r
637 for (int c = 0; c < chains.size(); c++)
\r
639 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
\r
640 menuItem.addItemListener(new ItemListener()
\r
642 public void itemStateChanged(ItemEvent evt)
\r
644 if (!allChainsSelected)
\r
649 chainMenu.add(menuItem);
\r
653 boolean allChainsSelected = false;
\r
655 private boolean alignAddedStructures = false;
\r
657 void centerViewer()
\r
659 Vector toshow = new Vector();
\r
661 int mlength, p, mnum;
\r
662 for (int i = 0; i < chainMenu.getItemCount(); i++)
\r
664 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
\r
666 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
\r
667 if (item.isSelected())
\r
669 toshow.addElement(item.getText());
\r
673 jmb.centerViewer(toshow);
\r
681 _alignwith.clear();
\r
682 _colourwith.clear();
\r
683 // TODO: check for memory leaks where instance isn't finalised because jmb
\r
684 // holds a reference to the window
\r
689 * state flag for PDB retrieval thread
\r
691 private boolean _started = false;
\r
697 // todo - record which pdbids were successfuly imported.
\r
698 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
\r
701 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
\r
702 // TODO: replace with reference fetching/transfer code (validate PDBentry
\r
704 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
\r
705 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
\r
707 String file = jmb.pdbentry[pi].getFile();
\r
710 // retrieve the pdb and store it locally
\r
711 AlignmentI pdbseq = null;
\r
712 pdbid = jmb.pdbentry[pi].getId();
\r
713 long hdl = pdbid.hashCode() - System.currentTimeMillis();
\r
714 if (progressBar != null)
\r
716 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
\r
720 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
\r
722 } catch (OutOfMemoryError oomerror)
\r
724 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
\r
725 } catch (Exception ex)
\r
727 ex.printStackTrace();
\r
728 errormsgs.append("'" + pdbid + "'");
\r
730 if (progressBar != null)
\r
732 progressBar.setProgressBar("Finished.", hdl);
\r
734 if (pdbseq != null)
\r
736 // just transfer the file name from the first sequence's first
\r
738 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
\r
739 .elementAt(0)).getFile()).getAbsolutePath();
\r
740 jmb.pdbentry[pi].setFile(file);
\r
742 files.append(" \"" + Platform.escapeString(file) + "\"");
\r
746 errormsgs.append("'" + pdbid + "' ");
\r
751 if (curfiles != null && curfiles.length > 0)
\r
753 addingStructures = true; // already files loaded.
\r
754 for (int c = 0; c < curfiles.length; c++)
\r
756 if (curfiles[c].equals(file))
\r
765 files.append(" \"" + Platform.escapeString(file) + "\"");
\r
769 } catch (OutOfMemoryError oomerror)
\r
771 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
\r
772 } catch (Exception ex)
\r
774 ex.printStackTrace();
\r
775 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
\r
778 if (errormsgs.length() > 0)
\r
781 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
782 MessageManager.formatMessage("label.pdb_entries_couldnt_be_retrieved", new String[]{errormsgs.toString()}),
\r
783 MessageManager.getString("label.couldnt_load_file"), JOptionPane.ERROR_MESSAGE);
\r
786 long lastnotify = jmb.getLoadNotifiesHandled();
\r
787 if (files.length() > 0)
\r
789 if (!addingStructures)
\r
794 initJmol("load FILES " + files.toString());
\r
795 } catch (OutOfMemoryError oomerror)
\r
797 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
\r
798 Cache.log.debug("File locations are " + files);
\r
799 } catch (Exception ex)
\r
801 Cache.log.error("Couldn't open Jmol viewer!", ex);
\r
806 StringBuffer cmd = new StringBuffer();
\r
807 cmd.append("loadingJalviewdata=true\nload APPEND ");
\r
808 cmd.append(files.toString());
\r
809 cmd.append("\nloadingJalviewdata=null");
\r
810 final String command = cmd.toString();
\r
812 lastnotify = jmb.getLoadNotifiesHandled();
\r
816 jmb.evalStateCommand(command);
\r
817 } catch (OutOfMemoryError oomerror)
\r
820 "When trying to add structures to the Jmol viewer!",
\r
822 Cache.log.debug("File locations are " + files);
\r
823 } catch (Exception ex)
\r
825 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
\r
829 // need to wait around until script has finished
\r
830 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
\r
831 : (jmb.isFinishedInit() && jmb.getPdbFile().length != jmb.pdbentry.length))
\r
835 Cache.log.debug("Waiting around for jmb notify.");
\r
837 } catch (Exception e)
\r
841 // refresh the sequence colours for the new structure(s)
\r
842 for (AlignmentPanel ap : _colourwith)
\r
844 jmb.updateColours(ap);
\r
846 // do superposition if asked to
\r
847 if (alignAddedStructures)
\r
849 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
853 alignStructs_withAllAlignPanels();
\r
854 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
\r
857 alignAddedStructures = false;
\r
859 addingStructures = false;
\r
866 public void pdbFile_actionPerformed(ActionEvent actionEvent)
\r
868 JalviewFileChooser chooser = new JalviewFileChooser(
\r
869 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
\r
871 chooser.setFileView(new JalviewFileView());
\r
872 chooser.setDialogTitle("Save PDB File");
\r
873 chooser.setToolTipText(MessageManager.getString("action.save"));
\r
875 int value = chooser.showSaveDialog(this);
\r
877 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
881 // TODO: cope with multiple PDB files in view
\r
882 BufferedReader in = new BufferedReader(new FileReader(
\r
883 jmb.getPdbFile()[0]));
\r
884 File outFile = chooser.getSelectedFile();
\r
886 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
\r
888 while ((data = in.readLine()) != null)
\r
890 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
\r
896 } catch (Exception ex)
\r
898 ex.printStackTrace();
\r
903 public void viewMapping_actionPerformed(ActionEvent actionEvent)
\r
905 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
\r
908 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
\r
910 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
\r
911 cap.appendText("\n");
\r
913 } catch (OutOfMemoryError e)
\r
916 "composing sequence-structure alignments for display in text box.",
\r
921 jalview.gui.Desktop.addInternalFrame(cap, MessageManager.getString("label.pdb_sequence_mapping"),
\r
931 public void eps_actionPerformed(ActionEvent e)
\r
933 makePDBImage(jalview.util.ImageMaker.EPS);
\r
942 public void png_actionPerformed(ActionEvent e)
\r
944 makePDBImage(jalview.util.ImageMaker.PNG);
\r
947 void makePDBImage(int type)
\r
949 int width = getWidth();
\r
950 int height = getHeight();
\r
952 jalview.util.ImageMaker im;
\r
954 if (type == jalview.util.ImageMaker.PNG)
\r
956 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
\r
957 "Make PNG image from view", width, height, null, null);
\r
961 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
\r
962 "Make EPS file from view", width, height, null,
\r
966 if (im.getGraphics() != null)
\r
968 Rectangle rect = new Rectangle(width, height);
\r
969 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
\r
974 public void jmolColour_actionPerformed(ActionEvent actionEvent)
\r
976 if (jmolColour.isSelected())
\r
978 // disable automatic sequence colouring.
\r
979 jmb.setColourBySequence(false);
\r
983 public void seqColour_actionPerformed(ActionEvent actionEvent)
\r
985 jmb.setColourBySequence(seqColour.isSelected());
\r
986 if (_colourwith == null)
\r
988 _colourwith = new Vector<AlignmentPanel>();
\r
990 if (jmb.isColourBySequence())
\r
992 if (!jmb.isLoadingFromArchive())
\r
994 if (_colourwith.size() == 0 && ap != null)
\r
996 // Make the currently displayed alignment panel the associated view
\r
997 _colourwith.add(ap.alignFrame.alignPanel);
\r
1000 // Set the colour using the current view for the associated alignframe
\r
1001 for (AlignmentPanel ap : _colourwith)
\r
1003 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
\r
1008 public void chainColour_actionPerformed(ActionEvent actionEvent)
\r
1010 chainColour.setSelected(true);
\r
1011 jmb.colourByChain();
\r
1014 public void chargeColour_actionPerformed(ActionEvent actionEvent)
\r
1016 chargeColour.setSelected(true);
\r
1017 jmb.colourByCharge();
\r
1020 public void zappoColour_actionPerformed(ActionEvent actionEvent)
\r
1022 zappoColour.setSelected(true);
\r
1023 jmb.setJalviewColourScheme(new ZappoColourScheme());
\r
1026 public void taylorColour_actionPerformed(ActionEvent actionEvent)
\r
1028 taylorColour.setSelected(true);
\r
1029 jmb.setJalviewColourScheme(new TaylorColourScheme());
\r
1032 public void hydroColour_actionPerformed(ActionEvent actionEvent)
\r
1034 hydroColour.setSelected(true);
\r
1035 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
\r
1038 public void helixColour_actionPerformed(ActionEvent actionEvent)
\r
1040 helixColour.setSelected(true);
\r
1041 jmb.setJalviewColourScheme(new HelixColourScheme());
\r
1044 public void strandColour_actionPerformed(ActionEvent actionEvent)
\r
1046 strandColour.setSelected(true);
\r
1047 jmb.setJalviewColourScheme(new StrandColourScheme());
\r
1050 public void turnColour_actionPerformed(ActionEvent actionEvent)
\r
1052 turnColour.setSelected(true);
\r
1053 jmb.setJalviewColourScheme(new TurnColourScheme());
\r
1056 public void buriedColour_actionPerformed(ActionEvent actionEvent)
\r
1058 buriedColour.setSelected(true);
\r
1059 jmb.setJalviewColourScheme(new BuriedColourScheme());
\r
1062 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
\r
1064 setJalviewColourScheme(new PurinePyrimidineColourScheme());
\r
1067 public void userColour_actionPerformed(ActionEvent actionEvent)
\r
1069 userColour.setSelected(true);
\r
1070 new UserDefinedColours(this, null);
\r
1073 public void backGround_actionPerformed(ActionEvent actionEvent)
\r
1075 java.awt.Color col = JColorChooser.showDialog(this,
\r
1076 "Select Background Colour", null);
\r
1079 jmb.setBackgroundColour(col);
\r
1083 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
\r
1087 jalview.util.BrowserLauncher
\r
1088 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
\r
1089 } catch (Exception ex)
\r
1094 public void showConsole(boolean showConsole)
\r
1099 if (splitPane == null)
\r
1101 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
\r
1102 splitPane.setTopComponent(renderPanel);
\r
1103 splitPane.setBottomComponent(scriptWindow);
\r
1104 this.getContentPane().add(splitPane, BorderLayout.CENTER);
\r
1105 splitPane.setDividerLocation(getHeight() - 200);
\r
1106 scriptWindow.setVisible(true);
\r
1107 scriptWindow.validate();
\r
1108 splitPane.validate();
\r
1114 if (splitPane != null)
\r
1116 splitPane.setVisible(false);
\r
1121 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
\r
1127 class RenderPanel extends JPanel
\r
1129 final Dimension currentSize = new Dimension();
\r
1131 final Rectangle rectClip = new Rectangle();
\r
1133 public void paintComponent(Graphics g)
\r
1135 getSize(currentSize);
\r
1136 g.getClipBounds(rectClip);
\r
1138 if (jmb.fileLoadingError != null)
\r
1140 g.setColor(Color.black);
\r
1141 g.fillRect(0, 0, currentSize.width, currentSize.height);
\r
1142 g.setColor(Color.white);
\r
1143 g.setFont(new Font("Verdana", Font.BOLD, 14));
\r
1144 g.drawString(MessageManager.getString("label.error_loading_file") + "...", 20, currentSize.height / 2);
\r
1145 StringBuffer sb = new StringBuffer();
\r
1147 for (int e = 0; e < jmb.pdbentry.length; e++)
\r
1149 sb.append(jmb.pdbentry[e].getId());
\r
1150 if (e < jmb.pdbentry.length - 1)
\r
1155 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
\r
1158 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
\r
1159 * g.getFontMetrics().getHeight());
\r
1163 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
\r
1165 g.setColor(Color.black);
\r
1166 g.fillRect(0, 0, currentSize.width, currentSize.height);
\r
1167 g.setColor(Color.white);
\r
1168 g.setFont(new Font("Verdana", Font.BOLD, 14));
\r
1169 g.drawString(MessageManager.getString("label.retrieving_pdb_data"), 20, currentSize.height / 2);
\r
1173 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
\r
1178 String viewId = null;
\r
1180 public String getViewId()
\r
1182 if (viewId == null)
\r
1184 viewId = System.currentTimeMillis() + "." + this.hashCode();
\r
1189 public void updateTitleAndMenus()
\r
1191 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
\r
1196 setChainMenuItems(jmb.chainNames);
\r
1198 this.setTitle(jmb.getViewerTitle());
\r
1199 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
\r
1201 jmolActionMenu.setVisible(true);
\r
1203 if (!jmb.isLoadingFromArchive())
\r
1205 seqColour_actionPerformed(null);
\r
1209 protected void buildJmolActionMenu()
\r
1211 if (_alignwith == null)
\r
1213 _alignwith = new Vector<AlignmentPanel>();
\r
1215 if (_alignwith.size() == 0 && ap != null)
\r
1217 _alignwith.add(ap);
\r
1220 for (Component c : jmolActionMenu.getMenuComponents())
\r
1222 if (c != alignStructs)
\r
1224 jmolActionMenu.remove((JMenuItem) c);
\r
1227 final ItemListener handler;
\r
1234 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
\r
1238 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
\r
1240 alignStructs_withAllAlignPanels();
\r
1243 private void alignStructs_withAllAlignPanels()
\r
1250 if (_alignwith.size() == 0)
\r
1252 _alignwith.add(ap);
\r
1257 AlignmentI[] als = new Alignment[_alignwith.size()];
\r
1258 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
\r
1259 int[] alm = new int[_alignwith.size()];
\r
1262 for (AlignmentPanel ap : _alignwith)
\r
1264 als[a] = ap.av.getAlignment();
\r
1266 alc[a++] = ap.av.getColumnSelection();
\r
1268 jmb.superposeStructures(als, alm, alc);
\r
1269 } catch (Exception e)
\r
1271 StringBuffer sp = new StringBuffer();
\r
1272 for (AlignmentPanel ap : _alignwith)
\r
1274 sp.append("'" + ap.alignFrame.getTitle() + "' ");
\r
1276 Cache.log.info("Couldn't align structures with the " + sp.toString()
\r
1277 + "associated alignment panels.", e);
\r
1283 public void setJalviewColourScheme(ColourSchemeI ucs)
\r
1285 jmb.setJalviewColourScheme(ucs);
\r
1291 * @param alignment
\r
1292 * @return first alignment panel displaying given alignment, or the default
\r
1295 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
\r
1297 for (AlignmentPanel ap : getAllAlignmentPanels())
\r
1299 if (ap.av.getAlignment() == alignment)
\r
1310 * @return true if this Jmol instance is linked with the given alignPanel
\r
1312 public boolean isLinkedWith(AlignmentPanel ap2)
\r
1314 return _aps.contains(ap2.av.getSequenceSetId());
\r
1317 public boolean isUsedforaligment(AlignmentPanel ap2)
\r
1320 return (_alignwith != null) && _alignwith.contains(ap2);
\r
1323 public boolean isUsedforcolourby(AlignmentPanel ap2)
\r
1325 return (_colourwith != null) && _colourwith.contains(ap2);
\r
1330 * @return TRUE if the view is NOT being coloured by sequence associations.
\r
1332 public boolean isColouredByJmol()
\r
1334 return !jmb.isColourBySequence();
\r