Clover coverage report - Graph - 1.0.0
Coverage timestamp: ven. déc. 26 2003 02:14:20 CET
file stats: LOC: 138   Methods: 2
NCLOC: 84   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
GridGraphRenderer.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.FontMetrics;
 11   
 import java.awt.Graphics;
 12   
 import java.awt.Insets;
 13   
 import java.awt.geom.Rectangle2D;
 14   
 import java.text.Format;
 15   
 
 16   
 import org.ejtools.graph.Axis;
 17   
 import org.ejtools.graph.GraphRenderer;
 18   
 
 19   
 /**
 20   
  * @author    Laurent Etiemble
 21   
  * @version   $Revision: 1.7 $
 22   
  * @todo      Javadoc to complete
 23   
  */
 24   
 public class GridGraphRenderer extends Axis
 25   
 {
 26   
    /** Description of the Field */
 27   
    protected Format horizontalFormat = null;
 28   
    /** Description of the Field */
 29   
    protected Format verticalFormat = null;
 30   
 
 31   
 
 32   
    /**
 33   
     *Constructor for the GridRenderer object
 34   
     *
 35   
     * @param horizontalFormat  Description of the Parameter
 36   
     * @param verticalFormat    Description of the Parameter
 37   
     */
 38  0
    public GridGraphRenderer(Format horizontalFormat, Format verticalFormat)
 39   
    {
 40  0
       this.format = horizontalFormat;
 41  0
       this.horizontalFormat = horizontalFormat;
 42  0
       this.verticalFormat = verticalFormat;
 43   
    }
 44   
 
 45   
 
 46   
    /**
 47   
     * @param graphics  Description of the Parameter
 48   
     */
 49  0
    protected void paintComponent(Graphics graphics)
 50   
    {
 51  0
       double multiplier = 0.0d;
 52   
 
 53  0
       graphics.setFont(FONT);
 54  0
       FontMetrics metrics = graphics.getFontMetrics();
 55  0
       graphics.setColor(Color.lightGray);
 56   
 
 57  0
       double minX = element.getXRange().getMin();
 58  0
       double maxX = element.getXRange().getMax();
 59  0
       double minY = element.getYRange().getMin();
 60  0
       double maxY = element.getYRange().getMax();
 61   
 
 62  0
       Insets insets = this.getInsets();
 63  0
       int x = insets.left;
 64  0
       int y = insets.top;
 65  0
       double width = (double) this.getWidth() - 1 - insets.left - insets.right;
 66  0
       double height = (double) this.getHeight() - 1 - insets.top - insets.bottom;
 67   
 
 68  0
       double scaleX = width / (maxX - minX);
 69  0
       double scaleY = -height / (maxY - minY);
 70  0
       double offsetX = x - scaleX * minX;
 71  0
       double offsetY = y - scaleY * maxY;
 72   
 
 73  0
       if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT)
 74   
       {
 75  0
          scaleX = 1.0d;
 76  0
          offsetX = -minX;
 77   
       }
 78  0
       if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT)
 79   
       {
 80  0
          scaleX = 1.0d * this.horizontalScale;
 81  0
          offsetX = width - maxX * this.horizontalScale;
 82   
       }
 83   
 
 84   
       // Render horizontal lines
 85  0
       minX = (x - offsetX) / scaleX;
 86  0
       this.format = this.horizontalFormat;
 87   
 
 88  0
       String minText = this.getFormated(minX);
 89  0
       Rectangle2D minBounds = metrics.getStringBounds(minText, graphics);
 90  0
       String maxText = this.getFormated(maxX);
 91  0
       Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics);
 92   
 
 93   
       // Horizontal drawing
 94  0
       double bound = Math.max(minBounds.getWidth() * 4.0d, maxBounds.getWidth() * 4.0d);
 95   
 
 96   
       // Specified the number of lines
 97  0
       int ticks = 1;
 98  0
       while ((width / ticks) > bound)
 99   
       {
 100  0
          ticks = ticks * 2;
 101   
       }
 102   
 
 103   
       // Draw the divisions
 104  0
       multiplier = width / ticks / 2;
 105  0
       for (int i = 0; i <= (2 * ticks); i++)
 106   
       {
 107  0
          graphics.drawLine((int) (i * multiplier), 0, (int) (i * multiplier), (int) height);
 108   
       }
 109   
 
 110   
       // Render horizontal lines
 111  0
       this.format = this.verticalFormat;
 112   
 
 113  0
       minText = this.getFormated(minY);
 114  0
       minBounds = metrics.getStringBounds(minText, graphics);
 115  0
       maxText = this.getFormated(maxY);
 116  0
       maxBounds = metrics.getStringBounds(maxText, graphics);
 117   
 
 118   
       // Vertical drawing
 119  0
       bound = Math.max(minBounds.getHeight() * 4.0d, maxBounds.getHeight() * 4.0d);
 120   
 
 121   
       // Specified the number of texts
 122  0
       ticks = 1;
 123  0
       while ((height / ticks) > bound)
 124   
       {
 125  0
          ticks = ticks * 2;
 126   
       }
 127   
 
 128   
       // Draw the divisions
 129  0
       multiplier = height / ticks / 2;
 130  0
       for (int i = 0; i <= (2 * ticks); i++)
 131   
       {
 132  0
          graphics.drawLine(0, (int) (i * multiplier), (int) width, (int) (i * multiplier));
 133   
       }
 134   
 
 135  0
       this.element.draw(graphics, scaleX, offsetX, scaleY, offsetY);
 136   
    }
 137   
 }
 138