Clover coverage report - Graph - 1.0.0
Coverage timestamp: ven. déc. 26 2003 02:14:20 CET
file stats: LOC: 160   Methods: 2
NCLOC: 103   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
VerticalAxis.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * EJTools, the Enterprise Java Tools
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at www.gnu.org.
 6   
  */
 7   
 package org.ejtools.graph.renderer;
 8   
 
 9   
 import java.awt.Color;
 10   
 import java.awt.Dimension;
 11   
 import java.awt.FontMetrics;
 12   
 import java.awt.Graphics;
 13   
 import java.awt.Insets;
 14   
 import java.awt.geom.Rectangle2D;
 15   
 import java.text.Format;
 16   
 
 17   
 import org.ejtools.graph.Axis;
 18   
 
 19   
 /**
 20   
  * @author    Laurent Etiemble
 21   
  * @version   $Revision: 1.7 $
 22   
  * @todo      Javadoc to complete
 23   
  */
 24   
 public class VerticalAxis extends Axis
 25   
 {
 26   
    /**
 27   
     * Constructor for VerticalAxis.
 28   
     *
 29   
     * @param format    Description of the Parameter
 30   
     * @param position  Description of the Parameter
 31   
     */
 32  0
    public VerticalAxis(Format format, int position)
 33   
    {
 34  0
       this.format = format;
 35  0
       this.orientation = VERTICAL;
 36  0
       this.position = position;
 37   
    }
 38   
 
 39   
 
 40   
    /**
 41   
     * Description of the Method
 42   
     *
 43   
     * @param graphics  Description of the Parameter
 44   
     */
 45  0
    public void paintComponent(Graphics graphics)
 46   
    {
 47  0
       String display;
 48  0
       double multiplier = 0.0d;
 49  0
       int base;
 50  0
       int small;
 51  0
       int middle;
 52  0
       int correction;
 53   
 
 54  0
       graphics.setFont(FONT);
 55  0
       FontMetrics metrics = graphics.getFontMetrics();
 56   
 
 57  0
       Insets insets = this.getInsets();
 58   
       // int x = this.getX() + insets.left;
 59   
       // int y = this.getY() + insets.top;
 60   
       // double width = (double) this.getWidth() - 1 - insets.left - insets.right;
 61  0
       double height = (double) this.getHeight() - 1 - insets.top - insets.bottom;
 62   
 
 63  0
       double min = element.getYRange().getMin();
 64  0
       double max = element.getYRange().getMax();
 65   
 
 66  0
       String minText = this.getFormated(min);
 67  0
       Rectangle2D minBounds = metrics.getStringBounds(minText, graphics);
 68  0
       String maxText = this.getFormated(max);
 69  0
       Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics);
 70   
 
 71   
       // New dimension
 72  0
       double newBound = Math.max(minBounds.getWidth(), maxBounds.getWidth());
 73  0
       this.dimension = new Dimension((int) (newBound + FONT.getSize()), this.getHeight());
 74  0
       this.revalidate();
 75   
 
 76   
       // Vertical drawing
 77  0
       double bound = Math.max(minBounds.getHeight() * 4.0d, maxBounds.getHeight() * 4.0d);
 78   
 
 79   
       // Specified the number of texts
 80  0
       int ticks = 1;
 81  0
       while ((height / ticks) > bound)
 82   
       {
 83  0
          ticks = ticks * 2;
 84   
       }
 85   
 
 86   
       // Set parameters
 87  0
       if (this.position == LEFT)
 88   
       {
 89  0
          middle = (int) (newBound);
 90  0
          small = middle + FONT.getSize() / 2 - 1;
 91  0
          base = middle + FONT.getSize() - 1;
 92   
       }
 93   
       else
 94   
       {
 95  0
          middle = FONT.getSize() - 2;
 96  0
          small = FONT.getSize() / 2 - 1;
 97  0
          base = 0;
 98   
       }
 99   
 
 100   
       // Draw the baseline
 101  0
       graphics.drawLine(base, 0, base, (int) height);
 102   
 
 103   
       // Draw the divisions
 104  0
       multiplier = height / ticks / 2;
 105  0
       graphics.setColor(Color.black);
 106  0
       for (int i = 0; i <= (2 * ticks); i++)
 107   
       {
 108  0
          graphics.drawLine(base, (int) (i * multiplier), small, (int) (i * multiplier));
 109   
       }
 110   
 
 111   
       // draw ticks
 112  0
       multiplier = height / ticks;
 113   
 
 114   
       // Draw first tick
 115  0
       graphics.drawLine(base, (int) height, middle, (int) height);
 116  0
       if (this.position == LEFT)
 117   
       {
 118  0
          correction = -(int) minBounds.getWidth();
 119   
       }
 120   
       else
 121   
       {
 122  0
          correction = 2;
 123   
       }
 124  0
       graphics.drawString(minText, middle + correction, (int) (height - metrics.getDescent()));
 125   
 
 126   
       // Draw others ticks
 127  0
       for (int i = 1; i < ticks; i++)
 128   
       {
 129  0
          int j = (int) (height - i * multiplier);
 130  0
          graphics.drawLine(base, j, middle, j);
 131   
 
 132  0
          display = this.getFormated(min + i * (max - min) / ticks);
 133  0
          Rectangle2D middleBounds = metrics.getStringBounds(display, graphics);
 134   
 
 135  0
          j = j + (int) (middleBounds.getHeight() / 2);
 136  0
          if (this.position == LEFT)
 137   
          {
 138  0
             correction = -(int) middleBounds.getWidth();
 139   
          }
 140   
          else
 141   
          {
 142  0
             correction = 2;
 143   
          }
 144  0
          graphics.drawString(display, middle + correction, j);
 145   
       }
 146   
 
 147   
       // Draw last tick
 148  0
       graphics.drawLine(base, 0, middle, 0);
 149  0
       if (this.position == LEFT)
 150   
       {
 151  0
          correction = -(int) maxBounds.getWidth();
 152   
       }
 153   
       else
 154   
       {
 155  0
          correction = 2;
 156   
       }
 157  0
       graphics.drawString(maxText, middle + correction, metrics.getAscent());
 158   
    }
 159   
 }
 160