From d0bab9de317fb505abfe88032ed39a3a1f7e3d1b Mon Sep 17 00:00:00 2001
From: tcarver <tjc>
Date: Tue, 6 Nov 2012 12:25:48 +0000
Subject: [PATCH] tidy code

---
 .../artemis/components/FeaturePlot.java       |  40 +++----
 uk/ac/sanger/artemis/components/Plot.java     | 108 ++++++------------
 2 files changed, 49 insertions(+), 99 deletions(-)

diff --git a/uk/ac/sanger/artemis/components/FeaturePlot.java b/uk/ac/sanger/artemis/components/FeaturePlot.java
index 646f45c36..6d3425b09 100644
--- a/uk/ac/sanger/artemis/components/FeaturePlot.java
+++ b/uk/ac/sanger/artemis/components/FeaturePlot.java
@@ -25,24 +25,30 @@
 
 package uk.ac.sanger.artemis.components;
 
-import uk.ac.sanger.artemis.sequence.*;
-import uk.ac.sanger.artemis.util.OutOfRangeException;
-import uk.ac.sanger.artemis.util.ReadOnlyException;
-import uk.ac.sanger.artemis.*;
-import uk.ac.sanger.artemis.io.EntryInformationException;
-import uk.ac.sanger.artemis.plot.*;
-import java.awt.*;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+
+import uk.ac.sanger.artemis.Feature;
+import uk.ac.sanger.artemis.FeatureChangeEvent;
+import uk.ac.sanger.artemis.FeatureChangeListener;
+import uk.ac.sanger.artemis.Options;
+import uk.ac.sanger.artemis.plot.FeatureAlgorithm;
+import uk.ac.sanger.artemis.plot.LineAttributes;
+import uk.ac.sanger.artemis.sequence.AminoAcidSequence;
+
 
 /**
  *  The components of this class display a plot of a FeatureAlgorithm for a
  *  particular feature.
- *
  *  @author Kim Rutherford
- *  @version $Id: FeaturePlot.java,v 1.11 2009-07-20 15:11:17 tjc Exp $
  **/
 
 public class FeaturePlot extends Plot
     implements DisplayAdjustmentListener, FeatureChangeListener {
+
+  private static final long serialVersionUID = 1L;
+
   /**
    *  Create a new FeatureDisplay object.
    *  @param algorithm The object that will generate the values we plot in
@@ -102,10 +108,9 @@ public class FeaturePlot extends Plot
   public void displayAdjustmentValueChanged (DisplayAdjustmentEvent event) {
     start_base = event.getStart ();
     end_base = event.getEnd ();
-    width_in_bases = event.getWidthInBases ();
+    //width_in_bases = event.getWidthInBases ();
 
     recalculate_flag = true;
-
     repaint();
   }
 
@@ -138,13 +143,6 @@ public class FeaturePlot extends Plot
     return end_base;
   }
 
-  /**
-   *  Return the width in bases of the display, from the last event.
-   **/
-  private int getWidthInBases () {
-    return width_in_bases;
-  }
-
   /**
    *  This array is used by drawGraph ().  It is reallocated when the scale
    *  changes.
@@ -386,12 +384,6 @@ public class FeaturePlot extends Plot
    **/
   private int end_base;
 
-  /**
-   *  The width in bases of the display, as obtained from the
-   *  DisplayAdjustmentEvent.
-   **/
-  private int width_in_bases;
-
   protected void calculateFeatures(boolean fromPeak)
   {
     // TODO Auto-generated method stub
diff --git a/uk/ac/sanger/artemis/components/Plot.java b/uk/ac/sanger/artemis/components/Plot.java
index 9fcc723af..b1f863a5d 100644
--- a/uk/ac/sanger/artemis/components/Plot.java
+++ b/uk/ac/sanger/artemis/components/Plot.java
@@ -29,8 +29,16 @@ import uk.ac.sanger.artemis.Options;
 import uk.ac.sanger.artemis.circular.TextFieldFloat;
 import uk.ac.sanger.artemis.plot.*;
 
-import java.awt.*;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.Image;
+import java.awt.Scrollbar;
 import java.awt.event.*;
+import java.util.Vector;
 
 import javax.swing.JMenu;
 import javax.swing.JPanel;
@@ -46,13 +54,12 @@ import javax.swing.JPopupMenu;
 
 /**
  *  This class implements a simple plot component.
- *
  *  @author Kim Rutherford
- *  @version $Id: Plot.java,v 1.26 2009-08-18 09:01:44 tjc Exp $
  **/
 
 public abstract class Plot extends JPanel 
 {
+  private static final long serialVersionUID = 1L;
 
   /** scroll bar for changing the window size. */
   private JScrollBar window_changer = null;
@@ -73,6 +80,8 @@ public abstract class Plot extends JPanel
    *  drawScaleLine() is called.
    **/
   private boolean draw_scale;
+  
+  private final int SCROLL_NOB_SIZE = 10;
 
   /**
    *  Set to true if drawMultiValueGraph() should call recalculateValues().
@@ -95,7 +104,7 @@ public abstract class Plot extends JPanel
   /**
    *  A vector of those objects listening for PlotMouse events.
    **/
-  final private java.util.Vector listener_list = new java.util.Vector();
+  final private Vector<PlotMouseListener> listener_list = new Vector<PlotMouseListener>();
 
   /**
    *  Recalculate the values all the state that is used for drawing the plot
@@ -116,10 +125,12 @@ public abstract class Plot extends JPanel
   /** number of graph lines to be drawn */
   private int numPlots;
 
-  /** colour array for graph drawing */
   protected LineAttributes lines[];
   
   private int lastPaintHeight = getHeight();
+  
+  /** the minimum distance in pixels between the labels */
+  private final static int MINIMUM_LABEL_SPACING = 50;
  
   /**
    *  Create a new plot component.
@@ -130,34 +141,27 @@ public abstract class Plot extends JPanel
    **/
   public Plot(Algorithm algorithm, boolean draw_scale) 
   {
-    super();
+    super(new BorderLayout());
     this.algorithm = algorithm;
     this.draw_scale = draw_scale;
 
-    final Font font = Options.getOptions().getFont();
-
-    setFont(font);
-    FontMetrics fm = getFontMetrics(font);
+    setFont(Options.getOptions().getFont());
+    FontMetrics fm = getFontMetrics(getFont());
     font_height = fm.getHeight();
 
-    setLayout(new BorderLayout());
-
     final int MAX_WINDOW;
-
     if(getAlgorithm().getDefaultMaxWindowSize() != null) 
       MAX_WINDOW = getAlgorithm().getDefaultMaxWindowSize().intValue();
     else 
       MAX_WINDOW = 500;
 
     final int MIN_WINDOW;
-
     if(getAlgorithm().getDefaultMinWindowSize() != null) 
       MIN_WINDOW = getAlgorithm().getDefaultMinWindowSize().intValue();
     else 
       MIN_WINDOW = 5;
 
     final int START_WINDOW;
-
     if(getAlgorithm().getDefaultWindowSize() == null) 
       START_WINDOW = 10;
     else 
@@ -189,17 +193,11 @@ public abstract class Plot extends JPanel
       }
     });
 
-
-//  setBackground(Color.white);
     add(window_changer, "East");
-
     addMouseListener(mouse_listener);
     addMouseMotionListener(mouse_motion_listener);
-
   }
 
-  final int SCROLL_NOB_SIZE = 10;
-
   /**
    *  Return the algorithm that was passed to the constructor.
    **/
@@ -220,8 +218,7 @@ public abstract class Plot extends JPanel
   final MouseListener mouse_listener = new MouseAdapter()
   {
     /**
-     *  Listen for mouse press events so that we can do a popup menu and a
-     *  crosshair.
+     *  Listen for mouse press popup menu and crosshair events.
      **/
     public void mousePressed(MouseEvent event) 
     {
@@ -351,13 +348,11 @@ public abstract class Plot extends JPanel
             }
           });
         }
-        
-        
+
         popup.addSeparator();
 
         final JMenu max_window_size =
               new JMenu("Maximum Window Size");
-
         popup.add(max_window_size);
 
         final int[] window_sizes = 
@@ -366,9 +361,7 @@ public abstract class Plot extends JPanel
           200000, 500000, 1000000
         };
 
-
         JMenuItem window_size_item;
-
         for(int i = 0 ; i < window_sizes.length ; ++i) 
         {
           final int size = i;
@@ -440,7 +433,6 @@ public abstract class Plot extends JPanel
         }
 
         final JSplitPane splitPane = getJSplitPane();
-
         if(splitPane == null)
         {
           popup.addSeparator();
@@ -611,7 +603,7 @@ public abstract class Plot extends JPanel
     PlotMouseListener listener;
     for(int i = 0; i < listener_list.size(); ++i)
     {
-      listener = (PlotMouseListener)listener_list.elementAt(i);
+      listener = listener_list.elementAt(i);
       listener.mouseClick(getPointPosition(cross_hair_position));
     }
   }
@@ -625,7 +617,7 @@ public abstract class Plot extends JPanel
     PlotMouseListener listener;
     for(int i = 0; i < listener_list.size(); ++i) 
     {
-      listener = (PlotMouseListener)listener_list.elementAt(i);
+      listener = listener_list.elementAt(i);
       listener.mouseDrag(getPointPosition(drag_start_position),
                          getPointPosition(cross_hair_position));
     }
@@ -640,7 +632,7 @@ public abstract class Plot extends JPanel
     PlotMouseListener listener;
     for(int i = 0; i < listener_list.size(); ++i) 
     {
-      listener = (PlotMouseListener)listener_list.elementAt(i);
+      listener = listener_list.elementAt(i);
       listener.mouseDoubleClick(getPointPosition(cross_hair_position));
     }
   }
@@ -737,31 +729,19 @@ public abstract class Plot extends JPanel
     drag_start_position = -1;
   }
 
-  // the minimum distance in pixels between the labels
-  private final static int MINIMUM_LABEL_SPACING = 50;
-
   /**
-   *  Draw the scale line at the bottom of the graph.
+   *  Draw the scale line at the bottom of the graph (used by FeaturePlot).
    *  @param start The base on the left
    *  @param end The base on the right
    **/
   protected void drawScaleLine(final Graphics g,
                                final int start, final int end) 
   {
-    final int width  = getWidth() - window_changer.getWidth();
-    final int height = getHeight();
-
-    final int scale_number_y_pos =  height - 1;
-
+    final int hgt = getHeight();
+    final int scale_number_y_pos =  hgt - 1;
     final float bases_per_pixel = 1.0F;
 
-    // set the spacing so that the labels are at multiples of 10
-    final int base_label_spacing = MINIMUM_LABEL_SPACING;
-
-    final int label_spacing = (int)(base_label_spacing / bases_per_pixel);
-
-    final int possible_index_of_first_label = start / base_label_spacing;
-
+    final int possible_index_of_first_label = start / MINIMUM_LABEL_SPACING;
     final int index_of_first_label;
 
     if(possible_index_of_first_label == 0) 
@@ -769,22 +749,18 @@ public abstract class Plot extends JPanel
     else 
       index_of_first_label = possible_index_of_first_label;
 
-    final int index_of_last_label = end / base_label_spacing;
-
-    String label_string;
+    final int index_of_last_label = end / MINIMUM_LABEL_SPACING;
     for(int i = index_of_first_label; i <= index_of_last_label; i++)
     {
-      label_string = String.valueOf((int)(i * base_label_spacing));
-
       final int scale_number_x_pos =
-        (int)((i * base_label_spacing - start) / bases_per_pixel);
+        (int)((i * MINIMUM_LABEL_SPACING - start) / bases_per_pixel);
 
-      g.drawString(label_string,
+      g.drawString(String.valueOf((int)(i * MINIMUM_LABEL_SPACING)),
                    scale_number_x_pos + 2,
                    scale_number_y_pos);
 
-      g.drawLine(scale_number_x_pos, height - getScaleHeight() / 2,
-                 scale_number_x_pos, height - getScaleHeight());
+      g.drawLine(scale_number_x_pos, hgt - getScaleHeight() / 2,
+                 scale_number_x_pos, hgt - getScaleHeight());
     }
   }
 
@@ -1129,22 +1105,6 @@ public abstract class Plot extends JPanel
   {
     return font_height;
   }
-
-  /**
-   *  Used to get the X coordinate for the tooltip text.
-   *  @param total_unit_count The maximum number of residues/bases we can
-   *    show.  This is used to draw the scale line and to calculate the
-   *    distance (in pixels) between plot points.
-   *  @param start_position The distance from the edge of the canvas (measured
-   *    in residues/bases) to start drawing the plot.
-   *  @param xpos The mouse position on the canvas.
-   **/
-  protected int getXCoordinate(final int total_unit_count,
-                               final int start_position,
-                               final int xpos) 
-  {
-    return (xpos * total_unit_count)/getSize().width + start_position;
-  }
   
   /**
    *  Used to get the Y coordinate for the tooltip text.
@@ -1162,7 +1122,6 @@ public abstract class Plot extends JPanel
       final float plot_values[], int base_pos)
   {
     int ypos = (int)((base_pos - start_position - (window_size/2))/step_size);
-    
     if(ypos < 0)
       ypos = 0;
     else if(ypos > plot_values.length-1)
@@ -1170,5 +1129,4 @@ public abstract class Plot extends JPanel
     
     return plot_values[ypos];
   }
-  
 }
-- 
GitLab