X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fappletgui%2FAppletJmol.java;h=b0722c084a30cacb609f8f3bb4d3a4f2b04e3d38;hb=a7169b1c72607f3c9357195b4999869650a2a891;hp=6e2047baa2eb62581d09fa0809e6e1cfdf3416bb;hpb=3c7a633b4868a7a95ed1cfe19be6dd44c22ac473;p=jalview.git
diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java
index 6e2047b..b0722c0 100644
--- a/src/jalview/appletgui/AppletJmol.java
+++ b/src/jalview/appletgui/AppletJmol.java
@@ -1,127 +1,222 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
- * This program 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 2
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ 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.
- *
- * This program 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.
- *
+ *
+ * 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
-
package jalview.appletgui;
-import java.util.*;
-import java.awt.*;
-import java.awt.event.*;
+import java.awt.BorderLayout;
+import java.awt.CheckboxMenuItem;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.Panel;
+import java.awt.TextArea;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+import jalview.bin.JalviewLite;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
+import jalview.io.FileParse;
+import jalview.io.StructureFile;
+import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.HelixColourScheme;
+import jalview.schemes.HydrophobicColourScheme;
+import jalview.schemes.PurinePyrimidineColourScheme;
+import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TaylorColourScheme;
+import jalview.schemes.TurnColourScheme;
+import jalview.schemes.UserColourScheme;
+import jalview.schemes.ZappoColourScheme;
+import jalview.structure.StructureSelectionManager;
+import jalview.util.MessageManager;
+
+public class AppletJmol extends EmbmenuFrame implements
+ // StructureListener,
+ KeyListener, ActionListener, ItemListener
-import jalview.datamodel.*;
-import jalview.structure.*;
-import jalview.io.*;
+{
+ Menu fileMenu = new Menu(MessageManager.getString("action.file"));
-import org.jmol.api.*;
-import org.jmol.adapter.smarter.SmarterJmolAdapter;
+ Menu viewMenu = new Menu(MessageManager.getString("action.view"));
-import org.jmol.popup.*;
-import jalview.schemes.*;
+ Menu coloursMenu = new Menu(MessageManager.getString("action.colour"));
+ Menu chainMenu = new Menu(MessageManager.getString("action.show_chain"));
-public class AppletJmol extends Frame
- implements StructureListener, JmolStatusListener,
- KeyListener, ActionListener, ItemListener
+ Menu helpMenu = new Menu(MessageManager.getString("action.help"));
-{
- Menu fileMenu = new Menu("File");
- Menu viewMenu = new Menu("View");
- Menu coloursMenu = new Menu("Colours");
- Menu chainMenu = new Menu("Show Chain");
- Menu helpMenu = new Menu("Help");
- MenuItem mappingMenuItem = new MenuItem("View Mapping");
-
- CheckboxMenuItem seqColour = new CheckboxMenuItem("By Sequence", true);
- MenuItem chain = new MenuItem("By Chain");
- MenuItem charge = new MenuItem("Charge & Cysteine");
- MenuItem zappo = new MenuItem("Zappo");
- MenuItem taylor = new MenuItem("Taylor");
- MenuItem hydro = new MenuItem("Hydrophobicity");
- MenuItem helix = new MenuItem("Helix Propensity");
- MenuItem strand = new MenuItem("Strand Propensity");
- MenuItem turn = new MenuItem("Turn Propensity");
- MenuItem buried = new MenuItem("Buried Index");
- MenuItem user = new MenuItem("User Defined Colours");
-
- MenuItem jmolHelp = new MenuItem("Jmol Help");
-
- JmolViewer viewer;
- JmolPopup jmolpopup;
+ MenuItem mappingMenuItem = new MenuItem(
+ MessageManager.getString("label.view_mapping"));
+
+ CheckboxMenuItem seqColour = new CheckboxMenuItem(
+ MessageManager.getString("action.by_sequence"), true);
+
+ CheckboxMenuItem jmolColour = new CheckboxMenuItem(
+ MessageManager.getString("action.using_jmol"), false);
+
+ MenuItem chain = new MenuItem(
+ MessageManager.getString("action.by_chain"));
+
+ MenuItem charge = new MenuItem(
+ MessageManager.getString("label.charge_cysteine"));
+
+ MenuItem zappo = new MenuItem(
+ MessageManager.getString("label.colourScheme_zappo"));
+
+ MenuItem taylor = new MenuItem(
+ MessageManager.getString("label.colourScheme_taylor"));
+
+ MenuItem hydro = new MenuItem(
+ MessageManager.getString("label.colourScheme_hydrophobic"));
+
+ MenuItem helix = new MenuItem(
+ MessageManager.getString("label.colourScheme_helixpropensity"));
+
+ MenuItem strand = new MenuItem(
+ MessageManager.getString("label.colourScheme_strandpropensity"));
+
+ MenuItem turn = new MenuItem(
+ MessageManager.getString("label.colourScheme_turnpropensity"));
+
+ MenuItem buried = new MenuItem(
+ MessageManager.getString("label.colourScheme_buriedindex"));
+
+ MenuItem purinepyrimidine = new MenuItem(
+ MessageManager.getString("label.colourScheme_purine/pyrimidine"));
+
+ MenuItem user = new MenuItem(
+ MessageManager.getString("label.user_defined_colours"));
+
+ MenuItem jmolHelp = new MenuItem(
+ MessageManager.getString("label.jmol_help"));
Panel scriptWindow;
+
TextField inputLine;
+
TextArea history;
- SequenceI[] sequence;
- String [] chains;
- StructureSelectionManager ssm;
+
RenderPanel renderPanel;
+
AlignmentPanel ap;
+
+ List _aps = new ArrayList<>(); // remove? never
+ // added to
+
String fileLoadingError;
+
boolean loadedInline;
- PDBEntry pdbentry;
- boolean colourBySequence = true;
- Vector atomsPicked = new Vector();
-
- public AppletJmol(PDBEntry pdbentry,
- SequenceI[] seq,
- String[] chains,
- AlignmentPanel ap,
- String protocol)
+
+ // boolean colourBySequence = true;
+
+ FeatureRenderer fr = null;
+
+ AppletJmolBinding jmb;
+
+ /**
+ * 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
+ */
+ public AppletJmol(PDBEntry[] pdbentries, SequenceI[][] boundseqs,
+ String[][] boundchains, boolean align, AlignmentPanel ap,
+ String protocol)
+ {
+ throw new Error(MessageManager.getString("error.not_yet_implemented"));
+ }
+
+ public AppletJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
+ AlignmentPanel ap, DataSourceType protocol)
{
this.ap = ap;
- this.sequence = seq;
- this.chains = chains;
- this.pdbentry = pdbentry;
+ jmb = new AppletJmolBinding(this, ap.getStructureSelectionManager(),
+ new PDBEntry[]
+ { pdbentry }, new SequenceI[][] { seq }, protocol);
+ jmb.setColourBySequence(true);
+ if (pdbentry.getId() == null || pdbentry.getId().length() < 1)
+ {
+ if (protocol == DataSourceType.PASTE)
+ {
+ pdbentry.setId(
+ "PASTED PDB" + (chains == null ? "_" : chains.toString()));
+ }
+ else
+ {
+ pdbentry.setId(pdbentry.getFile());
+ }
+ }
- String alreadyMapped = StructureSelectionManager
- .getStructureSelectionManager()
- .alreadyMappedToFile(pdbentry.getId());
+ if (JalviewLite.debug)
+ {
+ System.err
+ .println("AppletJmol: PDB ID is '" + pdbentry.getId() + "'");
+ }
+ String alreadyMapped = StructureSelectionManager
+ .getStructureSelectionManager(ap.av.applet)
+ .alreadyMappedToFile(pdbentry.getId());
+ StructureFile reader = null;
if (alreadyMapped != null)
{
- StructureSelectionManager.getStructureSelectionManager()
- .setMapping(seq, chains, pdbentry.getFile(), protocol);
- //PROMPT USER HERE TO ADD TO NEW OR EXISTING VIEW?
- //FOR NOW, LETS JUST OPEN A NEW WINDOW
+ reader = StructureSelectionManager
+ .getStructureSelectionManager(ap.av.applet)
+ .setMapping(seq, chains, pdbentry.getFile(), protocol, null);
+ // PROMPT USER HERE TO ADD TO NEW OR EXISTING VIEW?
+ // FOR NOW, LETS JUST OPEN A NEW WINDOW
}
-
- renderPanel = new RenderPanel();
-
- this.add(renderPanel, BorderLayout.CENTER);
- viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter());
-
- viewer.setAppletContext("jalview",
- ap.av.applet.getDocumentBase(),
- ap.av.applet.getCodeBase(),
- null);
-
- viewer.setJmolStatusListener(this);
-
- jmolpopup = JmolPopup.newJmolPopup(viewer);
-
- this.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent evt)
- {
- closeViewer();
- }
- });
-
MenuBar menuBar = new MenuBar();
menuBar.add(fileMenu);
fileMenu.add(mappingMenuItem);
@@ -135,12 +230,14 @@ public class AppletJmol extends Frame
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);
@@ -155,155 +252,261 @@ public class AppletJmol extends Frame
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());
- this.setMenuBar(menuBar);
+ setMenuBar(menuBar);
- if(pdbentry.getFile()!=null)
+ 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", scriptWindow, null);
+ } catch (Exception e)
+ {
+ System.err.println(
+ "Couldn't create a jmol viewer. Args to allocate viewer were:\nDocumentBase="
+ + ap.av.applet.getDocumentBase() + "\nCodebase="
+ + ap.av.applet.getCodeBase());
+ e.printStackTrace();
+ dispose();
+ return;
+ }
+ // jmb.newJmolPopup(true, "Jmol", true);
+
+ this.addWindowListener(new WindowAdapter()
{
- if (protocol.equals(AppletFormatAdapter.PASTE))
+ @Override
+ public void windowClosing(WindowEvent evt)
+ {
+ closeViewer();
+ }
+ });
+ pdbentry.setProperty("protocol", protocol);
+ if (pdbentry.getFile() != null)
+
+ {
+ // import structure data from pdbentry.getFile based on given protocol
+ if (protocol == DataSourceType.PASTE)
+ {
+ // TODO: JAL-623 : correctly record file contents for matching up later
+ // pdbentry.getProperty().put("pdbfilehash",""+pdbentry.getFile().hashCode());
loadInline(pdbentry.getFile());
+ }
+ else if (protocol == DataSourceType.FILE
+ || protocol == DataSourceType.URL)
+ {
+ jmb.jmolViewer.openFile(pdbentry.getFile());
+ }
else
- viewer.openFile(pdbentry.getFile());
+ {
+ // probably CLASSLOADER based datasource..
+ // Try and get a reader on the datasource, and pass that to Jmol
+ try
+ {
+ java.io.Reader freader = null;
+ if (reader != null)
+ {
+ if (jalview.bin.JalviewLite.debug)
+ {
+ System.err.println(
+ "AppletJmol:Trying to reuse existing PDBfile IO parser.");
+ }
+ // re-use the one we opened earlier
+ freader = reader.getReader();
+ }
+ if (freader == null)
+ {
+ if (jalview.bin.JalviewLite.debug)
+ {
+ System.err.println(
+ "AppletJmol:Creating new PDBfile IO parser.");
+ }
+ FileParse fp = new FileParse(pdbentry.getFile(), protocol);
+ fp.mark();
+ // reader = new mc_view.PDBfile(fp);
+ // could set ID, etc.
+ // if (!reader.isValid())
+ // {
+ // throw new Exception("Invalid datasource.
+ // "+reader.getWarningMessage());
+ // }
+ // fp.reset();
+ freader = fp.getReader();
+ }
+ if (freader == null)
+ {
+ throw new Exception(MessageManager.getString(
+ "exception.invalid_datasource_couldnt_obtain_reader"));
+ }
+ jmb.jmolViewer.openReader(pdbentry.getFile(), pdbentry.getId(),
+ freader);
+ } catch (Exception e)
+ {
+ // give up!
+ System.err.println("Couldn't access pdbentry id="
+ + pdbentry.getId() + " and file=" + pdbentry.getFile()
+ + " using protocol=" + protocol);
+ e.printStackTrace();
+ }
+ }
}
- jalview.bin.JalviewLite.addFrame(this, "Jmol", 400,400);
+ jalview.bin.JalviewLite.addFrame(this, jmb.getViewerTitle(), 400, 400);
}
public void loadInline(String string)
{
loadedInline = true;
- viewer.openStringInline(string);
+ jmb.loadInline(string);
}
-
- void setChainMenuItems(Vector chains)
+ void setChainMenuItems(List chains)
{
chainMenu.removeAll();
- MenuItem menuItem = new MenuItem("All");
+ MenuItem menuItem = new MenuItem(MessageManager.getString("label.all"));
menuItem.addActionListener(this);
chainMenu.add(menuItem);
CheckboxMenuItem menuItemCB;
- for (int c = 0; c < chains.size(); c++)
+ for (String ch : chains)
{
- menuItemCB = new CheckboxMenuItem(chains.elementAt(c).toString(), true);
+ menuItemCB = new CheckboxMenuItem(ch, true);
menuItemCB.addItemListener(this);
chainMenu.add(menuItemCB);
}
}
boolean allChainsSelected = false;
+
void centerViewer()
{
- StringBuffer cmd = new StringBuffer();
+ Vector toshow = new Vector<>();
for (int i = 0; i < chainMenu.getItemCount(); i++)
{
if (chainMenu.getItem(i) instanceof CheckboxMenuItem)
{
CheckboxMenuItem item = (CheckboxMenuItem) chainMenu.getItem(i);
if (item.getState())
- cmd.append(":" + item.getLabel() + " or ");
+ {
+ toshow.addElement(item.getLabel());
+ }
}
}
-
- if (cmd.length() > 0)
- cmd.setLength(cmd.length() - 4);
-
- viewer.evalString("select *;restrict "
- + cmd + ";cartoon;center " + cmd);
+ jmb.showChains(toshow);
}
-
void closeViewer()
{
- viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE);
- viewer.evalStringQuiet("zap");
- viewer.setJmolStatusListener(null);
- viewer = null;
-
- //We'll need to find out what other
- // listeners need to be shut down in Jmol
- StructureSelectionManager
- .getStructureSelectionManager()
- .removeStructureViewerListener(this, pdbentry.getId());
-
+ jmb.closeViewer(true);
+ jmb = null;
this.setVisible(false);
}
+ @Override
public void actionPerformed(ActionEvent evt)
{
- if(evt.getSource()==mappingMenuItem)
+ if (evt.getSource() == mappingMenuItem)
{
- jalview.appletgui.CutAndPasteTransfer cap
- = new jalview.appletgui.CutAndPasteTransfer(false, null);
+ jalview.appletgui.CutAndPasteTransfer cap = new jalview.appletgui.CutAndPasteTransfer(
+ false, null);
Frame frame = new Frame();
frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping", 550,
- 600);
- cap.setText(
- StructureSelectionManager.getStructureSelectionManager().printMapping(
- pdbentry.getFile())
- );
+ StringBuffer sb = new StringBuffer();
+ try
+ {
+ cap.setText(jmb.printMappings());
+ } catch (OutOfMemoryError ex)
+ {
+ frame.dispose();
+ System.err.println(
+ "Out of memory when trying to create dialog box with sequence-structure mapping.");
+ return;
+ }
+ jalview.bin.JalviewLite.addFrame(frame,
+ MessageManager.getString("label.pdb_sequence_mapping"), 550,
+ 600);
}
else if (evt.getSource() == charge)
{
- colourBySequence = false;
- seqColour.setState(false);
- viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;"
- +"select LYS,ARG;color blue;select CYS;color yellow");
+ setEnabled(charge);
+ jmb.colourByCharge();
}
else if (evt.getSource() == chain)
{
- colourBySequence = false;
- seqColour.setState(false);
- viewer.evalStringQuiet("select *;color chain");
+ setEnabled(chain);
+ jmb.colourByChain();
}
else if (evt.getSource() == zappo)
{
- setJalviewColourScheme(new ZappoColourScheme());
+ setEnabled(zappo);
+ jmb.colourByJalviewColourScheme(new ZappoColourScheme());
}
else if (evt.getSource() == taylor)
{
- setJalviewColourScheme(new TaylorColourScheme());
+ setEnabled(taylor);
+ jmb.colourByJalviewColourScheme(new TaylorColourScheme());
}
else if (evt.getSource() == hydro)
{
- setJalviewColourScheme(new HydrophobicColourScheme());
+ setEnabled(hydro);
+ jmb.colourByJalviewColourScheme(new HydrophobicColourScheme());
}
else if (evt.getSource() == helix)
{
- setJalviewColourScheme(new HelixColourScheme());
+ setEnabled(helix);
+ jmb.colourByJalviewColourScheme(new HelixColourScheme());
}
else if (evt.getSource() == strand)
{
- setJalviewColourScheme(new StrandColourScheme());
+ setEnabled(strand);
+ jmb.colourByJalviewColourScheme(new StrandColourScheme());
}
else if (evt.getSource() == turn)
{
- setJalviewColourScheme(new TurnColourScheme());
+ setEnabled(turn);
+ jmb.colourByJalviewColourScheme(new TurnColourScheme());
}
else if (evt.getSource() == buried)
{
- setJalviewColourScheme(new BuriedColourScheme());
+ setEnabled(buried);
+ jmb.colourByJalviewColourScheme(new BuriedColourScheme());
+ }
+ else if (evt.getSource() == purinepyrimidine)
+ {
+ jmb.colourByJalviewColourScheme(new PurinePyrimidineColourScheme());
}
else if (evt.getSource() == user)
{
+ setEnabled(user);
new UserDefinedColours(this);
}
- else if(evt.getSource() == jmolHelp)
+ else if (evt.getSource() == jmolHelp)
{
- try{
- ap.av.applet.getAppletContext().showDocument(
- new java.net.URL("http://jmol.sourceforge.net/docs/JmolUserGuide/"),
- "jmolHelp");
- }catch(java.net.MalformedURLException ex){}
+ try
+ {
+ ap.av.applet.getAppletContext()
+ .showDocument(new java.net.URL(
+ "http://jmol.sourceforge.net/docs/JmolUserGuide/"),
+ "jmolHelp");
+ } catch (java.net.MalformedURLException ex)
+ {
+ }
}
else
{
@@ -311,505 +514,213 @@ public class AppletJmol extends Frame
for (int i = 0; i < chainMenu.getItemCount(); i++)
{
if (chainMenu.getItem(i) instanceof CheckboxMenuItem)
- ( (CheckboxMenuItem) chainMenu.getItem(i)).setState(true);
+ {
+ ((CheckboxMenuItem) chainMenu.getItem(i)).setState(true);
+ }
}
+
centerViewer();
allChainsSelected = false;
}
}
- public void setJalviewColourScheme(ColourSchemeI cs)
+ /**
+ * 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)
{
- colourBySequence = false;
- seqColour.setState(false);
-
- if(cs==null)
- return;
-
- String res;
- int index;
- Color col;
-
- Enumeration en = ResidueProperties.aa3Hash.keys();
- StringBuffer command = new StringBuffer("select *;color white;");
- while(en.hasMoreElements())
- {
- res = en.nextElement().toString();
- index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
- if(index>20)
- continue;
-
- col = cs.findColour(ResidueProperties.aa[index].charAt(0));
-
- command.append("select "+res+";color["
- + col.getRed() + ","
- + col.getGreen() + ","
- + col.getBlue() + "];");
- }
-
- viewer.evalStringQuiet(command.toString());
+ jmolColour.setState(itm == jmolColour);
+ seqColour.setState(itm == seqColour);
+ jmb.setColourBySequence(itm == seqColour);
}
+ @Override
public void itemStateChanged(ItemEvent evt)
{
- if (evt.getSource() == seqColour)
+ if (evt.getSource() == jmolColour)
{
- colourBySequence = seqColour.getState();
- colourBySequence(ap);
+ setEnabled(jmolColour);
+ jmb.setColourBySequence(false);
+ }
+ else if (evt.getSource() == seqColour)
+ {
+ setEnabled(seqColour);
+ jmb.colourBySequence(ap);
}
else if (!allChainsSelected)
+ {
centerViewer();
+ }
}
+ @Override
public void keyPressed(KeyEvent evt)
{
- if (evt.getKeyCode() == KeyEvent.VK_ENTER
- && scriptWindow.isVisible())
+ if (evt.getKeyCode() == KeyEvent.VK_ENTER && scriptWindow.isVisible())
{
- viewer.evalString(inputLine.getText());
- history.append("\n$ "+inputLine.getText());
+ jmb.eval(inputLine.getText());
+ addToHistory("$ " + inputLine.getText());
inputLine.setText("");
}
}
+ @Override
public void keyTyped(KeyEvent evt)
- { }
-
- public void keyReleased(KeyEvent evt){}
-
- //////////////////////////////////
- ///StructureListener
- public String getPdbFile()
{
- return "???";
}
-
-
- String lastMessage;
- public void mouseOverStructure(int atomIndex, String strInfo)
+ @Override
+ public void keyReleased(KeyEvent evt)
{
- int pdbResNum;
-
- int chainSeparator = strInfo.indexOf(":");
-
- if(chainSeparator==-1)
- chainSeparator = strInfo.indexOf(".");
-
- pdbResNum = Integer.parseInt(
- strInfo.substring(strInfo.indexOf("]")+ 1, chainSeparator));
-
- String chainId;
-
- if (strInfo.indexOf(":") > -1)
- chainId = strInfo.substring
- (strInfo.indexOf(":")+1, strInfo.indexOf("."));
- else
- {
- chainId = " ";
- }
-
- if (lastMessage == null || !lastMessage.equals(strInfo))
- ssm.mouseOverStructure(pdbResNum, chainId, pdbentry.getFile());
-
- lastMessage = strInfo;
- }
-
- StringBuffer resetLastRes = new StringBuffer();
- StringBuffer eval = new StringBuffer();
-
- public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile)
- {
- if (!pdbfile.equals(pdbentry.getFile()))
- return;
-
- if (resetLastRes.length() > 0)
- {
- viewer.evalStringQuiet(resetLastRes.toString());
- }
-
- eval.setLength(0);
- eval.append("select " + pdbResNum);
-
- resetLastRes.setLength(0);
- resetLastRes.append("select " + pdbResNum);
-
- if (!chain.equals(" "))
- {
- eval.append(":" + chain);
- resetLastRes.append(":" + chain);
- }
-
- eval.append(";wireframe 100;"+eval.toString()+".CA;");
-
- resetLastRes.append(";wireframe 0;"+resetLastRes.toString()+".CA;spacefill 0;");
-
- eval.append("spacefill 200;select none");
-
- viewer.evalStringQuiet(eval.toString());
-
}
public void updateColours(Object source)
{
- colourBySequence( (AlignmentPanel) source);
- }
-
-//End StructureListener
-////////////////////////////
-
- public Color getColour(int atomIndex, int pdbResNum, String chain, String pdbfile)
- {
- if (!pdbfile.equals(pdbentry.getFile()))
- return null;
-
- return new Color(viewer.getAtomArgb(atomIndex));
+ AlignmentPanel panel = (AlignmentPanel) source;
+ jmb.colourBySequence(panel);
}
- FeatureRenderer fr;
- String lastCommand;
- public void colourBySequence(AlignmentPanel ap)
+ public void updateTitleAndMenus()
{
- if(!colourBySequence)
- return;
-
-
- StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
-
- if (mapping.length < 1)
- return;
-
- SequenceRenderer sr = new SequenceRenderer(ap.av);
-
- boolean showFeatures = false;
- if (ap.av.showSequenceFeatures)
+ if (jmb.hasFileLoadingError())
{
- showFeatures = true;
- if (fr == null)
- {
- fr = new jalview.appletgui.FeatureRenderer(ap.av);
- }
-
- fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
- }
-
- StringBuffer command = new StringBuffer();
-
- int lastPos = -1;
- for (int s = 0; s < sequence.length; s++)
- {
- for (int m = 0; m < mapping.length; m++)
- {
- if (mapping[m].getSequence() == sequence[s]
- && ap.av.alignment.findIndex(sequence[s])>-1)
- {
- for (int r = 0; r < sequence[s].getLength(); r++)
- {
- int pos = mapping[m].getPDBResNum(
- sequence[s].findPosition(r));
-
- if (pos < 1 || pos==lastPos)
- continue;
-
- lastPos = pos;
-
- Color col = sr.getResidueBoxColour(sequence[s], r);
-
- if (showFeatures)
- col = fr.findFeatureColour(col, sequence[s], r);
-
- if (command.toString().endsWith(":" + mapping[m].getChain()+
- ";color["
- + col.getRed() + ","
- + col.getGreen() + ","
- + col.getBlue() + "]"))
- {
- command = condenseCommand(command.toString(), pos);
- continue;
- }
-
- command.append(";select " + pos);
-
- if (!mapping[m].getChain().equals(" "))
- {
- command.append(":" + mapping[m].getChain());
- }
-
- command.append(";color["
- + col.getRed() + ","
- + col.getGreen() + ","
- + col.getBlue() + "]");
-
- }
- break;
- }
- }
- }
-
- if (lastCommand == null || !lastCommand.equals(command.toString()))
- viewer.evalStringQuiet(command.toString());
-
- lastCommand = command.toString();
- }
-
- StringBuffer condenseCommand(String command, int pos)
- {
-
- StringBuffer sb = new StringBuffer(command.substring(0, command.lastIndexOf("select")+7));
-
- command = command.substring(sb.length());
-
- String start;
-
- if (command.indexOf("-") > -1)
- {
- start = command.substring(0,command.indexOf("-"));
- }
- else
- {
- start = command.substring(0, command.indexOf(":"));
- }
-
- sb.append(start+"-"+pos+command.substring(command.indexOf(":")));
-
- return sb;
- }
-
- /////////////////////////////////
- //JmolStatusListener
-
- public String eval(String strEval)
- {
- // System.out.println(strEval);
- //"# 'eval' is implemented only for the applet.";
- return null;
- }
-
- public void createImage(String file, String type, int quality)
- {}
-
- public void setCallbackFunction(String callbackType,
- String callbackFunction)
- {}
-
- public void notifyFileLoaded(String fullPathName, String fileName,
- String modelName, Object clientFile,
- String errorMsg)
- {
- if(errorMsg!=null)
- {
- fileLoadingError = errorMsg;
repaint();
return;
}
+ setChainMenuItems(jmb.getChainNames());
+ jmb.colourBySequence(ap);
- fileLoadingError = null;
-
- if (fileName != null)
- {
- //FILE LOADED OK
- jmolpopup.updateComputedMenus();
- viewer.evalStringQuiet(
- "select backbone;restrict;cartoon;wireframe off;spacefill off");
-
- ssm = StructureSelectionManager.getStructureSelectionManager();
-
- MCview.PDBfile pdb;
- if (loadedInline)
- {
- pdb = ssm.setMapping(sequence,chains,
- pdbentry.getFile(),
- AppletFormatAdapter.PASTE);
- pdbentry.setFile("INLINE"+pdb.id);
- }
- else
- {
- pdb = ssm.setMapping(sequence,chains,
- pdbentry.getFile(),
- AppletFormatAdapter.URL);
- }
-
- pdbentry.setId(pdb.id);
-
- ssm.addStructureViewerListener(this);
-
- Vector chains = new Vector();
- for (int i = 0; i < pdb.chains.size(); i++)
- {
- chains.addElement( ( (MCview.PDBChain) pdb.chains.elementAt(i)).id);
- }
- setChainMenuItems(chains);
-
- colourBySequence(ap);
-
- StringBuffer title = new StringBuffer(sequence[0].getName() + ":" +
- pdbentry.getId());
-
- if (pdbentry.getProperty() != null)
- {
- if (pdbentry.getProperty().get("method") != null)
- {
- title.append(" Method: ");
- title.append(pdbentry.getProperty().get("method"));
- }
- if (pdbentry.getProperty().get("chains") != null)
- {
- title.append(" Chain:");
- title.append(pdbentry.getProperty().get("chains"));
- }
- }
-
- this.setTitle(title.toString());
-
- }
- else
- return;
+ setTitle(jmb.getViewerTitle());
}
- public void notifyFrameChanged(int frameNo)
- {
- boolean isAnimationRunning = (frameNo <= -2);
- }
-
- public void notifyScriptStart(String statusMessage, String additionalInfo)
- {}
-
- public void sendConsoleEcho(String strEcho)
- {
- if (scriptWindow == null)
- showConsole(true);
-
- history.append("\n"+strEcho);
- }
-
- public void sendConsoleMessage(String strStatus)
+ public void showUrl(String url)
{
- if(history!=null && strStatus!=null
- && !strStatus.equals("Script completed"))
+ try
+ {
+ ap.av.applet.getAppletContext().showDocument(new java.net.URL(url),
+ "jmolOutput");
+ } catch (java.net.MalformedURLException ex)
{
- history.append("\n"+strStatus);
}
}
- public void notifyScriptTermination(String strStatus, int msWalltime)
- { }
-
- public void handlePopupMenu(int x, int y)
- {
- jmolpopup.show(x, y);
- }
-
- public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
- {
- notifyAtomPicked(iatom, strMeasure);
- }
+ Panel splitPane = null;
- public void notifyNewDefaultModeMeasurement(int count, String strInfo)
- {}
-
- public void notifyAtomPicked(int atomIndex, String strInfo)
+ public void showConsole(boolean showConsole)
{
-
- int chainSeparator = strInfo.indexOf(":");
-
- if(chainSeparator==-1)
- chainSeparator = strInfo.indexOf(".");
-
- String picked =
- strInfo.substring(strInfo.indexOf("]")+ 1, chainSeparator);
-
-
- if (strInfo.indexOf(":") > -1)
- picked+=strInfo.substring(strInfo.indexOf(":")+1,
- strInfo.indexOf("."));
-
- picked+=".CA";
-
- if (!atomsPicked.contains(picked))
+ if (showConsole)
{
- viewer.evalString("select "+picked+";label %n %r:%c");
- atomsPicked.addElement(picked);
+ 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
{
- viewer.evalString("select "+picked+";label off");
- atomsPicked.removeElement(picked);
- }
- }
-
- public void notifyAtomHovered(int atomIndex, String strInfo)
- {
- mouseOverStructure(atomIndex, strInfo);
- }
-
- public void sendSyncScript(String script, String appletName)
- {}
-
- public void showUrl(String url)
- {
- try{
- ap.av.applet.getAppletContext().showDocument(new java.net.URL(url),
- "jmolOutput");
- }catch(java.net.MalformedURLException ex)
- {}
- }
-
- 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);
scriptWindow.setVisible(false);
- history.setEditable(false);
- inputLine.addKeyListener(this);
+ remove(splitPane);
+ add(renderPanel, BorderLayout.CENTER);
+ splitPane = null;
}
-
- scriptWindow.setVisible(!scriptWindow.isVisible());
validate();
}
- public float functionXY(String functionName, int x, int y)
+ public float[][] functionXY(String functionName, int x, int y)
{
- return 0;
+ return null;
}
- ///End JmolStatusListener
- ///////////////////////////////
-
+ // /End JmolStatusListener
+ // /////////////////////////////
- class RenderPanel
- extends Panel
+ class RenderPanel extends Panel
{
Dimension currentSize = new Dimension();
- Rectangle rectClip = new Rectangle();
- public void update(Graphics g) {
+ @Override
+ public void update(Graphics g)
+ {
paint(g);
}
+
+ @Override
public void paint(Graphics g)
{
currentSize = this.getSize();
- rectClip = g.getClipBounds();
- if (viewer == null)
+ if (jmb.jmolViewer == null)
{
g.setColor(Color.black);
g.fillRect(0, 0, currentSize.width, currentSize.height);
g.setColor(Color.white);
g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
+ g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
+ 20, currentSize.height / 2);
}
else
{
- viewer.renderScreenImage(g, currentSize, rectClip);
+ jmb.jmolViewer.renderScreenImage(g, currentSize.width,
+ currentSize.height);
+ }
+ }
+ }
+
+ /*
+ * @Override public Color getColour(int atomIndex, int pdbResNum, String
+ * chain, String pdbId) { return jmb.getColour(atomIndex, pdbResNum, chain,
+ * pdbId); }
+ *
+ * @Override public String[] getPdbFile() { return jmb.getPdbFile(); }
+ *
+ * @Override public void highlightAtom(int atomIndex, int pdbResNum, String
+ * chain, String pdbId) { jmb.highlightAtom(atomIndex, pdbResNum, chain,
+ * pdbId);
+ *
+ * }
+ *
+ * @Override public void mouseOverStructure(int atomIndex, String strInfo) {
+ * jmb.mouseOverStructure(atomIndex, strInfo);
+ *
+ * }
+ */
+ public void colourByJalviewColourScheme(UserColourScheme ucs)
+ {
+ jmb.colourByJalviewColourScheme(ucs);
+ }
+
+ public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
+ {
+ for (int i = 0; i < _aps.size(); i++)
+ {
+ if (_aps.get(i).av.getAlignment() == alignment)
+ {
+ return (_aps.get(i));
}
}
+ return ap;
}
+ /**
+ * Append the given text to the history object
+ *
+ * @param text
+ */
+ public void addToHistory(String text)
+ {
+ // actually currently never initialised
+ if (history != null)
+ {
+ history.append("\n" + text);
+ }
+ }
}