KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > util > ShiftedCategoryAxis


1 package hudson.util;
2
3 import org.jfree.chart.axis.CategoryAxis;
4 import org.jfree.ui.RectangleEdge;
5
6 import java.awt.geom.Rectangle2D JavaDoc;
7
8 /**
9  * {@link CategoryAxis} shifted to left to eliminate redundant space
10  * between area and the Y-axis.
11  */

12 public final class ShiftedCategoryAxis extends CategoryAxis {
13     public ShiftedCategoryAxis(String JavaDoc label) {
14         super(label);
15     }
16
17     protected double calculateCategorySize(int categoryCount, Rectangle2D JavaDoc area, RectangleEdge edge) {
18         // we cut the left-half of the first item and the right-half of the last item,
19
// so we have more space
20
return super.calculateCategorySize(categoryCount-1, area, edge);
21     }
22
23     public double getCategoryEnd(int category, int categoryCount, Rectangle2D JavaDoc area, RectangleEdge edge) {
24         return super.getCategoryStart(category, categoryCount, area, edge)
25            + calculateCategorySize(categoryCount, area, edge) / 2;
26     }
27
28     public double getCategoryMiddle(int category, int categoryCount, Rectangle2D JavaDoc area, RectangleEdge edge) {
29         return super.getCategoryStart(category, categoryCount, area, edge);
30     }
31
32     public double getCategoryStart(int category, int categoryCount, Rectangle2D JavaDoc area, RectangleEdge edge) {
33         return super.getCategoryStart(category, categoryCount, area, edge)
34             - calculateCategorySize(categoryCount, area, edge) / 2;
35     }
36 }
37
Popular Tags