X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FRotatableCanvas.java;h=d695ebbbc8895b9843d7a4569ee72f676be405a7;hb=d1e20f6a5654ea6baf378afa3277b4e751c69a96;hp=b00055b208fb80239ca4740570c64187d00e26ce;hpb=f20566c564e18f418c4ccc29fcf77d0471e49334;p=jalview.git diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index b00055b..d695ebb 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/RotatableCanvas.java @@ -57,9 +57,9 @@ import javax.swing.ToolTipManager; * Models a Panel on which a set of points, and optionally x/y/z axes, can be * drawn, and rotated or zoomed with the mouse */ -public class RotatableCanvas extends JPanel implements MouseListener, - MouseMotionListener, KeyListener, RotatableCanvasI, - MouseWheelListener +public class RotatableCanvas extends JPanel + implements MouseListener, MouseMotionListener, KeyListener, + RotatableCanvasI, MouseWheelListener { private static final float ZOOM_OUT = 0.9f; @@ -104,7 +104,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * half the available width or height (whichever is less); increase this * factor to zoom in, decrease it to zoom out */ - float scaleFactor; + private float scaleFactor; int npoint; @@ -116,7 +116,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, /* * x, y, z axis end points (PCA dimension values) */ - Point[] axisEndPoints; + private Point[] axisEndPoints; // fields for 'select rectangle' (JAL-1124) // int rectx1; @@ -128,11 +128,11 @@ public class RotatableCanvas extends JPanel implements MouseListener, AlignmentPanel ap; - boolean showLabels; + private boolean showLabels; - Color bgColour; + private Color bgColour; - boolean applyToAllViews; + private boolean applyToAllViews; /** * Constructor @@ -143,10 +143,10 @@ public class RotatableCanvas extends JPanel implements MouseListener, { this.av = panel.av; this.ap = panel; - axisEndPoints = new Point[DIMS]; - showLabels = false; - applyToAllViews = false; - bgColour = Color.BLACK; + setAxisEndPoints(new Point[DIMS]); + setShowLabels(false); + setApplyToAllViews(false); + setBgColour(Color.BLACK); resetAxes(); ToolTipManager.sharedInstance().registerComponent(this); @@ -163,7 +163,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ public void showLabels(boolean show) { - showLabels = show; + setShowLabels(show); repaint(); } @@ -176,7 +176,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, findWidths(); - scaleFactor = 1f; + setScaleFactor(1f); } /** @@ -185,9 +185,9 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ protected void resetAxes() { - axisEndPoints[0] = new Point(1f, 0f, 0f); - axisEndPoints[1] = new Point(0f, 1f, 0f); - axisEndPoints[2] = new Point(0f, 0f, 1f); + getAxisEndPoints()[0] = new Point(1f, 0f, 0f); + getAxisEndPoints()[1] = new Point(0f, 1f, 0f); + getAxisEndPoints()[2] = new Point(0f, 0f, 1f); } /** @@ -198,15 +198,15 @@ public class RotatableCanvas extends JPanel implements MouseListener, { float[] max = new float[DIMS]; float[] min = new float[DIMS]; - + max[0] = -Float.MAX_VALUE; max[1] = -Float.MAX_VALUE; max[2] = -Float.MAX_VALUE; - + min[0] = Float.MAX_VALUE; min[1] = Float.MAX_VALUE; min[2] = Float.MAX_VALUE; - + for (SequencePoint sp : sequencePoints) { max[0] = Math.max(max[0], sp.coord.x); @@ -216,7 +216,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, min[1] = Math.min(min[1], sp.coord.y); min[2] = Math.min(min[2], sp.coord.z); } - + seqMin = min; seqMax = max; } @@ -325,13 +325,13 @@ public class RotatableCanvas extends JPanel implements MouseListener, float maxWidth = Math.max(Math.abs(seqMax[0] - seqMin[0]), Math.abs(seqMax[1] - seqMin[1])); int pix = Math.min(getWidth(), getHeight()); - float scaleBy = pix * scaleFactor / (2f * maxWidth); + float scaleBy = pix * getScaleFactor() / (2f * maxWidth); for (int i = 0; i < DIMS; i++) { g.drawLine(midX, midY, - midX + (int) (axisEndPoints[i].x * scaleBy * seqMax[0]), - midY + (int) (axisEndPoints[i].y * scaleBy * seqMax[1])); + midX + (int) (getAxisEndPoints()[i].x * scaleBy * seqMax[0]), + midY + (int) (getAxisEndPoints()[i].y * scaleBy * seqMax[1])); } } @@ -342,7 +342,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ public void drawBackground(Graphics g) { - g.setColor(bgColour); + g.setColor(getBgColour()); g.fillRect(0, 0, prefSize.width, prefSize.height); } @@ -365,7 +365,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, float xWidth = Math.abs(seqMax[0] - seqMin[0]); float yWidth = Math.abs(seqMax[1] - seqMin[1]); float maxWidth = Math.max(xWidth, yWidth); - float scaleBy = pix * scaleFactor / (2f * maxWidth); + float scaleBy = pix * getScaleFactor() / (2f * maxWidth); float[] centre = getCentre(); @@ -385,19 +385,19 @@ public class RotatableCanvas extends JPanel implements MouseListener, int y = (int) ((sp.coord.y - centre[1]) * scaleBy) + halfheight; g.fillRect(x - 3, y - 3, 6, 6); - if (showLabels) + if (isShowLabels()) { g.setColor(Color.red); g.drawString(sp.getSequence().getName(), x - 3, y - 4); } } - if (showLabels) + if (isShowLabels()) { g.setColor(AXIS_COLOUR); int midX = getWidth() / 2; int midY = getHeight() / 2; Iterator axes = AXES.iterator(); - for (Point p : axisEndPoints) + for (Point p : getAxisEndPoints()) { int x = midX + (int) (p.x * scaleBy * seqMax[0]); int y = midY + (int) (p.y * scaleBy * seqMax[1]); @@ -508,7 +508,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, } else if (evt.getKeyChar() == 's') { - // Cache.log.warn("DEBUG: Rectangle selection"); + // Cache.warn("DEBUG: Rectangle selection"); // todo not yet enabled as rectx2, recty2 are always -1 // need to set them in mouseDragged; JAL-1124 // if ((rectx2 != -1) && (recty2 != -1)) @@ -525,7 +525,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, { if (factor > 0f) { - scaleFactor *= factor; + setScaleFactor(getScaleFactor() * factor); } } @@ -630,7 +630,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, int yDelta = yPos - mouseY; // Check if this is a rectangle drawing drag - if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0) + if ((evt.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) { // rectx2 = evt.getX(); // recty2 = evt.getY(); @@ -699,7 +699,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, // Now translate back again sp.translate(centre[0], centre[1], centre[2]); - + zMin = Math.min(zMin, sp.coord.z); zMax = Math.max(zMax, sp.coord.z); } @@ -712,7 +712,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ for (int i = 0; i < DIMS; i++) { - axisEndPoints[i] = rotmat.vectorMultiply(axisEndPoints[i]); + getAxisEndPoints()[i] = rotmat.vectorMultiply(getAxisEndPoints()[i]); } } @@ -748,9 +748,9 @@ public class RotatableCanvas extends JPanel implements MouseListener, for (int i = 0; i < npoint; i++) { SequencePoint sp = sequencePoints.get(i); - int tmp1 = (int) (((sp.coord.x - centre[0]) * scaleFactor) + int tmp1 = (int) (((sp.coord.x - centre[0]) * getScaleFactor()) + (getWidth() / 2.0)); - int tmp2 = (int) (((sp.coord.y - centre[1]) * scaleFactor) + int tmp2 = (int) (((sp.coord.y - centre[1]) * getScaleFactor()) + (getHeight() / 2.0)); if ((tmp1 > x1) && (tmp1 < x2) && (tmp2 > y1) && (tmp2 < y2)) @@ -758,8 +758,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, if (av != null) { SequenceI sequence = sp.getSequence(); - if (!av.getSelectionGroup().getSequences(null) - .contains(sequence)) + if (!av.getSelectionGroup().getSequences(null).contains(sequence)) { av.getSelectionGroup().addSequence(sequence, true); } @@ -787,17 +786,15 @@ public class RotatableCanvas extends JPanel implements MouseListener, float xWidth = Math.abs(seqMax[0] - seqMin[0]); float yWidth = Math.abs(seqMax[1] - seqMin[1]); float maxWidth = Math.max(xWidth, yWidth); - float scaleBy = pix * scaleFactor / (2f * maxWidth); + float scaleBy = pix * getScaleFactor() / (2f * maxWidth); float[] centre = getCentre(); for (int i = 0; i < npoint; i++) { SequencePoint sp = sequencePoints.get(i); - int px = (int) ((sp.coord.x - centre[0]) * scaleBy) - + halfwidth; - int py = (int) ((sp.coord.y - centre[1]) * scaleBy) - + halfheight; + int px = (int) ((sp.coord.x - centre[0]) * scaleBy) + halfwidth; + int py = (int) ((sp.coord.y - centre[1]) * scaleBy) + halfheight; if ((Math.abs(px - x) < NEARBY) && (Math.abs(py - y) < NEARBY)) { @@ -824,7 +821,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ AlignmentPanel[] getAssociatedPanels() { - if (applyToAllViews) + if (isApplyToAllViews()) { return PaintRefresher.getAssociatedPanels(av.getSequenceSetId()); } @@ -836,7 +833,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, public Color getBackgroundColour() { - return bgColour; + return getBgColour(); } /** @@ -894,4 +891,54 @@ public class RotatableCanvas extends JPanel implements MouseListener, seqMin = min; seqMax = max; } + + public float getScaleFactor() + { + return scaleFactor; + } + + public void setScaleFactor(float scaleFactor) + { + this.scaleFactor = scaleFactor; + } + + public boolean isShowLabels() + { + return showLabels; + } + + public void setShowLabels(boolean showLabels) + { + this.showLabels = showLabels; + } + + public boolean isApplyToAllViews() + { + return applyToAllViews; + } + + public void setApplyToAllViews(boolean applyToAllViews) + { + this.applyToAllViews = applyToAllViews; + } + + public Point[] getAxisEndPoints() + { + return axisEndPoints; + } + + public void setAxisEndPoints(Point[] axisEndPoints) + { + this.axisEndPoints = axisEndPoints; + } + + public Color getBgColour() + { + return bgColour; + } + + public void setBgColour(Color bgColour) + { + this.bgColour = bgColour; + } }