1 43 44 package org.jfree.chart.axis; 45 46 import java.awt.Color ; 47 import java.awt.Font ; 48 import java.awt.Graphics2D ; 49 import java.awt.Paint ; 50 import java.util.HashMap ; 51 import java.util.Map ; 52 53 import org.jfree.text.TextBlock; 54 import org.jfree.text.TextFragment; 55 import org.jfree.text.TextLine; 56 import org.jfree.ui.RectangleEdge; 57 58 62 public class ExtendedCategoryAxis extends CategoryAxis { 63 64 65 private Map sublabels; 66 67 68 private Font sublabelFont; 69 70 71 private Paint sublabelPaint; 72 73 78 public ExtendedCategoryAxis(String label) { 79 super(label); 80 this.sublabels = new HashMap (); 81 this.sublabelFont = new Font ("SansSerif", Font.PLAIN, 10); 82 this.sublabelPaint = Color.black; 83 } 84 85 90 public Font getSubLabelFont() { 91 return this.sublabelFont; 92 } 93 94 99 public void setSubLabelFont(Font font) { 100 this.sublabelFont = font; 101 } 102 103 108 public Paint getSubLabelPaint() { 109 return this.sublabelPaint; 110 } 111 112 117 public void setSubLabelPaint(Paint paint) { 118 this.sublabelPaint = paint; 119 } 120 121 127 public void addSubLabel(Comparable category, String label) { 128 this.sublabels.put(category, label); 129 } 130 131 142 protected TextBlock createLabel(Comparable category, float width, 143 RectangleEdge edge, Graphics2D g2) { 144 TextBlock label = super.createLabel(category, width, edge, g2); 145 String s = (String ) this.sublabels.get(category); 146 if (s != null) { 147 if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) { 148 TextLine line = new TextLine( 149 s, this.sublabelFont, this.sublabelPaint 150 ); 151 label.addLine(line); 152 } 153 else if (edge == RectangleEdge.LEFT 154 || edge == RectangleEdge.RIGHT) { 155 TextLine line = label.getLastLine(); 156 if (line != null) { 157 line.addFragment( 158 new TextFragment( 159 " " + s, this.sublabelFont, this.sublabelPaint 160 ) 161 ); 162 } 163 } 164 } 165 return label; 166 } 167 168 } 169 | Popular Tags |