X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAppletJmol.java;h=46f5b49d98533524c3ab0bec95376b2db0ea251b;hb=865a855a4ca87eadb3e5ff284ed32ed307d9c34b;hp=e45bd28ea55fe4f25bd70d9763d731b3a1d1c71f;hpb=05c04b298565cdc668027027e13d0ac6f8bc8517;p=jalview.git diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index e45bd28..46f5b49 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -1,19 +1,20 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) - * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1) + * Copyright (C) 2014 The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * + * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.appletgui; @@ -26,11 +27,6 @@ import jalview.datamodel.*; import jalview.structure.*; import jalview.io.*; -import org.jmol.api.*; - -import org.jmol.popup.*; -import org.jmol.viewer.JmolConstants; - import jalview.schemes.*; public class AppletJmol extends EmbmenuFrame implements @@ -52,6 +48,8 @@ public class AppletJmol extends EmbmenuFrame implements CheckboxMenuItem seqColour = new CheckboxMenuItem("By Sequence", true); + CheckboxMenuItem jmolColour = new CheckboxMenuItem("Using Jmol", false); + MenuItem chain = new MenuItem("By Chain"); MenuItem charge = new MenuItem("Charge & Cysteine"); @@ -70,6 +68,8 @@ public class AppletJmol extends EmbmenuFrame implements MenuItem buried = new MenuItem("Buried Index"); + MenuItem purinepyrimidine = new MenuItem("Purine/Pyrimidine"); + MenuItem user = new MenuItem("User Defined Colours"); MenuItem jmolHelp = new MenuItem("Jmol Help"); @@ -84,6 +84,8 @@ public class AppletJmol extends EmbmenuFrame implements AlignmentPanel ap; + ArrayList _aps = new ArrayList(); + String fileLoadingError; boolean loadedInline; @@ -98,25 +100,42 @@ public class AppletJmol extends EmbmenuFrame implements * datasource protocol for access to PDBEntry */ String protocol = null; + /** - * Load a bunch of pdb entries associated with sequences in the alignment and display them - aligning them if necessary. - * @param pdbentries each pdb file (at least one needed) - * @param boundseqs each set of sequences for each pdb file (must match number of pdb files) - * @param boundchains the target pdb chain corresponding with each sequence associated with each pdb file (may be null at any level) - * @param align true/false - * @param ap associated alignment - * @param protocol how to get pdb data + * Load a bunch of pdb entries associated with sequences in the alignment and + * display them - aligning them if necessary. + * + * @param pdbentries + * each pdb file (at least one needed) + * @param boundseqs + * each set of sequences for each pdb file (must match number of pdb + * files) + * @param boundchains + * the target pdb chain corresponding with each sequence associated + * with each pdb file (may be null at any level) + * @param align + * true/false + * @param ap + * associated alignment + * @param protocol + * how to get pdb data */ - public AppletJmol(PDBEntry[] pdbentries, SequenceI[][] boundseqs, String[][] boundchains, boolean align, AlignmentPanel ap, String protocol) + public AppletJmol(PDBEntry[] pdbentries, SequenceI[][] boundseqs, + String[][] boundchains, boolean align, AlignmentPanel ap, + String protocol) { throw new Error("Not yet implemented."); } + public AppletJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains, AlignmentPanel ap, String protocol) { this.ap = ap; - jmb = new AppletJmolBinding(this, new PDBEntry[] - { pdbentry }, new SequenceI[][]{seq}, new String[][]{ chains }, protocol); + jmb = new AppletJmolBinding(this, ap.getStructureSelectionManager(), + new PDBEntry[] + { pdbentry }, new SequenceI[][] + { seq }, new String[][] + { chains }, protocol); jmb.setColourBySequence(true); if (pdbentry.getId() == null || pdbentry.getId().length() < 1) { @@ -138,13 +157,14 @@ public class AppletJmol extends EmbmenuFrame implements } String alreadyMapped = StructureSelectionManager - .getStructureSelectionManager().alreadyMappedToFile( - pdbentry.getId()); + .getStructureSelectionManager(ap.av.applet) + .alreadyMappedToFile(pdbentry.getId()); MCview.PDBfile reader = null; if (alreadyMapped != null) { - reader = StructureSelectionManager.getStructureSelectionManager() - .setMapping(seq, chains, pdbentry.getFile(), protocol); + reader = StructureSelectionManager.getStructureSelectionManager( + ap.av.applet).setMapping(seq, chains, pdbentry.getFile(), + protocol); // PROMPT USER HERE TO ADD TO NEW OR EXISTING VIEW? // FOR NOW, LETS JUST OPEN A NEW WINDOW } @@ -161,12 +181,14 @@ public class AppletJmol extends EmbmenuFrame implements hydro.addActionListener(this); chain.addActionListener(this); seqColour.addItemListener(this); + jmolColour.addItemListener(this); zappo.addActionListener(this); taylor.addActionListener(this); helix.addActionListener(this); strand.addActionListener(this); turn.addActionListener(this); buried.addActionListener(this); + purinepyrimidine.addActionListener(this); user.addActionListener(this); jmolHelp.addActionListener(this); @@ -181,20 +203,26 @@ public class AppletJmol extends EmbmenuFrame implements coloursMenu.add(strand); coloursMenu.add(turn); coloursMenu.add(buried); + coloursMenu.add(purinepyrimidine); coloursMenu.add(user); - + coloursMenu.add(jmolColour); helpMenu.add(jmolHelp); + this.setLayout(new BorderLayout()); setMenuBar(menuBar); renderPanel = new RenderPanel(); embedMenuIfNeeded(renderPanel); this.add(renderPanel, BorderLayout.CENTER); + scriptWindow = new Panel(); + scriptWindow.setVisible(false); + // this.add(scriptWindow, BorderLayout.SOUTH); + try { - jmb.allocateViewer(renderPanel, true, ap.av.applet.getName()+"_jmol_", - ap.av.applet.getDocumentBase(), ap.av.applet.getCodeBase(), - "-applet"); + jmb.allocateViewer(renderPanel, true, ap.av.applet.getName() + + "_jmol_", ap.av.applet.getDocumentBase(), + ap.av.applet.getCodeBase(), "-applet", scriptWindow, null); } catch (Exception e) { System.err @@ -215,7 +243,7 @@ public class AppletJmol extends EmbmenuFrame implements closeViewer(); } }); - if (pdbentry.getProperty()==null) + if (pdbentry.getProperty() == null) { pdbentry.setProperty(new Hashtable()); pdbentry.getProperty().put("protocol", protocol); @@ -354,19 +382,19 @@ public class AppletJmol extends EmbmenuFrame implements frame.add(cap); StringBuffer sb = new StringBuffer(); - try { - for (int s = 0; s < jmb.pdbentry.length; s++) + try { - sb.append(StructureSelectionManager.getStructureSelectionManager() - .printMapping(jmb.pdbentry[s].getFile())); - sb.append("\n"); - } - cap.setText(sb.toString()); - } - catch (OutOfMemoryError ex) + for (int s = 0; s < jmb.pdbentry.length; s++) + { + sb.append(jmb.printMapping(jmb.pdbentry[s].getFile())); + sb.append("\n"); + } + cap.setText(sb.toString()); + } catch (OutOfMemoryError ex) { frame.dispose(); - System.err.println("Out of memory when trying to create dialog box with sequence-structure mapping."); + System.err + .println("Out of memory when trying to create dialog box with sequence-structure mapping."); return; } jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping", @@ -418,6 +446,10 @@ public class AppletJmol extends EmbmenuFrame implements setEnabled(buried); jmb.setJalviewColourScheme(new BuriedColourScheme()); } + else if (evt.getSource() == purinepyrimidine) + { + jmb.setJalviewColourScheme(new PurinePyrimidineColourScheme()); + } else if (evt.getSource() == user) { setEnabled(user); @@ -450,23 +482,29 @@ public class AppletJmol extends EmbmenuFrame implements } /** - * tick or untick the seqColour menu entry depending upon if it was selected - * or not. + * tick or untick the seqColour menu entry or jmoColour entry depending upon + * if it was selected or not. * * @param itm */ private void setEnabled(MenuItem itm) { + jmolColour.setState(itm == jmolColour); seqColour.setState(itm == seqColour); jmb.setColourBySequence(itm == seqColour); } public void itemStateChanged(ItemEvent evt) { - if (evt.getSource() == seqColour) + if (evt.getSource() == jmolColour) + { + setEnabled(jmolColour); + jmb.setColourBySequence(false); + } + else if (evt.getSource() == seqColour) { setEnabled(seqColour); - jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment); + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); } else if (!allChainsSelected) centerViewer(); @@ -494,7 +532,7 @@ public class AppletJmol extends EmbmenuFrame implements public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; - jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment); + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); } public void updateTitleAndMenus() @@ -505,7 +543,7 @@ public class AppletJmol extends EmbmenuFrame implements return; } setChainMenuItems(jmb.chainNames); - jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment); + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); setTitle(jmb.getViewerTitle()); } @@ -521,22 +559,30 @@ public class AppletJmol extends EmbmenuFrame implements } } + Panel splitPane = null; + public void showConsole(boolean showConsole) { - if (scriptWindow == null) - { - scriptWindow = new Panel(new BorderLayout()); - inputLine = new TextField(); - history = new TextArea(5, 40); - scriptWindow.add(history, BorderLayout.CENTER); - scriptWindow.add(inputLine, BorderLayout.SOUTH); - add(scriptWindow, BorderLayout.SOUTH); + if (showConsole) + { + remove(renderPanel); + splitPane = new Panel(); + + splitPane.setLayout(new java.awt.GridLayout(2, 1)); + splitPane.add(renderPanel); + splitPane.add(scriptWindow); + scriptWindow.setVisible(true); + this.add(splitPane, BorderLayout.CENTER); + splitPane.setVisible(true); + splitPane.validate(); + } + else + { scriptWindow.setVisible(false); - history.setEditable(false); - inputLine.addKeyListener(this); + remove(splitPane); + add(renderPanel, BorderLayout.CENTER); + splitPane = null; } - - scriptWindow.setVisible(!scriptWindow.isVisible()); validate(); } @@ -601,4 +647,16 @@ public class AppletJmol extends EmbmenuFrame implements { jmb.setJalviewColourScheme(ucs); } + + public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment) + { + for (int i = 0; i < _aps.size(); i++) + { + if (((AlignmentPanel) _aps.get(i)).av.getAlignment() == alignment) + { + return ((AlignmentPanel) _aps.get(i)); + } + } + return ap; + } }