Merge branch 'feature/JAL-3127_seqidChainshading' into merge/JAL-3127
[jalview.git] / src / jalview / gui / RotatableCanvas.java
index da48dd6..dc0cdb4 100755 (executable)
@@ -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);
   }
 
   /**
@@ -287,7 +287,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
         ig = img.getGraphics();
       }
 
-      drawBackground(ig, bgColour);
+      drawBackground(ig);
       drawScene(ig);
 
       if (drawAxes)
@@ -325,25 +325,24 @@ 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]));
     }
   }
 
   /**
-   * Fills the background with the specified colour
+   * Fills the background with the currently configured background colour
    * 
    * @param g
-   * @param col
    */
-  public void drawBackground(Graphics g, Color col)
+  public void drawBackground(Graphics g)
   {
-    g.setColor(col);
+    g.setColor(getBgColour());
     g.fillRect(0, 0, prefSize.width, prefSize.height);
   }
 
@@ -366,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();
 
@@ -386,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<String> 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]);
@@ -475,14 +474,37 @@ public class RotatableCanvas extends JPanel implements MouseListener,
   public void keyPressed(KeyEvent evt)
   {
     int keyCode = evt.getKeyCode();
+    boolean shiftDown = evt.isShiftDown();
 
     if (keyCode == KeyEvent.VK_UP)
     {
-      zoom(ZOOM_IN);
+      if (shiftDown)
+      {
+        rotate(0f, -1f);
+      }
+      else
+      {
+        zoom(ZOOM_IN);
+      }
     }
     else if (keyCode == KeyEvent.VK_DOWN)
     {
-      zoom(ZOOM_OUT);
+      if (shiftDown)
+      {
+        rotate(0f, 1f);
+      }
+      else
+      {
+        zoom(ZOOM_OUT);
+      }
+    }
+    else if (shiftDown && keyCode == KeyEvent.VK_LEFT)
+    {
+      rotate(1f, 0f);
+    }
+    else if (shiftDown && keyCode == KeyEvent.VK_RIGHT)
+    {
+      rotate(-1f, 0f);
     }
     else if (evt.getKeyChar() == 's')
     {
@@ -503,7 +525,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
   {
     if (factor > 0f)
     {
-      scaleFactor *= factor;
+      setScaleFactor(getScaleFactor() * factor);
     }
   }
 
@@ -690,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]);
     }
   }
 
@@ -726,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))
@@ -765,7 +787,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();
 
@@ -802,7 +824,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    */
   AlignmentPanel[] getAssociatedPanels()
   {
-    if (applyToAllViews)
+    if (isApplyToAllViews())
     {
       return PaintRefresher.getAssociatedPanels(av.getSequenceSetId());
     }
@@ -814,7 +836,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
 
   public Color getBackgroundColour()
   {
-    return bgColour;
+    return getBgColour();
   }
 
   /**
@@ -872,4 +894,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;
+  }
 }