X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FAppletPDBCanvas.java;h=4c62b605843033aed347548e1be61d1908ccbf3a;hb=0ec05d5a2b604aaedcca284a696a4fc71707b444;hp=1ee0828c6fc04028902d117db6669f43a5694da9;hpb=1ee385ddd9b62751473708cb494b652b17d56e7e;p=jalview.git diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index 1ee0828..4c62b60 100755 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -34,17 +34,6 @@ import java.util.*; public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener { - public AppletPDBCanvas() - { - try - { - jbInit(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } MCMatrix idmat = new MCMatrix(3, 3); MCMatrix objmat = new MCMatrix(3, 3); @@ -80,10 +69,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion jalview.appletgui.SequenceRenderer sr; jalview.appletgui.FeatureRenderer fr; jalview.appletgui.SeqCanvas seqcanvas; - Sequence sequence; + public Sequence sequence; final StringBuffer mappingDetails = new StringBuffer(); String appletToolTip = null; int toolx, tooly; + PDBChain mainchain; public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq) { @@ -92,7 +82,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion sr = seqcanvas.getSequenceRenderer(); fr = seqcanvas.getFeatureRenderer(); - seqcanvas.setPDBViewer(this); + seqcanvas.setPDBCanvas(this); addKeyListener(new KeyAdapter() { @@ -101,9 +91,34 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion doKeyPressed(evt); } }); - } + Bond highlightBond1, highlightBond2; + public void highlightRes(int ii) + { + highlightBond1 = null; + highlightBond2 = null; + + int index = ii - mainchain.seqstart; + if(index <0 ) + return; + + if(index<=mainchain.bonds.size()) + { + if(index>0) + { + highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1); + } + + if(index!=mainchain.bonds.size()) + highlightBond2 = (Bond) mainchain.bonds.elementAt(index); + } + + redrawneeded = true; + repaint(); + } + + public void setPDBFile(PDBfile pdb) { this.sr = sr; @@ -155,12 +170,14 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend); } - ((PDBChain) pdb.chains.elementAt(maxchain)).pdbstart = pdbstart; - ((PDBChain) pdb.chains.elementAt(maxchain)).pdbend = pdbend; - ((PDBChain) pdb.chains.elementAt(maxchain)).seqstart = seqstart; - ((PDBChain) pdb.chains.elementAt(maxchain)).seqend = seqend; - ((PDBChain) pdb.chains.elementAt(maxchain)).isVisible = true; - ((PDBChain) pdb.chains.elementAt(maxchain)).sequence = sequence; + mainchain = (PDBChain) pdb.chains.elementAt(maxchain); + + mainchain.pdbstart = pdbstart; + mainchain.pdbend = pdbend; + mainchain.seqstart = seqstart; + mainchain.seqend = seqend; + mainchain.isVisible = true; + mainchain.sequence = sequence; this.pdb = pdb; this.prefsize = new Dimension(getSize().width, getSize().height); @@ -373,14 +390,20 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion //this saves much memory usage if ((img == null) || (prefsize.width != getSize().width) || (prefsize.height != getSize().height)) { - prefsize.width = getSize().width; - prefsize.height = getSize().height; - scale = findScale(); - img = createImage(prefsize.width, prefsize.height); - ig = img.getGraphics(); + try{ prefsize.width = getSize().width; + prefsize.height = getSize().height; - redrawneeded = true; + scale = findScale(); + img = createImage(prefsize.width, prefsize.height); + ig = img.getGraphics(); + + redrawneeded = true; + }catch(Exception ex) + { + ex.printStackTrace(); + System.out.println(getSize()); + } } @@ -430,16 +453,21 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion for (int i = 0; i < chain.bonds.size(); i++) { Bond tmp = (Bond) chain.bonds.elementAt(i); - if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1))) { + int pos = chain.seqstart + (tmp.at1.resNumber - chain.pdbstart - chain.offset); int index = sequence.findIndex(pos); - tmp.startCol = sr.findSequenceColour(sequence, index); + if(jalview.util.Comparison.isGap((sequence.getCharAt(index)))) + { + index--; + } + + tmp.startCol = sr.findSequenceColour(sequence, index); // tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index); @@ -455,8 +483,13 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion int pos = chain.seqstart + (tmp.at2.resNumber - chain.pdbstart - chain.offset); int index = sequence.findIndex(pos); + if (jalview.util.Comparison.isGap( (sequence.getCharAt(index)))) + { + index--; + } + - tmp.endCol = sr.findSequenceColour( sequence, index); + tmp.endCol = sr.findSequenceColour(sequence, index); // tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index); } else @@ -479,7 +512,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion for (int i = 0; i < tmp.size(); i++) { - bonds.addElement(tmp.elementAt(i)); + bonds.addElement(tmp.elementAt(i)); } } } @@ -491,6 +524,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion for (int i = 0; i < bonds.size(); i++) { Bond tmpBond = (Bond) bonds.elementAt(i); + xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2)); ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) + @@ -504,7 +538,8 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion xmid = (xend + xstart) / 2; ymid = (yend + ystart) / 2; - if (depthcue && !bymolecule) { + if (depthcue && !bymolecule) + { if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) { g.setColor(tmpBond.startCol.darker().darker()); drawLine(g, xstart, ystart, xmid, ymid); @@ -543,6 +578,19 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion } else { drawLine(g, xstart, ystart, xend, yend); } + + if(highlightBond1!=null && highlightBond1==tmpBond) + { + g.setColor(Color.white); + drawLine(g, xmid, ymid, xend, yend); + } + + if(highlightBond2!=null && highlightBond2==tmpBond) + { + g.setColor(Color.white); + drawLine(g, xstart, ystart, xmid, ymid); + } + } } @@ -588,7 +636,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion } public void mousePressed(MouseEvent e) { - myAtom fatom = findAtom(e.getX(), e.getY()); + Atom fatom = findAtom(e.getX(), e.getY()); if(fatom!=null) { fatom.isSelected = !fatom.isSelected; @@ -604,17 +652,23 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion public void mouseMoved(MouseEvent e) { - myAtom fatom = findAtom(e.getX(), e.getY()); + Atom fatom = findAtom(e.getX(), e.getY()); + PDBChain chain = null; if(foundchain!=-1) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain); - int pos = chain.seqstart + - (fatom.resNumber - chain.pdbstart - chain.offset)+1; + chain = (PDBChain) pdb.chains.elementAt(foundchain); + if(chain == mainchain) + { + int pos = chain.seqstart + + (fatom.resNumber - chain.pdbstart - chain.offset) + 1; - int index = seqcanvas.getViewport().getAlignment().findIndex(sequence); + int index = seqcanvas.getViewport().getAlignment().findIndex( + sequence); - seqcanvas.highlightSearchResults(new int[]{index, pos, pos}); + seqcanvas.highlightSearchResults(new int[] + {index, pos, pos}); + } } else seqcanvas.highlightSearchResults(null); @@ -622,7 +676,8 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion if (fatom != null) { toolx = e.getX(); tooly = e.getY(); - appletToolTip = fatom.resNumber+" "+ fatom.resName; + + appletToolTip = chain.id+":"+ fatom.resNumber+" "+ fatom.resName; redrawneeded = true; repaint(); } else { @@ -747,8 +802,8 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion } int foundchain = -1; - public myAtom findAtom(int x, int y) { - myAtom fatom = null; + public Atom findAtom(int x, int y) { + Atom fatom = null; foundchain = -1; @@ -792,8 +847,15 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion paint(g); } - private void jbInit() - throws Exception - { - } + public void setAllchainsVisible(boolean b) + { + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + chain.isVisible = b; + } + mainchain.isVisible = true; + findCentre(); + } + }