From: gmungoc Date: Thu, 26 Apr 2018 11:38:58 +0000 (+0100) Subject: JAL-2962 code tidying/documentation (non-functional) changes X-Git-Tag: Release_2_11_1_0~78^2~9^2~19 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=04e134be96df26b6df83d030ad531cd3815eb9d4;p=jalview.git JAL-2962 code tidying/documentation (non-functional) changes --- diff --git a/src/jalview/analysis/PCA.java b/src/jalview/analysis/PCA.java index d11d322..6f02b71 100755 --- a/src/jalview/analysis/PCA.java +++ b/src/jalview/analysis/PCA.java @@ -214,7 +214,7 @@ public class PCA implements Runnable } /** - * Returns a PrintStream that wraps (sends its output to) the given + * Returns a PrintStream that wraps (appends its output to) the given * StringBuilder * * @param sb diff --git a/src/jalview/appletgui/RotatableCanvas.java b/src/jalview/appletgui/RotatableCanvas.java index afb4e95..c5ae339 100755 --- a/src/jalview/appletgui/RotatableCanvas.java +++ b/src/jalview/appletgui/RotatableCanvas.java @@ -87,7 +87,7 @@ public class RotatableCanvas extends Panel implements MouseListener, int npoint; - Vector points; + Vector points; float[][] orig; @@ -126,6 +126,7 @@ public class RotatableCanvas extends Panel implements MouseListener, repaint(); } + @Override public void setPoints(Vector points, int npoint) { this.points = points; @@ -230,7 +231,7 @@ public class RotatableCanvas extends Panel implements MouseListener, { for (int j = 0; j < npoint; j++) { - SequencePoint sp = (SequencePoint) points.elementAt(j); + SequencePoint sp = points.elementAt(j); if (sp.coord[i] >= max[i]) { max[i] = sp.coord[i]; @@ -287,7 +288,7 @@ public class RotatableCanvas extends Panel implements MouseListener, dim = height; } - return (float) (dim * scalefactor / (2 * maxwidth)); + return dim * scalefactor / (2 * maxwidth); } public void findCentre() @@ -304,6 +305,7 @@ public class RotatableCanvas extends Panel implements MouseListener, // System.out.println("Centre z " + centre[2]); } + @Override public Dimension getPreferredSize() { if (prefsize != null) @@ -316,16 +318,19 @@ public class RotatableCanvas extends Panel implements MouseListener, } } + @Override public Dimension getMinimumSize() { return getPreferredSize(); } + @Override public void update(Graphics g) { paint(g); } + @Override public void paint(Graphics g) { if (points == null) @@ -397,25 +402,26 @@ public class RotatableCanvas extends Panel implements MouseListener, for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); - int x = (int) ((float) (sp.coord[0] - centre[0]) * scale) + halfwidth; - int y = (int) ((float) (sp.coord[1] - centre[1]) * scale) + SequencePoint sp = points.elementAt(i); + int x = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth; + int y = (int) ((sp.coord[1] - centre[1]) * scale) + halfheight; float z = sp.coord[1] - centre[2]; - if (av.getSequenceColour(sp.sequence) == Color.black) + SequenceI sequence = sp.getSequence(); + if (av.getSequenceColour(sequence) == Color.black) { g.setColor(Color.white); } else { - g.setColor(av.getSequenceColour(sp.sequence)); + g.setColor(av.getSequenceColour(sequence)); } if (av.getSelectionGroup() != null) { if (av.getSelectionGroup().getSequences(null) - .contains(((SequencePoint) points.elementAt(i)).sequence)) + .contains(sequence)) { g.setColor(Color.gray); } @@ -429,9 +435,7 @@ public class RotatableCanvas extends Panel implements MouseListener, if (showLabels) { g.setColor(Color.red); - g.drawString( - ((SequencePoint) points.elementAt(i)).sequence.getName(), - x - 3, y - 4); + g.drawString(sequence.getName(), x - 3, y - 4); } } } @@ -446,14 +450,17 @@ public class RotatableCanvas extends Panel implements MouseListener, return prefsize; } + @Override public void keyTyped(KeyEvent evt) { } + @Override public void keyReleased(KeyEvent evt) { } + @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_UP) @@ -482,7 +489,7 @@ public class RotatableCanvas extends Panel implements MouseListener, { for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); + SequencePoint sp = points.elementAt(i); Format.print(System.out, "%5d ", i); for (int j = 0; j < 3; j++) { @@ -492,22 +499,27 @@ public class RotatableCanvas extends Panel implements MouseListener, } } + @Override public void mouseClicked(MouseEvent evt) { } + @Override public void mouseEntered(MouseEvent evt) { } + @Override public void mouseExited(MouseEvent evt) { } + @Override public void mouseReleased(MouseEvent evt) { } + @Override public void mousePressed(MouseEvent evt) { int x = evt.getX(); @@ -552,6 +564,7 @@ public class RotatableCanvas extends Panel implements MouseListener, repaint(); } + @Override public void mouseMoved(MouseEvent evt) { SequenceI found = findPoint(evt.getX(), evt.getY()); @@ -568,6 +581,7 @@ public class RotatableCanvas extends Panel implements MouseListener, repaint(); } + @Override public void mouseDragged(MouseEvent evt) { mx = evt.getX(); @@ -575,12 +589,12 @@ public class RotatableCanvas extends Panel implements MouseListener, rotmat.setIdentity(); - rotmat.rotate((float) (my - omy), 'x'); - rotmat.rotate((float) (mx - omx), 'y'); + rotmat.rotate(my - omy, 'x'); + rotmat.rotate(mx - omx, 'y'); for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); + SequencePoint sp = points.elementAt(i); sp.coord[0] -= centre[0]; sp.coord[1] -= centre[1]; sp.coord[2] -= centre[2]; @@ -609,20 +623,21 @@ public class RotatableCanvas extends Panel implements MouseListener, // boolean changedSel = false; for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); + SequencePoint sp = points.elementAt(i); int tmp1 = (int) ((sp.coord[0] - centre[0]) * scale - + (float) getSize().width / 2.0); + + getSize().width / 2.0); int tmp2 = (int) ((sp.coord[1] - centre[1]) * scale - + (float) getSize().height / 2.0); + + getSize().height / 2.0); + SequenceI sequence = sp.getSequence(); if (tmp1 > x1 && tmp1 < x2 && tmp2 > y1 && tmp2 < y2) { if (av != null) { if (!av.getSelectionGroup().getSequences(null) - .contains(sp.sequence)) + .contains(sequence)) { - av.getSelectionGroup().addSequence(sp.sequence, true); + av.getSelectionGroup().addSequence(sequence, true); } } } @@ -640,10 +655,10 @@ public class RotatableCanvas extends Panel implements MouseListener, for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); - int px = (int) ((float) (sp.coord[0] - centre[0]) * scale) + SequencePoint sp = points.elementAt(i); + int px = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth; - int py = (int) ((float) (sp.coord[1] - centre[1]) * scale) + int py = (int) ((sp.coord[1] - centre[1]) * scale) + halfheight; if (Math.abs(px - x) < 3 && Math.abs(py - y) < 3) @@ -653,7 +668,7 @@ public class RotatableCanvas extends Panel implements MouseListener, } if (found != -1) { - return ((SequencePoint) points.elementAt(found)).sequence; + return points.elementAt(found).getSequence(); } else { diff --git a/src/jalview/datamodel/SequencePoint.java b/src/jalview/datamodel/SequencePoint.java index a6b967e..28db278 100755 --- a/src/jalview/datamodel/SequencePoint.java +++ b/src/jalview/datamodel/SequencePoint.java @@ -21,33 +21,35 @@ package jalview.datamodel; /** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ + * A bean that models a point with (x, y, z) coordinates and a reference to a + * sequence */ public class SequencePoint { - // SMJS PUBLIC - /** - * for points with no real physical association with an alignment sequence + /* + * Associated alignment sequence, or dummy sequence object */ - public boolean isPlaceholder = false; + private final SequenceI sequence; - /** - * Associated alignment sequence, or dummy sequence object. + /* + * array of coordinates in embedded sequence space */ - public SequenceI sequence; + public float[] coord; /** - * array of coordinates in embedded sequence space. + * Constructor + * + * @param sequence + * @param coord */ - public float[] coord; - - // SMJS ENDPUBLIC public SequencePoint(SequenceI sequence, float[] coord) { this.sequence = sequence; this.coord = coord; } + + public SequenceI getSequence() + { + return sequence; + } } diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index 02368df..dc33b36 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/RotatableCanvas.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.api.RotatableCanvasI; +import jalview.bin.Cache; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.datamodel.SequencePoint; @@ -94,7 +95,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, int npoint; - Vector points; + Vector points; float[][] orig; @@ -128,6 +129,8 @@ public class RotatableCanvas extends JPanel implements MouseListener, boolean applyToAllViews = false; + boolean first = true; + public RotatableCanvas(AlignmentPanel ap) { this.av = ap.av; @@ -166,10 +169,8 @@ public class RotatableCanvas extends JPanel implements MouseListener, repaint(); } - boolean first = true; - @Override - public void setPoints(Vector points, int npoint) + public void setPoints(Vector points, int npoint) { this.points = points; this.npoint = npoint; @@ -184,7 +185,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); + SequencePoint sp = points.elementAt(i); for (int j = 0; j < 3; j++) { @@ -267,7 +268,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, { for (int j = 0; j < npoint; j++) { - SequencePoint sp = (SequencePoint) points.elementAt(j); + SequencePoint sp = points.elementAt(j); if (sp.coord[i] >= max[i]) { @@ -311,23 +312,23 @@ public class RotatableCanvas extends JPanel implements MouseListener, public float findScale() { int dim; - int width; + int w; int height; if (getWidth() != 0) { - width = getWidth(); + w = getWidth(); height = getHeight(); } else { - width = prefsize.width; + w = prefsize.width; height = prefsize.height; } - if (width < height) + if (w < height) { - dim = width; + dim = w; } else { @@ -423,7 +424,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, drawBackground(ig, bgColour); drawScene(ig); - if (drawAxes == true) + if (drawAxes) { drawAxes(ig); } @@ -484,25 +485,26 @@ public class RotatableCanvas extends JPanel implements MouseListener, for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); + SequencePoint sp = points.elementAt(i); int x = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth; int y = (int) ((sp.coord[1] - centre[1]) * scale) + halfheight; float z = sp.coord[1] - centre[2]; - if (av.getSequenceColour(sp.sequence) == Color.black) + SequenceI sequence = sp.getSequence(); + if (av.getSequenceColour(sequence) == Color.black) { g.setColor(Color.white); } else { - g.setColor(av.getSequenceColour(sp.sequence)); + g.setColor(av.getSequenceColour(sequence)); } if (av.getSelectionGroup() != null) { if (av.getSelectionGroup().getSequences(null) - .contains(((SequencePoint) points.elementAt(i)).sequence)) + .contains(sequence)) { g.setColor(Color.gray); } @@ -517,9 +519,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, if (showLabels) { g.setColor(Color.red); - g.drawString( - ((SequencePoint) points.elementAt(i)).sequence.getName(), - x - 3, y - 4); + g.drawString(sequence.getName(), x - 3, y - 4); } } @@ -594,8 +594,9 @@ public class RotatableCanvas extends JPanel implements MouseListener, } else if (evt.getKeyChar() == 's') { - System.err.println("DEBUG: Rectangle selection"); // log.debug - + Cache.log.warn("DEBUG: Rectangle selection"); + // todo not yet enabled as rectx2, recty2 are always -1 + // need to set them in mouseDragged if ((rectx2 != -1) && (recty2 != -1)) { rectSelect(rectx1, recty1, rectx2, recty2); @@ -605,55 +606,31 @@ public class RotatableCanvas extends JPanel implements MouseListener, repaint(); } - /** - * DOCUMENT ME! - * - * @param evt - * DOCUMENT ME! - */ @Override public void mouseClicked(MouseEvent evt) { } - /** - * DOCUMENT ME! - * - * @param evt - * DOCUMENT ME! - */ @Override public void mouseEntered(MouseEvent evt) { } - /** - * DOCUMENT ME! - * - * @param evt - * DOCUMENT ME! - */ @Override public void mouseExited(MouseEvent evt) { } - /** - * DOCUMENT ME! - * - * @param evt - * DOCUMENT ME! - */ @Override public void mouseReleased(MouseEvent evt) { } /** - * DOCUMENT ME! - * - * @param evt - * DOCUMENT ME! + * If the mouse press is at (within 2 pixels of) a sequence point, toggles + * (adds or removes) the corresponding sequence as a member of the viewport + * selection group. This supports configuring a group in the alignment by + * clicking on points in the PCA display. */ @Override public void mousePressed(MouseEvent evt) @@ -676,7 +653,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, rectx2 = -1; recty2 = -1; - SequenceI found = findPoint(x, y); + SequenceI found = findSequenceAtPoint(x, y); if (found != null) { @@ -704,23 +681,16 @@ public class RotatableCanvas extends JPanel implements MouseListener, repaint(); } - // private void fireSequenceSelectionEvent(Selection sel) { - // controller.handleSequenceSelectionEvent(new - // SequenceSelectionEvent(this,sel)); - // } + /** + * Sets the tooltip to the name of the sequence within 2 pixels of the mouse + * position, or clears the tooltip if none found + */ @Override public void mouseMoved(MouseEvent evt) { - SequenceI found = findPoint(evt.getX(), evt.getY()); + SequenceI found = findSequenceAtPoint(evt.getX(), evt.getY()); - if (found != null) - { - this.setToolTipText(found.getName()); - } - else - { - this.setToolTipText(null); - } + this.setToolTipText(found == null ? null : found.getName()); } /** @@ -750,7 +720,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); + SequencePoint sp = points.elementAt(i); sp.coord[0] -= centre[0]; sp.coord[1] -= centre[1]; sp.coord[2] -= centre[2]; @@ -777,22 +747,20 @@ public class RotatableCanvas extends JPanel implements MouseListener, } /** - * DOCUMENT ME! + * Adds any sequences whose displayed points are within the given rectangle to + * the viewport's current selection. Intended for key 's' after dragging to + * select a region of the PCA. * * @param x1 - * DOCUMENT ME! * @param y1 - * DOCUMENT ME! * @param x2 - * DOCUMENT ME! * @param y2 - * DOCUMENT ME! */ public void rectSelect(int x1, int y1, int x2, int y2) { for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); + SequencePoint sp = points.elementAt(i); int tmp1 = (int) (((sp.coord[0] - centre[0]) * scale) + (getWidth() / 2.0)); int tmp2 = (int) (((sp.coord[1] - centre[1]) * scale) @@ -802,31 +770,27 @@ public class RotatableCanvas extends JPanel implements MouseListener, { if (av != null) { + SequenceI sequence = sp.getSequence(); if (!av.getSelectionGroup().getSequences(null) - .contains(sp.sequence)) + .contains(sequence)) { - av.getSelectionGroup().addSequence(sp.sequence, true); + av.getSelectionGroup().addSequence(sequence, true); } } } } - - // if (changedSel) { - // fireSequenceSelectionEvent(av.getSelection()); - // } } /** - * DOCUMENT ME! + * Answers the first sequence found whose point on the display is within 2 + * pixels of the given coordinates, or null if none is found * * @param x - * DOCUMENT ME! * @param y - * DOCUMENT ME! * - * @return DOCUMENT ME! + * @return */ - public SequenceI findPoint(int x, int y) + public SequenceI findSequenceAtPoint(int x, int y) { int halfwidth = getWidth() / 2; int halfheight = getHeight() / 2; @@ -835,7 +799,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, for (int i = 0; i < npoint; i++) { - SequencePoint sp = (SequencePoint) points.elementAt(i); + SequencePoint sp = points.elementAt(i); int px = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth; int py = (int) ((sp.coord[1] - centre[1]) * scale) @@ -849,7 +813,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, if (found != -1) { - return ((SequencePoint) points.elementAt(found)).sequence; + return points.elementAt(found).getSequence(); } else { @@ -876,8 +840,8 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ public double[] getPointPosition(int s) { - double pts[] = new double[3]; - float[] p = ((SequencePoint) points.elementAt(s)).coord; + double[] pts = new double[3]; + float[] p = points.elementAt(s).coord; pts[0] = p[0]; pts[1] = p[1]; pts[2] = p[2]; diff --git a/src/jalview/viewmodel/PCAModel.java b/src/jalview/viewmodel/PCAModel.java index 0dcdbca..db0f4dd 100644 --- a/src/jalview/viewmodel/PCAModel.java +++ b/src/jalview/viewmodel/PCAModel.java @@ -51,7 +51,7 @@ public class PCAModel /* * outputs */ - private volatile PCA pca; + private PCA pca; int top; @@ -77,10 +77,14 @@ public class PCAModel similarityParams = params; } + /** + * Performs the PCA calculation (in the same thread) and extracts result data + * needed for visualisation by PCAPanel + */ public void run() { pca = new PCA(seqstrings, scoreModel, similarityParams); - pca.run(); + pca.run(); // executes in same thread, wait for completion // Now find the component coordinates int ii = 0;