X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FAppletPDBCanvas.java;h=c6553f817b7c626f678735fd95b17e788d19e96e;hb=9e338a58713e1f3a451aa34c5e6c488bdd6d8cab;hp=c1c4b2ff9066f224226d606d3006693392b01efc;hpb=c777b335d0332979123446f431b7f0c160eb4880;p=jalview.git diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index c1c4b2f..c6553f8 100644 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -20,10 +20,24 @@ */ package MCview; +import jalview.analysis.AlignSeq; +import jalview.appletgui.AlignmentPanel; +import jalview.appletgui.FeatureRenderer; +import jalview.appletgui.SequenceRenderer; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; +import jalview.io.StructureFile; +import jalview.renderer.seqfeatures.FeatureColourFinder; +import jalview.structure.AtomSpec; +import jalview.structure.StructureListener; +import jalview.structure.StructureMapping; +import jalview.structure.StructureSelectionManager; +import jalview.util.MessageManager; + import java.awt.Color; import java.awt.Dimension; -import java.awt.Event; -import java.awt.Font; +import java.awt.event.InputEvent;import java.awt.Font; import java.awt.Graphics; import java.awt.Image; // JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug @@ -37,20 +51,8 @@ import java.io.PrintStream; import java.util.List; import java.util.Vector; -import jalview.analysis.AlignSeq; -import jalview.appletgui.AlignmentPanel; -import jalview.appletgui.FeatureRenderer; -import jalview.appletgui.SequenceRenderer; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; -import jalview.structure.AtomSpec; -import jalview.structure.StructureListener; -import jalview.structure.StructureMapping; -import jalview.structure.StructureSelectionManager; -import jalview.util.MessageManager; - -public class AppletPDBCanvas extends Panel implements MouseListener, - MouseMotionListener, StructureListener +public class AppletPDBCanvas extends Panel + implements MouseListener, MouseMotionListener, StructureListener { MCMatrix idmat = new MCMatrix(3, 3); @@ -67,7 +69,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, int my = 0; - public PDBfile pdb; + public StructureFile pdb; PDBEntry pdbentry; @@ -144,7 +146,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, StructureSelectionManager ssm; public AppletPDBCanvas(PDBEntry pdbentry, SequenceI[] seq, - String[] chains, AlignmentPanel ap, String protocol) + String[] chains, AlignmentPanel ap, DataSourceType protocol) { this.ap = ap; @@ -156,11 +158,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, try { - pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol); + pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol, null); - if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) + if (protocol == DataSourceType.PASTE) { - pdbentry.setFile("INLINE" + pdb.id); + pdbentry.setFile("INLINE" + pdb.getId()); } } catch (Exception ex) @@ -169,13 +171,13 @@ public class AppletPDBCanvas extends Panel implements MouseListener, return; } - pdbentry.setId(pdb.id); + pdbentry.setId(pdb.getId()); ssm.addStructureViewerListener(this); colourBySequence(); - int max = -10; + float max = -10; int maxchain = -1; int pdbstart = 0; int pdbend = 0; @@ -185,33 +187,34 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // JUST DEAL WITH ONE SEQUENCE FOR NOW SequenceI sequence = seq[0]; - for (int i = 0; i < pdb.chains.size(); i++) + for (int i = 0; i < pdb.getChains().size(); i++) { mappingDetails.append("\n\nPDB Sequence is :\nSequence = " - + pdb.chains.elementAt(i).sequence + + pdb.getChains().elementAt(i).sequence .getSequenceAsString()); mappingDetails.append("\nNo of residues = " - + pdb.chains.elementAt(i).residues.size() - + "\n\n"); + + pdb.getChains().elementAt(i).residues.size() + "\n\n"); // Now lets compare the sequences to get // the start and end points. // Align the sequence to the pdb // TODO: DNa/Pep switch AlignSeq as = new AlignSeq(sequence, - pdb.chains.elementAt(i).sequence, - pdb.chains.elementAt(i).isNa ? AlignSeq.DNA + pdb.getChains().elementAt(i).sequence, + pdb.getChains().elementAt(i).isNa ? AlignSeq.DNA : AlignSeq.PEP); as.calcScoreMatrix(); as.traceAlignment(); PrintStream ps = new PrintStream(System.out) { + @Override public void print(String x) { mappingDetails.append(x); } + @Override public void println() { mappingDetails.append("\n"); @@ -235,7 +238,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend); } - mainchain = pdb.chains.elementAt(maxchain); + mainchain = pdb.getChains().elementAt(maxchain); mainchain.pdbstart = pdbstart; mainchain.pdbend = pdbend; @@ -270,6 +273,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, addKeyListener(new KeyAdapter() { + @Override public void keyPressed(KeyEvent evt) { doKeyPressed(evt); @@ -292,11 +296,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // Sort the bonds by z coord visiblebonds = new Vector(); - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - if (pdb.chains.elementAt(ii).isVisible) + if (pdb.getChains().elementAt(ii).isVisible) { - Vector tmp = pdb.chains.elementAt(ii).bonds; + Vector tmp = pdb.getChains().elementAt(ii).bonds; for (int i = 0; i < tmp.size(); i++) { @@ -323,11 +327,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, min[1] = (float) 1e30; min[2] = (float) 1e30; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - if (pdb.chains.elementAt(ii).isVisible) + if (pdb.getChains().elementAt(ii).isVisible) { - Vector bonds = pdb.chains.elementAt(ii).bonds; + Vector bonds = pdb.getChains().elementAt(ii).bonds; for (Bond tmp : bonds) { @@ -451,11 +455,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, int bsize = 0; // Find centre coordinate - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - if (pdb.chains.elementAt(ii).isVisible) + if (pdb.getChains().elementAt(ii).isVisible) { - Vector bonds = pdb.chains.elementAt(ii).bonds; + Vector bonds = pdb.getChains().elementAt(ii).bonds; bsize += bonds.size(); @@ -473,6 +477,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, centre[2] = ztot / (2 * (float) bsize); } + @Override public void paint(Graphics g) { @@ -482,9 +487,8 @@ public class AppletPDBCanvas extends Panel implements MouseListener, g.fillRect(0, 0, getSize().width, getSize().height); g.setColor(Color.black); g.setFont(new Font("Verdana", Font.BOLD, 14)); - g.drawString( - MessageManager.getString("label.error_loading_pdb_data"), 50, - getSize().height / 2); + g.drawString(MessageManager.getString("label.error_loading_pdb_data"), + 50, getSize().height / 2); return; } @@ -572,12 +576,14 @@ public class AppletPDBCanvas extends Panel implements MouseListener, showFeatures = true; } + FeatureColourFinder finder = new FeatureColourFinder(fr); + PDBChain chain; if (bysequence && pdb != null) { - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - chain = pdb.chains.elementAt(ii); + chain = pdb.getChains().elementAt(ii); for (int i = 0; i < chain.bonds.size(); i++) { @@ -599,25 +605,16 @@ public class AppletPDBCanvas extends Panel implements MouseListener, if (pos > 0) { pos = sequence[s].findIndex(pos); - tmp.startCol = sr.getResidueBoxColour(sequence[s], pos); - if (showFeatures) - { - tmp.startCol = fr.findFeatureColour(tmp.startCol, - sequence[s], pos); - } + tmp.startCol = sr.getResidueColour(sequence[s], pos, + finder); } pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1; if (pos > 0) { pos = sequence[s].findIndex(pos); - tmp.endCol = sr.getResidueBoxColour(sequence[s], pos); - if (showFeatures) - { - tmp.endCol = fr.findFeatureColour(tmp.endCol, - sequence[s], pos); - } + tmp.endCol = sr.getResidueColour(sequence[s], pos, + finder); } - } } } @@ -645,11 +642,15 @@ public class AppletPDBCanvas extends Panel implements MouseListener, { tmpBond = visiblebonds.elementAt(i); - xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2)); - ystart = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getSize().height / 2)); + xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + + (getSize().width / 2)); + ystart = (int) (((centre[1] - tmpBond.start[1]) * scale) + + (getSize().height / 2)); - xend = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getSize().width / 2)); - yend = (int) (((centre[1] - tmpBond.end[1]) * scale) + (getSize().height / 2)); + xend = (int) (((tmpBond.end[0] - centre[0]) * scale) + + (getSize().width / 2)); + yend = (int) (((centre[1] - tmpBond.end[1]) * scale) + + (getSize().height / 2)); xmid = (xend + xstart) / 2; ymid = (yend + ystart) / 2; @@ -777,6 +778,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, } } + @Override public void mousePressed(MouseEvent e) { pdbAction = true; @@ -789,7 +791,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, repaint(); if (foundchain != -1) { - PDBChain chain = pdb.chains.elementAt(foundchain); + PDBChain chain = pdb.getChains().elementAt(foundchain); if (chain == mainchain) { if (fatom.alignmentMapping != -1) @@ -821,6 +823,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, dragging = false; } + @Override public void mouseMoved(MouseEvent e) { pdbAction = true; @@ -837,7 +840,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, PDBChain chain = null; if (foundchain != -1) { - chain = pdb.chains.elementAt(foundchain); + chain = pdb.getChains().elementAt(foundchain); if (chain == mainchain) { mouseOverStructure(fatom.resNumber, chain.id); @@ -863,18 +866,22 @@ public class AppletPDBCanvas extends Panel implements MouseListener, } } + @Override public void mouseClicked(MouseEvent e) { } + @Override public void mouseEntered(MouseEvent e) { } + @Override public void mouseExited(MouseEvent e) { } + @Override public void mouseDragged(MouseEvent evt) { int x = evt.getX(); @@ -885,7 +892,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MCMatrix objmat = new MCMatrix(3, 3); objmat.setIdentity(); - if ((evt.getModifiers() & Event.META_MASK) != 0) + if ((evt.getModifiersEx() & InputEvent.META_DOWN_MASK) != 0) { objmat.rotatez(((mx - omx))); } @@ -896,7 +903,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, } // Alter the bonds - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { for (Bond tmpBond : chain.bonds) { @@ -924,6 +931,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, repaint(); } + @Override public void mouseReleased(MouseEvent evt) { dragging = false; @@ -933,7 +941,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, void drawLabels(Graphics g) { - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -959,8 +967,10 @@ public class AppletPDBCanvas extends Panel implements MouseListener, if (n == 1) { - int xstart = (int) (((b.start[0] - centre[0]) * scale) + (getSize().width / 2)); - int ystart = (int) (((centre[1] - b.start[1]) * scale) + (getSize().height / 2)); + int xstart = (int) (((b.start[0] - centre[0]) * scale) + + (getSize().width / 2)); + int ystart = (int) (((centre[1] - b.start[1]) * scale) + + (getSize().height / 2)); g.setColor(Color.red); g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); @@ -968,8 +978,10 @@ public class AppletPDBCanvas extends Panel implements MouseListener, if (n == 2) { - int xstart = (int) (((b.end[0] - centre[0]) * scale) + (getSize().width / 2)); - int ystart = (int) (((centre[1] - b.end[1]) * scale) + (getSize().height / 2)); + int xstart = (int) (((b.end[0] - centre[0]) * scale) + + (getSize().width / 2)); + int ystart = (int) (((centre[1] - b.end[1]) * scale) + + (getSize().height / 2)); g.setColor(Color.red); g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); @@ -984,25 +996,27 @@ public class AppletPDBCanvas extends Panel implements MouseListener, foundchain = -1; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - PDBChain chain = pdb.chains.elementAt(ii); + PDBChain chain = pdb.getChains().elementAt(ii); int truex; Bond tmpBond = null; if (chain.isVisible) { - Vector bonds = pdb.chains.elementAt(ii).bonds; + Vector bonds = pdb.getChains().elementAt(ii).bonds; for (int i = 0; i < bonds.size(); i++) { tmpBond = bonds.elementAt(i); - truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2)); + truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + + (getSize().width / 2)); if (Math.abs(truex - x) <= 2) { - int truey = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getSize().height / 2)); + int truey = (int) (((centre[1] - tmpBond.start[1]) * scale) + + (getSize().height / 2)); if (Math.abs(truey - y) <= 2) { @@ -1015,11 +1029,13 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // Still here? Maybe its the last bond - truex = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getSize().width / 2)); + truex = (int) (((tmpBond.end[0] - centre[0]) * scale) + + (getSize().width / 2)); if (Math.abs(truex - x) <= 2) { - int truey = (int) (((tmpBond.end[1] - centre[1]) * scale) + (getSize().height / 2)); + int truey = (int) (((tmpBond.end[1] - centre[1]) * scale) + + (getSize().height / 2)); if (Math.abs(truey - y) <= 2) { @@ -1033,13 +1049,14 @@ public class AppletPDBCanvas extends Panel implements MouseListener, if (fatom != null) // )&& chain.ds != null) { - chain = pdb.chains.elementAt(foundchain); + chain = pdb.getChains().elementAt(foundchain); } } return fatom; } + @Override public void update(Graphics g) { paint(g); @@ -1099,9 +1116,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener, public void setAllchainsVisible(boolean b) { - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - PDBChain chain = pdb.chains.elementAt(ii); + PDBChain chain = pdb.getChains().elementAt(ii); chain.isVisible = b; } mainchain.isVisible = true; @@ -1111,10 +1128,10 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // //////////////////////////////// // /StructureListener - public String[] getPdbFile() + @Override + public String[] getStructureFiles() { - return new String[] - { pdbentry.getFile() }; + return new String[] { pdbentry.getFile() }; } String lastMessage; @@ -1214,6 +1231,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // return new Color(viewer.getAtomArgb(atomIndex)); } + @Override public void updateColours(Object source) { colourBySequence(); @@ -1227,4 +1245,20 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // 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; + } }