1 7 package org.ejtools.graph; 8 9 import java.awt.Dimension ; 10 import java.awt.Font ; 11 import java.text.DateFormat ; 12 import java.text.DecimalFormat ; 13 import java.text.Format ; 14 import java.text.NumberFormat ; 15 import java.util.Date ; 16 17 import org.ejtools.graph.renderer.AbstractGraphRenderer; 18 19 24 public abstract class Axis extends AbstractGraphRenderer 25 { 26 27 protected Dimension dimension = null; 28 29 protected Format format = new DecimalFormat ("0"); 30 31 protected int orientation; 32 33 protected int position; 34 35 protected Range range = new Range(0.0d, 1.0d); 36 37 protected static Font FONT = new Font ("Courrier", Font.PLAIN, 10); 38 39 public final static int BOTTOM = 4; 40 41 public final static int HORIZONTAL = 0; 42 43 public final static int LEFT = 2; 44 45 public final static int RIGHT = 3; 46 47 public final static int TOP = 5; 48 49 public final static int VERTICAL = 1; 50 51 52 53 public Axis() { } 54 55 56 61 public Format getFormat() 62 { 63 return format; 64 } 65 66 67 73 public String getFormated(double value) 74 { 75 if (this.format instanceof NumberFormat ) 76 { 77 return ((NumberFormat ) this.format).format(value); 78 } 79 if (this.format instanceof DateFormat ) 80 { 81 return ((DateFormat ) this.format).format(new Date ((long) value)); 82 } 83 return null; 84 } 85 86 87 90 public Dimension getMinimumSize() 91 { 92 if (this.dimension == null) 93 { 94 this.dimension = new Dimension (FONT.getSize() * 2, FONT.getSize() * 2); 95 } 96 return dimension; 97 } 98 99 100 105 public int getOrientation() 106 { 107 return orientation; 108 } 109 110 111 116 public int getPosition() 117 { 118 return position; 119 } 120 121 122 125 public Dimension getPreferredSize() 126 { 127 return this.getMinimumSize(); 128 } 129 130 131 136 public Range getRange() 137 { 138 return range; 139 } 140 141 142 147 public void setFormat(Format format) 148 { 149 this.format = format; 150 } 151 152 153 158 public void setPosition(int position) 159 { 160 this.position = position; 161 } 162 163 164 169 public void setRange(Range range) 170 { 171 this.range = range; 172 } 173 } 174 | Popular Tags |