X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBCanvas.java;h=a34e574b263dfba179cfbf0be476b62bbb1f6cc6;hb=cfdde25ee8c4f6284b2422d3768b96f02bffc090;hp=406d9f1fa86e67d570b42910bebbc2d979ab3a27;hpb=43b415c68805f3dec44a6ddc666d52220483c120;p=jalview.git diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index 406d9f1..a34e574 100644 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -20,10 +20,23 @@ */ package MCview; +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.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 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.Graphics2D; // JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug @@ -41,19 +54,8 @@ import java.util.Vector; import javax.swing.JPanel; import javax.swing.ToolTipManager; -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; - -public class PDBCanvas extends JPanel implements MouseListener, - MouseMotionListener, StructureListener +public class PDBCanvas extends JPanel + implements MouseListener, MouseMotionListener, StructureListener { boolean redrawneeded = true; @@ -65,7 +67,7 @@ public class PDBCanvas extends JPanel implements MouseListener, int my = 0; - public PDBfile pdb; + public StructureFile pdb; PDBEntry pdbentry; @@ -140,7 +142,7 @@ public class PDBCanvas extends JPanel implements MouseListener, String errorMessage; void init(PDBEntry pdbentry, SequenceI[] seq, String[] chains, - AlignmentPanel ap, String protocol) + AlignmentPanel ap, DataSourceType protocol) { this.ap = ap; this.pdbentry = pdbentry; @@ -150,11 +152,12 @@ public class PDBCanvas extends JPanel implements MouseListener, try { - pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol); + pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol, + ap.alignFrame); - if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) + if (protocol.equals(jalview.io.DataSourceType.PASTE)) { - pdbentry.setFile("INLINE" + pdb.id); + pdbentry.setFile("INLINE" + pdb.getId()); } } catch (Exception ex) @@ -168,13 +171,13 @@ public class PDBCanvas extends JPanel implements MouseListener, errorMessage = "Error loading file: " + pdbentry.getId(); 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; @@ -184,30 +187,31 @@ public class PDBCanvas extends JPanel 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 AlignSeq as = new AlignSeq(sequence, - pdb.chains.elementAt(i).sequence, "pep"); + pdb.getChains().elementAt(i).sequence, "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"); @@ -231,7 +235,7 @@ public class PDBCanvas extends JPanel 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; @@ -247,6 +251,7 @@ public class PDBCanvas extends JPanel implements MouseListener, addKeyListener(new KeyAdapter() { + @Override public void keyPressed(KeyEvent evt) { keyPressed(evt); @@ -273,7 +278,7 @@ public class PDBCanvas extends JPanel implements MouseListener, // Sort the bonds by z coord visiblebonds = new Vector(); - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -303,7 +308,7 @@ public class PDBCanvas extends JPanel implements MouseListener, min[1] = (float) 1e30; min[2] = (float) 1e30; - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -434,7 +439,7 @@ public class PDBCanvas extends JPanel implements MouseListener, int bsize = 0; // Find centre coordinate - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -454,6 +459,7 @@ public class PDBCanvas extends JPanel implements MouseListener, centre[2] = ztot / (2 * (float) bsize); } + @Override public void paintComponent(Graphics g) { super.paintComponent(g); @@ -540,12 +546,13 @@ public class PDBCanvas extends JPanel 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++) { @@ -567,23 +574,15 @@ public class PDBCanvas extends JPanel 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); } } @@ -613,11 +612,15 @@ public class PDBCanvas extends JPanel implements MouseListener, { tmpBond = visiblebonds.elementAt(i); - xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2)); - ystart = (int) (((centre[1] - tmpBond.start[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) (((centre[1] - tmpBond.end[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; @@ -681,8 +684,8 @@ public class PDBCanvas extends JPanel implements MouseListener, 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); } @@ -747,6 +750,7 @@ public class PDBCanvas extends JPanel implements MouseListener, } } + @Override public void mousePressed(MouseEvent e) { pdbAction = true; @@ -759,7 +763,7 @@ public class PDBCanvas extends JPanel 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) @@ -791,6 +795,7 @@ public class PDBCanvas extends JPanel implements MouseListener, dragging = false; } + @Override public void mouseMoved(MouseEvent e) { pdbAction = true; @@ -807,7 +812,7 @@ public class PDBCanvas extends JPanel 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); @@ -816,8 +821,8 @@ public class PDBCanvas extends JPanel implements MouseListener, if (fatom != null) { - this.setToolTipText(chain.id + ":" + fatom.resNumber + " " - + fatom.resName); + this.setToolTipText( + chain.id + ":" + fatom.resNumber + " " + fatom.resName); } else { @@ -826,18 +831,22 @@ public class PDBCanvas extends JPanel 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(); @@ -848,7 +857,7 @@ public class PDBCanvas extends JPanel 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))); } @@ -859,7 +868,7 @@ public class PDBCanvas extends JPanel implements MouseListener, } // Alter the bonds - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { for (Bond tmpBond : chain.bonds) { @@ -887,6 +896,7 @@ public class PDBCanvas extends JPanel implements MouseListener, repaint(); } + @Override public void mouseReleased(MouseEvent evt) { dragging = false; @@ -896,7 +906,7 @@ public class PDBCanvas extends JPanel implements MouseListener, void drawLabels(Graphics g) { - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -922,16 +932,20 @@ public class PDBCanvas extends JPanel implements MouseListener, g.setColor(Color.red); if (n == 1) { - int xstart = (int) (((b.start[0] - centre[0]) * scale) + (getWidth() / 2)); - int ystart = (int) (((centre[1] - b.start[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) (((centre[1] - b.end[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); } @@ -945,9 +959,9 @@ public class PDBCanvas extends JPanel 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; @@ -957,11 +971,13 @@ public class PDBCanvas extends JPanel implements MouseListener, { 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) (((centre[1] - tmpBond.start[1]) * scale) + (getHeight() / 2)); + int truey = (int) (((centre[1] - tmpBond.start[1]) * scale) + + (getHeight() / 2)); if (Math.abs(truey - y) <= 2) { @@ -974,11 +990,13 @@ public class PDBCanvas extends JPanel implements MouseListener, // 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) { @@ -992,7 +1010,7 @@ public class PDBCanvas extends JPanel implements MouseListener, if (fatom != null) // )&& chain.ds != null) { // dead code? value of chain is either overwritten or discarded - chain = pdb.chains.elementAt(foundchain); + chain = pdb.getChains().elementAt(foundchain); } } @@ -1055,9 +1073,9 @@ public class PDBCanvas extends JPanel 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; @@ -1067,10 +1085,10 @@ public class PDBCanvas extends JPanel implements MouseListener, // //////////////////////////////// // /StructureListener - public String[] getPdbFile() + @Override + public String[] getStructureFiles() { - return new String[] - { pdbentry.getFile() }; + return new String[] { pdbentry.getFile() }; } String lastMessage; @@ -1172,6 +1190,7 @@ public class PDBCanvas extends JPanel implements MouseListener, // return new Color(viewer.getAtomArgb(atomIndex)); } + @Override public void updateColours(Object source) { colourBySequence();