2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import javax.swing.event.*;
25 import java.awt.event.*;
28 import jalview.jbgui.GStructureViewer;
29 import jalview.api.SequenceStructureBinding;
30 import jalview.bin.Cache;
31 import jalview.datamodel.*;
32 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
33 import jalview.structure.*;
34 import jalview.datamodel.PDBEntry;
36 import jalview.schemes.*;
38 public class AppJmol extends GStructureViewer implements Runnable,
39 SequenceStructureBinding, ViewSetProvider
48 RenderPanel renderPanel;
52 Vector atomsPicked = new Vector();
54 private boolean addingStructures = false;
64 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
66 public AppJmol(String file, String id, SequenceI[] seq,
67 AlignmentPanel ap, String loadStatus, Rectangle bounds)
69 this(file, id, seq, ap, loadStatus, bounds, null);
75 public AppJmol(String file, String id, SequenceI[] seq,
76 AlignmentPanel ap, String loadStatus, Rectangle bounds,
80 { file }, new String[]
81 { id }, new SequenceI[][]
82 { seq }, ap, true, true, loadStatus, bounds, viewid);
85 ViewSelectionMenu seqColourBy;
94 * - add the alignment panel to the list used for colouring these
97 * - add the alignment panel to the list used for aligning these
103 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
104 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
105 String loadStatus, Rectangle bounds, String viewid)
107 PDBEntry[] pdbentrys = new PDBEntry[files.length];
108 for (int i = 0; i < pdbentrys.length; i++)
110 PDBEntry pdbentry = new PDBEntry();
111 pdbentry.setFile(files[i]);
112 pdbentry.setId(ids[i]);
113 pdbentrys[i] = pdbentry;
115 // / TODO: check if protocol is needed to be set, and if chains are
117 jmb = new AppJmolBinding(this, pdbentrys, seqs, null, null);
119 jmb.setLoadingFromArchive(true);
120 addAlignmentPanel(ap);
123 useAlignmentPanelForSuperposition(ap);
127 useAlignmentPanelForColourbyseq(ap);
128 jmb.setColourBySequence(true);
129 seqColour.setSelected(true);
131 jmb.setColourBySequence(false);
132 seqColour.setSelected(false);
133 jmolColour.setSelected(true);
135 this.setBounds(bounds);
138 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
139 // bounds.width,bounds.height);
141 this.addInternalFrameListener(new InternalFrameAdapter()
143 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
148 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
152 private void initMenus()
154 seqColour.setSelected(jmb.isColourBySequence());
155 jmolColour.setSelected(!jmb.isColourBySequence());
156 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
161 public void itemStateChanged(ItemEvent e)
163 if (!seqColour.isSelected())
169 // update the jmol display now.
170 seqColour_actionPerformed(null);
174 viewMenu.add(seqColourBy);
175 final ItemListener handler;
176 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
177 _alignwith, handler = new ItemListener()
181 public void itemStateChanged(ItemEvent e)
183 alignStructs.setEnabled(_alignwith.size() > 0);
184 alignStructs.setToolTipText("Align structures using "
185 + _alignwith.size() + " linked alignment views");
188 handler.itemStateChanged(null);
189 jmolActionMenu.add(alpanels);
190 jmolActionMenu.addMenuListener(new MenuListener()
194 public void menuSelected(MenuEvent e)
196 handler.itemStateChanged(null);
200 public void menuDeselected(MenuEvent e)
202 // TODO Auto-generated method stub
207 public void menuCanceled(MenuEvent e)
209 // TODO Auto-generated method stub
213 colourMenu.addMenuListener(new MenuListener()
217 public void menuSelected(MenuEvent arg0)
220 handlingGuiEvents=true;
224 public void menuDeselected(MenuEvent arg0)
226 handlingGuiEvents=false;
230 public void menuCanceled(MenuEvent arg0)
232 handlingGuiEvents=false;
237 IProgressIndicator progressBar = null;
239 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
242 progressBar = ap.alignFrame;
243 // ////////////////////////////////
244 // Is the pdb file already loaded?
245 String alreadyMapped = StructureSelectionManager
246 .getStructureSelectionManager().alreadyMappedToFile(
249 if (alreadyMapped != null)
251 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
252 pdbentry.getId() + " is already displayed."
253 + "\nDo you want to re-use this viewer ?",
254 "Map Sequences to Visible Window: " + pdbentry.getId(),
255 JOptionPane.YES_NO_OPTION);
257 if (option == JOptionPane.YES_OPTION)
259 StructureSelectionManager.getStructureSelectionManager()
260 .setMapping(seq, chains, alreadyMapped,
261 AppletFormatAdapter.FILE);
262 if (ap.seqPanel.seqCanvas.fr != null)
264 ap.seqPanel.seqCanvas.fr.featuresAdded();
265 ap.paintAlignment(true);
268 // Now this AppJmol is mapped to new sequences. We must add them to
269 // the exisiting array
270 JInternalFrame[] frames = Desktop.instance.getAllFrames();
272 for (int i = 0; i < frames.length; i++)
274 if (frames[i] instanceof AppJmol)
276 AppJmol topJmol = ((AppJmol) frames[i]);
277 // JBPNOTE: this looks like a binding routine, rather than a gui
279 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
281 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
283 topJmol.jmb.addSequence(pe, seq);
284 topJmol.addAlignmentPanel(ap);
285 topJmol.buildJmolActionMenu();
295 // /////////////////////////////////
296 // Check if there are other Jmol views involving this alignment
297 // and prompt user about adding this molecule to one of them
298 Vector existingViews = getJmolsFor(ap);
299 if (existingViews.size() > 0)
301 Enumeration jm = existingViews.elements();
302 while (jm.hasMoreElements())
304 AppJmol topJmol = (AppJmol) jm.nextElement();
305 // TODO: highlight topJmol in view somehow
306 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
307 "Do you want to add " + pdbentry.getId()
308 + " to the view called\n'" + topJmol.getTitle()
309 + "'\n", "Align to existing structure view",
310 JOptionPane.YES_NO_OPTION);
311 if (option == JOptionPane.YES_OPTION)
313 topJmol.useAlignmentPanelForSuperposition(ap);
314 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
319 // /////////////////////////////////
321 jmb = new AppJmolBinding(this, new PDBEntry[]
322 { pdbentry }, new SequenceI[][]
323 { seq }, null, null);
324 addAlignmentPanel(ap);
325 useAlignmentPanelForColourbyseq(ap);
326 jmb.setColourBySequence(true);
327 setSize(400, 400); // probably should be a configurable/dynamic default here
330 if (pdbentry.getFile() != null)
332 initJmol("load \"" + pdbentry.getFile() + "\"");
336 addingStructures = false;
337 worker = new Thread(this);
341 this.addInternalFrameListener(new InternalFrameAdapter()
343 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
352 * list of sequenceSet ids associated with the view
354 ArrayList<String> _aps = new ArrayList();
356 public AlignmentPanel[] getAllAlignmentPanels()
358 AlignmentPanel[] t, list = new AlignmentPanel[0];
359 for (String setid : _aps)
361 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
364 t = new AlignmentPanel[list.length + panels.length];
365 System.arraycopy(list, 0, t, 0, list.length);
366 System.arraycopy(panels, 0, t, list.length, panels.length);
375 * list of alignment panels to use for superposition
377 ArrayList<AlignmentPanel> _alignwith = new ArrayList();
380 * list of alignment panels that are used for colouring structures by aligned
383 ArrayList<AlignmentPanel> _colourwith = new ArrayList();
386 * set the primary alignmentPanel reference and add another alignPanel to the
387 * list of ones to use for colouring and aligning
391 public void addAlignmentPanel(AlignmentPanel nap)
397 if (!_aps.contains(nap.av.getSequenceSetId()))
399 _aps.add(nap.av.getSequenceSetId());
404 * remove any references held to the given alignment panel
408 public void removeAlignmentPanel(AlignmentPanel nap)
412 _alignwith.remove(nap);
413 _colourwith.remove(nap);
417 for (AlignmentPanel aps : getAllAlignmentPanels())
426 } catch (Exception ex)
431 buildJmolActionMenu();
435 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
437 addAlignmentPanel(nap);
438 if (!_alignwith.contains(nap))
444 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
446 if (_alignwith.contains(nap))
448 _alignwith.remove(nap);
452 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
454 addAlignmentPanel(nap);
455 if (!_colourwith.contains(nap))
457 _colourwith.add(nap);
461 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
463 if (_colourwith.contains(nap))
465 _colourwith.remove(nap);
470 * pdb retrieval thread.
472 private Thread worker = null;
475 * add a new structure (with associated sequences and chains) to this viewer,
476 * retrieving it if necessary first.
483 * if true, new structure(s) will be align using associated alignment
485 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
486 final String[] chains, final boolean b,
487 final IProgressIndicator alignFrame)
489 if (pdbentry.getFile() == null)
491 if (worker != null && worker.isAlive())
493 // a retrieval is in progress, wait around and add ourselves to the
495 new Thread(new Runnable()
499 while (worker != null && worker.isAlive() && _started)
503 Thread.sleep(100 + ((int) Math.random() * 100));
505 } catch (Exception e)
510 // and call ourselves again.
511 addStructure(pdbentry, seq, chains, b, alignFrame);
517 // otherwise, start adding the structure.
518 jmb.addSequenceAndChain(new PDBEntry[]
519 { pdbentry }, new SequenceI[][]
520 { seq }, new String[][]
522 addingStructures = true;
524 alignAddedStructures = b;
525 progressBar = alignFrame; // visual indication happens on caller frame.
526 (worker = new Thread(this)).start();
530 private Vector getJmolsFor(AlignmentPanel ap2)
532 Vector otherJmols = new Vector();
533 // Now this AppJmol is mapped to new sequences. We must add them to
534 // the exisiting array
535 JInternalFrame[] frames = Desktop.instance.getAllFrames();
537 for (int i = 0; i < frames.length; i++)
539 if (frames[i] instanceof AppJmol)
541 AppJmol topJmol = ((AppJmol) frames[i]);
542 if (topJmol.isLinkedWith(ap2))
544 otherJmols.addElement(topJmol);
551 void initJmol(String command)
553 jmb.setFinishedInit(false);
554 renderPanel = new RenderPanel();
555 // TODO: consider waiting until the structure/view is fully loaded before
557 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
558 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
559 getBounds().width, getBounds().height);
560 if (scriptWindow == null)
562 BorderLayout bl = new BorderLayout();
565 scriptWindow = new JPanel(bl);
566 scriptWindow.setVisible(false);
569 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
571 jmb.newJmolPopup(true, "Jmol", true);
576 jmb.evalStateCommand(command);
577 jmb.setFinishedInit(true);
580 void setChainMenuItems(Vector chains)
582 chainMenu.removeAll();
587 JMenuItem menuItem = new JMenuItem("All");
588 menuItem.addActionListener(new ActionListener()
590 public void actionPerformed(ActionEvent evt)
592 allChainsSelected = true;
593 for (int i = 0; i < chainMenu.getItemCount(); i++)
595 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
596 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
599 allChainsSelected = false;
603 chainMenu.add(menuItem);
605 for (int c = 0; c < chains.size(); c++)
607 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
608 menuItem.addItemListener(new ItemListener()
610 public void itemStateChanged(ItemEvent evt)
612 if (!allChainsSelected)
617 chainMenu.add(menuItem);
621 boolean allChainsSelected = false;
623 private boolean alignAddedStructures = false;
627 Vector toshow = new Vector();
629 int mlength, p, mnum;
630 for (int i = 0; i < chainMenu.getItemCount(); i++)
632 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
634 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
635 if (item.isSelected())
637 toshow.addElement(item.getText());
641 jmb.centerViewer(toshow);
651 // TODO: check for memory leaks where instance isn't finalised because jmb
652 // holds a reference to the window
657 * state flag for PDB retrieval thread
659 private boolean _started = false;
662 * state flag indicating if the GUI is active when a particular button event
663 * takes place (e.g. when a stateChange occurs on a checkbox - this could be
664 * programmatic or due to the user doing something)
666 private boolean handlingGuiEvents=false;
672 // todo - record which pdbids were successfuly imported.
673 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
676 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
677 // TODO: replace with reference fetching/transfer code (validate PDBentry
679 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
680 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
682 String file = jmb.pdbentry[pi].getFile();
685 // retrieve the pdb and store it locally
686 AlignmentI pdbseq = null;
687 pdbid = jmb.pdbentry[pi].getId();
688 long hdl = pdbid.hashCode() - System.currentTimeMillis();
689 if (progressBar != null)
691 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
695 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
697 } catch (OutOfMemoryError oomerror)
699 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
700 } catch (Exception ex)
702 ex.printStackTrace();
703 errormsgs.append("'" + pdbid + "'");
705 if (progressBar != null)
707 progressBar.setProgressBar("Finished.", hdl);
711 // just transfer the file name from the first sequence's first
713 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
714 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
715 files.append(" \"" + file + "\"");
719 errormsgs.append("'" + pdbid + "' ");
724 if (curfiles != null && curfiles.length > 0)
726 addingStructures = true; // already files loaded.
727 for (int c = 0; c < curfiles.length; c++)
729 if (curfiles[c].equals(file))
738 files.append(" \"" + file + "\"");
742 } catch (OutOfMemoryError oomerror)
744 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
745 } catch (Exception ex)
747 ex.printStackTrace();
748 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
751 if (errormsgs.length() > 0)
754 JOptionPane.showInternalMessageDialog(Desktop.desktop,
755 "The following pdb entries could not be retrieved from the PDB:\n"
756 + errormsgs.toString()
757 + "\nPlease try downloading them manually.",
758 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
761 if (files.length() > 0)
763 if (!addingStructures)
768 initJmol("load FILES " + files.toString());
769 } catch (OutOfMemoryError oomerror)
771 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
772 Cache.log.debug("File locations are " + files);
773 } catch (Exception ex)
775 Cache.log.error("Couldn't open Jmol viewer!", ex);
780 StringBuffer cmd = new StringBuffer();
781 cmd.append("loadingJalviewdata=true\nload APPEND ");
782 cmd.append(files.toString());
783 cmd.append("\nloadingJalviewdata=null");
784 final String command = cmd.toString();
786 long lastnotify = jmb.getLoadNotifiesHandled();
789 jmb.evalStateCommand(command);
790 } catch (OutOfMemoryError oomerror)
793 "When trying to add structures to the Jmol viewer!",
795 Cache.log.debug("File locations are " + files);
796 } catch (Exception ex)
798 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
800 // need to wait around until script has finished
801 while (lastnotify >= jmb.getLoadNotifiesHandled())
807 } catch (Exception e)
811 // refresh the sequence colours for the new structure(s)
812 for (AlignmentPanel ap : _colourwith)
814 jmb.updateColours(ap);
816 // do superposition if asked to
817 if (alignAddedStructures)
819 javax.swing.SwingUtilities.invokeLater(new Runnable()
823 alignStructs_withAllAlignPanels();
824 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
827 alignAddedStructures = false;
829 addingStructures = false;
836 public void pdbFile_actionPerformed(ActionEvent actionEvent)
838 JalviewFileChooser chooser = new JalviewFileChooser(
839 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
841 chooser.setFileView(new JalviewFileView());
842 chooser.setDialogTitle("Save PDB File");
843 chooser.setToolTipText("Save");
845 int value = chooser.showSaveDialog(this);
847 if (value == JalviewFileChooser.APPROVE_OPTION)
851 // TODO: cope with multiple PDB files in view
852 BufferedReader in = new BufferedReader(new FileReader(
853 jmb.getPdbFile()[0]));
854 File outFile = chooser.getSelectedFile();
856 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
858 while ((data = in.readLine()) != null)
860 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
866 } catch (Exception ex)
868 ex.printStackTrace();
873 public void viewMapping_actionPerformed(ActionEvent actionEvent)
875 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
878 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
880 cap.appendText(StructureSelectionManager
881 .getStructureSelectionManager().printMapping(
882 jmb.pdbentry[pdbe].getFile()));
883 cap.appendText("\n");
885 } catch (OutOfMemoryError e)
888 "composing sequence-structure alignments for display in text box.",
893 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
903 public void eps_actionPerformed(ActionEvent e)
905 makePDBImage(jalview.util.ImageMaker.EPS);
914 public void png_actionPerformed(ActionEvent e)
916 makePDBImage(jalview.util.ImageMaker.PNG);
919 void makePDBImage(int type)
921 int width = getWidth();
922 int height = getHeight();
924 jalview.util.ImageMaker im;
926 if (type == jalview.util.ImageMaker.PNG)
928 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
929 "Make PNG image from view", width, height, null, null);
933 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
934 "Make EPS file from view", width, height, null,
938 if (im.getGraphics() != null)
940 Rectangle rect = new Rectangle(width, height);
941 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
945 public void jmolColour_actionPerformed(ActionEvent actionEvent)
947 if (jmolColour.isSelected()) {
948 // disable automatic sequence colouring.
949 jmb.setColourBySequence(false);
952 public void seqColour_actionPerformed(ActionEvent actionEvent)
954 jmb.setColourBySequence(seqColour.isSelected());
955 if (_colourwith == null)
957 _colourwith = new ArrayList<AlignmentPanel>();
959 if (jmb.isColourBySequence())
961 if (!jmb.isLoadingFromArchive() && handlingGuiEvents)
964 // Make the currently displayed alignment panel the associated view
965 _colourwith.add(ap.alignFrame.alignPanel);
968 // Set the colour using the current view for the associated alignframe
969 for (AlignmentPanel ap : _colourwith)
971 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
976 public void chainColour_actionPerformed(ActionEvent actionEvent)
978 chainColour.setSelected(true);
982 public void chargeColour_actionPerformed(ActionEvent actionEvent)
984 chargeColour.setSelected(true);
985 jmb.colourByCharge();
988 public void zappoColour_actionPerformed(ActionEvent actionEvent)
990 zappoColour.setSelected(true);
991 jmb.setJalviewColourScheme(new ZappoColourScheme());
994 public void taylorColour_actionPerformed(ActionEvent actionEvent)
996 taylorColour.setSelected(true);
997 jmb.setJalviewColourScheme(new TaylorColourScheme());
1000 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1002 hydroColour.setSelected(true);
1003 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1006 public void helixColour_actionPerformed(ActionEvent actionEvent)
1008 helixColour.setSelected(true);
1009 jmb.setJalviewColourScheme(new HelixColourScheme());
1012 public void strandColour_actionPerformed(ActionEvent actionEvent)
1014 strandColour.setSelected(true);
1015 jmb.setJalviewColourScheme(new StrandColourScheme());
1018 public void turnColour_actionPerformed(ActionEvent actionEvent)
1020 turnColour.setSelected(true);
1021 jmb.setJalviewColourScheme(new TurnColourScheme());
1024 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1026 buriedColour.setSelected(true);
1027 jmb.setJalviewColourScheme(new BuriedColourScheme());
1030 public void userColour_actionPerformed(ActionEvent actionEvent)
1032 userColour.setSelected(true);
1033 new UserDefinedColours(this, null);
1036 public void backGround_actionPerformed(ActionEvent actionEvent)
1038 java.awt.Color col = JColorChooser.showDialog(this,
1039 "Select Background Colour", null);
1042 jmb.setBackgroundColour(col);
1046 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1050 jalview.util.BrowserLauncher
1051 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1052 } catch (Exception ex)
1057 public void showConsole(boolean showConsole)
1062 if (splitPane == null)
1064 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1065 splitPane.setTopComponent(renderPanel);
1066 splitPane.setBottomComponent(scriptWindow);
1067 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1068 splitPane.setDividerLocation(getHeight() - 200);
1069 scriptWindow.setVisible(true);
1070 scriptWindow.validate();
1071 splitPane.validate();
1077 if (splitPane != null)
1079 splitPane.setVisible(false);
1084 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1090 class RenderPanel extends JPanel
1092 final Dimension currentSize = new Dimension();
1094 final Rectangle rectClip = new Rectangle();
1096 public void paintComponent(Graphics g)
1098 getSize(currentSize);
1099 g.getClipBounds(rectClip);
1101 if (jmb.fileLoadingError != null)
1103 g.setColor(Color.black);
1104 g.fillRect(0, 0, currentSize.width, currentSize.height);
1105 g.setColor(Color.white);
1106 g.setFont(new Font("Verdana", Font.BOLD, 14));
1107 g.drawString("Error loading file...", 20, currentSize.height / 2);
1108 StringBuffer sb = new StringBuffer();
1110 for (int e = 0; e < jmb.pdbentry.length; e++)
1112 sb.append(jmb.pdbentry[e].getId());
1113 if (e < jmb.pdbentry.length - 1)
1118 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1121 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1122 * g.getFontMetrics().getHeight());
1126 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1128 g.setColor(Color.black);
1129 g.fillRect(0, 0, currentSize.width, currentSize.height);
1130 g.setColor(Color.white);
1131 g.setFont(new Font("Verdana", Font.BOLD, 14));
1132 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1136 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1141 String viewId = null;
1143 public String getViewId()
1147 viewId = System.currentTimeMillis() + "." + this.hashCode();
1152 public void updateTitleAndMenus()
1154 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1159 setChainMenuItems(jmb.chainNames);
1161 this.setTitle(jmb.getViewerTitle());
1162 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1164 jmolActionMenu.setVisible(true);
1166 if (!jmb.isLoadingFromArchive())
1168 seqColour_actionPerformed(null);
1172 protected void buildJmolActionMenu()
1174 if (_alignwith == null)
1176 _alignwith = new ArrayList<AlignmentPanel>();
1178 if (_alignwith.size() == 0 && ap != null)
1183 for (Component c : jmolActionMenu.getMenuComponents())
1185 if (c != alignStructs)
1187 jmolActionMenu.remove((JMenuItem) c);
1190 final ItemListener handler;
1197 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1201 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1203 alignStructs_withAllAlignPanels();
1206 private void alignStructs_withAllAlignPanels()
1213 if (_alignwith.size() == 0)
1220 AlignmentI[] als = new Alignment[_alignwith.size()];
1221 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1222 int[] alm = new int[_alignwith.size()];
1225 for (AlignmentPanel ap : _alignwith)
1227 als[a] = ap.av.getAlignment();
1229 alc[a++] = ap.av.getColumnSelection();
1231 jmb.superposeStructures(als, alm, alc);
1232 } catch (Exception e)
1234 StringBuffer sp = new StringBuffer();
1235 for (AlignmentPanel ap : _alignwith)
1237 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1239 Cache.log.info("Couldn't align structures with the " + sp.toString()
1240 + "associated alignment panels.", e);
1246 public void setJalviewColourScheme(ColourSchemeI ucs)
1248 jmb.setJalviewColourScheme(ucs);
1255 * @return first alignment panel displaying given alignment, or the default
1258 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1260 for (AlignmentPanel ap : getAllAlignmentPanels())
1262 if (ap.av.getAlignment() == alignment)
1273 * @return true if this Jmol instance is linked with the given alignPanel
1275 public boolean isLinkedWith(AlignmentPanel ap2)
1277 return _aps.contains(ap2.av.getSequenceSetId());
1280 public boolean isUsedforaligment(AlignmentPanel ap2)
1283 return (_alignwith != null) && _alignwith.contains(ap2);
1286 public boolean isUsedforcolourby(AlignmentPanel ap2)
1288 return (_colourwith != null) && _colourwith.contains(ap2);