X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBCanvas.java;h=fdd673bb591ab486faaa97e7db1dd33bb3482cd4;hb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;hp=dcaea2b7d45bf19062e3a43f541ab9d7b44f01d2;hpb=f3f3f5d2d3d137ab12ea944a7a120de51677a5c6;p=jalview.git diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java old mode 100755 new mode 100644 index dcaea2b..fdd673b --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -1,110 +1,171 @@ /* - * 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 2.9) + * Copyright (C) 2015 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 MCview; -import java.io.*; -import java.util.*; - +import jalview.analysis.AlignSeq; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignmentPanel; +import jalview.gui.FeatureRenderer; +import jalview.gui.SequenceRenderer; +import jalview.structure.AtomSpec; +import jalview.structure.StructureListener; +import jalview.structure.StructureMapping; +import jalview.structure.StructureSelectionManager; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Event; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; // JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; - -import jalview.analysis.*; -import jalview.datamodel.*; -import jalview.gui.*; -import jalview.structure.*; - -public class PDBCanvas - extends JPanel implements MouseListener, MouseMotionListener, StructureListener +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.io.PrintStream; +import java.util.List; +import java.util.Vector; + +import javax.swing.JPanel; +import javax.swing.ToolTipManager; + +public class PDBCanvas extends JPanel implements MouseListener, + MouseMotionListener, StructureListener { boolean redrawneeded = true; + int omx = 0; + int mx = 0; + int omy = 0; + int my = 0; + public PDBfile pdb; + PDBEntry pdbentry; + int bsize; + Image img; + Graphics ig; + Dimension prefsize; + float[] centre = new float[3]; + float[] width = new float[3]; + float maxwidth; + float scale; + String inStr; + String inType; + boolean bysequence = true; + boolean depthcue = true; + boolean wire = false; + boolean bymolecule = false; + boolean zbuffer = true; + boolean dragging; + int xstart; + int xend; + int ystart; + int yend; + int xmid; + int ymid; + Font font = new Font("Helvetica", Font.PLAIN, 10); + jalview.gui.SeqCanvas seqcanvas; - public SequenceI [] sequence; + + public SequenceI[] sequence; + final StringBuffer mappingDetails = new StringBuffer(); + PDBChain mainchain; - Vector highlightRes; + + Vector highlightRes; + boolean pdbAction = false; + boolean seqColoursReady = false; - jalview.gui.FeatureRenderer fr; + + jalview.renderer.seqfeatures.FeatureRenderer fr; + Color backgroundColour = Color.black; + AlignmentPanel ap; + StructureSelectionManager ssm; - String errorMessage; + String errorMessage; - void init(PDBEntry pdbentry, - SequenceI[] seq, - String [] chains, - AlignmentPanel ap, - String protocol) + void init(PDBEntry pdbentry, SequenceI[] seq, String[] chains, + AlignmentPanel ap, String protocol) { this.ap = ap; this.pdbentry = pdbentry; this.sequence = seq; - ssm = StructureSelectionManager.getStructureSelectionManager(); + ssm = ap.av.getStructureSelectionManager(); - try{ + try + { pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol); - if(protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) - pdbentry.setFile("INLINE"+pdb.id); + if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) + { + pdbentry.setFile("INLINE" + pdb.id); + } - }catch(Exception ex) + } catch (Exception ex) { ex.printStackTrace(); return; } - if(pdb==null) + if (pdb == null) { - errorMessage = "Error loading file: "+pdbentry.getId(); + errorMessage = "Error loading file: " + pdbentry.getId(); return; } pdbentry.setId(pdb.id); @@ -120,25 +181,22 @@ public class PDBCanvas int seqstart = 0; int seqend = 0; - //JUST DEAL WITH ONE SEQUENCE FOR NOW + // JUST DEAL WITH ONE SEQUENCE FOR NOW SequenceI sequence = seq[0]; for (int i = 0; i < pdb.chains.size(); i++) { - mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + - ( (PDBChain) pdb.chains.elementAt(i)).sequence. - getSequenceAsString()); - mappingDetails.append("\nNo of residues = " + - ( (PDBChain) pdb.chains.elementAt(i)).residues.size() + - "\n\n"); + mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + + pdb.chains.elementAt(i).sequence.getSequenceAsString()); + mappingDetails.append("\nNo of residues = " + + pdb.chains.elementAt(i).residues.size() + "\n\n"); // Now lets compare the sequences to get // the start and end points. // Align the sequence to the pdb AlignSeq as = new AlignSeq(sequence, - ( (PDBChain) pdb.chains.elementAt(i)).sequence, - "pep"); + pdb.chains.elementAt(i).sequence, "pep"); as.calcScoreMatrix(); as.traceAlignment(); PrintStream ps = new PrintStream(System.out) @@ -171,7 +229,7 @@ public class PDBCanvas mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend); } - mainchain = (PDBChain) pdb.chains.elementAt(maxchain); + mainchain = pdb.chains.elementAt(maxchain); mainchain.pdbstart = pdbstart; mainchain.pdbend = pdbend; @@ -182,7 +240,6 @@ public class PDBCanvas this.pdb = pdb; this.prefsize = new Dimension(getSize().width, getSize().height); - addMouseMotionListener(this); addMouseListener(this); @@ -206,22 +263,21 @@ public class PDBCanvas ToolTipManager.sharedInstance().setDismissDelay(10000); } - Vector visiblebonds; + Vector visiblebonds; + void setupBonds() { seqColoursReady = false; // Sort the bonds by z coord - visiblebonds = new Vector(); + visiblebonds = new Vector(); - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (PDBChain chain : pdb.chains) { - if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + if (chain.isVisible) { - Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - - for (int i = 0; i < tmp.size(); i++) + for (Bond bond : chain.bonds) { - visiblebonds.addElement(tmp.elementAt(i)); + visiblebonds.addElement(bond); } } } @@ -237,24 +293,20 @@ public class PDBCanvas float[] max = new float[3]; float[] min = new float[3]; - max[0] = (float) - 1e30; - max[1] = (float) - 1e30; - max[2] = (float) - 1e30; + max[0] = (float) -1e30; + max[1] = (float) -1e30; + max[2] = (float) -1e30; min[0] = (float) 1e30; min[1] = (float) 1e30; min[2] = (float) 1e30; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (PDBChain chain : pdb.chains) { - if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + if (chain.isVisible) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - - for (int i = 0; i < bonds.size(); i++) + for (Bond tmp : chain.bonds) { - Bond tmp = (Bond) bonds.elementAt(i); - if (tmp.start[0] >= max[0]) { max[0] = tmp.start[0]; @@ -318,13 +370,14 @@ public class PDBCanvas } } /* - System.out.println("xmax " + max[0] + " min " + min[0]); - System.out.println("ymax " + max[1] + " min " + min[1]); - System.out.println("zmax " + max[2] + " min " + min[2]);*/ + * System.out.println("xmax " + max[0] + " min " + min[0]); + * System.out.println("ymax " + max[1] + " min " + min[1]); + * System.out.println("zmax " + max[2] + " min " + min[2]); + */ - width[0] = (float) Math.abs(max[0] - min[0]); - width[1] = (float) Math.abs(max[1] - min[1]); - width[2] = (float) Math.abs(max[2] - min[2]); + width[0] = Math.abs(max[0] - min[0]); + width[1] = Math.abs(max[1] - min[1]); + width[2] = Math.abs(max[2] - min[2]); maxwidth = width[0]; @@ -378,25 +431,18 @@ public class PDBCanvas int bsize = 0; - //Find centre coordinate - for (int ii = 0; ii < pdb.chains.size(); ii++) + // Find centre coordinate + for (PDBChain chain : pdb.chains) { - if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + if (chain.isVisible) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - - bsize += bonds.size(); + bsize += chain.bonds.size(); - for (int i = 0; i < bonds.size(); i++) + for (Bond bond : chain.bonds) { - xtot = xtot + ( (Bond) bonds.elementAt(i)).start[0] + - ( (Bond) bonds.elementAt(i)).end[0]; - - ytot = ytot + ( (Bond) bonds.elementAt(i)).start[1] + - ( (Bond) bonds.elementAt(i)).end[1]; - - ztot = ztot + ( (Bond) bonds.elementAt(i)).start[2] + - ( (Bond) bonds.elementAt(i)).end[2]; + xtot = xtot + bond.start[0] + bond.end[0]; + ytot = ytot + bond.start[1] + bond.end[1]; + ztot = ztot + bond.start[2] + bond.end[2]; } } } @@ -410,21 +456,19 @@ public class PDBCanvas { super.paintComponent(g); - if (!seqColoursReady || errorMessage!=null) + if (!seqColoursReady || errorMessage != null) { g.setColor(Color.black); g.setFont(new Font("Verdana", Font.BOLD, 14)); - g.drawString(errorMessage==null? - "Retrieving PDB data....":errorMessage, - 20, getHeight() / 2); + g.drawString(errorMessage == null ? "Retrieving PDB data...." + : errorMessage, 20, getHeight() / 2); return; } - //Only create the image at the beginning - - //this saves much memory usage - if ( (img == null) - || (prefsize.width != getWidth()) - || (prefsize.height != getHeight())) + // Only create the image at the beginning - + // this saves much memory usage + if ((img == null) || (prefsize.width != getWidth()) + || (prefsize.height != getHeight())) { prefsize.width = getWidth(); @@ -436,7 +480,7 @@ public class PDBCanvas Graphics2D ig2 = (Graphics2D) ig; ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + RenderingHints.VALUE_ANTIALIAS_ON); redrawneeded = true; } @@ -473,7 +517,6 @@ public class PDBCanvas repaint(); } - // This method has been taken out of PDBChain to allow // Applet and Application specific sequence renderers to be used void colourBySequence() @@ -483,7 +526,7 @@ public class PDBCanvas StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile()); boolean showFeatures = false; - if (ap.av.getShowSequenceFeatures()) + if (ap.av.isShowSequenceFeatures()) { if (fr == null) { @@ -500,11 +543,11 @@ public class PDBCanvas { for (int ii = 0; ii < pdb.chains.size(); ii++) { - chain = (PDBChain) pdb.chains.elementAt(ii); + chain = pdb.chains.elementAt(ii); for (int i = 0; i < chain.bonds.size(); i++) { - Bond tmp = (Bond) chain.bonds.elementAt(i); + Bond tmp = chain.bonds.elementAt(i); tmp.startCol = Color.lightGray; tmp.endCol = Color.lightGray; if (chain != mainchain) @@ -518,7 +561,7 @@ public class PDBCanvas { if (mapping[m].getSequence() == sequence[s]) { - int pos = mapping[m].getSeqPos(tmp.at1.resNumber)-1; + int pos = mapping[m].getSeqPos(tmp.at1.resNumber) - 1; if (pos > 0) { pos = sequence[s].findIndex(pos); @@ -526,11 +569,10 @@ public class PDBCanvas if (showFeatures) { tmp.startCol = fr.findFeatureColour(tmp.startCol, - sequence[s], - pos); + sequence[s], pos); } } - pos = mapping[m].getSeqPos(tmp.at2.resNumber)-1; + pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1; if (pos > 0) { pos = sequence[s].findIndex(pos); @@ -538,8 +580,7 @@ public class PDBCanvas if (showFeatures) { tmp.endCol = fr.findFeatureColour(tmp.endCol, - sequence[s], - pos); + sequence[s], pos); } } @@ -552,6 +593,7 @@ public class PDBCanvas } Zsort zsort; + public void drawScene(Graphics g) { if (zbuffer) @@ -561,23 +603,19 @@ public class PDBCanvas zsort = new Zsort(); } - zsort.Zsort(visiblebonds); + zsort.sort(visiblebonds); } Bond tmpBond = null; for (int i = 0; i < visiblebonds.size(); i++) { - tmpBond = (Bond) visiblebonds.elementAt(i); + tmpBond = visiblebonds.elementAt(i); - xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) + - (getWidth() / 2)); - ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) + - (getHeight() / 2)); + xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2)); + ystart = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getHeight() / 2)); - xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) + - (getWidth() / 2)); - yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) + - (getHeight() / 2)); + xend = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getWidth() / 2)); + yend = (int) (((centre[1] - tmpBond.end[1]) * scale) + (getHeight() / 2)); xmid = (xend + xstart) / 2; ymid = (yend + ystart) / 2; @@ -641,13 +679,15 @@ public class PDBCanvas if (highlightBond1 != null && highlightBond1 == tmpBond) { - g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter()); + g.setColor(tmpBond.endCol.brighter().brighter().brighter() + .brighter()); drawLine(g, xmid, ymid, xend, yend); } if (highlightBond2 != null && highlightBond2 == tmpBond) { - g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter()); + g.setColor(tmpBond.startCol.brighter().brighter().brighter() + .brighter()); drawLine(g, xstart, ystart, xmid, ymid); } @@ -659,7 +699,7 @@ public class PDBCanvas { if (!wire) { - if ( ( (float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) + if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) { g.drawLine(x1, y1, x2, y2); g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1); @@ -717,23 +757,25 @@ public class PDBCanvas repaint(); if (foundchain != -1) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain); + PDBChain chain = pdb.chains.elementAt(foundchain); if (chain == mainchain) { if (fatom.alignmentMapping != -1) { if (highlightRes == null) { - highlightRes = new Vector(); + highlightRes = new Vector(); } - if (highlightRes.contains(fatom.alignmentMapping + "")) + final String atomString = Integer + .toString(fatom.alignmentMapping); + if (highlightRes.contains(atomString)) { - highlightRes.remove(fatom.alignmentMapping + ""); + highlightRes.remove(atomString); } else { - highlightRes.add(fatom.alignmentMapping + ""); + highlightRes.add(atomString); } } } @@ -763,7 +805,7 @@ public class PDBCanvas PDBChain chain = null; if (foundchain != -1) { - chain = (PDBChain) pdb.chains.elementAt(foundchain); + chain = pdb.chains.elementAt(foundchain); if (chain == mainchain) { mouseOverStructure(fatom.resNumber, chain.id); @@ -772,24 +814,27 @@ public class PDBCanvas if (fatom != null) { - this.setToolTipText(chain.id + ":" + fatom.resNumber + " " + - fatom.resName); + this.setToolTipText(chain.id + ":" + fatom.resNumber + " " + + fatom.resName); } else { - mouseOverStructure(-1, chain!=null?chain.id:null); + mouseOverStructure(-1, chain != null ? chain.id : null); this.setToolTipText(null); } } public void mouseClicked(MouseEvent e) - {} + { + } public void mouseEntered(MouseEvent e) - {} + { + } public void mouseExited(MouseEvent e) - {} + { + } public void mouseDragged(MouseEvent evt) { @@ -801,33 +846,29 @@ public class PDBCanvas MCMatrix objmat = new MCMatrix(3, 3); objmat.setIdentity(); - if ( (evt.getModifiers() & Event.META_MASK) != 0) + if ((evt.getModifiers() & Event.META_MASK) != 0) { - objmat.rotatez( (float) ( (mx - omx))); + objmat.rotatez(((mx - omx))); } else { - objmat.rotatex( (float) ( (my - omy))); - objmat.rotatey( (float) ( (omx - mx))); + objmat.rotatex(((my - omy))); + objmat.rotatey(((omx - mx))); } - //Alter the bonds - for (int ii = 0; ii < pdb.chains.size(); ii++) + // Alter the bonds + for (PDBChain chain : pdb.chains) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - - for (int i = 0; i < bonds.size(); i++) + for (Bond tmpBond : chain.bonds) { - Bond tmpBond = (Bond) bonds.elementAt(i); + // Translate the bond so the centre is 0,0,0 + tmpBond.translate(-centre[0], -centre[1], -centre[2]); - //Translate the bond so the centre is 0,0,0 - tmpBond.translate( -centre[0], -centre[1], -centre[2]); - - //Now apply the rotation matrix + // Now apply the rotation matrix tmpBond.start = objmat.vectorMultiply(tmpBond.start); tmpBond.end = objmat.vectorMultiply(tmpBond.end); - //Now translate back again + // Now translate back again tmpBond.translate(centre[0], centre[1], centre[2]); } } @@ -853,18 +894,12 @@ public class PDBCanvas void drawLabels(Graphics g) { - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (PDBChain chain : pdb.chains) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); - if (chain.isVisible) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - - for (int i = 0; i < bonds.size(); i++) + for (Bond tmpBond : chain.bonds) { - Bond tmpBond = (Bond) bonds.elementAt(i); - if (tmpBond.at1.isSelected) { labelAtom(g, tmpBond, 1); @@ -872,7 +907,6 @@ public class PDBCanvas if (tmpBond.at2.isSelected) { - labelAtom(g, tmpBond, 2); } } @@ -886,26 +920,23 @@ public class PDBCanvas g.setColor(Color.red); if (n == 1) { - int xstart = (int) ( ( (b.start[0] - centre[0]) * scale) + - (getWidth() / 2)); - int ystart = (int) ( ( (b.start[1] - centre[1]) * scale) + - (getHeight() / 2)); + int xstart = (int) (((b.start[0] - centre[0]) * scale) + (getWidth() / 2)); + int ystart = (int) (((centre[1] - b.start[1]) * scale) + (getHeight() / 2)); g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); } if (n == 2) { - int xstart = (int) ( ( (b.end[0] - centre[0]) * scale) + - (getWidth() / 2)); - int ystart = (int) ( ( (b.end[1] - centre[1]) * scale) + - (getHeight() / 2)); + int xstart = (int) (((b.end[0] - centre[0]) * scale) + (getWidth() / 2)); + int ystart = (int) (((centre[1] - b.end[1]) * scale) + (getHeight() / 2)); g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); } } int foundchain = -1; + public Atom findAtom(int x, int y) { Atom fatom = null; @@ -914,25 +945,21 @@ public class PDBCanvas for (int ii = 0; ii < pdb.chains.size(); ii++) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + PDBChain chain = pdb.chains.elementAt(ii); int truex; Bond tmpBond = null; if (chain.isVisible) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - - for (int i = 0; i < bonds.size(); i++) + for (Bond bond : chain.bonds) { - tmpBond = (Bond) bonds.elementAt(i); + tmpBond = bond; - truex = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) + - (getWidth() / 2)); + truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2)); if (Math.abs(truex - x) <= 2) { - int truey = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) + - (getHeight() / 2)); + int truey = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getHeight() / 2)); if (Math.abs(truey - y) <= 2) { @@ -945,13 +972,11 @@ public class PDBCanvas // Still here? Maybe its the last bond - truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) + - (getWidth() / 2)); + truex = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getWidth() / 2)); if (Math.abs(truex - x) <= 2) { - int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) + - (getHeight() / 2)); + int truey = (int) (((tmpBond.end[1] - centre[1]) * scale) + (getHeight() / 2)); if (Math.abs(truey - y) <= 2) { @@ -963,9 +988,9 @@ public class PDBCanvas } - if (fatom != null) //)&& chain.ds != null) - { - chain = (PDBChain) pdb.chains.elementAt(foundchain); + if (fatom != null) // )&& chain.ds != null) + { // dead code? value of chain is either overwritten or discarded + chain = pdb.chains.elementAt(foundchain); } } @@ -973,6 +998,7 @@ public class PDBCanvas } Bond highlightBond1, highlightBond2; + public void highlightRes(int ii) { if (!seqColoursReady) @@ -980,8 +1006,7 @@ public class PDBCanvas return; } - if (highlightRes != null - && highlightRes.contains( (ii - 1) + "")) + if (highlightRes != null && highlightRes.contains((ii - 1) + "")) { return; } @@ -990,7 +1015,7 @@ public class PDBCanvas Bond tmpBond; for (index = 0; index < mainchain.bonds.size(); index++) { - tmpBond = (Bond) mainchain.bonds.elementAt(index); + tmpBond = mainchain.bonds.elementAt(index); if (tmpBond.at1.alignmentMapping == ii - 1) { if (highlightBond1 != null) @@ -1008,13 +1033,13 @@ public class PDBCanvas if (index > 0) { - highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1); + highlightBond1 = mainchain.bonds.elementAt(index - 1); highlightBond1.at2.isSelected = true; } if (index != mainchain.bonds.size()) { - highlightBond2 = (Bond) mainchain.bonds.elementAt(index); + highlightBond2 = mainchain.bonds.elementAt(index); highlightBond2.at1.isSelected = true; } @@ -1030,7 +1055,7 @@ public class PDBCanvas { for (int ii = 0; ii < pdb.chains.size(); ii++) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + PDBChain chain = pdb.chains.elementAt(ii); chain.isVisible = b; } mainchain.isVisible = true; @@ -1038,44 +1063,70 @@ public class PDBCanvas setupBonds(); } - ////////////////////////////////// - ///StructureListener - public String getPdbFile() + // //////////////////////////////// + // /StructureListener + public String[] getPdbFile() { - return pdbentry.getFile(); + return new String[] { pdbentry.getFile() }; } - String lastMessage; + public void mouseOverStructure(int pdbResNum, String chain) { - if (lastMessage == null || !lastMessage.equals(pdbResNum+chain)) - ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile()); + if (lastMessage == null || !lastMessage.equals(pdbResNum + chain)) + { + ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile()); + } - lastMessage = pdbResNum+chain; + lastMessage = pdbResNum + chain; } StringBuffer resetLastRes = new StringBuffer(); + StringBuffer eval = new StringBuffer(); - public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile) + /** + * Highlight the specified atoms in the structure. + * + * @param atoms + */ + @Override + public void highlightAtoms(List atoms) { if (!seqColoursReady) { return; } - if (highlightRes != null - && highlightRes.contains( (atomIndex - 1) + "")) + for (AtomSpec atom : atoms) { - return; + int atomIndex = atom.getAtomIndex(); + if (highlightRes != null + && highlightRes.contains((atomIndex - 1) + "")) + { + continue; + } + + highlightAtom(atomIndex); } + redrawneeded = true; + repaint(); + } + + /** + * Highlight the atom at the specified index. + * + * @param atomIndex + */ + protected void highlightAtom(int atomIndex) + { int index = -1; Bond tmpBond; for (index = 0; index < mainchain.bonds.size(); index++) { - tmpBond = (Bond) mainchain.bonds.elementAt(index); + tmpBond = mainchain.bonds.elementAt(index); if (tmpBond.at1.atomIndex == atomIndex) { if (highlightBond1 != null) @@ -1093,32 +1144,29 @@ public class PDBCanvas if (index > 0) { - highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1); + highlightBond1 = mainchain.bonds.elementAt(index - 1); highlightBond1.at2.isSelected = true; } if (index != mainchain.bonds.size()) { - highlightBond2 = (Bond) mainchain.bonds.elementAt(index); + highlightBond2 = mainchain.bonds.elementAt(index); highlightBond2.at1.isSelected = true; } break; } } - - redrawneeded = true; - repaint(); } - - public Color getColour(int atomIndex, int pdbResNum, String chain, String pdbfile) + public Color getColour(int atomIndex, int pdbResNum, String chain, + String pdbfile) { return Color.white; - // if (!pdbfile.equals(pdbentry.getFile())) - // return null; + // if (!pdbfile.equals(pdbentry.getFile())) + // return null; - //return new Color(viewer.getAtomArgb(atomIndex)); + // return new Color(viewer.getAtomArgb(atomIndex)); } public void updateColours(Object source) @@ -1128,4 +1176,26 @@ public class PDBCanvas repaint(); } + @Override + public void releaseReferences(Object svl) + { + // TODO Auto-generated method stub + + } + + @Override + public boolean isListeningFor(SequenceI seq) + { + if (sequence != null) + { + for (SequenceI s : sequence) + { + if (s == seq) + { + return true; + } + } + } + return false; + } }