X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FRotatableCanvas.java;h=c5ae3399f374bb51b8df0f9131f0c5091b14f84e;hb=82de3ff949ae61b771136fbdb49baacc20e652fd;hp=1c38c56f7088c6081b453527668ef6ca59e173ae;hpb=2f4f1d8fb6878271b64f327bc58c895f458137af;p=jalview.git diff --git a/src/jalview/appletgui/RotatableCanvas.java b/src/jalview/appletgui/RotatableCanvas.java index 1c38c56..c5ae339 100755 --- a/src/jalview/appletgui/RotatableCanvas.java +++ b/src/jalview/appletgui/RotatableCanvas.java @@ -1,32 +1,46 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ 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. + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. * * 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 Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.appletgui; -import java.util.*; - -import java.awt.*; -import java.awt.event.*; - import jalview.api.RotatableCanvasI; -import jalview.datamodel.*; -import jalview.math.*; -import jalview.util.*; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.datamodel.SequencePoint; +import jalview.math.RotatableMatrix; +import jalview.util.Format; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Panel; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.util.Vector; public class RotatableCanvas extends Panel implements MouseListener, MouseMotionListener, KeyListener, RotatableCanvasI @@ -73,7 +87,7 @@ public class RotatableCanvas extends Panel implements MouseListener, int npoint; - Vector points; + Vector points; float[][] orig; @@ -97,11 +111,11 @@ public class RotatableCanvas extends Panel implements MouseListener, float scalefactor = 1; - AlignViewport av; + AlignmentViewport av; boolean showLabels = false; - public RotatableCanvas(AlignViewport av) + public RotatableCanvas(AlignmentViewport av) { this.av = av; } @@ -112,6 +126,7 @@ public class RotatableCanvas extends Panel implements MouseListener, repaint(); } + @Override public void setPoints(Vector points, int npoint) { this.points = points; @@ -216,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]; @@ -273,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() @@ -290,6 +305,7 @@ public class RotatableCanvas extends Panel implements MouseListener, // System.out.println("Centre z " + centre[2]); } + @Override public Dimension getPreferredSize() { if (prefsize != null) @@ -302,22 +318,27 @@ 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) { g.setFont(new Font("Verdana", Font.PLAIN, 18)); - g.drawString(MessageManager.getString("label.calculating_pca") + "....", 20, getSize().height / 2); + g.drawString( + MessageManager.getString("label.calculating_pca") + "....", + 20, getSize().height / 2); } else { @@ -381,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); } @@ -413,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); } } } @@ -430,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) @@ -466,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++) { @@ -476,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(); @@ -536,6 +564,7 @@ public class RotatableCanvas extends Panel implements MouseListener, repaint(); } + @Override public void mouseMoved(MouseEvent evt) { SequenceI found = findPoint(evt.getX(), evt.getY()); @@ -552,6 +581,7 @@ public class RotatableCanvas extends Panel implements MouseListener, repaint(); } + @Override public void mouseDragged(MouseEvent evt) { mx = evt.getX(); @@ -559,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]; @@ -593,18 +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); - int tmp1 = (int) ((sp.coord[0] - centre[0]) * scale + (float) getSize().width / 2.0); - int tmp2 = (int) ((sp.coord[1] - centre[1]) * scale + (float) getSize().height / 2.0); + SequencePoint sp = points.elementAt(i); + int tmp1 = (int) ((sp.coord[0] - centre[0]) * scale + + getSize().width / 2.0); + int tmp2 = (int) ((sp.coord[1] - centre[1]) * scale + + 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); } } } @@ -622,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) @@ -635,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 {